Skip to content

Commit

Permalink
Fix test classes
Browse files Browse the repository at this point in the history
Issue #297
  • Loading branch information
towsey committed Apr 21, 2020
1 parent aaa3fa7 commit 99d3394
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void TestConfigSerialization()
CollectionAssert.Contains(lines, " TestAed: !AedParameters");
CollectionAssert.Contains(lines, " TestOscillation: !OscillationParameters");
CollectionAssert.Contains(lines, " TestBlob: !BlobParameters");
CollectionAssert.Contains(lines, " TestWhistle: !WhistleParameters");
CollectionAssert.Contains(lines, " TestWhistle: !OnebinTrackParameters");

//lines.ForEach(x => Trace.WriteLine(x));

Expand Down Expand Up @@ -188,9 +188,9 @@ public void TestWhistleAlgorithm()

// NOTE: The whistle algorithm assigns the top and bottom freq bounds of an event based on where it finds the whistle.
// Not on what the user has set.
// In this test the margin of error has been set arbitrarily to 10.
Assert.AreEqual(340, @event.LowFrequencyHertz, 20.0);
Assert.AreEqual(560, @event.HighFrequencyHertz, 50.0);
// In this test the margin of error has been set arbitrarily to width of one frequency bin.
Assert.AreEqual(430, @event.LowFrequencyHertz, 44.0);
Assert.AreEqual(516, @event.HighFrequencyHertz, 44.0);
Assert.AreEqual("TestWhistle", @event.Profile);
Assert.AreEqual("NoName", @event.SpeciesName);
Assert.AreEqual("Whistle400Hz", @event.Name);
Expand Down Expand Up @@ -326,6 +326,7 @@ public void TestOnebinTrackAlgorithm()
//Set up the virtual recording.
int samplerate = 22050;
double signalDuration = 13.0; //seconds
var segmentStartOffset = TimeSpan.FromSeconds(60.0);

// set up the config for a virtual spectrogram.
var sonoConfig = new SonogramConfig()
Expand All @@ -345,7 +346,6 @@ public void TestOnebinTrackAlgorithm()
//var image1 = SpectrogramTools.GetSonogramPlusCharts(spectrogram, null, null, null);
//results.Sonogram.GetImage().Save(this.outputDirectory + "\\debug.png");

var segmentStartOffset = TimeSpan.Zero;
var plots = new List<Plot>();
double[] dBArray;
List<AcousticEvent> acousticEvents;
Expand All @@ -360,7 +360,7 @@ public void TestOnebinTrackAlgorithm()
segmentStartOffset);

// draw a plot of max decibels in each frame
double decibelNormalizationMax = 3 * decibelThreshold;
double decibelNormalizationMax = 5 * decibelThreshold;
var dBThreshold = decibelThreshold / decibelNormalizationMax;
var normalisedDecibelArray = DataTools.NormaliseInZeroOne(dBArray, 0, decibelNormalizationMax);
var plot1 = new Plot("decibel max", normalisedDecibelArray, dBThreshold);
Expand All @@ -384,19 +384,21 @@ public void TestOnebinTrackAlgorithm()
var outputDirectory = new DirectoryInfo("C:\\temp");
GenericRecognizer.SaveDebugSpectrogram(allResults, null, outputDirectory, "WhistleTrack");

Assert.AreEqual(16, allResults.Events.Count);
//NOTE: There are 16 whistles in the test spectrogram ...
// but three of them are too weak to be detected at this threshold.
Assert.AreEqual(13, allResults.Events.Count);

var @event = allResults.Events[4];
Assert.AreEqual(2.0, @event.EventStartSeconds, 0.1);
Assert.AreEqual(2.5, @event.EventEndSeconds, 0.1);
Assert.AreEqual(1723, @event.LowFrequencyHertz);
Assert.AreEqual(2067, @event.HighFrequencyHertz);
Assert.AreEqual(60 + 5.0, @event.EventStartSeconds, 0.1);
Assert.AreEqual(60 + 6.0, @event.EventEndSeconds, 0.1);
Assert.AreEqual(989, @event.LowFrequencyHertz);
Assert.AreEqual(1032, @event.HighFrequencyHertz);

