From a577f49d2e285886b87f5d0cfc252aefc1457db3 Mon Sep 17 00:00:00 2001 From: towsey Date: Fri, 14 Aug 2020 13:43:30 +1000 Subject: [PATCH] Fis oscillation tests Issue #291 --- .../Oscillations2014/OscillationTests.cs | 31 +++++++------------ ...0.FreqOscilSpectrogram.Matrix.EXPECTED.csv | 2 +- ...1008-085040.SpectralIndex.OSC.EXPECTED.csv | 2 +- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/tests/Acoustics.Test/AudioAnalysisTools/Oscillations2014/OscillationTests.cs b/tests/Acoustics.Test/AudioAnalysisTools/Oscillations2014/OscillationTests.cs index da8485b0d..456e97d0f 100644 --- a/tests/Acoustics.Test/AudioAnalysisTools/Oscillations2014/OscillationTests.cs +++ b/tests/Acoustics.Test/AudioAnalysisTools/Oscillations2014/OscillationTests.cs @@ -85,18 +85,13 @@ public void TwoOscillationTests() // construct name of expected matrix osc spectrogram to save file var expectedMatrixFile = PathHelper.ResolveAsset("Oscillations2014", stem + ".Matrix.EXPECTED.csv"); - // SAVE THE OUTPUT if true + // SAVE THE image of oscillation spectrogram if true. // WARNING: this will overwrite fixtures if (false) { - // 1: save image of oscillation spectrogram string imageName = stem + ".EXPECTED.png"; string imagePath = Path.Combine(PathHelper.ResolveAssetPath("Oscillations2014"), imageName); tuple.Item1.Save(imagePath); - - // 2: Save matrix of oscillation data stored in freqOscilMatrix1 - //Csv.WriteMatrixToCsv(expectedMatrixFile, tuple.Item2); - Binary.Serialize(expectedMatrixFile, tuple.Item2); } // Run two tests. Have to deserialise the expected data files @@ -105,6 +100,8 @@ public void TwoOscillationTests() Assert.AreEqual(675, tuple.Item1.Height); // 2. Compare matrix data + // Save matrix in expectedMatrixFile + // Binary.Serialize(expectedMatrixFile, tuple.Item2); var expectedMatrix = Binary.Deserialize(expectedMatrixFile); //TODO Following test fails when using CSV reader because the reader cuts out first line of the matrix @@ -132,35 +129,31 @@ public void SpectralIndexOsc_Test() var threshold = Oscillations2014.DefaultSensitivityThreshold; var spectralIndex = Oscillations2014.GetSpectralIndex_Osc(recordingSegment, frameLength, sampleLength, threshold); - // 3. construct name of spectral index vector - // SAVE THE OUTPUT if true + // 3. construct name of spectral index vector and save as image file + // No need to do tests on this image but it is useful to visualise output // WARNING: this will overwrite fixtures var sourceName = Path.GetFileNameWithoutExtension(sourceRecording.Name); - var stem = sourceName + ".SpectralIndex.OSC"; - var expectedIndexPath = PathHelper.ResolveAsset("Oscillations2014", stem + ".EXPECTED.csv"); if (false) { - // 4. Save spectral index vector to file - //Csv.WriteToCsv(expectedIndexPath, spectralIndex); - //Json.Serialise(expectedIndexPath, spectralIndex); - Binary.Serialize(expectedIndexPath, spectralIndex); - - // 5. Get the vector as image and save as image file - // no need to do tests on this image but it is useful to visualise output var expectedVectorImage = ImageTools.DrawVectorInColour(DataTools.reverseArray(spectralIndex), cellWidth: 10); - var expectedImagePath = PathHelper.ResolveAsset("Oscillations2014", stem + ".png"); + var expectedImagePath = PathHelper.ResolveAsset("Oscillations2014", sourceName + ".SpectralIndex.OSC.png"); expectedVectorImage.Save(expectedImagePath.FullName); } // 6. Get the vector as image and save as image file // no need to do tests on this image but it is useful to compare with expected visual output var currentVectorImage = ImageTools.DrawVectorInColour(DataTools.reverseArray(spectralIndex), cellWidth: 10); - var currentImagePath = Path.Combine(this.outputDirectory.FullName, stem + ".png"); + var currentImagePath = Path.Combine(this.outputDirectory.FullName, sourceName + ".SpectralIndex.OSC.png"); currentVectorImage.Save(currentImagePath); // 7. Run test. Compare vectors // TODO this test fails when using CSV reader because the reader cuts out first element/line of the vector //var expectedVector = (double[])Csv.ReadFromCsv(expectedIndexPath); + var expectedIndexPath = PathHelper.ResolveAsset("Oscillations2014", sourceName + ".SpectralIndex.OSC.EXPECTED.csv"); + + //comment the following line once fixture is saved. + // Binary.Serialize(expectedIndexPath, spectralIndex); + var expectedVector = Binary.Deserialize(expectedIndexPath); CollectionAssert.That.AreEqual(expectedVector, spectralIndex, 0.000001); } diff --git a/tests/Fixtures/Oscillations2014/BAC2_20071008-085040.FreqOscilSpectrogram.Matrix.EXPECTED.csv b/tests/Fixtures/Oscillations2014/BAC2_20071008-085040.FreqOscilSpectrogram.Matrix.EXPECTED.csv index 965d0e436..6f67d8981 100644 --- a/tests/Fixtures/Oscillations2014/BAC2_20071008-085040.FreqOscilSpectrogram.Matrix.EXPECTED.csv +++ b/tests/Fixtures/Oscillations2014/BAC2_20071008-085040.FreqOscilSpectrogram.Matrix.EXPECTED.csv @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f7a36074ac20d0b29ac679d54dfc2be63c3c42579fe3fa41bd26ccd546861286 +oid sha256:5f2be8472fe6134428adafc277f1631cca41317bb52bc2fbf5aa9bb0065df998 size 65574 diff --git a/tests/Fixtures/Oscillations2014/BAC2_20071008-085040.SpectralIndex.OSC.EXPECTED.csv b/tests/Fixtures/Oscillations2014/BAC2_20071008-085040.SpectralIndex.OSC.EXPECTED.csv index 160c7a576..c231cc31b 100644 --- a/tests/Fixtures/Oscillations2014/BAC2_20071008-085040.SpectralIndex.OSC.EXPECTED.csv +++ b/tests/Fixtures/Oscillations2014/BAC2_20071008-085040.SpectralIndex.OSC.EXPECTED.csv @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:85c6ddad05a8d85886bc6723106a2a08f7f505da38a153c1939922e276849284 +oid sha256:4a4c6e6db9d4ae60db44451f3aee123e583ebd848541a7f91dc8cbb932a36aa0 size 1052