From cf95e136142b0471b2680868161379ab330fe91d Mon Sep 17 00:00:00 2001 From: Anthony Truskinger Date: Mon, 5 Mar 2018 19:10:55 +1000 Subject: [PATCH] Apply style and fix some warnings [RELEASE] Also attempted to suppress log verbosity to console on CI server --- .../AnalysisBase/AnalysisCoordinatorTests.cs | 3 +- .../AnalysisBase/AnalysisSettingsTests.cs | 1 - .../Concatenation/ConcatenationTests.cs | 24 ++++++------- .../Draw/Zooming/DrawZoomingTests.cs | 1 - tests/Acoustics.Test/ArrayExtensionsTests.cs | 34 ++----------------- .../Indices/ClusterIndexTest.cs | 1 + .../TileImage/AbsoluteDateTimeTilerTests.cs | 8 ++--- .../Acoustics.Test/TestHelpers/Assertions.cs | 5 ++- tests/Acoustics.Test/TestHelpers/Setup.cs | 15 ++++---- .../AudioUtilityChannelTests.cs | 6 ++-- .../Tools/AudioUtilityFfmpegPcmRawTests.cs | 7 ++++ .../Tools/AudioUtilityWavTests.cs | 8 +++++ .../Tools/AudioUtilityWavpackTests.cs | 7 +++- 13 files changed, 51 insertions(+), 69 deletions(-) diff --git a/tests/Acoustics.Test/AnalysisBase/AnalysisCoordinatorTests.cs b/tests/Acoustics.Test/AnalysisBase/AnalysisCoordinatorTests.cs index 6ccf6618c..3794727f9 100644 --- a/tests/Acoustics.Test/AnalysisBase/AnalysisCoordinatorTests.cs +++ b/tests/Acoustics.Test/AnalysisBase/AnalysisCoordinatorTests.cs @@ -25,7 +25,7 @@ namespace Acoustics.Test.AnalysisBase [TestClass] public class AnalysisCoordinatorTests { - protected DirectoryInfo outputDirectory; + private DirectoryInfo outputDirectory; [TestInitialize] public void Setup() @@ -188,7 +188,6 @@ public void RemovesDuplicateSegmentsAfterSplitting() { SegmentStartOffset = 0.Seconds(), SegmentEndOffset = 60.0.Seconds(), - }, }; diff --git a/tests/Acoustics.Test/AnalysisBase/AnalysisSettingsTests.cs b/tests/Acoustics.Test/AnalysisBase/AnalysisSettingsTests.cs index 2ec27ba3f..c10896132 100644 --- a/tests/Acoustics.Test/AnalysisBase/AnalysisSettingsTests.cs +++ b/tests/Acoustics.Test/AnalysisBase/AnalysisSettingsTests.cs @@ -28,7 +28,6 @@ public void Initialize() this.original.AnalysisOutputDirectory = new DirectoryInfo("/"); this.cloned = (AnalysisSettings)this.original.Clone(); - } [TestMethod] diff --git a/tests/Acoustics.Test/AnalysisPrograms/Concatenation/ConcatenationTests.cs b/tests/Acoustics.Test/AnalysisPrograms/Concatenation/ConcatenationTests.cs index 0b6c73047..549cba4c1 100644 --- a/tests/Acoustics.Test/AnalysisPrograms/Concatenation/ConcatenationTests.cs +++ b/tests/Acoustics.Test/AnalysisPrograms/Concatenation/ConcatenationTests.cs @@ -29,19 +29,18 @@ namespace Acoustics.Test.AnalysisPrograms.Concatenation /// (4) for binary large objects(BLOBs) make sure git-lfs is tracking them /// [TestClass] - // [Ignore] public class ConcatenationTests : OutputDirectoryTest { - private static DirectoryInfo indonesiaIndicesDirectory; - - private static DirectoryInfo newZealandArk01IndicesDirectory; - private const string IndonesiaReduced = "Indonesia_2Reduced"; private const string NewZealandArk01 = "NewZealandArk01"; - /// Use ClassInitialize to run code before running the first test in the class - [ClassInitialize()] + private static DirectoryInfo indonesiaIndicesDirectory; + + private static DirectoryInfo newZealandArk01IndicesDirectory; + + // Use ClassInitialize to run code before running the first test in the class + [ClassInitialize] public static void MyClassInitialize(TestContext testContext) { var indonesiaIndices = PathHelper.ResolveAsset("Concatenation", IndonesiaReduced + ".zip"); @@ -157,8 +156,8 @@ public void ConcatenateIndexFilesTest24Hour() Assert.That.FileExists(outputDataDir.CombineFile(prefix + "Towsey.Acoustic.Indices.csv")); Assert.That.FileNotExists(outputDataDir.CombineFile(prefix + "SummaryIndex.csv")); - var actualImage = ImageTools.ReadImage2Bitmap(imageFileInfo.FullName); + // we expect only the second half (past midnight) of the image to be rendered Assert.That.ImageIsSize(512, 632, actualImage); Assert.That.PixelIsColor(new Point(100, 100), Color.FromArgb(32, 25, 36), actualImage); @@ -222,7 +221,7 @@ public void ConcatenateIndexFilesTest24HourWithoutDateRange() // IMAGE 2: Compare image files - check that image exists and dimensions are correct var dateString2 = "20160726"; - var outputDataDir2= this.outputDirectory.Combine(arguments.FileStemName, dateString2); + var outputDataDir2 = this.outputDirectory.Combine(arguments.FileStemName, dateString2); var prefix2 = arguments.FileStemName + "_" + dateString2 + "__"; var image2FileInfo = outputDataDir2.CombineFile(prefix2 + "2Maps.png"); @@ -298,7 +297,7 @@ public void ConcatenateIndexFilesTestConfigFileChanges() /// Thus there's a column of data for every 20 pixels. /// [DataTestMethod] - [DataRow(ConcatMode.TimedGaps, new [] {1440, 1420, 1440})] + [DataRow(ConcatMode.TimedGaps, new[] { 1440, 1420, 1440 })] [DataRow(ConcatMode.NoGaps, new[] { 73, 72, 73 })] [DataRow(ConcatMode.EchoGaps, new[] { 1440, 1420, 1440 })] public void SampledDataConcatModeTests(ConcatMode gapRendering, int[] expectedWidths) @@ -325,7 +324,7 @@ public void SampledDataConcatModeTests(ConcatMode gapRendering, int[] expectedWi ConcatenateIndexFiles.Execute(arguments); - var dateStrings = new[] {"20161209", "20161210", "20161211"}.Zip(expectedWidths, ValueTuple.Create); + var dateStrings = new[] { "20161209", "20161210", "20161211" }.Zip(expectedWidths, ValueTuple.Create); foreach (var (dateString, expectedWidth) in dateStrings) { var prefix = Path.Combine(this.outputDirectory.FullName, Ark01, dateString, Ark01 + "_" + dateString + "__"); @@ -379,10 +378,7 @@ public void SampledDataConcatModeTests(ConcatMode gapRendering, int[] expectedWi default: throw new ArgumentOutOfRangeException(nameof(gapRendering), gapRendering, null); } - } } - - } } diff --git a/tests/Acoustics.Test/AnalysisPrograms/Draw/Zooming/DrawZoomingTests.cs b/tests/Acoustics.Test/AnalysisPrograms/Draw/Zooming/DrawZoomingTests.cs index 81a0e2530..38f353637 100644 --- a/tests/Acoustics.Test/AnalysisPrograms/Draw/Zooming/DrawZoomingTests.cs +++ b/tests/Acoustics.Test/AnalysisPrograms/Draw/Zooming/DrawZoomingTests.cs @@ -136,7 +136,6 @@ public void TestGenerateTiles() /// Tests the rendering of zooming spectrograms for a minute of audio indices /// [TestMethod] - //[Timeout(45_000)] public void TestGenerateTilesSqlite() { // generate the zooming spectrograms diff --git a/tests/Acoustics.Test/ArrayExtensionsTests.cs b/tests/Acoustics.Test/ArrayExtensionsTests.cs index 3122db16a..1612ca6ae 100644 --- a/tests/Acoustics.Test/ArrayExtensionsTests.cs +++ b/tests/Acoustics.Test/ArrayExtensionsTests.cs @@ -14,19 +14,10 @@ namespace Acoustics.Test using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; - /// - /// Summary description for ArrayExtensionsTests - /// [TestClass] public class ArrayExtensionsTests { - public ArrayExtensionsTests() - { - // - // TODO: Add constructor logic here - // - } - + private const int TestSize = 1000000; private TestContext testContextInstance; /// @@ -39,34 +30,13 @@ public TestContext TestContext { return this.testContextInstance; } + set { this.testContextInstance = value; } } - // - // You can use the following additional attributes as you write your tests: - // - // Use ClassInitialize to run code before running the first test in the class - // [ClassInitialize()] - // public static void MyClassInitialize(TestContext testContext) { } - // - // Use ClassCleanup to run code after all tests in a class have run - // [ClassCleanup()] - // public static void MyClassCleanup() { } - // - // Use TestInitialize to run code before running each test - // [TestInitialize()] - // public void MyTestInitialize() { } - // - // Use TestCleanup to run code after each test has run - // [TestCleanup()] - // public void MyTestCleanup() { } - // - - private const int TestSize = 1000000; - [TestMethod] public void TestArrayFill() { diff --git a/tests/Acoustics.Test/AudioAnalysisTools/Indices/ClusterIndexTest.cs b/tests/Acoustics.Test/AudioAnalysisTools/Indices/ClusterIndexTest.cs index 9ed58d7e3..1b535e747 100644 --- a/tests/Acoustics.Test/AudioAnalysisTools/Indices/ClusterIndexTest.cs +++ b/tests/Acoustics.Test/AudioAnalysisTools/Indices/ClusterIndexTest.cs @@ -83,6 +83,7 @@ public void TestBinaryClusteringOfSpectra() // test what used to be the CLS spectral index. Sum of the rows of the weight vectors. var expectedSpectrumFile = new FileInfo(outputDir + "\\clusterSpectrum.bin"); + // Binary.Serialize(expectedSpectrumFile, clusterSpectrum); var expectedVector = Binary.Deserialize(expectedSpectrumFile); CollectionAssert.AreEqual(expectedVector, clusterSpectrum); diff --git a/tests/Acoustics.Test/AudioAnalysisTools/TileImage/AbsoluteDateTimeTilerTests.cs b/tests/Acoustics.Test/AudioAnalysisTools/TileImage/AbsoluteDateTimeTilerTests.cs index 97a09b3c5..3716a7129 100644 --- a/tests/Acoustics.Test/AudioAnalysisTools/TileImage/AbsoluteDateTimeTilerTests.cs +++ b/tests/Acoustics.Test/AudioAnalysisTools/TileImage/AbsoluteDateTimeTilerTests.cs @@ -16,11 +16,11 @@ namespace Acoustics.Test.AudioAnalysisTools.TileImage [TestClass] public class AbsoluteDateTimeTilerTests { + private readonly DateTimeOffset dateTimeOffset = new DateTimeOffset(2015, 04, 10, 3, 30, 15, 123, TimeSpan.FromHours(10)); private AbsoluteDateTilingProfile tilingProfile; private Tiler tiler; private DirectoryInfo outputDirectory; private AbsoluteDateTilingProfile tilingProfileNotRoundStart; - private readonly DateTimeOffset dateTimeOffset = new DateTimeOffset(2015, 04, 10, 3, 30, 15, 123, TimeSpan.FromHours(10)); [TestInitialize] public void Setup() @@ -64,7 +64,7 @@ public void TestNamingPattern() Assert.AreEqual("Basename__Tag_20150409T173015.123Z_60", profile.GetFileBaseName(this.tiler.CalculatedLayers, this.tiler.CalculatedLayers.First(), new Point(0, 0))); - var profile2 = new AbsoluteDateTilingProfile("", "Tag", this.dateTimeOffset, 256, 300); + var profile2 = new AbsoluteDateTilingProfile(string.Empty, "Tag", this.dateTimeOffset, 256, 300); Assert.AreEqual("Tag_20150409T173015.123Z_60", profile2.GetFileBaseName(this.tiler.CalculatedLayers, this.tiler.CalculatedLayers.First(), new Point(0, 0))); } @@ -73,7 +73,7 @@ public void TestNamingPattern() public void TestLeftPaddingInLowerLayers() { const int TileWidth = 180; - var startDate = new DateTimeOffset(2014, 05, 29, 08,13, 58, TimeSpan.FromHours(10)); + var startDate = new DateTimeOffset(2014, 05, 29, 08, 13, 58, TimeSpan.FromHours(10)); var boundary = ZoomTiledSpectrograms.GetPreviousTileBoundary(TileWidth, 0.1, startDate); var padding = startDate - boundary; @@ -136,7 +136,7 @@ public void TestLeftPaddingInLowerLayers() var expectedImages = expectedFiles .OrderBy(x => x) - .Select((x, i) => testBitmap.Crop(new Rectangle(i * TileWidth - 100, 0, TileWidth, 256))) + .Select((x, i) => testBitmap.Crop(new Rectangle((i * TileWidth) - 100, 0, TileWidth, 256))) .ToArray(); for (var i = 0; i < expectedImages.Length; i++) diff --git a/tests/Acoustics.Test/TestHelpers/Assertions.cs b/tests/Acoustics.Test/TestHelpers/Assertions.cs index d320be1aa..e930281bd 100644 --- a/tests/Acoustics.Test/TestHelpers/Assertions.cs +++ b/tests/Acoustics.Test/TestHelpers/Assertions.cs @@ -79,6 +79,7 @@ public static void AreEqual( actualEnum.Dispose(); } } + public static void AreEqual( this CollectionAssert collectionAssert, double[,] expected, @@ -112,7 +113,6 @@ public static void AreEqual( $"At index [{i},{j}], expected item `{expectedItem}` does not match `{actualItem}`. " + $"Actual delta is `{actualDelta}`"); } - } } } @@ -226,8 +226,7 @@ public static void ShouldEqualWithDiff(this string actualValue, string expectedV i < expectedValue.Length ? ((int)expectedValue[i]).ToString() : string.Empty, // character decimal value i < expectedValue.Length ? expectedValue[i].ToSafeString() : string.Empty, // character safe string i < actualValue.Length ? ((int)actualValue[i]).ToString() : string.Empty, // character decimal value - i < actualValue.Length ? actualValue[i].ToSafeString() : string.Empty // character safe string - ); + i < actualValue.Length ? actualValue[i].ToSafeString() : string.Empty); // character safe string } } diff --git a/tests/Acoustics.Test/TestHelpers/Setup.cs b/tests/Acoustics.Test/TestHelpers/Setup.cs index 86b837271..9dc7d2f8c 100644 --- a/tests/Acoustics.Test/TestHelpers/Setup.cs +++ b/tests/Acoustics.Test/TestHelpers/Setup.cs @@ -1,15 +1,14 @@ -// +// // All code in this file and all associated files are the copyright and property of the QUT Ecoacoustics Research Group (formerly MQUTeR, and formerly QUT Bioacoustics Research Group). // -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace Acoustics.Test.TestHelpers { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using System.Threading.Tasks; using global::AnalysisPrograms; using global::AnalysisPrograms.Production.Arguments; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -20,7 +19,7 @@ public class Setup [AssemblyInitialize] public static void AssemblyInitialize(TestContext context) { - MainEntry.SetLogVerbosity(LogVerbosity.Warn, false); + MainEntry.SetLogVerbosity(LogVerbosity.Warn, true); } } } diff --git a/tests/Acoustics.Test/Tools/AudioUtilityChannelSelection/AudioUtilityChannelTests.cs b/tests/Acoustics.Test/Tools/AudioUtilityChannelSelection/AudioUtilityChannelTests.cs index e40e8993f..a526a620b 100644 --- a/tests/Acoustics.Test/Tools/AudioUtilityChannelSelection/AudioUtilityChannelTests.cs +++ b/tests/Acoustics.Test/Tools/AudioUtilityChannelSelection/AudioUtilityChannelTests.cs @@ -174,7 +174,7 @@ public void SoxSelectsChannels1234Correctly() new[] { 1000 }, }; - ChannelTest(FourChannelFile, new[] {1, 2, 3, 4 }, false, expectedFrequencies); + ChannelTest(FourChannelFile, new[] { 1, 2, 3, 4 }, false, expectedFrequencies); } [TestMethod] @@ -183,7 +183,7 @@ public void SoxMixesDownChannels1And2Correctly() // array of channels of frequencies (expected in each channel) var expectedFrequencies = new[] { - new[] { 4000, 3000}, + new[] { 4000, 3000 }, }; ChannelTest(FourChannelFile, new[] { 1, 2 }, true, expectedFrequencies); @@ -210,7 +210,7 @@ public void SoxMixesDownChannels1234Correctly() new[] { 4000, 3000, 2000, 1000 }, }; - ChannelTest(FourChannelFile, new[] {1, 2, 3, 4 }, true, expectedFrequencies); + ChannelTest(FourChannelFile, new[] { 1, 2, 3, 4 }, true, expectedFrequencies); } [TestMethod] diff --git a/tests/Acoustics.Test/Tools/AudioUtilityFfmpegPcmRawTests.cs b/tests/Acoustics.Test/Tools/AudioUtilityFfmpegPcmRawTests.cs index efe255c25..9de123b89 100644 --- a/tests/Acoustics.Test/Tools/AudioUtilityFfmpegPcmRawTests.cs +++ b/tests/Acoustics.Test/Tools/AudioUtilityFfmpegPcmRawTests.cs @@ -150,6 +150,7 @@ public void FailsWithMissingBitDepth() //BitDepth = 16, TargetSampleRate = 22050, Channels = new[] { 1, 2, 3, 4 }, + //BandPass }; @@ -176,6 +177,7 @@ public void FailsWithInvalidBitDepth() BitDepth = 64, TargetSampleRate = 22050, Channels = new[] { 1, 2, 3, 4 }, + //BandPass }; @@ -200,8 +202,11 @@ public void FailsWithMissingSampleRate() var request = new AudioUtilityRequest { BitDepth = 16, + //TargetSampleRate = 22050, + Channels = new[] { 1, 2, 3, 4 }, + //BandPass }; @@ -217,6 +222,7 @@ public void FailsWithMissingChannels() { BitDepth = 16, TargetSampleRate = 22050, + //Channels = new[] { 1, 2, 3, 4 }, //BandPass }; @@ -234,6 +240,7 @@ public void FailsChannelSelection() BitDepth = 16, TargetSampleRate = 22050, Channels = new[] { 5, 2, 3, 4 }, + //BandPass }; diff --git a/tests/Acoustics.Test/Tools/AudioUtilityWavTests.cs b/tests/Acoustics.Test/Tools/AudioUtilityWavTests.cs index 8bb3384db..9b230be6a 100644 --- a/tests/Acoustics.Test/Tools/AudioUtilityWavTests.cs +++ b/tests/Acoustics.Test/Tools/AudioUtilityWavTests.cs @@ -227,8 +227,10 @@ public void SegmentsWavCorrectly1Shntool() var request = new AudioUtilityRequest { //MixDownToMono = true, + OffsetStart = TimeSpan.FromSeconds(20), OffsetEnd = TimeSpan.FromSeconds(50), + //TargetSampleRate = 17460 }; @@ -262,7 +264,9 @@ public void SegmentsWavCorrectly2Shntool() var request = new AudioUtilityRequest { //MixDownToMono = true, + OffsetEnd = TimeSpan.FromSeconds(35), + //TargetSampleRate = 17460 }; @@ -364,8 +368,10 @@ public void SegmentsWavCorrectly5Shntool() var request = new AudioUtilityRequest { //MixDownToMono = true, + OffsetStart = TimeSpan.FromSeconds(27), OffsetEnd = TimeSpan.FromSeconds(117), + //TargetSampleRate = 17460 }; @@ -400,7 +406,9 @@ public void SegmentsWavCorrectly6Shntool() { //MixDownToMono = false, //Channel = 2, + OffsetStart = TimeSpan.FromSeconds(27), + //TargetSampleRate = 17460, }; diff --git a/tests/Acoustics.Test/Tools/AudioUtilityWavpackTests.cs b/tests/Acoustics.Test/Tools/AudioUtilityWavpackTests.cs index 1bbd93c6f..26ae57208 100644 --- a/tests/Acoustics.Test/Tools/AudioUtilityWavpackTests.cs +++ b/tests/Acoustics.Test/Tools/AudioUtilityWavpackTests.cs @@ -31,6 +31,7 @@ public void SegmentsWavpackCorrectly1Wavunpack() MixDownToMono = false, OffsetStart = TimeSpan.FromSeconds(20), OffsetEnd = TimeSpan.FromSeconds(50), + //SampleRate = 11025 }; @@ -94,6 +95,7 @@ public void SegmentsWavpackCorrectly3Wavunpack() MixDownToMono = false, OffsetStart = TimeSpan.FromSeconds(0), OffsetEnd = TimeSpan.FromSeconds(55), + //SampleRate = 11025 }; @@ -157,10 +159,10 @@ public void SegmentsWavpackCorrectly5Wavunpack() { MixDownToMono = false, OffsetStart = TimeSpan.FromSeconds(27), + //SampleRate = 44100 }; - var source = TestHelper.GetAudioFile("f969b39d-2705-42fc-992c-252a776f1af3_090705-0600.wv"); var output = PathHelper.GetTempFile(MediaTypes.ExtWav); @@ -188,8 +190,11 @@ public void SegmentsWavpackCorrectly6Wavunpack() var request = new AudioUtilityRequest { MixDownToMono = false, + //Channel = 2, + OffsetStart = TimeSpan.FromMinutes(5) + TimeSpan.FromSeconds(27), + //SampleRate = 11025, };