@event = allResults.Events[11];
Assert.AreEqual(6.0, @event.EventStartSeconds, 0.1);
Assert.AreEqual(6.5, @event.EventEndSeconds, 0.1);
Assert.AreEqual(2153, @event.LowFrequencyHertz);
Assert.AreEqual(2541, @event.HighFrequencyHertz);
Assert.AreEqual(60 + 11.0, @event.EventStartSeconds, 0.1);
Assert.AreEqual(60 + 12.0, @event.EventEndSeconds, 0.1);
Assert.AreEqual(989, @event.LowFrequencyHertz);
Assert.AreEqual(1032, @event.HighFrequencyHertz);
}

[TestMethod]
Expand All @@ -410,7 +412,7 @@ public void TestForwardTrackAlgorithm()
var minDuration = 0.2;
var maxDuration = 1.1;
var decibelThreshold = 2.0;
var combinePossibleHarmonics = true;
var combinePossibleHarmonics = false;

//Set up the virtual recording.
int samplerate = 22050;
Expand Down Expand Up @@ -438,7 +440,7 @@ public void TestForwardTrackAlgorithm()
var plots = new List<Plot>();
double[] dBArray;
List<AcousticEvent> acousticEvents;
(acousticEvents, dBArray) = FowardTrackParameters.GetFowardTracks(
(acousticEvents, dBArray) = ForwardTrackParameters.GetForwardTracks(
spectrogram,
minHertz,
maxHertz,
Expand All @@ -449,7 +451,7 @@ public void TestForwardTrackAlgorithm()
segmentStartOffset);

// draw a plot of max decibels in each frame
double decibelNormalizationMax = 3 * decibelThreshold;
double decibelNormalizationMax = 5 * decibelThreshold;
var dBThreshold = decibelThreshold / decibelNormalizationMax;
var normalisedDecibelArray = DataTools.NormaliseInZeroOne(dBArray, 0, decibelNormalizationMax);
var plot1 = new Plot("decibel max", normalisedDecibelArray, dBThreshold);
Expand Down Expand Up @@ -480,14 +482,14 @@ public void TestForwardTrackAlgorithm()
var @event = allResults.Events[4];
Assert.AreEqual(2.0, @event.EventStartSeconds, 0.1);
Assert.AreEqual(2.5, @event.EventEndSeconds, 0.1);
Assert.AreEqual(1723, @event.LowFrequencyHertz);
Assert.AreEqual(2067, @event.HighFrequencyHertz);
Assert.AreEqual(1720, @event.LowFrequencyHertz);
Assert.AreEqual(2107, @event.HighFrequencyHertz);

@event = allResults.Events[11];
Assert.AreEqual(6.0, @event.EventStartSeconds, 0.1);
Assert.AreEqual(6.5, @event.EventEndSeconds, 0.1);
Assert.AreEqual(2153, @event.LowFrequencyHertz);
Assert.AreEqual(2541, @event.HighFrequencyHertz);
Assert.AreEqual(2150, @event.LowFrequencyHertz);
Assert.AreEqual(2580, @event.HighFrequencyHertz);
}

[TestMethod]
Expand Down Expand Up @@ -540,7 +542,7 @@ public void TestOneframeTrackAlgorithm()
segmentStartOffset);

// draw a plot of max decibels in each frame
double decibelNormalizationMax = 3 * decibelThreshold;
double decibelNormalizationMax = 5 * decibelThreshold;
var dBThreshold = decibelThreshold / decibelNormalizationMax;
var normalisedDecibelArray = DataTools.NormaliseInZeroOne(dBArray, 0, decibelNormalizationMax);
var plot1 = new Plot("decibel max", normalisedDecibelArray, dBThreshold);
Expand Down Expand Up @@ -571,14 +573,14 @@ public void TestOneframeTrackAlgorithm()
var @event = allResults.Events[0];
Assert.AreEqual(10.0, @event.EventStartSeconds, 0.1);
Assert.AreEqual(10.1, @event.EventEndSeconds, 0.1);
Assert.AreEqual(6474, @event.LowFrequencyHertz);
Assert.AreEqual(10781, @event.HighFrequencyHertz);
Assert.AreEqual(6450, @event.LowFrequencyHertz);
Assert.AreEqual(10750, @event.HighFrequencyHertz);

