Skip to content

Commit

Permalink
Fixed test of drawing events
Browse files Browse the repository at this point in the history
Issue #300 Fixed test of drawing events on spectrograms. Test now uses the new image comparison facility.
Set the event name to empty string in order to prevent test failing due to writing of poorly anti-aliased text.
Returned font type to the original.
Included new expected events image in Fixtures.
  • Loading branch information
towsey committed Mar 20, 2020
1 parent 1d4e524 commit 04f9b04
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
3 changes: 1 addition & 2 deletions src/AudioAnalysisTools/AcousticEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,7 @@ public void DrawEvent<T>(Image<T> imageToReturn, double framesPerSecond, double
imageToReturn.Mutate(g =>
{
g.NoAA().DrawLine(scorePen, t1, y2 - scoreHt, t1, y2 + 1);
//g.DrawTextSafe(this.Name, Drawing.Tahoma6, Color.Black, new PointF(t1, y1 - 5));
g.DrawTextSafe(this.Name, Drawing.Arial8, Color.Black, new PointF(t1, y1 - 5));
g.DrawTextSafe(this.Name, Drawing.Tahoma6, Color.Black, new PointF(t1, y1 - 4));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ namespace Acoustics.Test.AudioAnalysisTools.EventStatistics
{
using System;
using System.Collections.Generic;
using Acoustics.Test.TestHelpers;
using global::AudioAnalysisTools;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;

[TestClass]
public class EventTests
public class EventTests : GeneratedImageTest<Rgb24>
{
[TestMethod]
public void TestEventMerging()
Expand Down Expand Up @@ -103,26 +104,28 @@ public void TestSonogramWithEventsOverlay()
// set colour for the events
foreach (AcousticEvent ev in events)
{
// do not set an event name because text is not drawing anit-aliased at present time.
ev.Name = string.Empty;
ev.BorderColour = AcousticEvent.DefaultBorderColor;
ev.ScoreColour = AcousticEvent.DefaultScoreColor;
ev.DrawEvent(substituteSonogram, framesPerSecond, freqBinWidth, height);
}

substituteSonogram.Save("C:\\temp\\image.png");

var redPixel = new Argb32(220, 20, 60);
var expectedRed = new Color(redPixel);
var greenPixel = new Argb32(0, 255, 0);
var expectedGreen = new Color(greenPixel);

Assert.AreEqual<Color>(expectedRed, substituteSonogram[60, 119]);
Assert.AreEqual<Color>(expectedRed, substituteSonogram[70, 122]);
Assert.AreEqual<Color>(expectedRed, substituteSonogram[90, 181]);
Assert.AreEqual<Color>(expectedRed, substituteSonogram[36, 232]);
Assert.AreEqual<Color>(expectedRed, substituteSonogram[56, 69]);

Assert.AreEqual<Color>(expectedGreen, substituteSonogram[10, 72]);
Assert.AreEqual<Color>(expectedGreen, substituteSonogram[70, 217]);
substituteSonogram.Save("C:\\temp\\EventTests_SuperimposeEventsOnImage.png");

this.Actual = substituteSonogram;
/*
var pattern = @"
⬇150
E100R50
48×E100RE48R
E100R50
";
this.Expected = TestImage.Create(width: 100, height: 100, Color.Black, pattern);
*/

this.Expected = Image.Load<Rgb24>(PathHelper.ResolveAssetPath("EventTests_SuperimposeEventsOnImage.png"));
this.AssertImagesEqual();
}
}
}
3 changes: 3 additions & 0 deletions tests/Fixtures/EventTests_SuperimposeEventsOnImage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 04f9b04

Please sign in to comment.