@event = allResults.Events[1];
Assert.AreEqual(11.0, @event.EventStartSeconds, 0.1);
Assert.AreEqual(11.24, @event.EventEndSeconds, 0.1);
Assert.AreEqual(6474, @event.LowFrequencyHertz);
Assert.AreEqual(7335, @event.HighFrequencyHertz);
Assert.AreEqual(11.2, @event.EventEndSeconds, 0.1);
Assert.AreEqual(6450, @event.LowFrequencyHertz);
Assert.AreEqual(7310, @event.HighFrequencyHertz);
}

/// <summary>
Expand Down Expand Up @@ -634,7 +636,7 @@ public void Test1UpwardsTrackAlgorithm()
segmentStartOffset);

// draw a plot of max decibels in each frame
double decibelNormalizationMax = 3 * decibelThreshold;
double decibelNormalizationMax = 5 * decibelThreshold;
var dBThreshold = decibelThreshold / decibelNormalizationMax;
var normalisedDecibelArray = DataTools.NormaliseInZeroOne(dBArray, 0, decibelNormalizationMax);
var plot1 = new Plot("decibel max", normalisedDecibelArray, dBThreshold);
Expand Down Expand Up @@ -726,7 +728,7 @@ public void Test2UpwardsTrackAlgorithm()
segmentStartOffset);

// draw a plot of max decibels in each frame
double decibelNormalizationMax = 3 * decibelThreshold;
double decibelNormalizationMax = 5 * decibelThreshold;
var dBThreshold = decibelThreshold / decibelNormalizationMax;
var normalisedDecibelArray = DataTools.NormaliseInZeroOne(dBArray, 0, decibelNormalizationMax);
var plot2 = new Plot("decibel max", normalisedDecibelArray, dBThreshold);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public void TestTrackProperties()
Assert.AreEqual(5, track.PointCount);

// frame duration = 0.1 seconds. First frame = 5.
Assert.AreEqual(60 + 0.25, track.StartTimeSeconds);
Assert.AreEqual(60 + 0.25, track.StartTimeSeconds, 0.01);

//Last frame = 9
Assert.AreEqual(60 + 0.55, track.EndTimeSeconds);
Assert.AreEqual(60 + 0.55, track.EndTimeSeconds, 0.01);

//This test returns the bottom side of the 5th freq bin.
Assert.AreEqual(50, track.LowFreqHertz);
Expand All @@ -64,7 +64,7 @@ public void TestTrackProperties()

[TestMethod]
public void TestWhistleProperties()
{
{
//create new track with whistle
var track = new Track(NiceTestConverter, TrackType.OneBinTrack);
track.SetPoint(5, 5, 1);
Expand All @@ -74,10 +74,10 @@ public void TestWhistleProperties()
track.SetPoint(9, 5, 5);

// frame duration = 0.1 seconds. First frame = 5.
Assert.AreEqual(60 + 0.25, track.StartTimeSeconds);
Assert.AreEqual(60 + 0.25, track.StartTimeSeconds, 0.001);

//Last frame = 9
Assert.AreEqual(60 + 0.55, track.EndTimeSeconds);
Assert.AreEqual(60 + 0.55, track.EndTimeSeconds, 0.001);

//This test returns the bottom side of the 5th freq bin.
Assert.AreEqual(50, track.LowFreqHertz);
Expand All @@ -99,10 +99,10 @@ public void TestClickProperties()
track.SetPoint(5, 9, 5);

// frame duration = 0.1 seconds. First frame = 5.
Assert.AreEqual(60 + 0.25, track.StartTimeSeconds);
Assert.AreEqual(60 + 0.25, track.StartTimeSeconds, 0.001);

//Last frame = 9
Assert.AreEqual(60 + 0.35, track.EndTimeSeconds);
Assert.AreEqual(60 + 0.35, track.EndTimeSeconds, 0.001);

//This test returns the bottom side of the 5th freq bin.
Assert.AreEqual(50, track.LowFreqHertz);
Expand Down

0 comments on commit 99d3394

Please sign in to comment.