From af306f148226a9292c527204d812070ba4a81e6a Mon Sep 17 00:00:00 2001 From: Nikolay Pozdnichenko Date: Sun, 17 Mar 2024 14:30:03 +0600 Subject: [PATCH] Update unit tests to NUnit 4 Also updated other nuget libraries. And refactored unit tests. --- .../ClusterizatorsFactoryTests.cs | 2 +- .../FRiSCluster/FRiSClusterTests.cs | 17 +- .../EquipotencyCalculatorSecondTests.cs | 67 +-- .../Calculators/EquipotencyCalculatorTests.cs | 38 +- .../Krab/Calculators/LambdaCalculatorTests.cs | 60 +-- .../Krab/Calculators/LinearCalculatorTests.cs | 109 +++-- .../NormalizedLinearCalculatorTests.cs | 98 ++-- .../Krab/Calculators/TauCalculatorTests.cs | 56 ++- .../Calculators/TauStarCalculatorTests.cs | 58 ++- .../Krab/ConnectionTests.cs | 59 +-- .../Krab/GraphElementTests.cs | 34 +- .../Krab/GraphManagerTests.cs | 185 ++++---- .../Krab/KrabClusterizationTests.cs | 32 +- .../Libiada.Clusterizator.Tests.csproj | 10 +- .../kMeans/KMeansClusterizationTests.cs | 37 +- Libiada.Core.Tests/Core/AbstractChainTests.cs | 42 +- Libiada.Core.Tests/Core/AlphabetTests.cs | 93 ++-- .../BinaryIntervalsManagerTests.cs | 67 +-- .../IntervalsManagerTests.cs | 4 +- .../ArrangementManagers/SeriesManagerTests.cs | 4 +- Libiada.Core.Tests/Core/BaseChainTests.cs | 94 ++-- Libiada.Core.Tests/Core/ChainTests.cs | 26 +- Libiada.Core.Tests/Core/ChainsStorage.cs | 212 ++++----- .../AccordanceCalculatorsFactoryTests.cs | 2 +- .../AccordanceCalculatorsTests.cs | 8 +- .../BinaryCalculatorsFactoryTests.cs | 2 +- .../BinaryCalculatorsTests.cs | 6 +- ...volvedPartialDependenceCoefficientTests.cs | 34 +- .../MutualDependenceCoefficientTests.cs | 43 +- ...alizedPartialDependenceCoefficientTests.cs | 43 +- .../PartialDependenceCoefficientTests.cs | 43 +- .../CongenericCalculatorsFactoryTests.cs | 2 +- .../CongenericCalculatorsTests.cs | 4 +- .../FullCalculators/AverageWordLengthTests.cs | 8 +- .../FullCalculatorsFactoryTests.cs | 2 +- .../FullCalculators/FullCalculatorsTests.cs | 6 +- .../LinkedFullCalculatorTests.cs | 2 +- .../Core/CongenericChainTests.cs | 47 +- .../Core/CongenericScoreTrackTests.cs | 260 +++++------ Libiada.Core.Tests/Core/FmotifChainTests.cs | 14 +- Libiada.Core.Tests/Core/LinkTests.cs | 10 +- .../Core/SimpleTypes/AccidentalTests.cs | 11 +- .../Core/SimpleTypes/DurationTests.cs | 30 +- .../Core/SimpleTypes/FmotifTests.cs | 114 ++--- .../Core/SimpleTypes/FmotifTypeTests.cs | 10 +- .../Core/SimpleTypes/InstrumentTests.cs | 10 +- .../Core/SimpleTypes/MeasureTests.cs | 6 +- .../Core/SimpleTypes/NoteSymbolTests.cs | 23 +- .../Core/SimpleTypes/NullValueTests.cs | 4 +- .../Core/SimpleTypes/PitchTests.cs | 8 +- .../Core/SimpleTypes/TieTests.cs | 10 +- .../Core/SimpleTypes/ValueIntTests.cs | 6 +- .../Core/SimpleTypes/ValueNoteTests.cs | 26 +- .../Core/SimpleTypes/ValuePhantomTests.cs | 24 +- .../Core/SimpleTypes/ValueStringTests.cs | 7 +- .../DissimilarChainFactoryTests.cs | 4 +- .../DataTransformers/DnaTransformerTests.cs | 198 ++++---- .../DataTransformers/HighOrderFactoryTests.cs | 4 +- .../PermutationGeneratorTests.cs | 24 +- .../SequenceConcatenatorTests.cs | 18 +- .../Exceptions/TypeArgumentExceptionTests.cs | 12 +- .../Extensions/ArrayExtensionsTests.cs | 153 ++++--- .../Extensions/EnumExtensionsTests.cs | 4 +- .../Extensions/StringExtensionsTests.cs | 46 +- .../Images/ImageProcessorTests.cs | 61 ++- .../Images/ZigzagOrderExtractorTests.cs | 63 ++- .../Iterators/CustomIteratorTests.cs | 12 +- .../Iterators/CutRuleWithFixedStartTests.cs | 11 +- .../CutRuleWithShiftedAndFixedStartTests.cs | 7 +- .../Iterators/DiffCutterTests.cs | 8 +- .../Iterators/IteratorEndTests.cs | 56 +-- .../Iterators/IteratorStartTests.cs | 52 +-- .../Iterators/IteratorWritableEndTests.cs | 4 +- .../Iterators/IteratorWritableStartTests.cs | 19 +- .../Iterators/SimpleCutRuleTests.cs | 9 +- .../SimpleCutRuleWithShiftedStartTests.cs | 9 +- Libiada.Core.Tests/Libiada.Core.Tests.csproj | 10 +- .../Music/FmotifDividerTests.cs | 304 ++++++------ .../Music/FmotifIdentifierTests.cs | 24 +- .../Music/MidiNumberManagerTests.cs | 18 +- .../Music/MusicXml/MusicXmlParserTests.cs | 308 +++++++------ .../Music/MusicXml/XmlReaderTests.cs | 2 +- .../Music/PauseTreatmentTests.cs | 7 +- .../Music/PriorityDiscoverTests.cs | 432 +++++++++--------- .../NullCycleSpaceReorganizerTests.cs | 4 +- .../SpaceReorganizers/NullReorganizerTests.cs | 4 +- .../TimeSeries/Aggregators/AverageTests.cs | 9 +- .../Aggregators/DifferenceModuleTests.cs | 9 +- .../Aggregators/DifferenceSquareRootTests.cs | 9 +- .../TimeSeries/Aggregators/MaxTests.cs | 9 +- .../TimeSeries/Aggregators/MinTests.cs | 9 +- .../TimeSeries/Aggregators/SumModuleTests.cs | 10 +- .../Aggregators/SumSquareRootTests.cs | 9 +- .../Aligners/AllOffsetsAlignerTests.cs | 35 +- .../Aligners/ByShortestAlignerTests.cs | 14 +- .../ByShortestFromRightAlignerTests.cs | 14 +- .../Aligners/FirstElementDuplicatorTests.cs | 25 +- .../Aligners/LastElementDuplicatorTests.cs | 25 +- .../OneDimensionalTimeSeriesComparerTests.cs | 220 ++++----- ...istanceBetweenOneDimensionalPointsTests.cs | 4 +- ...istanceBetweenOneDimensionalPointsTests.cs | 4 +- .../NullArrangementManager.cs | 2 +- Libiada.Core/Core/BaseChain.cs | 20 +- Libiada.Core/Libiada.Core.csproj | 2 +- .../Libiada.MarkovChains.Tests.csproj | 10 +- .../MarkovChainNotCongenericStaticTests.cs | 4 +- .../Probability/ProbabilityMatrixTests.cs | 190 ++++---- .../MarkovCompare/MarkovMetricsTests.cs | 2 +- .../Libiada.PhantomChains.Tests.csproj | 10 +- .../PhantomChainGeneratorTests.cs | 29 +- .../PhantomTableTests.cs | 40 +- Libiada.PhantomChains.Tests/TestObject.cs | 8 +- Libiada.PhantomChains.Tests/TreeTests.cs | 8 +- .../Collectors/FrequencyDictionaryTests.cs | 101 ++-- .../Base/Iterators/EndIteratorTests.cs | 78 ++-- .../Base/Iterators/StartIteratorTests.cs | 58 +-- .../Base/Seekers/Converters/FilterTests.cs | 13 +- .../Converters/SequenceCleanerTests.cs | 34 +- .../Base/Seekers/SeekerSequenceTests.cs | 12 +- .../Base/Seekers/SeekerTests.cs | 68 +-- .../Base/Sequences/ComplexChainTests.cs | 125 ++--- .../Libiada.Segmenter.Tests.csproj | 10 +- .../Model/Threshold/ThresholdLinearTests.cs | 12 +- .../Base/Collectors/FrequencyDictionary.cs | 10 + .../Base/Sequences/ComplexChain.cs | 6 +- .../Model/Threshold/ThresholdLinear.cs | 2 +- .../IntervalsDistributionExtractorTests.cs | 10 +- .../IntervalsDistributionsStorage.cs | 40 +- .../Libiada.SequenceGenerator.Tests.csproj | 10 +- .../NonredundantSequenceGeneratorTests.cs | 74 +-- ...onredundantStrictSequenceGeneratorTests.cs | 104 ++--- .../OrderEqualityComparerTests.cs | 4 +- .../OrderGeneratorTests.cs | 74 +-- .../OrderIteratorTests.cs | 24 +- .../SequenceGeneratorTests.cs | 104 ++--- .../SequenceIteratorTests.cs | 24 +- .../StrictSequenceGeneratorTests.cs | 104 ++--- 137 files changed, 3058 insertions(+), 2889 deletions(-) diff --git a/Libiada.Clusterizator.Tests/ClusterizatorsFactoryTests.cs b/Libiada.Clusterizator.Tests/ClusterizatorsFactoryTests.cs index 6079f3e6..674d1a3e 100644 --- a/Libiada.Clusterizator.Tests/ClusterizatorsFactoryTests.cs +++ b/Libiada.Clusterizator.Tests/ClusterizatorsFactoryTests.cs @@ -31,7 +31,7 @@ public void SelectionTest(ClusterizationType type, Type expected) }; var clusterizator = ClusterizatorsFactory.CreateClusterizator(type, parameters); - Assert.IsInstanceOf(expected, clusterizator); + Assert.That(clusterizator, Is.InstanceOf(expected)); } /// diff --git a/Libiada.Clusterizator.Tests/FRiSCluster/FRiSClusterTests.cs b/Libiada.Clusterizator.Tests/FRiSCluster/FRiSClusterTests.cs index 04a13e5f..e098ec4e 100644 --- a/Libiada.Clusterizator.Tests/FRiSCluster/FRiSClusterTests.cs +++ b/Libiada.Clusterizator.Tests/FRiSCluster/FRiSClusterTests.cs @@ -15,9 +15,9 @@ public class FRiSClusterTests public void SimpleClusterTest() { var cluster = new FRiSCluster(2, 2); - double[][] data = { new double[] { 1 }, new double[] { 2 }, new double[] { 10 } }; + double[][] data = [[1], [2], [10]]; int[] actual = cluster.Cluster(2, data); - Assert.AreEqual(new[] { 0, 0, 1 }, actual); + Assert.That(actual, Is.EqualTo(new[] { 0, 0, 1 })); } /// @@ -27,9 +27,9 @@ public void SimpleClusterTest() public void FourPointsClusterTest() { var cluster = new FRiSCluster(2, 2); - double[][] data = { new double[] { -5 }, new double[] { -4 }, new double[] { 4 }, new double[] { 5 } }; + double[][] data = [[-5], [-4], [4], [5]]; int[] actual = cluster.Cluster(2, data); - Assert.AreEqual(new[] { 0, 0, 1, 1 }, actual); + Assert.That(actual, Is.EqualTo(new int[] { 0, 0, 1, 1 })); } /// @@ -39,9 +39,10 @@ public void FourPointsClusterTest() public void TwoDimensionDataClusterTest() { var cluster = new FRiSCluster(2, 2); - double[][] data = { new double[] { -5, 1 }, new double[] { -5, 2 }, new double[] { 0, 0 }, new double[] { 1, 1 } }; + double[][] data = [[-5, 1], [-5, 2], [0, 0], [1, 1]]; int[] actual = cluster.Cluster(2, data); - Assert.AreEqual(new[] { 0, 0, 1, 1 }, actual); + Assert.That(actual, Is.EqualTo(new int[] { 0, 0, 1, 1 })); + } /// @@ -51,8 +52,8 @@ public void TwoDimensionDataClusterTest() public void MultipleDataPointsClusterTest() { var cluster = new FRiSCluster(2, 2); - double[][] data = { new[] { -2.1 }, new[] { -1.0 }, new[] { 0.3 }, new[] { 1.0 }, new[] { 1.1 }, new[] { 7.0 }, new[] { 9.0} }; + double[][] data = [[-2.1], [-1.0], [0.3], [1.0], [1.1], [7.0], [9.0]]; int[] actual = cluster.Cluster(2, data); - Assert.AreEqual(new[] { 0, 0, 0, 0, 0, 1, 1 }, actual); + Assert.That(actual, Is.EqualTo(new int[] { 0, 0, 0, 0, 0, 1, 1 })); } } diff --git a/Libiada.Clusterizator.Tests/Krab/Calculators/EquipotencyCalculatorSecondTests.cs b/Libiada.Clusterizator.Tests/Krab/Calculators/EquipotencyCalculatorSecondTests.cs index 1d396f71..0d42e1a8 100644 --- a/Libiada.Clusterizator.Tests/Krab/Calculators/EquipotencyCalculatorSecondTests.cs +++ b/Libiada.Clusterizator.Tests/Krab/Calculators/EquipotencyCalculatorSecondTests.cs @@ -1,7 +1,7 @@ namespace Libiada.Clusterizator.Tests.Krab.Calculators; -using Clusterizator.Krab; -using Clusterizator.Krab.Calculators; +using Libiada.Clusterizator.Krab.Calculators; +using Libiada.Clusterizator.Krab; /// /// The equipotency calculator second test. @@ -20,28 +20,28 @@ public class EquipotencyCalculatorSecondTests [SetUp] public void Initialization() { - var elements = new List - { - new GraphElement(new[] { 0.0, 10.0 }, "1"), - new GraphElement(new[] { 2.0, 15.0 }, "2"), - new GraphElement(new[] { 5.0, 25.0 }, "3"), - new GraphElement(new[] { 6.0, 15.0 }, "4"), - new GraphElement(new[] { 6.0, 18.0 }, "5") - }; - - var connections = new List - { - new Connection(0, 1), - new Connection(0, 2), - new Connection(0, 3), - new Connection(0, 4), - new Connection(1, 2), - new Connection(1, 3), - new Connection(1, 4), - new Connection(2, 3), - new Connection(2, 4), - new Connection(3, 4) - }; + List elements = + [ + new GraphElement([0.0, 10.0], "1"), + new GraphElement([2.0, 15.0], "2"), + new GraphElement([5.0, 25.0], "3"), + new GraphElement([6.0, 15.0], "4"), + new GraphElement([6.0, 18.0], "5") + ]; + + List connections = + [ + new Connection(0, 1), + new Connection(0, 2), + new Connection(0, 3), + new Connection(0, 4), + new Connection(1, 2), + new Connection(1, 3), + new Connection(1, 4), + new Connection(2, 3), + new Connection(2, 4), + new Connection(3, 4) + ]; manager = new GraphManager(connections, elements); } @@ -52,23 +52,23 @@ public void Initialization() [Test] public void FourPointsZeroTest() { - var connected = new[] { true, false, false, false, true, false, false, true, false, false }; + bool[] connected = [true, false, false, false, true, false, false, true, false, false]; for (int i = 0; i < connected.Length; i++) { manager.Connections[i].Connected = connected[i]; } - var taxonNumbers = new[] { 1, 1, 1, 1, 2 }; + int[] taxonNumbers = [1, 1, 1, 1, 2]; for (int i = 0; i < taxonNumbers.Length; i++) { manager.Elements[i].TaxonNumber = taxonNumbers[i]; } - var d = EquipotencyCalculator.Calculate(manager); + double d = EquipotencyCalculator.Calculate(manager); d = Math.Round(d * 100) / 100; - Assert.AreEqual(0.64, d); + Assert.That(d, Is.EqualTo(0.64)); } /// @@ -77,22 +77,23 @@ public void FourPointsZeroTest() [Test] public void FourPointsOneTest() { - var connected = new[] { true, false, false, false, false, false, false, false, false, true }; + bool[] connected = [true, false, false, false, false, false, false, false, false, true]; + for (int i = 0; i < connected.Length; i++) { manager.Connections[i].Connected = connected[i]; } - var taxonNumbers = new[] { 1, 1, 3, 2, 2 }; + int[] taxonNumbers = [1, 1, 3, 2, 2]; for (int i = 0; i < taxonNumbers.Length; i++) { manager.Elements[i].TaxonNumber = taxonNumbers[i]; } - var d = EquipotencyCalculator.Calculate(manager); + double d = EquipotencyCalculator.Calculate(manager); d = Math.Round(d * 100) / 100; - Assert.AreEqual(0.86, d); + Assert.That(d, Is.EqualTo(0.86)); } /// @@ -111,6 +112,6 @@ public void FourPointsSixTest() manager.Elements[i].TaxonNumber = i + 1; } - Assert.AreEqual(1, EquipotencyCalculator.Calculate(manager)); + Assert.That(EquipotencyCalculator.Calculate(manager), Is.EqualTo(1)); } } diff --git a/Libiada.Clusterizator.Tests/Krab/Calculators/EquipotencyCalculatorTests.cs b/Libiada.Clusterizator.Tests/Krab/Calculators/EquipotencyCalculatorTests.cs index 76c4591b..d57293c2 100644 --- a/Libiada.Clusterizator.Tests/Krab/Calculators/EquipotencyCalculatorTests.cs +++ b/Libiada.Clusterizator.Tests/Krab/Calculators/EquipotencyCalculatorTests.cs @@ -22,20 +22,20 @@ public void Initialization() { var elements = new List { - new GraphElement(new[] { 0.0 }, "1"), - new GraphElement(new[] { 2.0 }, "2"), - new GraphElement(new[] { 5.0 }, "3"), - new GraphElement(new[] { 6.0 }, "4") + new([0.0], "1"), + new([2.0], "2"), + new([5.0], "3"), + new([6.0], "4") }; var connections = new List { - new Connection(0, 1), - new Connection(0, 2), - new Connection(0, 3), - new Connection(1, 2), - new Connection(1, 3), - new Connection(2, 3) + new(0, 1), + new(0, 2), + new(0, 3), + new(1, 2), + new(1, 3), + new(2, 3) }; manager = new GraphManager(connections, elements); @@ -61,7 +61,7 @@ public void FourPointsZeroTest() manager.Elements[i].TaxonNumber = taxonNumbers[i]; } - Assert.AreEqual(0.75, EquipotencyCalculator.Calculate(manager)); + Assert.That(EquipotencyCalculator.Calculate(manager), Is.EqualTo(0.75)); } /// @@ -84,7 +84,7 @@ public void FourPointsOneTest() manager.Elements[i].TaxonNumber = taxonNumbers[i]; } - Assert.AreEqual(1, EquipotencyCalculator.Calculate(manager)); + Assert.That(EquipotencyCalculator.Calculate(manager), Is.EqualTo(1)); } /// @@ -107,7 +107,7 @@ public void FourPointsTwoTest() manager.Elements[i].TaxonNumber = taxonNumbers[i]; } - Assert.AreEqual(0.75, EquipotencyCalculator.Calculate(manager)); + Assert.That(EquipotencyCalculator.Calculate(manager), Is.EqualTo(0.75)); } /// @@ -130,7 +130,7 @@ public void FourPointsThreeTest() manager.Elements[i].TaxonNumber = taxonNumbers[i]; } - Assert.AreEqual(0.84375, EquipotencyCalculator.Calculate(manager)); + Assert.That(EquipotencyCalculator.Calculate(manager), Is.EqualTo(0.84375)); } /// @@ -153,7 +153,7 @@ public void FourPointsFourTest() manager.Elements[i].TaxonNumber = taxonNumbers[i]; } - Assert.AreEqual(0.84375, EquipotencyCalculator.Calculate(manager)); + Assert.That(EquipotencyCalculator.Calculate(manager), Is.EqualTo(0.84375)); } /// @@ -176,7 +176,7 @@ public void FourPointsFiveTest() manager.Elements[i].TaxonNumber = taxonNumbers[i]; } - Assert.AreEqual(0.84375, EquipotencyCalculator.Calculate(manager)); + Assert.That(EquipotencyCalculator.Calculate(manager) ,Is.EqualTo(0.84375)); } /// @@ -195,7 +195,7 @@ public void FourPointsSixTest() manager.Elements[i].TaxonNumber = i + 1; } - Assert.AreEqual(1, EquipotencyCalculator.Calculate(manager)); + Assert.That(EquipotencyCalculator.Calculate(manager), Is.EqualTo(1)); } /// @@ -218,7 +218,7 @@ public void FourPointsSevenTest() manager.Elements[i].TaxonNumber = taxonNumbers[i]; } - Assert.AreEqual(1, EquipotencyCalculator.Calculate(manager)); + Assert.That(EquipotencyCalculator.Calculate(manager), Is.EqualTo(1)); } /// @@ -241,6 +241,6 @@ public void FourPointsElevenTest() manager.Elements[i].TaxonNumber = taxonNumbers[i]; } - Assert.AreEqual(1, EquipotencyCalculator.Calculate(manager)); + Assert.That(EquipotencyCalculator.Calculate(manager), Is.EqualTo(1)); } } diff --git a/Libiada.Clusterizator.Tests/Krab/Calculators/LambdaCalculatorTests.cs b/Libiada.Clusterizator.Tests/Krab/Calculators/LambdaCalculatorTests.cs index 4ea69405..6804ad77 100644 --- a/Libiada.Clusterizator.Tests/Krab/Calculators/LambdaCalculatorTests.cs +++ b/Libiada.Clusterizator.Tests/Krab/Calculators/LambdaCalculatorTests.cs @@ -15,19 +15,19 @@ public class LambdaCalculatorTests [Test] public void ThreePointsTest() { - var node1 = new GraphElement(new[] { 15.0 }, "node1"); - var node2 = new GraphElement(new[] { 10.0 }, "node2"); - var node3 = new GraphElement(new[] { -3.0 }, "node3"); + GraphElement node1 = new([15.0], "node1"); + GraphElement node2 = new([10.0], "node2"); + GraphElement node3 = new([-3.0], "node3"); - var el = new List { node1, node2, node3 }; + List el = [node1, node2, node3]; - var conn1 = new Connection(0, 1); - var conn2 = new Connection(0, 2); - var conn3 = new Connection(1, 2); + Connection conn1 = new(0, 1); + Connection conn2 = new(0, 2); + Connection conn3 = new(1, 2); - var graph = new List { conn1, conn2, conn3 }; + List graph = [conn1, conn2, conn3]; - var gm = new GraphManager(graph, el); + GraphManager gm = new(graph, el); ICalculator calculator = new LinearCalculator(); calculator.Calculate(gm); @@ -37,11 +37,15 @@ public void ThreePointsTest() calculator.Calculate(gm); calculator = new TauCalculator(); calculator.Calculate(gm); - var lambdaCalculator = new LambdaCalculator(); + LambdaCalculator lambdaCalculator = new(); lambdaCalculator.Calculate(gm, 2, 1); - Assert.AreEqual(57, Math.Round(gm.Connections[0].Lambda * 1000)); - Assert.AreEqual(678, Math.Round(gm.Connections[2].Lambda * 100)); - Assert.AreEqual(18, gm.Connections[1].Lambda); + + Assert.Multiple(() => + { + Assert.That(gm.Connections[0].Lambda, Is.EqualTo(0.057).Within(0.0001d)); + Assert.That(gm.Connections[1].Lambda, Is.EqualTo(18)); + Assert.That(gm.Connections[2].Lambda, Is.EqualTo(6.78).Within(0.001d)); + }); } /// @@ -50,19 +54,19 @@ public void ThreePointsTest() [Test] public void ThreePoints3DTest() { - var node1 = new GraphElement(new[] { 15.0, 1.0, -20.0 }, "node1"); - var node2 = new GraphElement(new[] { 0.0, -3.0, -4.0 }, "node2"); - var node3 = new GraphElement(new[] { 15.0, 1.0, -25.0 }, "node3"); + GraphElement node1 = new([15.0, 1.0, -20.0], "node1"); + GraphElement node2 = new([0.0, -3.0, -4.0], "node2"); + GraphElement node3 = new([15.0, 1.0, -25.0], "node3"); - var el = new List { node1, node2, node3 }; + List el = [node1, node2, node3]; - var conn1 = new Connection(0, 1); - var conn2 = new Connection(0, 2); - var conn3 = new Connection(1, 2); + Connection conn1 = new(0, 1); + Connection conn2 = new(0, 2); + Connection conn3 = new(1, 2); - var graph = new List { conn1, conn2, conn3 }; + List graph = [conn1, conn2, conn3]; - var gm = new GraphManager(graph, el); + GraphManager gm = new(graph, el); ICalculator calculator = new LinearCalculator(); calculator.Calculate(gm); @@ -72,10 +76,14 @@ public void ThreePoints3DTest() calculator.Calculate(gm); calculator = new TauCalculator(); calculator.Calculate(gm); - var lambdaCalculator = new LambdaCalculator(); + LambdaCalculator lambdaCalculator = new(); lambdaCalculator.Calculate(gm, 2, 1); - Assert.AreEqual(1625, Math.Round(gm.Connections[0].Lambda * 100)); - Assert.AreEqual(9, Math.Round(gm.Connections[1].Lambda * 1000)); - Assert.AreEqual(2612, Math.Round(gm.Connections[2].Lambda * 100)); + + Assert.Multiple(() => + { + Assert.That(gm.Connections[0].Lambda, Is.EqualTo(16.25).Within(0.01d)); + Assert.That(gm.Connections[1].Lambda, Is.EqualTo(0.009).Within(0.001d)); + Assert.That(gm.Connections[2].Lambda, Is.EqualTo(26.12).Within(0.01d)); + }); } } diff --git a/Libiada.Clusterizator.Tests/Krab/Calculators/LinearCalculatorTests.cs b/Libiada.Clusterizator.Tests/Krab/Calculators/LinearCalculatorTests.cs index ac8fd6ec..9b5b1592 100644 --- a/Libiada.Clusterizator.Tests/Krab/Calculators/LinearCalculatorTests.cs +++ b/Libiada.Clusterizator.Tests/Krab/Calculators/LinearCalculatorTests.cs @@ -15,19 +15,19 @@ public class LinearCalculatorTests [Test] public void TwoPointsTest() { - var node1 = new GraphElement(new[] { 15.0 }, "node1"); - var node2 = new GraphElement(new[] { 15.0 }, "node2"); + GraphElement node1 = new([15.0], "node1"); + GraphElement node2 = new([15.0], "node2"); - var el = new List { node1, node2 }; + List el = [node1, node2]; - var conn1 = new Connection(0, 1); - var con = new List { conn1 }; + Connection conn1 = new(0, 1); + List con = [conn1]; - var gm = new GraphManager(con, el); + GraphManager gm = new(con, el); - var calculator = new LinearCalculator(); + LinearCalculator calculator = new(); calculator.Calculate(gm); - Assert.AreEqual(0, gm.Connections[0].Distance); + Assert.That(gm.Connections[0].Distance, Is.Zero); } /// @@ -36,18 +36,18 @@ public void TwoPointsTest() [Test] public void TwoIntPointsTest() { - var node1 = new GraphElement(new[] { 15.0 }, "node1"); - var node2 = new GraphElement(new[] { 15.0 }, "node2"); - var el = new List { node1, node2 }; + GraphElement node1 = new([15.0], "node1"); + GraphElement node2 = new([15.0], "node2"); + List el = [node1, node2]; - var conn1 = new Connection(0, 1); - var con = new List { conn1 }; + Connection conn1 = new(0, 1); + List con = [conn1]; - var gm = new GraphManager(con, el); + GraphManager gm = new(con, el); - var calculator = new LinearCalculator(); + LinearCalculator calculator = new(); calculator.Calculate(gm); - Assert.AreEqual(0, gm.Connections[0].Distance); + Assert.That(gm.Connections[0].Distance, Is.Zero); } /// @@ -56,25 +56,29 @@ public void TwoIntPointsTest() [Test] public void ThreePointsTest() { - var node1 = new GraphElement(new[] { 15.0 }, "node1"); - var node2 = new GraphElement(new[] { 10.0 }, "node2"); - var node3 = new GraphElement(new[] { -3.0 }, "node3"); + GraphElement node1 = new([15.0], "node1"); + GraphElement node2 = new([10.0], "node2"); + GraphElement node3 = new([-3.0], "node3"); - var el = new List { node1, node2, node3 }; + List el = [node1, node2, node3]; - var conn1 = new Connection(0, 1); - var conn2 = new Connection(1, 2); - var conn3 = new Connection(0, 2); + Connection conn1 = new(0, 1); + Connection conn2 = new(1, 2); + Connection conn3 = new(0, 2); - var con = new List { conn1, conn2, conn3 }; + List con = [conn1, conn2, conn3]; - var gm = new GraphManager(con, el); + GraphManager gm = new(con, el); - var calculator = new LinearCalculator(); + LinearCalculator calculator = new(); calculator.Calculate(gm); - Assert.AreEqual(5, gm.Connections[0].Distance); - Assert.AreEqual(13, gm.Connections[1].Distance); - Assert.AreEqual(18, gm.Connections[2].Distance); + + Assert.Multiple(() => + { + Assert.That(gm.Connections[0].Distance, Is.EqualTo(5)); + Assert.That(gm.Connections[1].Distance, Is.EqualTo(13)); + Assert.That(gm.Connections[2].Distance, Is.EqualTo(18)); + }); } /// @@ -83,20 +87,21 @@ public void ThreePointsTest() [Test] public void TwoPoints3DTest() { - var node1 = new GraphElement(new[] { 15.0, 1.0, -20.0 }, "node1"); - var node2 = new GraphElement(new[] { 0.0, -3.0, -4.0 }, "node2"); + GraphElement node1 = new([15.0, 1.0, -20.0], "node1"); + GraphElement node2 = new([0.0, -3.0, -4.0], "node2"); - var el = new List { node1, node2 }; + List el = [node1, node2]; - var conn1 = new Connection(0, 1); + Connection conn1 = new(0, 1); - var con = new List { conn1 }; + List con = [conn1]; - var gm = new GraphManager(con, el); + GraphManager gm = new(con, el); - var calculator = new LinearCalculator(); + LinearCalculator calculator = new(); calculator.Calculate(gm); - Assert.AreEqual(22293, Math.Round(gm.Connections[0].Distance * 1000)); + + Assert.That(gm.Connections[0].Distance, Is.EqualTo(22.293).Within(0.001d)); } /// @@ -105,23 +110,27 @@ public void TwoPoints3DTest() [Test] public void ThreePoints3DTest() { - var node1 = new GraphElement(new[] { 15.0, 1.0, -20.0 }, "node1"); - var node2 = new GraphElement(new[] { 0.0, -3.0, -4.0 }, "node2"); - var node3 = new GraphElement(new[] { 15.0, 1.0, -20.0 }, "node3"); + GraphElement node1 = new([15.0, 1.0, -20.0], "node1"); + GraphElement node2 = new([0.0, -3.0, -4.0], "node2"); + GraphElement node3 = new([15.0, 1.0, -20.0], "node3"); - var el = new List { node1, node2, node3 }; + List el = [node1, node2, node3]; - var conn1 = new Connection(0, 1); - var conn2 = new Connection(0, 2); - var conn3 = new Connection(1, 2); - var con = new List { conn1, conn2, conn3 }; + Connection conn1 = new(0, 1); + Connection conn2 = new(0, 2); + Connection conn3 = new(1, 2); + List con = [conn1, conn2, conn3]; - var gm = new GraphManager(con, el); + GraphManager gm = new(con, el); - var calculator = new LinearCalculator(); + LinearCalculator calculator = new(); calculator.Calculate(gm); - Assert.AreEqual(22293, Math.Round(gm.Connections[0].Distance * 1000)); - Assert.AreEqual(0, Math.Round(gm.Connections[1].Distance * 1000)); - Assert.AreEqual(22293, Math.Round(gm.Connections[2].Distance * 1000)); + + Assert.Multiple(() => + { + Assert.That(gm.Connections[0].Distance, Is.EqualTo(22.293).Within(0.001d)); + Assert.That(gm.Connections[1].Distance, Is.Zero); + Assert.That(gm.Connections[2].Distance, Is.EqualTo(22.293).Within(0.001d)); + }); } } diff --git a/Libiada.Clusterizator.Tests/Krab/Calculators/NormalizedLinearCalculatorTests.cs b/Libiada.Clusterizator.Tests/Krab/Calculators/NormalizedLinearCalculatorTests.cs index e36d1f76..c6fc131e 100644 --- a/Libiada.Clusterizator.Tests/Krab/Calculators/NormalizedLinearCalculatorTests.cs +++ b/Libiada.Clusterizator.Tests/Krab/Calculators/NormalizedLinearCalculatorTests.cs @@ -15,22 +15,23 @@ public class NormalizedLinearCalculatorTests [Test] public void TwoPointsTest() { - var node1 = new GraphElement(new[] { 15.0 }, "node1"); - var node2 = new GraphElement(new[] { 20.0 }, "node2"); + GraphElement node1 = new([15.0], "node1"); + GraphElement node2 = new([20.0], "node2"); - var el = new List { node1, node2 }; + List el = [node1, node2]; - var conn1 = new Connection(0, 1); - var graph = new List { conn1 }; + Connection conn1 = new(0, 1); + List graph = [conn1]; - var gm = new GraphManager(graph, el); + GraphManager gm = new(graph, el); ICalculator calculator = new LinearCalculator(); calculator.Calculate(gm); calculator = new NormalizedLinearCalculator(); calculator.Calculate(gm); - Assert.AreEqual(1, gm.Connections[0].NormalizedDistance); + + Assert.That(gm.Connections[0].NormalizedDistance, Is.EqualTo(1)); } /// @@ -39,22 +40,23 @@ public void TwoPointsTest() [Test] public void TwoIntPointsTest() { - var node1 = new GraphElement(new[] { 15.0 }, "node1"); - var node2 = new GraphElement(new[] { 20.0 }, "node2"); + GraphElement node1 = new([15.0], "node1"); + GraphElement node2 = new([20.0], "node2"); - var el = new List { node1, node2 }; + List el = [node1, node2]; - var conn1 = new Connection(0, 1); + Connection conn1 = new(0, 1); - var graph = new List { conn1 }; + List graph = [conn1]; - var gm = new GraphManager(graph, el); + GraphManager gm = new(graph, el); ICalculator calculator = new LinearCalculator(); calculator.Calculate(gm); calculator = new NormalizedLinearCalculator(); calculator.Calculate(gm); - Assert.AreEqual(1, gm.Connections[0].NormalizedDistance); + + Assert.That(gm.Connections[0].NormalizedDistance, Is.EqualTo(1)); } /// @@ -63,27 +65,31 @@ public void TwoIntPointsTest() [Test] public void ThreePointsTest() { - var node1 = new GraphElement(new[] { 15.0 }, "node1"); - var node2 = new GraphElement(new[] { 10.0 }, "node2"); - var node3 = new GraphElement(new[] { -3.0 }, "node3"); + GraphElement node1 = new([15.0], "node1"); + GraphElement node2 = new([10.0], "node2"); + GraphElement node3 = new([-3.0], "node3"); - var el = new List { node1, node2, node3 }; + List el = [node1, node2, node3]; - var conn1 = new Connection(0, 1); - var conn2 = new Connection(1, 2); - var conn3 = new Connection(0, 2); + Connection conn1 = new(0, 1); + Connection conn2 = new(1, 2); + Connection conn3 = new(0, 2); - var graph = new List { conn1, conn2, conn3 }; + List graph = [conn1, conn2, conn3]; - var gm = new GraphManager(graph, el); + GraphManager gm = new(graph, el); ICalculator calculator = new LinearCalculator(); calculator.Calculate(gm); calculator = new NormalizedLinearCalculator(); calculator.Calculate(gm); - Assert.AreEqual(278, Math.Round(gm.Connections[0].NormalizedDistance * 1000)); - Assert.AreEqual(722, Math.Round(gm.Connections[1].NormalizedDistance * 1000)); - Assert.AreEqual(1, gm.Connections[2].NormalizedDistance); + + Assert.Multiple(() => + { + Assert.That(gm.Connections[0].NormalizedDistance, Is.EqualTo(0.278).Within(0.001d)); + Assert.That(gm.Connections[1].NormalizedDistance, Is.EqualTo(0.722).Within(0.001d)); + Assert.That(gm.Connections[2].NormalizedDistance, Is.EqualTo(1)); + }); } /// @@ -92,22 +98,23 @@ public void ThreePointsTest() [Test] public void TwoPoints3DTest() { - var node1 = new GraphElement(new[] { 15.0, 1.0, -20.0 }, "node1"); - var node2 = new GraphElement(new[] { 0.0, -3.0, -4.0 }, "node2"); + GraphElement node1 = new([15.0, 1.0, -20.0], "node1"); + GraphElement node2 = new([0.0, -3.0, -4.0], "node2"); - var el = new List { node1, node2 }; + List el = [node1, node2]; - var conn1 = new Connection(0, 1); + Connection conn1 = new(0, 1); - var graph = new List { conn1 }; + List graph = [conn1]; - var gm = new GraphManager(graph, el); + GraphManager gm = new(graph, el); ICalculator calculator = new LinearCalculator(); calculator.Calculate(gm); calculator = new NormalizedLinearCalculator(); calculator.Calculate(gm); - Assert.AreEqual(1, gm.Connections[0].NormalizedDistance); + + Assert.That(gm.Connections[0].NormalizedDistance, Is.EqualTo(1)); } /// @@ -116,26 +123,27 @@ public void TwoPoints3DTest() [Test] public void ThreePoints3DTest() { - var node1 = new GraphElement(new[] { 15.0, 1.0, -20.0 }, "node1"); - var node2 = new GraphElement(new[] { 0.0, -3.0, -4.0 }, "node2"); - var node3 = new GraphElement(new[] { 15.0, 1.0, -20.0 }, "node3"); + GraphElement node1 = new([15.0, 1.0, -20.0], "node1"); + GraphElement node2 = new([0.0, -3.0, -4.0], "node2"); + GraphElement node3 = new([15.0, 1.0, -20.0], "node3"); - var el = new List { node1, node2, node3 }; + List el = [node1, node2, node3]; - var conn1 = new Connection(0, 1); - var conn2 = new Connection(0, 2); - var conn3 = new Connection(1, 2); + Connection conn1 = new(0, 1); + Connection conn2 = new(0, 2); + Connection conn3 = new(1, 2); - var graph = new List { conn1, conn2, conn3 }; + List graph = [conn1, conn2, conn3]; - var gm = new GraphManager(graph, el); + GraphManager gm = new(graph, el); ICalculator calculator = new LinearCalculator(); calculator.Calculate(gm); calculator = new NormalizedLinearCalculator(); calculator.Calculate(gm); - Assert.AreEqual(1, gm.Connections[0].NormalizedDistance); - Assert.AreEqual(0, gm.Connections[1].NormalizedDistance); - Assert.AreEqual(1, gm.Connections[2].NormalizedDistance); + + Assert.That(gm.Connections[0].NormalizedDistance, Is.EqualTo(1)); + Assert.That(gm.Connections[1].NormalizedDistance, Is.Zero); + Assert.That(gm.Connections[2].NormalizedDistance, Is.EqualTo(1)); } } diff --git a/Libiada.Clusterizator.Tests/Krab/Calculators/TauCalculatorTests.cs b/Libiada.Clusterizator.Tests/Krab/Calculators/TauCalculatorTests.cs index c3fb88c2..2f063549 100644 --- a/Libiada.Clusterizator.Tests/Krab/Calculators/TauCalculatorTests.cs +++ b/Libiada.Clusterizator.Tests/Krab/Calculators/TauCalculatorTests.cs @@ -15,19 +15,19 @@ public class TauCalculatorTests [Test] public void ThreePointsTest() { - var node1 = new GraphElement(new[] { 15.0 }, "node1"); - var node2 = new GraphElement(new[] { 10.0 }, "node2"); - var node3 = new GraphElement(new[] { -3.0 }, "node3"); + GraphElement node1 = new([15.0], "node1"); + GraphElement node2 = new([10.0], "node2"); + GraphElement node3 = new([-3.0], "node3"); - var el = new List { node1, node2, node3 }; + List el = [node1, node2, node3]; - var conn1 = new Connection(0, 1); - var conn2 = new Connection(0, 2); - var conn3 = new Connection(1, 2); + Connection conn1 = new(0, 1); + Connection conn2 = new(0, 2); + Connection conn3 = new(1, 2); - var graph = new List { conn1, conn2, conn3 }; + List graph = [conn1, conn2, conn3]; - var gm = new GraphManager(graph, el); + GraphManager gm = new(graph, el); ICalculator calculator = new LinearCalculator(); calculator.Calculate(gm); @@ -37,9 +37,13 @@ public void ThreePointsTest() calculator.Calculate(gm); calculator = new TauCalculator(); calculator.Calculate(gm); - Assert.AreEqual(107, Math.Round(gm.Connections[0].Tau * 1000)); - Assert.AreEqual(722, Math.Round(gm.Connections[2].Tau * 1000)); - Assert.AreEqual(1, gm.Connections[1].Tau); + + Assert.Multiple(() => + { + Assert.That(gm.Connections[0].Tau, Is.EqualTo(0.107).Within(0.001d)); + Assert.That(gm.Connections[1].Tau, Is.EqualTo(1)); + Assert.That(gm.Connections[2].Tau, Is.EqualTo(0.722).Within(0.001d)); + }); } /// @@ -48,19 +52,19 @@ public void ThreePointsTest() [Test] public void ThreePoints3DTest() { - var node1 = new GraphElement(new[] { 15.0, 1.0, -20.0 }, "node1"); - var node2 = new GraphElement(new[] { 0.0, -3.0, -4.0 }, "node2"); - var node3 = new GraphElement(new[] { 15.0, 1.0, -25.0 }, "node3"); + GraphElement node1 = new([15.0, 1.0, -20.0], "node1"); + GraphElement node2 = new([0.0, -3.0, -4.0], "node2"); + GraphElement node3 = new([15.0, 1.0, -25.0], "node3"); - var el = new List { node1, node2, node3 }; + List el = [node1, node2, node3]; - var conn1 = new Connection(0, 1); - var conn2 = new Connection(0, 2); - var conn3 = new Connection(1, 2); + Connection conn1 = new(0, 1); + Connection conn2 = new(0, 2); + Connection conn3 = new(1, 2); - var graph = new List { conn1, conn2, conn3 }; + List graph = [conn1, conn2, conn3]; - var gm = new GraphManager(graph, el); + GraphManager gm = new(graph, el); ICalculator calculator = new LinearCalculator(); @@ -71,8 +75,12 @@ public void ThreePoints3DTest() calculator.Calculate(gm); calculator = new TauCalculator(); calculator.Calculate(gm); - Assert.AreEqual(854, Math.Round(gm.Connections[0].Tau * 1000)); - Assert.AreEqual(43, Math.Round(gm.Connections[1].Tau * 1000)); - Assert.AreEqual(1, gm.Connections[2].Tau); + + Assert.Multiple(() => + { + Assert.That(gm.Connections[0].Tau, Is.EqualTo(0.854).Within(0.001d)); + Assert.That(gm.Connections[1].Tau, Is.EqualTo(0.043).Within(0.001d)); + Assert.That(gm.Connections[2].Tau, Is.EqualTo(1)); + }); } } diff --git a/Libiada.Clusterizator.Tests/Krab/Calculators/TauStarCalculatorTests.cs b/Libiada.Clusterizator.Tests/Krab/Calculators/TauStarCalculatorTests.cs index 56cfbcab..377ac7d7 100644 --- a/Libiada.Clusterizator.Tests/Krab/Calculators/TauStarCalculatorTests.cs +++ b/Libiada.Clusterizator.Tests/Krab/Calculators/TauStarCalculatorTests.cs @@ -15,21 +15,21 @@ public class TauStarCalculatorTests [Test] public void ThreePointsTest() { - var node1 = new GraphElement(new[] { 15.0 }, "node1"); + GraphElement node1 = new([15.0], "node1"); - var node2 = new GraphElement(new[] { 10.0 }, "node2"); + GraphElement node2 = new([10.0], "node2"); - var node3 = new GraphElement(new[] { -3.0 }, "node3"); + GraphElement node3 = new([-3.0], "node3"); - var el = new List { node1, node2, node3 }; + List el = [node1, node2, node3]; - var conn1 = new Connection(0, 1); - var conn2 = new Connection(0, 2); - var conn3 = new Connection(1, 2); + Connection conn1 = new(0, 1); + Connection conn2 = new(0, 2); + Connection conn3 = new(1, 2); - var graph = new List { conn1, conn2, conn3 }; + List graph = [conn1, conn2, conn3]; - var gm = new GraphManager(graph, el); + GraphManager gm = new(graph, el); ICalculator calculator = new LinearCalculator(); calculator.Calculate(gm); @@ -37,30 +37,34 @@ public void ThreePointsTest() calculator.Calculate(gm); calculator = new TauStarCalculator(); calculator.Calculate(gm); - Assert.AreEqual(385, Math.Round(gm.Connections[0].TauStar * 1000)); - Assert.AreEqual(3.6, gm.Connections[1].TauStar); - Assert.AreEqual(2.6, gm.Connections[2].TauStar); + + Assert.Multiple(() => + { + Assert.That(gm.Connections[0].TauStar, Is.EqualTo(0.385).Within(0.001d)); + Assert.That(gm.Connections[1].TauStar, Is.EqualTo(3.6).Within(0.00001d)); + Assert.That(gm.Connections[2].TauStar, Is.EqualTo(2.6).Within(0.00001d)); + }); } /// - /// The three points 3 d test. + /// The three points 3d test. /// [Test] public void ThreePoints3DTest() { - var node1 = new GraphElement(new[] { 15.0, 1.0, -20.0 }, "node1"); - var node2 = new GraphElement(new[] { 0.0, -3.0, -4.0 }, "node2"); - var node3 = new GraphElement(new[] { 15.0, 1.0, -25.0 }, "node3"); + GraphElement node1 = new([15.0, 1.0, -20.0], "node1"); + GraphElement node2 = new([0.0, -3.0, -4.0], "node2"); + GraphElement node3 = new([15.0, 1.0, -25.0], "node3"); - var el = new List { node1, node2, node3 }; + List el = [node1, node2, node3]; - var conn1 = new Connection(0, 1); - var conn2 = new Connection(0, 2); - var conn3 = new Connection(1, 2); + Connection conn1 = new(0, 1); + Connection conn2 = new(0, 2); + Connection conn3 = new(1, 2); - var graph = new List { conn1, conn2, conn3 }; + List graph = [conn1, conn2, conn3]; - var gm = new GraphManager(graph, el); + GraphManager gm = new(graph, el); ICalculator calculator = new LinearCalculator(); calculator.Calculate(gm); @@ -68,8 +72,12 @@ public void ThreePoints3DTest() calculator.Calculate(gm); calculator = new TauStarCalculator(); calculator.Calculate(gm); - Assert.AreEqual(4459, Math.Round(gm.Connections[0].TauStar * 1000)); - Assert.AreEqual(224, Math.Round(gm.Connections[1].TauStar * 1000)); - Assert.AreEqual(5223, Math.Round(gm.Connections[2].TauStar * 1000)); + + Assert.Multiple(() => + { + Assert.That(gm.Connections[0].TauStar, Is.EqualTo(4.459).Within(0.001d)); + Assert.That(gm.Connections[1].TauStar, Is.EqualTo(0.224).Within(0.001d)); + Assert.That(gm.Connections[2].TauStar, Is.EqualTo(5.223).Within(0.001d)); + }); } } diff --git a/Libiada.Clusterizator.Tests/Krab/ConnectionTests.cs b/Libiada.Clusterizator.Tests/Krab/ConnectionTests.cs index 167bef7c..b1a7a92a 100644 --- a/Libiada.Clusterizator.Tests/Krab/ConnectionTests.cs +++ b/Libiada.Clusterizator.Tests/Krab/ConnectionTests.cs @@ -14,8 +14,8 @@ public class ConnectionTests [Test] public void ConnectionOneTest() { - var conn1 = new Connection(0, 1); - Assert.IsFalse(conn1.Connected); + var connection = new Connection(0, 1); + Assert.That(connection.Connected, Is.False); } /// @@ -24,7 +24,7 @@ public void ConnectionOneTest() [Test] public void CloneOneTest() { - var conn1 = new Connection(2, 5) + var connection = new Connection(2, 5) { Connected = false, Distance = 6, @@ -33,17 +33,21 @@ public void CloneOneTest() TauStar = 7, Lambda = 13 }; - var conn2 = conn1.Clone(); - Assert.AreEqual(conn1.Connected, conn2.Connected); - Assert.AreEqual(conn1.FirstElementIndex, conn2.FirstElementIndex); - Assert.AreEqual(conn1.SecondElementIndex, conn2.SecondElementIndex); - Assert.AreEqual(conn1.Distance, conn2.Distance); - Assert.AreEqual(conn1.NormalizedDistance, conn2.NormalizedDistance); - Assert.AreEqual(conn1.Tau, conn2.Tau); - Assert.AreEqual(conn1.TauStar, conn2.TauStar); - Assert.AreEqual(conn1.Lambda, conn2.Lambda); - Assert.IsInstanceOf(typeof(Connection), conn2); - Assert.AreNotSame(conn1, conn2); + var secondConnection = connection.Clone(); + Assert.Multiple(() => + { + Assert.That(connection.Connected, Is.EqualTo(secondConnection.Connected)); + Assert.That(connection.FirstElementIndex, Is.EqualTo(secondConnection.FirstElementIndex)); + Assert.That(connection.SecondElementIndex, Is.EqualTo(secondConnection.SecondElementIndex)); + Assert.That(connection.Distance, Is.EqualTo(secondConnection.Distance)); + Assert.That(connection.NormalizedDistance, Is.EqualTo(secondConnection.NormalizedDistance)); + Assert.That(connection.Tau, Is.EqualTo(secondConnection.Tau)); + Assert.That(connection.TauStar, Is.EqualTo(secondConnection.TauStar)); + Assert.That(connection.Lambda, Is.EqualTo(secondConnection.Lambda)); + Assert.That(secondConnection, Is.TypeOf(typeof(Connection))); + Assert.That(secondConnection, Is.Not.SameAs(connection)); + }); + } /// @@ -52,7 +56,7 @@ public void CloneOneTest() [Test] public void CloneTwoTest() { - var conn1 = new Connection(2, 3) + var connection = new Connection(2, 3) { Connected = true, Distance = 1, @@ -61,16 +65,19 @@ public void CloneTwoTest() TauStar = 0, Lambda = 5 }; - var conn2 = conn1.Clone(); - Assert.AreEqual(conn1.Connected, conn2.Connected); - Assert.AreEqual(conn1.FirstElementIndex, conn2.FirstElementIndex); - Assert.AreEqual(conn1.SecondElementIndex, conn2.SecondElementIndex); - Assert.AreEqual(conn1.Distance, conn2.Distance); - Assert.AreEqual(conn1.NormalizedDistance, conn2.NormalizedDistance); - Assert.AreEqual(conn1.Tau, conn2.Tau); - Assert.AreEqual(conn1.TauStar, conn2.TauStar); - Assert.AreEqual(conn1.Lambda, conn2.Lambda); - Assert.IsInstanceOf(typeof(Connection), conn2); - Assert.AreNotSame(conn1, conn2); + var secondConnection = connection.Clone(); + Assert.Multiple(() => + { + Assert.That(connection.Connected, Is.EqualTo(secondConnection.Connected)); + Assert.That(connection.FirstElementIndex, Is.EqualTo(secondConnection.FirstElementIndex)); + Assert.That(connection.SecondElementIndex, Is.EqualTo(secondConnection.SecondElementIndex)); + Assert.That(connection.Distance, Is.EqualTo(secondConnection.Distance)); + Assert.That(connection.NormalizedDistance, Is.EqualTo(secondConnection.NormalizedDistance)); + Assert.That(connection.Tau, Is.EqualTo(secondConnection.Tau)); + Assert.That(connection.TauStar, Is.EqualTo(secondConnection.TauStar)); + Assert.That(connection.Lambda, Is.EqualTo(secondConnection.Lambda)); + Assert.That(secondConnection, Is.TypeOf(typeof(Connection))); + Assert.That(secondConnection, Is.Not.SameAs(connection)); + }); } } diff --git a/Libiada.Clusterizator.Tests/Krab/GraphElementTests.cs b/Libiada.Clusterizator.Tests/Krab/GraphElementTests.cs index 541f0b45..0e82ab4e 100644 --- a/Libiada.Clusterizator.Tests/Krab/GraphElementTests.cs +++ b/Libiada.Clusterizator.Tests/Krab/GraphElementTests.cs @@ -14,10 +14,10 @@ public class GraphElementTests [Test] public void NodeTest() { - var node = new GraphElement(new[] { 15.0 }, "node"); + var node = new GraphElement([15.0], "node"); - Assert.AreEqual(15, node.Content[0]); - Assert.AreEqual(0, node.TaxonNumber); + Assert.That(node.Content[0], Is.EqualTo(15)); + Assert.That(node.TaxonNumber, Is.Zero); } /// @@ -26,18 +26,17 @@ public void NodeTest() [Test] public void NodeTwoTest() { - var node = new GraphElement(new[] { 15.0 }, 1) { TaxonNumber = 5 }; + var node = new GraphElement([15.0], 1) { TaxonNumber = 5 }; - Assert.AreEqual(15, node.Content[0]); + Assert.That(node.Content[0], Is.EqualTo(15)); - node.Content = new[] { -8.0 }; + node.Content = [-8.0]; - Assert.AreEqual(-8, node.Content[0]); - - Assert.AreEqual(5, node.TaxonNumber); + Assert.That(node.Content[0], Is.EqualTo(-8)); + Assert.That(node.TaxonNumber, Is.EqualTo(5)); node.TaxonNumber = -5; - Assert.AreEqual(5, node.TaxonNumber); + Assert.That(node.TaxonNumber, Is.EqualTo(5)); } /// @@ -46,11 +45,16 @@ public void NodeTwoTest() [Test] public void CloneTest() { - var node = new GraphElement(new[] { 15.0 }, "node"); + var node = new GraphElement([15.0], "node"); var nodeClone = node.Clone(); - Assert.AreEqual(node.Content, nodeClone.Content); - Assert.AreEqual(node.Id, nodeClone.Id); - Assert.AreNotSame(node, nodeClone); - Assert.IsInstanceOf(typeof(GraphElement), nodeClone); + + Assert.Multiple(() => + { + Assert.That(nodeClone.Content, Is.EqualTo(node.Content)); + Assert.That(nodeClone.Id, Is.EqualTo(node.Id)); + Assert.That(nodeClone, Is.Not.SameAs(node)); + Assert.That(nodeClone, Is.TypeOf(typeof(GraphElement))); + }); + } } diff --git a/Libiada.Clusterizator.Tests/Krab/GraphManagerTests.cs b/Libiada.Clusterizator.Tests/Krab/GraphManagerTests.cs index a9c7fa6e..76ec70ba 100644 --- a/Libiada.Clusterizator.Tests/Krab/GraphManagerTests.cs +++ b/Libiada.Clusterizator.Tests/Krab/GraphManagerTests.cs @@ -24,34 +24,32 @@ public class GraphManagerTests [SetUp] public void Initialization() { - elementsList = new List - { - new GraphElement(new[] { 2.0, 3.0 }, "1"), - new GraphElement(new[] { 3.0, 5.0 }, "2"), - new GraphElement(new[] { 6.0, 2.0 }, "3"), - new GraphElement(new[] { 6.0, 5.0 }, "4"), - new GraphElement(new[] { 7.0, 4.0 }, "5"), - new GraphElement(new[] { 8.0, 3.0 }, "6") - }; + elementsList = [ + new GraphElement([2.0, 3.0], "1"), + new GraphElement([3.0, 5.0], "2"), + new GraphElement([6.0, 2.0], "3"), + new GraphElement([6.0, 5.0], "4"), + new GraphElement([7.0, 4.0], "5"), + new GraphElement([8.0, 3.0], "6") + ]; - connectionsList = new List - { - new Connection(0, 1), - new Connection(0, 2), - new Connection(0, 3), - new Connection(0, 4), - new Connection(0, 5), - new Connection(1, 2), - new Connection(1, 3), - new Connection(1, 4), - new Connection(1, 5), - new Connection(2, 3), - new Connection(2, 4), - new Connection(2, 5), - new Connection(3, 4), - new Connection(3, 5), - new Connection(4, 5) - }; + connectionsList = [ + new Connection(0, 1), + new Connection(0, 2), + new Connection(0, 3), + new Connection(0, 4), + new Connection(0, 5), + new Connection(1, 2), + new Connection(1, 3), + new Connection(1, 4), + new Connection(1, 5), + new Connection(2, 3), + new Connection(2, 4), + new Connection(2, 5), + new Connection(3, 4), + new Connection(3, 5), + new Connection(4, 5) + ]; connectionsList[0].Connected = true; connectionsList[14].Connected = true; @@ -69,9 +67,10 @@ public void UnConnectedGraphsTest() { var connector = new GraphManager(connectionsList, elementsList); connector.Connect(2, 3); - Assert.IsTrue(connectionsList[9].Connected); - Assert.AreEqual(3, elementsList[2].TaxonNumber); - Assert.AreEqual(3, elementsList[3].TaxonNumber); + + Assert.That(connectionsList[9].Connected, Is.True); + Assert.That(elementsList[2].TaxonNumber, Is.EqualTo(3)); + Assert.That(elementsList[3].TaxonNumber, Is.EqualTo(3)); } /// @@ -81,13 +80,13 @@ public void UnConnectedGraphsTest() public void SearchConnectionTest() { var connector = new GraphManager(connectionsList, elementsList); - Assert.AreEqual(-1, connector.SearchConnection(elementsList[0], elementsList[0]), "Search fault failure"); - Assert.AreEqual(-1, connector.SearchConnection(elementsList[4], elementsList[4]), "Search fault failure"); - Assert.AreEqual(0, connector.SearchConnection(elementsList[0], elementsList[1]), "Search fault failure"); - Assert.AreEqual(0, connector.SearchConnection(elementsList[1], elementsList[0]), "Search fault failure"); - Assert.AreEqual(14, connector.SearchConnection(elementsList[4], elementsList[5]), "Search fault failure"); - Assert.AreEqual(14, connector.SearchConnection(elementsList[5], elementsList[4]), "Search fault failure"); - Assert.AreEqual(0, connector.SearchConnection(elementsList[1], elementsList[0]), "Search fault failure"); + Assert.That(connector.SearchConnection(elementsList[0], elementsList[0]), Is.EqualTo(-1)); + Assert.That(connector.SearchConnection(elementsList[4], elementsList[4]), Is.EqualTo(-1)); + Assert.That(connector.SearchConnection(elementsList[0], elementsList[1]), Is.Zero); + Assert.That(connector.SearchConnection(elementsList[1], elementsList[0]), Is.Zero); + Assert.That(connector.SearchConnection(elementsList[4], elementsList[5]), Is.EqualTo(14)); + Assert.That(connector.SearchConnection(elementsList[5], elementsList[4]), Is.EqualTo(14)); + Assert.That(connector.SearchConnection(elementsList[1], elementsList[0]), Is.Zero); } /// @@ -98,10 +97,11 @@ public void OneConnectedGraphTest() { var connector = new GraphManager(connectionsList, elementsList); connector.Connect(0, 2); - Assert.IsTrue(connectionsList[1].Connected); - Assert.AreEqual(1, elementsList[0].TaxonNumber); - Assert.AreEqual(1, elementsList[1].TaxonNumber); - Assert.AreEqual(1, elementsList[2].TaxonNumber); + + Assert.That(connectionsList[1].Connected, Is.True); + Assert.That(elementsList[0].TaxonNumber, Is.EqualTo(1)); + Assert.That(elementsList[1].TaxonNumber, Is.EqualTo(1)); + Assert.That(elementsList[2].TaxonNumber, Is.EqualTo(1)); } /// @@ -112,11 +112,11 @@ public void BothConnectionGraphTest() { var connector = new GraphManager(connectionsList, elementsList); connector.Connect(1, 5); - Assert.IsTrue(connectionsList[8].Connected); - Assert.AreEqual(1, elementsList[5].TaxonNumber); - Assert.AreEqual(1, elementsList[1].TaxonNumber); - Assert.AreEqual(1, elementsList[4].TaxonNumber); - Assert.AreEqual(1, elementsList[5].TaxonNumber); + Assert.That(connectionsList[8].Connected, Is.True); + Assert.That(elementsList[0].TaxonNumber, Is.EqualTo(1)); + Assert.That(elementsList[1].TaxonNumber, Is.EqualTo(1)); + Assert.That(elementsList[4].TaxonNumber, Is.EqualTo(1)); + Assert.That(elementsList[5].TaxonNumber, Is.EqualTo(1)); } /// @@ -129,10 +129,11 @@ public void UnBothConnectionGraphTest() connectionsList[1].Connected = true; elementsList[2].TaxonNumber = 1; connector.Connect(1, 2); - Assert.IsFalse(connectionsList[5].Connected); - Assert.AreEqual(1, elementsList[0].TaxonNumber); - Assert.AreEqual(1, elementsList[1].TaxonNumber); - Assert.AreEqual(1, elementsList[2].TaxonNumber); + + Assert.That(connectionsList[5].Connected, Is.False); + Assert.That(elementsList[0].TaxonNumber, Is.EqualTo(1)); + Assert.That(elementsList[1].TaxonNumber, Is.EqualTo(1)); + Assert.That(elementsList[2].TaxonNumber, Is.EqualTo(1)); } /// @@ -143,11 +144,12 @@ public void CutGraphTest() { var connector = new GraphManager(connectionsList, elementsList); connector.Cut(elementsList[0], elementsList[1]); - Assert.IsFalse(connectionsList[0].Connected); - Assert.AreEqual(3, elementsList[0].TaxonNumber); - Assert.AreEqual(1, elementsList[1].TaxonNumber); - Assert.AreEqual(2, elementsList[4].TaxonNumber); - Assert.AreEqual(2, elementsList[5].TaxonNumber); + + Assert.That(connectionsList[0].Connected, Is.False); + Assert.That(elementsList[0].TaxonNumber, Is.EqualTo(3)); + Assert.That(elementsList[1].TaxonNumber, Is.EqualTo(1)); + Assert.That(elementsList[4].TaxonNumber, Is.EqualTo(2)); + Assert.That(elementsList[5].TaxonNumber, Is.EqualTo(2)); } /// @@ -160,10 +162,11 @@ public void CutGraphTrioTest() connectionsList[1].Connected = true; elementsList[2].TaxonNumber = 1; connector.Cut(elementsList[0], elementsList[2]); - Assert.IsFalse(connectionsList[1].Connected); - Assert.AreEqual(3, elementsList[0].TaxonNumber); - Assert.AreEqual(3, elementsList[1].TaxonNumber); - Assert.AreEqual(1, elementsList[2].TaxonNumber); + + Assert.That(connectionsList[1].Connected, Is.False); + Assert.That(elementsList[0].TaxonNumber, Is.EqualTo(3)); + Assert.That(elementsList[1].TaxonNumber, Is.EqualTo(3)); + Assert.That(elementsList[2].TaxonNumber, Is.EqualTo(1)); } /// @@ -174,12 +177,13 @@ public void CloneTest() { var connector = new GraphManager(connectionsList, elementsList); var connector2 = connector.Clone(); - Assert.IsInstanceOf(typeof(GraphManager), connector2); - Assert.IsInstanceOf(typeof(Connection), connector2.Connections[0]); - Assert.IsInstanceOf(typeof(GraphElement), connector2.Elements[1]); - Assert.AreNotSame(connector, connector2); - Assert.AreNotSame(connector.Elements[0], connector2.Elements[0]); - Assert.AreNotSame(connector.Connections[1], connector2.Connections[1]); + + Assert.That(connector2, Is.TypeOf(typeof(GraphManager))); + Assert.That(connector2.Connections[0], Is.TypeOf(typeof(Connection))); + Assert.That(connector2.Elements[1], Is.TypeOf(typeof(GraphElement))); + Assert.That(connector, Is.Not.SameAs(connector2)); + Assert.That(connector.Elements[0], Is.Not.SameAs(connector2.Elements[0])); + Assert.That(connector.Connections[1], Is.Not.SameAs(connector2.Connections[1])); } /// @@ -206,21 +210,22 @@ public void GraphConnectionTest() var connector = new GraphManager(connectionsList, elementsList); connector.ConnectGraph(); - Assert.IsTrue(connectionsList[0].Connected); - Assert.IsTrue(connectionsList[4].Connected); - Assert.IsTrue(connectionsList[5].Connected); - Assert.IsTrue(connectionsList[9].Connected); - Assert.IsTrue(connectionsList[12].Connected); - Assert.IsFalse(connectionsList[1].Connected); - Assert.IsFalse(connectionsList[2].Connected); - Assert.IsFalse(connectionsList[3].Connected); - Assert.IsFalse(connectionsList[6].Connected); - Assert.IsFalse(connectionsList[7].Connected); - Assert.IsFalse(connectionsList[8].Connected); - Assert.IsFalse(connectionsList[10].Connected); - Assert.IsFalse(connectionsList[11].Connected); - Assert.IsFalse(connectionsList[13].Connected); - Assert.IsFalse(connectionsList[14].Connected); + + Assert.That(connectionsList[0].Connected, Is.True); + Assert.That(connectionsList[4].Connected, Is.True); + Assert.That(connectionsList[5].Connected, Is.True); + Assert.That(connectionsList[9].Connected, Is.True); + Assert.That(connectionsList[12].Connected, Is.True); + Assert.That(connectionsList[1].Connected, Is.False); + Assert.That(connectionsList[2].Connected, Is.False); + Assert.That(connectionsList[3].Connected, Is.False); + Assert.That(connectionsList[6].Connected, Is.False); + Assert.That(connectionsList[7].Connected, Is.False); + Assert.That(connectionsList[8].Connected, Is.False); + Assert.That(connectionsList[10].Connected, Is.False); + Assert.That(connectionsList[11].Connected, Is.False); + Assert.That(connectionsList[13].Connected, Is.False); + Assert.That(connectionsList[14].Connected, Is.False); } /// @@ -231,11 +236,12 @@ public void CutConnectionTest() { var connector = new GraphManager(connectionsList, elementsList); connector.Cut(connector.Connections[0]); - Assert.IsFalse(connectionsList[0].Connected); - Assert.AreEqual(3, elementsList[0].TaxonNumber); - Assert.AreEqual(1, elementsList[1].TaxonNumber); - Assert.AreEqual(2, elementsList[4].TaxonNumber); - Assert.AreEqual(2, elementsList[5].TaxonNumber); + + Assert.That(connectionsList[0].Connected, Is.False); + Assert.That(elementsList[0].TaxonNumber, Is.EqualTo(3)); + Assert.That(elementsList[1].TaxonNumber, Is.EqualTo(1)); + Assert.That(elementsList[4].TaxonNumber, Is.EqualTo(2)); + Assert.That(elementsList[5].TaxonNumber, Is.EqualTo(2)); } /// @@ -248,9 +254,10 @@ public void CutConnectionTrioTest() connectionsList[1].Connected = true; elementsList[2].TaxonNumber = 1; connector.Cut(connector.Connections[1]); - Assert.IsFalse(connectionsList[1].Connected); - Assert.AreEqual(3, elementsList[0].TaxonNumber); - Assert.AreEqual(3, elementsList[1].TaxonNumber); - Assert.AreEqual(1, elementsList[2].TaxonNumber); + + Assert.That(connectionsList[1].Connected, Is.False); + Assert.That(elementsList[0].TaxonNumber, Is.EqualTo(3)); + Assert.That(elementsList[1].TaxonNumber, Is.EqualTo(3)); + Assert.That(elementsList[2].TaxonNumber, Is.EqualTo(1)); } } diff --git a/Libiada.Clusterizator.Tests/Krab/KrabClusterizationTests.cs b/Libiada.Clusterizator.Tests/Krab/KrabClusterizationTests.cs index 816b63ae..dd9ab85b 100644 --- a/Libiada.Clusterizator.Tests/Krab/KrabClusterizationTests.cs +++ b/Libiada.Clusterizator.Tests/Krab/KrabClusterizationTests.cs @@ -16,24 +16,26 @@ public void ClusterizationTest() { var krab = new KrabClusterization(4, 2, 1); - var data = new[] - { - new[] { 2.0, 2.0 }, - new[] { 5.0, 2.0 }, - new[] { 4.0, 3.0 }, - new[] { 3.0, 6.0 }, - new[] { 8.0, 8.0 }, - new[] { 9.0, 7.0 } - }; + double[][] data = [ + [2.0, 2.0], + [5.0, 2.0], + [4.0, 3.0], + [3.0, 6.0], + [8.0, 8.0], + [9.0, 7.0] + ]; var result = krab.Cluster(2, data); - Assert.AreEqual(result[0], 2); - Assert.AreEqual(result[1], 2); - Assert.AreEqual(result[2], 2); - Assert.AreEqual(result[3], 2); + Assert.Multiple(() => + { + Assert.That(result[0], Is.EqualTo(2)); + Assert.That(result[1], Is.EqualTo(2)); + Assert.That(result[2], Is.EqualTo(2)); + Assert.That(result[3], Is.EqualTo(2)); - Assert.AreEqual(result[4], 1); - Assert.AreEqual(result[5], 1); + Assert.That(result[4], Is.EqualTo(1)); + Assert.That(result[5], Is.EqualTo(1)); + }); } } diff --git a/Libiada.Clusterizator.Tests/Libiada.Clusterizator.Tests.csproj b/Libiada.Clusterizator.Tests/Libiada.Clusterizator.Tests.csproj index 299c3c8d..bbb46a3b 100644 --- a/Libiada.Clusterizator.Tests/Libiada.Clusterizator.Tests.csproj +++ b/Libiada.Clusterizator.Tests/Libiada.Clusterizator.Tests.csproj @@ -13,9 +13,13 @@ - - - + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/Libiada.Clusterizator.Tests/kMeans/KMeansClusterizationTests.cs b/Libiada.Clusterizator.Tests/kMeans/KMeansClusterizationTests.cs index 681ac1e3..85f696c7 100644 --- a/Libiada.Clusterizator.Tests/kMeans/KMeansClusterizationTests.cs +++ b/Libiada.Clusterizator.Tests/kMeans/KMeansClusterizationTests.cs @@ -15,10 +15,10 @@ public class KMeansClusterizationTests public void SimpleClusterTest() { var cluster = new KMeansClusterization(); - double[][] data = { new double[] { 1 }, new double[] { 2 }, new double[] { 10 } }; + double[][] data = [[1], [2], [10]]; int[] actual = cluster.Cluster(2, data); - Assert.IsTrue(actual[0] == actual[1]); - Assert.IsTrue(actual[0] != actual[2]); + Assert.That(actual[0], Is.EqualTo(actual[1])); + Assert.That(actual[0], Is.Not.EqualTo(actual[2])); } /// @@ -28,11 +28,11 @@ public void SimpleClusterTest() public void FourPointsClusterTest() { var cluster = new KMeansClusterization(); - double[][] data = { new double[] { -5 }, new double[] { -4 }, new double[] { 4 }, new double[] { 5 } }; + double[][] data = [[-5], [-4], [4], [5]]; int[] actual = cluster.Cluster(2, data); - Assert.IsTrue(actual[0] == actual[1]); - Assert.IsTrue(actual[0] != actual[2]); - Assert.IsTrue(actual[2] == actual[3]); + Assert.That(actual[0], Is.EqualTo(actual[1])); + Assert.That(actual[0], Is.Not.EqualTo(actual[2])); + Assert.That(actual[2], Is.EqualTo(actual[3])); } /// @@ -42,11 +42,11 @@ public void FourPointsClusterTest() public void TwoDimensionDataClusterTest() { var cluster = new KMeansClusterization(); - double[][] data = { new double[] { -5, 1 }, new double[] { -5, 2 }, new double[] { 0, 0 }, new double[] { 1, 1 } }; + double[][] data = [[-5, 1], [-5, 2], [0, 0], [1, 1]]; int[] actual = cluster.Cluster(2, data); - Assert.IsTrue(actual[0] == actual[1]); - Assert.IsTrue(actual[0] != actual[2]); - Assert.IsTrue(actual[2] == actual[3]); + Assert.That(actual[0], Is.EqualTo(actual[1])); + Assert.That(actual[0], Is.Not.EqualTo(actual[2])); + Assert.That(actual[2], Is.EqualTo(actual[3])); } /// @@ -56,13 +56,14 @@ public void TwoDimensionDataClusterTest() public void MultipleDataPointsClusterTest() { var cluster = new KMeansClusterization(); - double[][] data = { new[] { -2.1 }, new[] { -1.0 }, new[] { 0.3 }, new[] { 1.0 }, new[] { 1.1 }, new[] { 7.0 }, new[] { 9.0} }; + double[][] data = [[-2.1], [-1.0], [0.3], [1.0], [1.1], [7.0], [9.0]]; int[] actual = cluster.Cluster(2, data); - Assert.IsTrue(actual[0] == actual[1]); - Assert.IsTrue(actual[0] == actual[2]); - Assert.IsTrue(actual[0] == actual[3]); - Assert.IsTrue(actual[0] == actual[4]); - Assert.IsTrue(actual[0] != actual[5]); - Assert.IsTrue(actual[5] == actual[6]); + Assert.That(actual[0], Is.EqualTo(actual[1])); + Assert.That(actual[0], Is.EqualTo(actual[2])); + Assert.That(actual[0], Is.EqualTo(actual[3])); + Assert.That(actual[0], Is.EqualTo(actual[4])); + Assert.That(actual[0], Is.Not.EqualTo(actual[5])); + Assert.That(actual[5], Is.EqualTo(actual[6])); } + } diff --git a/Libiada.Core.Tests/Core/AbstractChainTests.cs b/Libiada.Core.Tests/Core/AbstractChainTests.cs index 9a355982..7e2f4555 100644 --- a/Libiada.Core.Tests/Core/AbstractChainTests.cs +++ b/Libiada.Core.Tests/Core/AbstractChainTests.cs @@ -14,11 +14,11 @@ public class AbstractChainTests [Test] public void ToStringTest() { - var stringExpected = "abcabccc"; - var chain = new Chain(stringExpected); - Assert.AreEqual(stringExpected, chain.ToString()); - var baseChain = new BaseChain(stringExpected); - Assert.AreEqual(stringExpected, baseChain.ToString()); + const string expected = "abcabccc"; + var chain = new Chain(expected); + Assert.That(chain.ToString(), Is.EqualTo(expected)); + var baseChain = new BaseChain(expected); + Assert.That(baseChain.ToString(), Is.EqualTo(expected)); } /// @@ -27,17 +27,23 @@ public void ToStringTest() [Test] public void ToStringDelimiterTest() { - var source = "abcabccc"; + const string source = "abcabccc"; var chain = new Chain(source); var baseChain = new BaseChain(source); var expected = "a b c a b c c c"; - Assert.AreEqual(expected, chain.ToString(" ")); - Assert.AreEqual(expected, baseChain.ToString(" ")); + Assert.Multiple(() => + { + Assert.That(chain.ToString(" "), Is.EqualTo(expected)); + Assert.That(baseChain.ToString(" "), Is.EqualTo(expected)); + }); expected = "acbcccacbcccccc"; - Assert.AreEqual(expected, chain.ToString("c")); - Assert.AreEqual(expected, baseChain.ToString("c")); + Assert.Multiple(() => + { + Assert.That(chain.ToString("c"), Is.EqualTo(expected)); + Assert.That(baseChain.ToString("c"), Is.EqualTo(expected)); + }); } /// @@ -46,16 +52,22 @@ public void ToStringDelimiterTest() [Test] public void ToStringLongDelimiterTest() { - var source = "abcabccc"; + const string source = "abcabccc"; var chain = new Chain(source); var baseChain = new BaseChain(source); var expected = "a - b - c - a - b - c - c - c"; - Assert.AreEqual(expected, chain.ToString(" - ")); - Assert.AreEqual(expected, baseChain.ToString(" - ")); + Assert.Multiple(() => + { + Assert.That(chain.ToString(" - "), Is.EqualTo(expected)); + Assert.That(baseChain.ToString(" - "), Is.EqualTo(expected)); + }); expected = "a, b, c, a, b, c, c, c"; - Assert.AreEqual(expected, chain.ToString(", ")); - Assert.AreEqual(expected, baseChain.ToString(", ")); + Assert.Multiple(() => + { + Assert.That(chain.ToString(", "), Is.EqualTo(expected)); + Assert.That(baseChain.ToString(", "), Is.EqualTo(expected)); + }); } } diff --git a/Libiada.Core.Tests/Core/AlphabetTests.cs b/Libiada.Core.Tests/Core/AlphabetTests.cs index 09c4714c..2a2455e4 100644 --- a/Libiada.Core.Tests/Core/AlphabetTests.cs +++ b/Libiada.Core.Tests/Core/AlphabetTests.cs @@ -25,8 +25,8 @@ public class AlphabetTests [SetUp] public void Initialization() { - firstAlphabet = new Alphabet(); - secondAlphabet = new Alphabet(); + firstAlphabet = []; + secondAlphabet = []; } /// @@ -35,8 +35,8 @@ public void Initialization() [Test] public void ConstructorTest() { - Assert.IsNotNull(firstAlphabet); - Assert.AreEqual(0, firstAlphabet.Cardinality); + Assert.That(firstAlphabet, Is.Not.Null); + Assert.That(firstAlphabet.Cardinality, Is.Zero); } /// @@ -78,10 +78,10 @@ public void GetTest() firstAlphabet.Add(new ValueInt(3)); firstAlphabet.Add(new ValueInt(4)); firstAlphabet.Add(new ValueInt(5)); - Assert.AreEqual(new ValueInt(2), firstAlphabet[0]); - Assert.AreEqual(new ValueInt(3), firstAlphabet[1]); - Assert.AreEqual(new ValueInt(4), firstAlphabet[2]); - Assert.AreEqual(new ValueInt(5), firstAlphabet[3]); + Assert.That(firstAlphabet[0], Is.EqualTo(new ValueInt(2))); + Assert.That(firstAlphabet[1], Is.EqualTo(new ValueInt(3))); + Assert.That(firstAlphabet[2], Is.EqualTo(new ValueInt(4))); + Assert.That(firstAlphabet[3], Is.EqualTo(new ValueInt(5))); } /// @@ -95,10 +95,10 @@ public void IndependentNumberTest() firstAlphabet.Add(new ValueInt(3)); firstAlphabet.Add(new ValueInt(4)); firstAlphabet[0] = new ValueInt(3); - Assert.AreEqual(new ValueInt(2), firstAlphabet[0]); - Assert.AreEqual(new ValueInt(1), firstAlphabet[1]); - Assert.AreEqual(new ValueInt(3), firstAlphabet[2]); - Assert.AreEqual(new ValueInt(4), firstAlphabet[3]); + Assert.That(firstAlphabet[0], Is.EqualTo(new ValueInt(2))); + Assert.That(firstAlphabet[1], Is.EqualTo(new ValueInt(1))); + Assert.That(firstAlphabet[2], Is.EqualTo(new ValueInt(3))); + Assert.That(firstAlphabet[3], Is.EqualTo(new ValueInt(4))); } /// @@ -112,10 +112,10 @@ public void IndependentStringTest() firstAlphabet.Add(new ValueString("5")); firstAlphabet.Add(new ValueString("1")); firstAlphabet[0] = new ValueString("3"); - Assert.AreEqual(new ValueString("2"), firstAlphabet[0]); - Assert.AreEqual(new ValueString("3"), firstAlphabet[1]); - Assert.AreEqual(new ValueString("5"), firstAlphabet[2]); - Assert.AreEqual(new ValueString("1"), firstAlphabet[3]); + Assert.That(firstAlphabet[0], Is.EqualTo(new ValueString("2"))); + Assert.That(firstAlphabet[1], Is.EqualTo(new ValueString("3"))); + Assert.That(firstAlphabet[2], Is.EqualTo(new ValueString("5"))); + Assert.That(firstAlphabet[3], Is.EqualTo(new ValueString("1"))); } /// @@ -136,7 +136,7 @@ public void CardinalityTest() firstAlphabet.Add(new ValueInt(100)); firstAlphabet.Add(new ValueInt(200)); firstAlphabet.Add(new ValueInt(300)); - Assert.AreEqual(3, firstAlphabet.Cardinality); + Assert.That(firstAlphabet.Cardinality, Is.EqualTo(3)); } /// @@ -150,8 +150,8 @@ public void RemoveTest() firstAlphabet.Add(new ValueInt(300)); firstAlphabet.Add(new ValueInt(400)); firstAlphabet.Remove(2); - Assert.AreEqual(3, firstAlphabet.Cardinality); - Assert.AreEqual(new ValueInt(400), firstAlphabet[2]); + Assert.That(firstAlphabet.Cardinality, Is.EqualTo(3)); + Assert.That(firstAlphabet[2], Is.EqualTo(new ValueInt(400))); } /// @@ -160,9 +160,11 @@ public void RemoveTest() [Test] public void CloneTest() { - Assert.AreNotSame(firstAlphabet, firstAlphabet.Clone()); + var clone = firstAlphabet.Clone(); - Assert.IsTrue(firstAlphabet.Equals(firstAlphabet.Clone())); + Assert.That(firstAlphabet, Is.Not.SameAs(clone)); + + Assert.That(firstAlphabet, Is.EqualTo(clone)); } /// @@ -196,8 +198,8 @@ public void EqualsTests(string[] firstElementsList, string[] secondElementsList, secondAlphabet.Add(new ValueString(element)); } - Assert.AreEqual(equals, firstAlphabet.Equals(secondAlphabet)); - Assert.AreEqual(equals, secondAlphabet.Equals(firstAlphabet)); + Assert.That(firstAlphabet.Equals(secondAlphabet), Is.EqualTo(equals)); + Assert.That(secondAlphabet.Equals(firstAlphabet), Is.EqualTo(equals)); } /// @@ -231,8 +233,8 @@ public void SetEqualsTests(string[] firstElementsList, string[] secondElementsLi secondAlphabet.Add(new ValueString(element)); } - Assert.AreEqual(equals, firstAlphabet.SetEquals(secondAlphabet)); - Assert.AreEqual(equals, secondAlphabet.SetEquals(firstAlphabet)); + Assert.That(firstAlphabet.SetEquals(secondAlphabet), Is.EqualTo(equals)); + Assert.That(secondAlphabet.SetEquals(firstAlphabet), Is.EqualTo(equals)); } /// @@ -250,16 +252,16 @@ public void SetEqualsWithNullValueTest() secondAlphabet.Add((ValueInt)1); secondAlphabet.Add((ValueString)"a"); secondAlphabet.Add((ValueInt)2); - Assert.IsTrue(firstAlphabet.SetEquals(secondAlphabet)); + Assert.That(firstAlphabet.SetEquals(secondAlphabet), Is.True); - firstAlphabet = new Alphabet { NullValue.Instance(), (ValueInt)1, (ValueString)"a", (ValueInt)2 }; - secondAlphabet = new Alphabet { NullValue.Instance(), (ValueInt)2, (ValueInt)1, (ValueString)"a" }; - Assert.IsTrue(firstAlphabet.SetEquals(secondAlphabet)); + firstAlphabet = [NullValue.Instance(), (ValueInt)1, (ValueString)"a", (ValueInt)2]; + secondAlphabet = [NullValue.Instance(), (ValueInt)2, (ValueInt)1, (ValueString)"a"]; + Assert.That(firstAlphabet.SetEquals(secondAlphabet), Is.True); - firstAlphabet = new Alphabet { NullValue.Instance(), (ValueInt)1, (ValueString)"a", (ValueInt)2 }; - secondAlphabet = new Alphabet { (ValueInt)2, (ValueInt)1, (ValueString)"a" }; - Assert.IsFalse(firstAlphabet.SetEquals(secondAlphabet)); - Assert.IsFalse(secondAlphabet.SetEquals(firstAlphabet)); + firstAlphabet = [NullValue.Instance(), (ValueInt)1, (ValueString)"a", (ValueInt)2]; + secondAlphabet = [(ValueInt)2, (ValueInt)1, (ValueString)"a"]; + Assert.That(firstAlphabet.SetEquals(secondAlphabet), Is.False); + Assert.That(secondAlphabet.SetEquals(firstAlphabet), Is.False); } /// @@ -271,10 +273,10 @@ public void ContainsTest() firstAlphabet.Add(new ValueString('a')); firstAlphabet.Add(new ValueString('b')); firstAlphabet.Add(new ValueString('c')); - Assert.IsTrue(firstAlphabet.Contains(new ValueString('a'))); - Assert.IsTrue(firstAlphabet.Contains(new ValueString('b'))); - Assert.IsTrue(firstAlphabet.Contains(new ValueString('c'))); - Assert.IsFalse(firstAlphabet.Contains(new ValueString('d'))); + Assert.That(firstAlphabet.Contains(new ValueString('a')), Is.True); + Assert.That(firstAlphabet.Contains(new ValueString('b')), Is.True); + Assert.That(firstAlphabet.Contains(new ValueString('c')), Is.True); + Assert.That(firstAlphabet.Contains(new ValueString('d')), Is.False); } /// @@ -286,9 +288,9 @@ public void IndexOfTest() firstAlphabet.Add(new ValueString('a')); firstAlphabet.Add(new ValueString('b')); firstAlphabet.Add(new ValueString('c')); - Assert.IsTrue(firstAlphabet.IndexOf(new ValueString('d')).Equals(-1)); - Assert.IsTrue(firstAlphabet.IndexOf(new ValueString('a')).Equals(0)); - Assert.IsTrue(firstAlphabet.IndexOf(new ValueString('c')).Equals(2)); + Assert.That(firstAlphabet.IndexOf(new ValueString('d')), Is.EqualTo(-1)); + Assert.That(firstAlphabet.IndexOf(new ValueString('a')), Is.Zero); + Assert.That(firstAlphabet.IndexOf(new ValueString('c')), Is.EqualTo(2)); } /// @@ -308,9 +310,12 @@ public void ToArrayTest() firstAlphabet.Add(new ValueString('d')); firstAlphabet.Add(e); - Assert.AreNotSame(e, firstAlphabet[4]); - Assert.AreNotSame(c, firstAlphabet[2]); - Assert.AreNotSame(a, firstAlphabet[0]); + Assert.Multiple(() => + { + Assert.That(firstAlphabet[4], Is.Not.SameAs(e)); + Assert.That(firstAlphabet[2], Is.Not.SameAs(c)); + Assert.That(firstAlphabet[0], Is.Not.SameAs(a)); + }); } /// @@ -325,6 +330,6 @@ public void ToStringTest() firstAlphabet.Add((ValueInt)2); var result = firstAlphabet.ToString(); - Assert.AreEqual("< -, 1, a, 2 >", result); + Assert.That(result, Is.EqualTo("< -, 1, a, 2 >")); } } diff --git a/Libiada.Core.Tests/Core/ArrangementManagers/BinaryIntervalsManagerTests.cs b/Libiada.Core.Tests/Core/ArrangementManagers/BinaryIntervalsManagerTests.cs index 0eda4c2c..9d3a4d5e 100644 --- a/Libiada.Core.Tests/Core/ArrangementManagers/BinaryIntervalsManagerTests.cs +++ b/Libiada.Core.Tests/Core/ArrangementManagers/BinaryIntervalsManagerTests.cs @@ -21,23 +21,32 @@ public void GetBinaryIntervalTest() { var chain = ChainsStorage.Chains[2]; var intervalManager = chain.GetRelationIntervalsManager(elements["A"], elements["C"]); - Assert.AreEqual(1, intervalManager.GetBinaryInterval(1)); - Assert.AreEqual(1, intervalManager.GetBinaryInterval(2)); - Assert.AreEqual(-1, intervalManager.GetBinaryInterval(3)); + Assert.Multiple(() => + { + Assert.That(intervalManager.GetBinaryInterval(1), Is.EqualTo(1)); + Assert.That(intervalManager.GetBinaryInterval(2), Is.EqualTo(1)); + Assert.That(intervalManager.GetBinaryInterval(3), Is.EqualTo(-1)); + }); intervalManager = chain.GetRelationIntervalsManager(elements["C"], elements["A"]); - Assert.AreEqual(-1, intervalManager.GetBinaryInterval(1)); - Assert.AreEqual(1, intervalManager.GetBinaryInterval(2)); - Assert.AreEqual(-1, intervalManager.GetBinaryInterval(3)); - Assert.AreEqual(3, intervalManager.GetBinaryInterval(4)); - Assert.AreEqual(-1, intervalManager.GetBinaryInterval(5)); + Assert.Multiple(() => + { + Assert.That(intervalManager.GetBinaryInterval(1), Is.EqualTo(-1)); + Assert.That(intervalManager.GetBinaryInterval(2), Is.EqualTo(1)); + Assert.That(intervalManager.GetBinaryInterval(3), Is.EqualTo(-1)); + Assert.That(intervalManager.GetBinaryInterval(4), Is.EqualTo(3)); + Assert.That(intervalManager.GetBinaryInterval(5), Is.EqualTo(-1)); + }); intervalManager = chain.GetRelationIntervalsManager(elements["C"], elements["T"]); - Assert.AreEqual(-1, intervalManager.GetBinaryInterval(1)); - Assert.AreEqual(-1, intervalManager.GetBinaryInterval(2)); - Assert.AreEqual(-1, intervalManager.GetBinaryInterval(3)); - Assert.AreEqual(1, intervalManager.GetBinaryInterval(4)); - Assert.AreEqual(1, intervalManager.GetBinaryInterval(4)); + Assert.Multiple(() => + { + Assert.That(intervalManager.GetBinaryInterval(1), Is.EqualTo(-1)); + Assert.That(intervalManager.GetBinaryInterval(2), Is.EqualTo(-1)); + Assert.That(intervalManager.GetBinaryInterval(3), Is.EqualTo(-1)); + Assert.That(intervalManager.GetBinaryInterval(4), Is.EqualTo(1)); + }); + Assert.That(intervalManager.GetBinaryInterval(4), Is.EqualTo(1)); } /// @@ -48,20 +57,26 @@ public void GetBinaryIntervalIncompleteChainTest() { var chain = ChainsStorage.BinaryChains[20]; var intervalManager = chain.GetRelationIntervalsManager(elements["A"], elements["C"]); - Assert.AreEqual(1, intervalManager.GetBinaryInterval(1)); - Assert.AreEqual(2, intervalManager.GetBinaryInterval(2)); - Assert.AreEqual(-1, intervalManager.GetBinaryInterval(3)); - Assert.AreEqual(-1, intervalManager.GetBinaryInterval(4)); - Assert.AreEqual(1, intervalManager.GetBinaryInterval(5)); - Assert.AreEqual(-1, intervalManager.GetBinaryInterval(6)); - Assert.AreEqual(-1, intervalManager.GetBinaryInterval(7)); + Assert.Multiple(() => + { + Assert.That(intervalManager.GetBinaryInterval(1), Is.EqualTo(1)); + Assert.That(intervalManager.GetBinaryInterval(2), Is.EqualTo(2)); + Assert.That(intervalManager.GetBinaryInterval(3), Is.EqualTo(-1)); + Assert.That(intervalManager.GetBinaryInterval(4), Is.EqualTo(-1)); + Assert.That(intervalManager.GetBinaryInterval(5), Is.EqualTo(1)); + Assert.That(intervalManager.GetBinaryInterval(6), Is.EqualTo(-1)); + Assert.That(intervalManager.GetBinaryInterval(7), Is.EqualTo(-1)); + }); intervalManager = chain.GetRelationIntervalsManager(elements["C"], elements["A"]); - Assert.AreEqual(1, intervalManager.GetBinaryInterval(1)); - Assert.AreEqual(-1, intervalManager.GetBinaryInterval(2)); - Assert.AreEqual(2, intervalManager.GetBinaryInterval(3)); - Assert.AreEqual(-1, intervalManager.GetBinaryInterval(4)); - Assert.AreEqual(1, intervalManager.GetBinaryInterval(5)); - Assert.AreEqual(-1, intervalManager.GetBinaryInterval(6)); + Assert.Multiple(() => + { + Assert.That(intervalManager.GetBinaryInterval(1), Is.EqualTo(1)); + Assert.That(intervalManager.GetBinaryInterval(2), Is.EqualTo(-1)); + Assert.That(intervalManager.GetBinaryInterval(3), Is.EqualTo(2)); + Assert.That(intervalManager.GetBinaryInterval(4), Is.EqualTo(-1)); + Assert.That(intervalManager.GetBinaryInterval(5), Is.EqualTo(1)); + Assert.That(intervalManager.GetBinaryInterval(6), Is.EqualTo(-1)); + }); } } diff --git a/Libiada.Core.Tests/Core/ArrangementManagers/IntervalsManagerTests.cs b/Libiada.Core.Tests/Core/ArrangementManagers/IntervalsManagerTests.cs index 3aa84e56..96a01c13 100644 --- a/Libiada.Core.Tests/Core/ArrangementManagers/IntervalsManagerTests.cs +++ b/Libiada.Core.Tests/Core/ArrangementManagers/IntervalsManagerTests.cs @@ -68,11 +68,11 @@ public void IntervalsManagerCreationNoneLinkTest(int index, Link link) var intervalsManager = new IntervalsManager(congenericChains[index]); var intervals = allIntervals[index][link]; - Assert.AreEqual(intervalsManager.GetArrangement(link).Length, intervals.Count); + Assert.That(intervals, Has.Count.EqualTo(intervalsManager.GetArrangement(link).Length)); for (int i = 0; i < intervals.Count; i++) { - Assert.AreEqual(intervals[i], intervalsManager.GetArrangement(link)[i]); + Assert.That(intervalsManager.GetArrangement(link)[i], Is.EqualTo(intervals[i])); } } } diff --git a/Libiada.Core.Tests/Core/ArrangementManagers/SeriesManagerTests.cs b/Libiada.Core.Tests/Core/ArrangementManagers/SeriesManagerTests.cs index a06e6eb4..35f61e95 100644 --- a/Libiada.Core.Tests/Core/ArrangementManagers/SeriesManagerTests.cs +++ b/Libiada.Core.Tests/Core/ArrangementManagers/SeriesManagerTests.cs @@ -43,8 +43,8 @@ public class SeriesManagerTests [TestCase(17, new[] { 1, 1, 1, 1 })] public void SimpleSeriesManagerTests(int index, int[] expected) { - SeriesManager manager = new SeriesManager(congenericChains[index]); + SeriesManager manager = new(congenericChains[index]); int[] actual = manager.GetArrangement(Link.NotApplied); - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } } diff --git a/Libiada.Core.Tests/Core/BaseChainTests.cs b/Libiada.Core.Tests/Core/BaseChainTests.cs index 6b7f6c98..e28fe125 100644 --- a/Libiada.Core.Tests/Core/BaseChainTests.cs +++ b/Libiada.Core.Tests/Core/BaseChainTests.cs @@ -16,11 +16,11 @@ public class BaseChainTests public void ConstructorWithLengthTest() { var chain = new BaseChain(100); - Assert.AreEqual(100, chain.Length); + Assert.That(chain.Length, Is.EqualTo(100)); var expectedOrder = new int[100]; - Assert.AreEqual(expectedOrder, chain.Order); + Assert.That(chain.Order, Is.EqualTo(expectedOrder)); var expectedAlphabet = new Alphabet(); - Assert.AreEqual(expectedAlphabet, chain.Alphabet); + Assert.That(chain.Alphabet, Is.EqualTo(expectedAlphabet)); } /// @@ -39,46 +39,46 @@ public void ConstructorLessZeroLengthTest() public void ConstructorWithStringTest() { var chain = new BaseChain("A"); - Assert.AreEqual(1, chain.Length); + Assert.That(chain.Length, Is.EqualTo(1)); var expectedOrder = new[] { 1 }; - Assert.AreEqual(expectedOrder, chain.Order); + Assert.That(chain.Order, Is.EqualTo(expectedOrder)); var expectedAlphabet = new Alphabet() { (ValueString)"A"}; - Assert.AreEqual(expectedAlphabet, chain.Alphabet); + Assert.That(chain.Alphabet, Is.EqualTo(expectedAlphabet)); chain = new BaseChain("ABC"); - Assert.AreEqual(3, chain.Length); - expectedOrder = new[] { 1, 2, 3 }; - Assert.AreEqual(expectedOrder, chain.Order); - expectedAlphabet = new Alphabet() { (ValueString)"A", (ValueString)"B", (ValueString)"C" }; - Assert.AreEqual(expectedAlphabet, chain.Alphabet); + Assert.That(chain.Length, Is.EqualTo(3)); + expectedOrder = [1, 2, 3]; + Assert.That(chain.Order, Is.EqualTo(expectedOrder)); + expectedAlphabet = [(ValueString)"A", (ValueString)"B", (ValueString)"C"]; + Assert.That(chain.Alphabet, Is.EqualTo(expectedAlphabet)); chain = new BaseChain("AAABBBCCC"); - Assert.AreEqual(9, chain.Length); - expectedOrder = new[] { 1, 1, 1, 2, 2, 2, 3, 3, 3 }; - Assert.AreEqual(expectedOrder, chain.Order); - expectedAlphabet = new Alphabet() { (ValueString)"A", (ValueString)"B", (ValueString)"C" }; - Assert.AreEqual(expectedAlphabet, chain.Alphabet); + Assert.That(chain.Length, Is.EqualTo(9)); + expectedOrder = [1, 1, 1, 2, 2, 2, 3, 3, 3]; + Assert.That(chain.Order, Is.EqualTo(expectedOrder)); + expectedAlphabet = [(ValueString)"A", (ValueString)"B", (ValueString)"C"]; + Assert.That(chain.Alphabet, Is.EqualTo(expectedAlphabet)); chain = new BaseChain("AAABBBCCC"); - Assert.AreEqual(9, chain.Length); - expectedOrder = new[] { 1, 1, 1, 2, 2, 2, 3, 3, 3 }; - Assert.AreEqual(expectedOrder, chain.Order); - expectedAlphabet = new Alphabet() { (ValueString)"A", (ValueString)"B", (ValueString)"C" }; - Assert.AreEqual(expectedAlphabet, chain.Alphabet); + Assert.That(chain.Length, Is.EqualTo(9)); + expectedOrder = [1, 1, 1, 2, 2, 2, 3, 3, 3]; + Assert.That(chain.Order, Is.EqualTo(expectedOrder)); + expectedAlphabet = [(ValueString)"A", (ValueString)"B", (ValueString)"C"]; + Assert.That(chain.Alphabet, Is.EqualTo(expectedAlphabet)); chain = new BaseChain("BBBCCCAAA"); - Assert.AreEqual(9, chain.Length); - expectedOrder = new[] { 1, 1, 1, 2, 2, 2, 3, 3, 3 }; - Assert.AreEqual(expectedOrder, chain.Order); - expectedAlphabet = new Alphabet() { (ValueString)"B", (ValueString)"C", (ValueString)"A" }; - Assert.AreEqual(expectedAlphabet, chain.Alphabet); + Assert.That(chain.Length, Is.EqualTo(9)); + expectedOrder = [1, 1, 1, 2, 2, 2, 3, 3, 3]; + Assert.That(chain.Order, Is.EqualTo(expectedOrder)); + expectedAlphabet = [(ValueString)"B", (ValueString)"C", (ValueString)"A"]; + Assert.That(chain.Alphabet, Is.EqualTo(expectedAlphabet)); chain = new BaseChain("BBB---"); - Assert.AreEqual(6, chain.Length); - expectedOrder = new[] { 1, 1, 1, 2, 2, 2 }; - Assert.AreEqual(expectedOrder, chain.Order); - expectedAlphabet = new Alphabet() { (ValueString)"B", (ValueString)"-" }; - Assert.AreEqual(expectedAlphabet, chain.Alphabet); + Assert.That(chain.Length, Is.EqualTo(6)); + expectedOrder = [1, 1, 1, 2, 2, 2]; + Assert.That(chain.Order, Is.EqualTo(expectedOrder)); + expectedAlphabet = [(ValueString)"B", (ValueString)"-"]; + Assert.That(chain.Alphabet, Is.EqualTo(expectedAlphabet)); } /// @@ -89,7 +89,7 @@ public void GetByThisTest() { var chain = new BaseChain(10); chain.Set(new ValueString('1'), 0); - Assert.IsTrue(((ValueString)chain[0]).Equals("1")); + Assert.That(((ValueString)chain[0]).Equals("1"), Is.True); } /// @@ -100,7 +100,7 @@ public void SetByThisTest() { var chain = new BaseChain(10); chain[0] = new ValueString('1'); - Assert.IsTrue(((ValueString)chain.Get(0)).Equals("1")); + Assert.That(((ValueString)chain.Get(0)).Equals("1"), Is.True); } /// @@ -111,7 +111,7 @@ public void GetTest() { var chain = new BaseChain(10); chain.Set(new ValueString('1'), 0); - Assert.IsTrue(((ValueString)chain.Get(0)).Equals("1")); + Assert.That(((ValueString)chain.Get(0)).Equals("1"), Is.True); } /// @@ -122,7 +122,7 @@ public void SetTest() { var chain = new BaseChain(10); chain.Set(new ValueString('1'), 0); - Assert.IsTrue(((ValueString)chain.Get(0)).Equals("1")); + Assert.That(((ValueString)chain.Get(0)).Equals("1"), Is.True); } /// @@ -133,24 +133,24 @@ public void RemoveTest() { var chain = new BaseChain(10); chain.Set(new ValueString('1'), 0); - Assert.IsTrue(((ValueString)chain[0]).Equals("1")); + Assert.That(((ValueString)chain[0]).Equals("1"), Is.True); chain.RemoveAt(0); - Assert.AreEqual(NullValue.Instance(), chain[0]); + Assert.That(chain[0], Is.EqualTo(NullValue.Instance())); } /// - /// The dekete test. + /// The delete test. /// [Test] public void DeleteTest() { var chain = new BaseChain(10); chain.Set(new ValueString('1'), 0); - Assert.IsTrue(((ValueString)chain[0]).Equals("1")); + Assert.That(((ValueString)chain[0]).Equals("1"), Is.True); chain.DeleteAt(0); - Assert.AreEqual(NullValue.Instance(), chain[0]); + Assert.That(chain[0], Is.EqualTo(NullValue.Instance())); } /// @@ -160,7 +160,7 @@ public void DeleteTest() public void GetLengthTest() { var chain = new BaseChain(10); - Assert.AreEqual(10, chain.Length); + Assert.That(chain.Length, Is.EqualTo(10)); } /// @@ -171,9 +171,9 @@ public void CloneTest() { var chain = new BaseChain("123456789A"); - var itsClone = (BaseChain)chain.Clone(); - Assert.AreEqual(chain, itsClone); - Assert.AreNotSame(chain, itsClone); + var clone = (BaseChain)chain.Clone(); + Assert.That(clone, Is.EqualTo(chain)); + Assert.That(clone, Is.Not.SameAs(chain)); } [TestCase(9, 0, "C", 10)] @@ -199,11 +199,11 @@ public void SetInFullSequenceTests(int sourceIndex, int index, string element, i Chain expected = ChainsStorage.Chains[expectedIndex]; source.Set(new ValueString(element), index); - Assert.AreEqual(expected, source); + Assert.That(source, Is.EqualTo(expected)); charArraySource[index] = element[0]; expected = new Chain(new string(charArraySource)); - Assert.AreEqual(expected, source); + Assert.That(source, Is.EqualTo(expected)); } [TestCase(18, 0, "A", 19)] @@ -221,6 +221,6 @@ public void SetInSparseSequenceTests(int sourceIndex, int index, string element, Chain expected = ChainsStorage.Chains[expectedIndex]; source.Set(new ValueString(element), index); - Assert.AreEqual(expected, source); + Assert.That(source, Is.EqualTo(expected)); } } diff --git a/Libiada.Core.Tests/Core/ChainTests.cs b/Libiada.Core.Tests/Core/ChainTests.cs index 49948097..e141147a 100644 --- a/Libiada.Core.Tests/Core/ChainTests.cs +++ b/Libiada.Core.Tests/Core/ChainTests.cs @@ -25,11 +25,11 @@ public class ChainTests [Test] public void SimilarChainsGetTest() { - var congenericChainA = new CongenericChain(new List { 2, 8 }, elements["A"], 10); + var congenericChainA = new CongenericChain([2, 8], elements["A"], 10); var chainCreatedCongenericChain = chains[2].CongenericChain(elements["A"]); - Assert.AreEqual(congenericChainA, chainCreatedCongenericChain); + Assert.That(chainCreatedCongenericChain, Is.EqualTo(congenericChainA)); } /// @@ -38,13 +38,13 @@ public void SimilarChainsGetTest() [Test] public void ChainTest() { - var source = new short[] { 1, 2, 3, 2, 2, 4, 5, 1 }; + short[] source = [1, 2, 3, 2, 2, 4, 5, 1]; var actual = new Chain(source); var alphabet = new Alphabet() {new ValueInt(1), new ValueInt(2) , new ValueInt(3) , new ValueInt(4), new ValueInt(5) }; - Assert.AreEqual(alphabet,actual.Alphabet); + Assert.That(actual.Alphabet, Is.EqualTo(alphabet)); var order = new int[] { 1, 2, 3, 2, 2, 4, 5, 1 }; - Assert.AreEqual(order, actual.Order); + Assert.That(actual.Order, Is.EqualTo(order)); } @@ -54,18 +54,18 @@ public void ChainTest() [Test] public void IntervalsTest() { - var intervals = new List> - { - new List { 1, 1, 4, 4, 1 }, - new List { 3, 1, 3, 4 }, - new List { 5, 3, 1, 2 } - }; + List> intervals = + [ + [1, 1, 4, 4, 1], + [3, 1, 3, 4], + [5, 3, 1, 2] + ]; for (int i = 0; i < chains[0].Alphabet.Cardinality; i++) { var actualIntervals = chains[0].CongenericChain(i).GetArrangement(Link.Both); for (int j = 0; j < actualIntervals.Length; j++) { - Assert.AreEqual(intervals[i][j], actualIntervals[j], "{0} and {1} intervals of sequence are not equal", j, i); + Assert.That(actualIntervals[j], Is.EqualTo(intervals[i][j]), $"{j} and {i} intervals of sequence are not equal"); } } } @@ -103,6 +103,6 @@ public void IntervalsTest() public void GetElementPositionTest(int expected, int chainIndex, string element, int occurrence) { var actual = chains[chainIndex].GetOccurrence(elements[element], occurrence); - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } } diff --git a/Libiada.Core.Tests/Core/ChainsStorage.cs b/Libiada.Core.Tests/Core/ChainsStorage.cs index f1067919..dccd9f1d 100644 --- a/Libiada.Core.Tests/Core/ChainsStorage.cs +++ b/Libiada.Core.Tests/Core/ChainsStorage.cs @@ -11,7 +11,7 @@ public static class ChainsStorage /// /// Creates dictionary of elements with their string reprasentations as keys. /// - public static Dictionary Elements => new Dictionary + public static Dictionary Elements => new() { { "A", new ValueString("A") }, { "B", new ValueString("B") }, @@ -23,8 +23,8 @@ public static class ChainsStorage /// /// Creates list of chains. /// - public static List Chains => new List - { + public static List Chains => + [ // B B A A C B A C C B // _ _ A A _ _ A _ _ _ // B B _ _ _ B _ _ _ B @@ -133,71 +133,71 @@ public static class ChainsStorage // 18 _ _ _ _ _ _ _ _ _ _ new Chain( - new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - new Alphabet() { NullValue.Instance() }), + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [NullValue.Instance()]), // 19 A _ _ _ _ _ _ _ _ _ new Chain( - new[] { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - new Alphabet() { NullValue.Instance(), Elements["A"] }), + [1, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [NullValue.Instance(), Elements["A"]]), // 20 _ A _ _ _ _ _ _ _ _ new Chain( - new[] { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 }, - new Alphabet() { NullValue.Instance(), Elements["A"] }), + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0], + [NullValue.Instance(), Elements["A"]]), // 21 A A _ _ _ _ _ _ _ _ new Chain( - new[] { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 }, - new Alphabet() { NullValue.Instance(), Elements["A"] }), + [1, 1, 0, 0, 0, 0, 0, 0, 0, 0], + [NullValue.Instance(), Elements["A"]]), // 22 A B _ _ _ _ _ _ _ _ new Chain( - new[] { 1, 2, 0, 0, 0, 0, 0, 0, 0, 0 }, - new Alphabet() { NullValue.Instance(), Elements["A"], Elements["B"] }), + [1, 2, 0, 0, 0, 0, 0, 0, 0, 0], + [NullValue.Instance(), Elements["A"], Elements["B"]]), // 23 B _ _ _ _ _ _ _ _ _ new Chain( - new[] { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - new Alphabet() { NullValue.Instance(), Elements["B"] }), + [1, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [NullValue.Instance(), Elements["B"]]), // 24 A _ _ A _ _ _ _ _ _ new Chain( - new[] { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, - new Alphabet() { NullValue.Instance(), Elements["A"] }), + [1, 0, 0, 1, 0, 0, 0, 0, 0, 0], + [NullValue.Instance(), Elements["A"]]), // 25 A _ _ _ _ B _ _ _ _ new Chain( - new[] { 1, 0, 0, 0, 0, 2, 0, 0, 0, 0 }, - new Alphabet() { NullValue.Instance(), Elements["A"], Elements["B"] }), + [1, 0, 0, 0, 0, 2, 0, 0, 0, 0], + [NullValue.Instance(), Elements["A"], Elements["B"]]), // 26 A _ _ B _ B _ _ _ _ new Chain( - new[] { 1, 0, 0, 2, 0, 2, 0, 0, 0, 0 }, - new Alphabet() { NullValue.Instance(), Elements["A"], Elements["B"] }), + [1, 0, 0, 2, 0, 2, 0, 0, 0, 0], + [NullValue.Instance(), Elements["A"], Elements["B"]]), // 27 A _ _ _ _ C _ _ _ _ new Chain( - new[] { 1, 0, 0, 0, 0, 2, 0, 0, 0, 0 }, - new Alphabet() { NullValue.Instance(), Elements["A"], Elements["C"] }), + [1, 0, 0, 0, 0, 2, 0, 0, 0, 0], + [NullValue.Instance(), Elements["A"], Elements["C"]]), // 28 A _ _ B _ C _ _ _ _ new Chain( - new[] { 1, 0, 0, 2, 0, 3, 0, 0, 0, 0 }, - new Alphabet() { NullValue.Instance(), Elements["A"], Elements["B"], Elements["C"] }), + [1, 0, 0, 2, 0, 3, 0, 0, 0, 0], + [NullValue.Instance(), Elements["A"], Elements["B"], Elements["C"]]), // 29 _ _ _ _ _ C _ _ _ _ new Chain( - new[] { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, - new Alphabet() { NullValue.Instance(), Elements["C"] }) + [0, 0, 0, 0, 0, 1, 0, 0, 0, 0], + [NullValue.Instance(), Elements["C"]]) - }; + ]; /// /// Cretes list of chains of "high order". /// - public static List HighOrderChains => new List - { + public static List HighOrderChains => + [ // 1 1 3 1 5 4 3 3 1 4 new Chain(new List { 1, 1, 3, 1, 5, 4, 3, 3, 1, 4 }), // 0 @@ -219,13 +219,13 @@ public static class ChainsStorage // 2 4 5 1 6 1 4 2 2 1 new Chain(new List { 2, 4, 5, 1, 6, 1, 4, 2, 2, 1 }), // 6 - }; + ]; /// /// Cretes list of chains for concatenation. /// - public static List ConcatinationChains => new List - { + public static List ConcatinationChains => + [ new Chain("BBAACBACCB"), // 0 new Chain("ACTTGATACG"), // 1 new Chain("CCACGCTTAC"), // 2 @@ -235,14 +235,14 @@ public static class ChainsStorage new Chain("ACTTGATACGCCACGCTTACBBAACBACCB"), // 6 new Chain("CCACGCTTACBBAACBACCBACTTGATACG"), // 7 new Chain("CCACGCTTACACTTGATACGBBAACBACCB") // 8 - }; + ]; /// /// Creates list of dissimilar chains. /// - public static List DissimilarChains => new List - { + public static List DissimilarChains => + [ // 1 2 1 2 1 3 3 2 3 4 new Chain(new List { 1, 2, 1, 2, 1, 3, 3, 2, 3, 4 }), // 0 @@ -260,188 +260,188 @@ public static class ChainsStorage // 1 1 2 1 3 1 4 2 3 1 new Chain(new List { 1, 1, 2, 1, 3, 1, 4, 2, 3, 1 }), // 5 - }; + ]; /// /// Creates list of congeneric chains. /// - public static List CongenericChains => new List - { + public static List CongenericChains => + [ // 0 _ _ _ A A _ _ A _ _ - new CongenericChain(new List { 3, 4, 7 }, Elements["A"], 10), + new CongenericChain([3, 4, 7], Elements["A"], 10), // 1 _ _ _ B _ B B _ _ _ _ B _ _ _ - new CongenericChain(new List { 3, 5, 6, 11 }, Elements["B"], 15), + new CongenericChain([3, 5, 6, 11], Elements["B"], 15), // 2 B - new CongenericChain(new List { 0 }, Elements["A"], 1), + new CongenericChain([0], Elements["A"], 1), // 3 _ _ _ _ _ _ _ B - new CongenericChain(new List { 7 }, Elements["A"], 8), + new CongenericChain([7], Elements["A"], 8), // 4 - new CongenericChain(new List { 100, 100000, 500000 }, Elements["A"], 1000000), + new CongenericChain([100, 100000, 500000], Elements["A"], 1000000), // 5 A A A A A - new CongenericChain(new List { 0, 1, 2, 3, 4 }, Elements["A"], 5), + new CongenericChain([0, 1, 2, 3, 4], Elements["A"], 5), // 6 A _ _ A _ _ _ _ _ _ _ _ _ _ _ _ _ _ - new CongenericChain(new List { 0, 3 }, Elements["A"], 18), + new CongenericChain([0, 3], Elements["A"], 18), // 7 _ _ A _ _ _ _ _ _ _ _ _ _ _ _ _ _ a - new CongenericChain(new List { 2, 17 }, Elements["A"], 18), + new CongenericChain([2, 17], Elements["A"], 18), // 8 A _ _ _ _ A _ _ _ _ _ A _ _ _ _ _ _ _ A _ _ _ _ A _ _ _ _ - new CongenericChain(new List { 0, 5, 11, 19, 24 }, Elements["A"], 30), + new CongenericChain([0, 5, 11, 19, 24], Elements["A"], 30), // 9 _ _ A _ _ _ A _ _ _ _ _ _ _ _ A _ _ _ _ _ _ _ A _ _ A _ _ - new CongenericChain(new List { 2, 6, 15, 23, 26 }, Elements["A"], 30), + new CongenericChain([2, 6, 15, 23, 26], Elements["A"], 30), // 10 A _ _ _ _ _ _ _ A _ A _ _ A _ _ _ _ _ _ - new CongenericChain(new List { 0, 8, 10, 13 }, Elements["A"], 20), + new CongenericChain([0, 8, 10, 13], Elements["A"], 20), // 11 _ A a _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ A _ - new CongenericChain(new List { 1, 2, 18 }, Elements["A"], 20), + new CongenericChain([1, 2, 18], Elements["A"], 20), // 12 A _ _ _ _ _ _ _ A _ _ A _ A _ A _ A _ A _ _ _ _ A _ _ - new CongenericChain(new List { 0, 8, 11, 13, 15, 17, 19, 24 }, Elements["A"], 27), + new CongenericChain([0, 8, 11, 13, 15, 17, 19, 24], Elements["A"], 27), // 13 _ A _ A a _ A _ _ A a _ _ _ _ A _ _ _ _ _ _ A _ _ _ A - new CongenericChain(new List { 1, 3, 4, 6, 9, 10, 22, 26 }, Elements["A"], 27), + new CongenericChain([1, 3, 4, 6, 9, 10, 22, 26], Elements["A"], 27), // 14 A _ _ A _ _ _ _ _ A _ A _ _ _ _ _ - new CongenericChain(new List { 0, 3, 9, 11 }, Elements["A"], 17), + new CongenericChain([0, 3, 9, 11], Elements["A"], 17), // 15 _ A _ _ _ _ _ A _ _ A _ _ _ A _ _ - new CongenericChain(new List { 1, 7, 10, 14 }, Elements["A"], 17), + new CongenericChain([1, 7, 10, 14], Elements["A"], 17), // 16 A _ _ _ A _ _ _ _ _ A _ _ A _ _ _ _ _ _ _ _ _ - new CongenericChain(new List { 0, 4, 10, 13 }, Elements["A"], 23), + new CongenericChain([0, 4, 10, 13], Elements["A"], 23), // 17 _ A _ _ _ _ _ _ _ A _ _ A _ _ _ _ _ A _ _ _ _ - new CongenericChain(new List { 1, 9, 12, 18 }, Elements["A"], 23), - }; + new CongenericChain([1, 9, 12, 18], Elements["A"], 23), + ]; /// /// Creates list of "binary" chains. /// - public static List BinaryChains => new List - { + public static List BinaryChains => + [ // 0 A A B A _ A _ _ B A new Chain( - new[] { 1, 1, 2, 1, 0, 1, 0, 0, 2 }, - new Alphabet() { NullValue.Instance(), Elements["A"], Elements["B"] }), + [1, 1, 2, 1, 0, 1, 0, 0, 2], + [NullValue.Instance(), Elements["A"], Elements["B"]]), // ----------- sequences from Morozenko's paper ----------- // 1 A B new Chain( - new[] { 1, 2 }, - new Alphabet() { NullValue.Instance(), Elements["A"], Elements["B"] }), + [1, 2], + [NullValue.Instance(), Elements["A"], Elements["B"]]), // 2 A _ _ B _ _ new Chain( - new[] { 1, 0, 0, 2, 0, 0 }, - new Alphabet() { NullValue.Instance(), Elements["A"], Elements["B"] }), + [1, 0, 0, 2, 0, 0], + [NullValue.Instance(), Elements["A"], Elements["B"]]), // 3 A _ _ B A _ _ _ _ B _ _ A _ _ _ B _ _ A _ _ _ _ _ _ B new Chain( - new[] { 1, 0, 0, 2, 1, 0, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0, 2 }, - new Alphabet() { NullValue.Instance(), Elements["A"], Elements["B"] }), + [1, 0, 0, 2, 1, 0, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0, 2], + [NullValue.Instance(), Elements["A"], Elements["B"]]), // 4 A B _ _ _ new Chain( - new[] { 1, 2, 0, 0, 0 }, - new Alphabet() { NullValue.Instance(), Elements["A"], Elements["B"] }), + [1, 2, 0, 0, 0], + [NullValue.Instance(), Elements["A"], Elements["B"]]), // 5 A B _ _ _ _ _ _ _ _ _ _ new Chain( - new[] { 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - new Alphabet() { NullValue.Instance(), Elements["A"], Elements["B"] }), + [1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [NullValue.Instance(), Elements["A"], Elements["B"]]), // 6 A _ _ _ _ _ _ _ _ _ _ _ B new Chain( - new[] { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2 }, - new Alphabet() { NullValue.Instance(), Elements["A"], Elements["B"] }), + [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2], + [NullValue.Instance(), Elements["A"], Elements["B"]]), // 7 A _ _ _ _ _ _ _ _ _ B _ B B A _ _ A A A _ _ A _ _ _ _ _ B new Chain( - new[] { 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 2, 2, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 2 }, - new Alphabet() { NullValue.Instance(), Elements["A"], Elements["B"] }), + [1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 2, 2, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 2], + [NullValue.Instance(), Elements["A"], Elements["B"]]), // 8 // 7 A _ _ A _ _ B _ _ _ _ _ A A _ A _ A _ _ _ B _ A B new Chain( - new[] { 1, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 2, 0, 1, 2 }, - new Alphabet() { NullValue.Instance(), Elements["A"], Elements["B"] }), + [1, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 2, 0, 1, 2], + [NullValue.Instance(), Elements["A"], Elements["B"]]), // 9 A _ B A A _ A _ _ _ _ _ _ _ _ _ _ B A _ _ A _ _ _ _ _ _ B new Chain( - new[] { 1, 0, 2, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 2 }, - new Alphabet() { NullValue.Instance(), Elements["A"], Elements["B"] }), + [1, 0, 2, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 2], + [NullValue.Instance(), Elements["A"], Elements["B"]]), // 10 A _ _ _ B _ _ _ A _ _ _ B _ _ _ A B A B _ _ _ _ _ _ _ _ new Chain( - new[] { 1, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 1, 2, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0 }, - new Alphabet() { NullValue.Instance(), Elements["A"], Elements["B"] }), + [1, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 1, 2, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0], + [NullValue.Instance(), Elements["A"], Elements["B"]]), // 11 A _ B _ _ _ _ _ _ A _ B _ _ _ _ A _ _ B _ _ _ _ A B _ 0 new Chain( - new[] { 1, 0, 2, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 1, 2, 0, 0 }, - new Alphabet() { NullValue.Instance(), Elements["A"], Elements["B"] }), + [1, 0, 2, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 1, 2, 0, 0], + [NullValue.Instance(), Elements["A"], Elements["B"]]), // 12 A _ _ _ B _ _ _ A _ _ _ B _ _ _ new Chain( - new[] { 1, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0 }, - new Alphabet() { NullValue.Instance(), Elements["A"], Elements["B"] }), + [1, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0], + [NullValue.Instance(), Elements["A"], Elements["B"]]), // 13 A _ _ B _ _ A _ _ B A _ _ B _ _ _ _ A _ _ B _ _ _ _ _ _ _ _ new Chain( - new[] { 1, 0, 0, 2, 0, 0, 1, 0, 0, 2, 1, 0, 0, 2, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0 }, - new Alphabet() { NullValue.Instance(), Elements["A"], Elements["B"] }), + [1, 0, 0, 2, 0, 0, 1, 0, 0, 2, 1, 0, 0, 2, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0], + [NullValue.Instance(), Elements["A"], Elements["B"]]), // 14 _ _ _ _ A B _ _ A B _ _ _ _ A B _ _ A B _ _ _ new Chain( - new[] { 0, 0, 0, 0, 1, 2, 0, 0, 1, 2, 0, 0, 0, 0, 1, 2, 0, 0, 1, 2, 0, 0, 0 }, - new Alphabet() { NullValue.Instance(), Elements["A"], Elements["B"] }), + [0, 0, 0, 0, 1, 2, 0, 0, 1, 2, 0, 0, 0, 0, 1, 2, 0, 0, 1, 2, 0, 0, 0], + [NullValue.Instance(), Elements["A"], Elements["B"]]), // 15 _ B _ B A B _ _ B _ _ _ new Chain( - new[] { 0, 2, 0, 2, 1, 2, 0, 0, 2, 0, 0, 0 }, - new Alphabet() { NullValue.Instance(), Elements["A"], Elements["B"] }), + [0, 2, 0, 2, 1, 2, 0, 0, 2, 0, 0, 0], + [NullValue.Instance(), Elements["A"], Elements["B"]]), // 16 _ _ A _ _ _ B _ _ A A _ _ _ B _ _ A _ _ _ _ B _ _ _ _ _ _ new Chain( - new[] { 0, 0, 1, 0, 0, 0, 2, 0, 0, 1, 1, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0 }, - new Alphabet() { NullValue.Instance(), Elements["A"], Elements["B"] }), + [0, 0, 1, 0, 0, 0, 2, 0, 0, 1, 1, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0], + [NullValue.Instance(), Elements["A"], Elements["B"]]), // -------------- sequences from the monograph -------------- // 17 A _ B _ _ _ A _ B _ _ _ A _ _ _ _ _ _ B _ _ _ _ _ _ new Chain( - new[] { 1, 0, 2, 0, 0, 0, 1, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0 }, - new Alphabet() { NullValue.Instance(), Elements["A"], Elements["B"] }), + [1, 0, 2, 0, 0, 0, 1, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0], + [NullValue.Instance(), Elements["A"], Elements["B"]]), // 18 A B C B A B C C B C C C new Chain( - new[] { 1, 2, 3, 2, 1, 2, 3, 3, 2, 3, 3, 3 }, - new Alphabet() { NullValue.Instance(), Elements["A"], Elements["B"], Elements["C"] }), + [1, 2, 3, 2, 1, 2, 3, 3, 2, 3, 3, 3], + [NullValue.Instance(), Elements["A"], Elements["B"], Elements["C"]]), // 19 A B _ _ _ _ A B _ _ _ A B _ _ _ _ _ _ _ _ A B new Chain( - new[] { 1, 2, 0, 0, 0, 0, 1, 2, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2 }, - new Alphabet() { NullValue.Instance(), Elements["A"], Elements["B"] }), + [1, 2, 0, 0, 0, 0, 1, 2, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2], + [NullValue.Instance(), Elements["A"], Elements["B"]]), // 20 A C A _ C C _ A A A C C A new Chain( - new [] { 1, 2, 1, 0, 2, 2, 0, 1, 1, 1, 2, 2, 1 }, - new Alphabet(){ NullValue.Instance(), Elements["A"], Elements["C"] }) - }; + [1, 2, 1, 0, 2, 2, 0, 1, 1, 1, 2, 2, 1], + [NullValue.Instance(), Elements["A"], Elements["C"]]) + ]; /// /// Creates dictionary of intervals with as keys. /// - public static List>> Intervals => new List>> - { + public static List>> Intervals => + [ new Dictionary> { { Link.Start, new List { 4, 1, 3 } }, @@ -495,5 +495,5 @@ public static class ChainsStorage { Link.Cycle, new List { 1, 1, 1, 1, 1 } }, { Link.None, new List { 1, 1, 1, 1 } } } - }; + ]; } diff --git a/Libiada.Core.Tests/Core/Characteristics/Calculators/AccordanceCalculators/AccordanceCalculatorsFactoryTests.cs b/Libiada.Core.Tests/Core/Characteristics/Calculators/AccordanceCalculators/AccordanceCalculatorsFactoryTests.cs index 624f786f..d0ea4beb 100644 --- a/Libiada.Core.Tests/Core/Characteristics/Calculators/AccordanceCalculators/AccordanceCalculatorsFactoryTests.cs +++ b/Libiada.Core.Tests/Core/Characteristics/Calculators/AccordanceCalculators/AccordanceCalculatorsFactoryTests.cs @@ -23,7 +23,7 @@ public class AccordanceCalculatorsFactoryTests [TestCase(AccordanceCharacteristic.PartialComplianceDegree, typeof(PartialComplianceDegree))] public void CreateCalculatorTest(AccordanceCharacteristic type, Type calculator) { - Assert.IsInstanceOf(calculator, AccordanceCalculatorsFactory.CreateCalculator(type)); + Assert.That(AccordanceCalculatorsFactory.CreateCalculator(type), Is.TypeOf(calculator)); } /// diff --git a/Libiada.Core.Tests/Core/Characteristics/Calculators/AccordanceCalculators/AccordanceCalculatorsTests.cs b/Libiada.Core.Tests/Core/Characteristics/Calculators/AccordanceCalculators/AccordanceCalculatorsTests.cs index ac9b28b1..ea869c64 100644 --- a/Libiada.Core.Tests/Core/Characteristics/Calculators/AccordanceCalculators/AccordanceCalculatorsTests.cs +++ b/Libiada.Core.Tests/Core/Characteristics/Calculators/AccordanceCalculators/AccordanceCalculatorsTests.cs @@ -29,7 +29,7 @@ /// /// Gets or sets the calculator. /// - private readonly T calculator = new T(); + private readonly T calculator = new(); /// /// The calculation test. @@ -49,8 +49,8 @@ protected void CalculationTest(int index, double firstValue, double secondValue) var secondChain = binaryChains[index].CongenericChain(elements["B"]); double result1 = calculator.Calculate(firstChain, secondChain, Link.End); double result2 = calculator.Calculate(secondChain, firstChain, Link.End); - Assert.AreEqual(firstValue, result1, 0.0001); - Assert.AreEqual(secondValue, result2, 0.0001); + Assert.That(result1, Is.EqualTo(firstValue).Within(0.0001d)); + Assert.That(result2, Is.EqualTo(secondValue).Within(0.0001d)); } /// @@ -68,6 +68,6 @@ protected void CalculationTest(int index, double firstValue, double secondValue) protected void CalculationTest(int firstIndex, int secondIndex, double firstValue) { double result = calculator.Calculate(congenericChains[firstIndex], congenericChains[secondIndex], Link.End); - Assert.AreEqual(firstValue, result, 0.0001); + Assert.That(result, Is.EqualTo(firstValue).Within(0.0001d)); } } diff --git a/Libiada.Core.Tests/Core/Characteristics/Calculators/BinaryCalculators/BinaryCalculatorsFactoryTests.cs b/Libiada.Core.Tests/Core/Characteristics/Calculators/BinaryCalculators/BinaryCalculatorsFactoryTests.cs index dbc0eab8..ed964f8b 100644 --- a/Libiada.Core.Tests/Core/Characteristics/Calculators/BinaryCalculators/BinaryCalculatorsFactoryTests.cs +++ b/Libiada.Core.Tests/Core/Characteristics/Calculators/BinaryCalculators/BinaryCalculatorsFactoryTests.cs @@ -27,7 +27,7 @@ public class BinaryCalculatorsFactoryTests [TestCase(BinaryCharacteristic.Redundancy, typeof(Redundancy))] public void CreateCalculatorTest(BinaryCharacteristic type, Type calculator) { - Assert.IsInstanceOf(calculator, BinaryCalculatorsFactory.CreateCalculator(type)); + Assert.That(BinaryCalculatorsFactory.CreateCalculator(type), Is.TypeOf(calculator)); } /// diff --git a/Libiada.Core.Tests/Core/Characteristics/Calculators/BinaryCalculators/BinaryCalculatorsTests.cs b/Libiada.Core.Tests/Core/Characteristics/Calculators/BinaryCalculators/BinaryCalculatorsTests.cs index e1a43d20..4b849de1 100644 --- a/Libiada.Core.Tests/Core/Characteristics/Calculators/BinaryCalculators/BinaryCalculatorsTests.cs +++ b/Libiada.Core.Tests/Core/Characteristics/Calculators/BinaryCalculators/BinaryCalculatorsTests.cs @@ -19,7 +19,7 @@ /// /// Gets or sets the calculator. /// - protected readonly T Calculator = new T(); + protected readonly T Calculator = new(); /// /// The elements. @@ -42,7 +42,7 @@ protected void CalculationTest(int index, double firstValue, double secondValue) { double result1 = Calculator.Calculate(Chains[index].GetRelationIntervalsManager(elements["A"], elements["B"]), Link.End); double result2 = Calculator.Calculate(Chains[index].GetRelationIntervalsManager(elements["B"], elements["A"]), Link.End); - Assert.AreEqual(firstValue, result1, 0.0001); - Assert.AreEqual(secondValue, result2, 0.0001); + Assert.That(result1, Is.EqualTo(firstValue).Within(0.0001)); + Assert.That(result2, Is.EqualTo(secondValue).Within(0.0001)); } } diff --git a/Libiada.Core.Tests/Core/Characteristics/Calculators/BinaryCalculators/InvolvedPartialDependenceCoefficientTests.cs b/Libiada.Core.Tests/Core/Characteristics/Calculators/BinaryCalculators/InvolvedPartialDependenceCoefficientTests.cs index e286e70d..0a44e9bb 100644 --- a/Libiada.Core.Tests/Core/Characteristics/Calculators/BinaryCalculators/InvolvedPartialDependenceCoefficientTests.cs +++ b/Libiada.Core.Tests/Core/Characteristics/Calculators/BinaryCalculators/InvolvedPartialDependenceCoefficientTests.cs @@ -51,28 +51,28 @@ public void GetK2Test() { List> result = Calculator.CalculateAll(Chains[1], Link.End); - Assert.AreEqual(0, result[0][0]); - Assert.AreEqual(0, result[0][1]); - Assert.AreEqual(0, result[1][0]); - Assert.AreEqual(0, result[1][1]); + Assert.That(result[0][0], Is.Zero); + Assert.That(result[0][1], Is.Zero); + Assert.That(result[1][0], Is.Zero); + Assert.That(result[1][1], Is.Zero); result = Calculator.CalculateAll(Chains[10], Link.End); - Assert.AreEqual(0, result[0][0]); - Assert.AreEqual(0.614, Math.Round(result[0][1], 3)); - Assert.AreEqual(0.402, Math.Round(result[1][0], 3)); - Assert.AreEqual(0, result[1][1]); + Assert.That(result[0][0], Is.Zero); + Assert.That(Math.Round(result[0][1], 3), Is.EqualTo(0.614)); + Assert.That(Math.Round(result[1][0], 3), Is.EqualTo(0.402)); + Assert.That(result[1][1], Is.Zero); result = Calculator.CalculateAll(Chains[18], Link.End); - Assert.AreEqual(0, result[0][0]); - Assert.AreEqual(0.5407, Math.Round(result[0][1], 4)); - Assert.AreEqual(0.296, Math.Round(result[0][2], 3)); - Assert.AreEqual(0.292, Math.Round(result[1][0], 3)); - Assert.AreEqual(0, result[1][1]); - Assert.AreEqual(0.418, Math.Round(result[1][2], 3)); - Assert.AreEqual(0.1875, Math.Round(result[2][0], 4)); - Assert.AreEqual(0.311, Math.Round(result[2][1], 3)); - Assert.AreEqual(0, result[2][2]); + Assert.That(result[0][0], Is.Zero); + Assert.That(Math.Round(result[0][1], 4), Is.EqualTo(0.5407)); + Assert.That(Math.Round(result[0][2], 3), Is.EqualTo(0.296)); + Assert.That(Math.Round(result[1][0], 3), Is.EqualTo(0.292)); + Assert.That(result[1][1], Is.Zero); + Assert.That(Math.Round(result[1][2], 3), Is.EqualTo(0.418)); + Assert.That(Math.Round(result[2][0], 4), Is.EqualTo(0.1875)); + Assert.That(Math.Round(result[2][1], 3), Is.EqualTo(0.311)); + Assert.That(result[2][2], Is.Zero); } } diff --git a/Libiada.Core.Tests/Core/Characteristics/Calculators/BinaryCalculators/MutualDependenceCoefficientTests.cs b/Libiada.Core.Tests/Core/Characteristics/Calculators/BinaryCalculators/MutualDependenceCoefficientTests.cs index df097bd2..c49dacdd 100644 --- a/Libiada.Core.Tests/Core/Characteristics/Calculators/BinaryCalculators/MutualDependenceCoefficientTests.cs +++ b/Libiada.Core.Tests/Core/Characteristics/Calculators/BinaryCalculators/MutualDependenceCoefficientTests.cs @@ -49,28 +49,37 @@ public void GetK3Test() { List> result = Calculator.CalculateAll(Chains[1], Link.End); - Assert.AreEqual(0, result[0][0]); - Assert.AreEqual(0, result[0][1]); - Assert.AreEqual(0, result[1][0]); - Assert.AreEqual(0, result[1][1]); + Assert.Multiple(() => + { + Assert.That(result[0][0], Is.Zero); + Assert.That(result[0][1], Is.Zero); + Assert.That(result[1][0], Is.Zero); + Assert.That(result[1][1], Is.Zero); + }); result = Calculator.CalculateAll(Chains[10], Link.End); - Assert.AreEqual(0, result[0][0]); - Assert.AreEqual(0.497, Math.Round(result[0][1], 3)); - Assert.AreEqual(0.497, Math.Round(result[1][0], 3)); - Assert.AreEqual(0, result[1][1]); + Assert.Multiple(() => + { + Assert.That(result[0][0], Is.Zero); + Assert.That(result[0][1], Is.EqualTo(0.497).Within(0.001d)); + Assert.That(result[1][0], Is.EqualTo(0.497).Within(0.001d)); + Assert.That(result[1][1], Is.Zero); + }); result = Calculator.CalculateAll(Chains[18], Link.End); - Assert.AreEqual(0, result[0][0]); - Assert.AreEqual(0.397, Math.Round(result[0][1], 3)); - Assert.AreEqual(0.236, Math.Round(result[0][2], 3)); - Assert.AreEqual(0.397, Math.Round(result[1][0], 3)); - Assert.AreEqual(0, result[1][1]); - Assert.AreEqual(0.360, Math.Round(result[1][2], 3)); - Assert.AreEqual(0.236, Math.Round(result[2][0], 3)); - Assert.AreEqual(0.360, Math.Round(result[2][1], 3)); - Assert.AreEqual(0, result[2][2]); + Assert.Multiple(() => + { + Assert.That(result[0][0], Is.Zero); + Assert.That(result[0][1], Is.EqualTo(0.397).Within(0.001d)); + Assert.That(result[0][2], Is.EqualTo(0.236).Within(0.001d)); + Assert.That(result[1][0], Is.EqualTo(0.397).Within(0.001d)); + Assert.That(result[1][1], Is.Zero); + Assert.That(result[1][2], Is.EqualTo(0.360).Within(0.001d)); + Assert.That(result[2][0], Is.EqualTo(0.236).Within(0.001d)); + Assert.That(result[2][1], Is.EqualTo(0.360).Within(0.001d)); + Assert.That(result[2][2], Is.Zero); + }); } } diff --git a/Libiada.Core.Tests/Core/Characteristics/Calculators/BinaryCalculators/NormalizedPartialDependenceCoefficientTests.cs b/Libiada.Core.Tests/Core/Characteristics/Calculators/BinaryCalculators/NormalizedPartialDependenceCoefficientTests.cs index faab21ff..d53f5616 100644 --- a/Libiada.Core.Tests/Core/Characteristics/Calculators/BinaryCalculators/NormalizedPartialDependenceCoefficientTests.cs +++ b/Libiada.Core.Tests/Core/Characteristics/Calculators/BinaryCalculators/NormalizedPartialDependenceCoefficientTests.cs @@ -51,28 +51,37 @@ public void GetNormalizedK1Test() { List> result = Calculator.CalculateAll(Chains[1], Link.End); - Assert.AreEqual(0, result[0][0]); - Assert.AreEqual(0, result[0][1]); - Assert.AreEqual(0, result[1][0]); - Assert.AreEqual(0, result[1][1]); + Assert.Multiple(() => + { + Assert.That(result[0][0], Is.Zero); + Assert.That(result[0][1], Is.Zero); + Assert.That(result[1][0], Is.Zero); + Assert.That(result[1][1], Is.Zero); + }); result = Calculator.CalculateAll(Chains[10], Link.End); - Assert.AreEqual(0, result[0][0]); - Assert.AreEqual(0.175, Math.Round(result[0][1], 3)); - Assert.AreEqual(0.086, Math.Round(result[1][0], 3)); - Assert.AreEqual(0, result[1][1]); + Assert.Multiple(() => + { + Assert.That(result[0][0], Is.Zero); + Assert.That(result[0][1], Is.EqualTo(0.175).Within(0.001d)); + Assert.That(result[1][0], Is.EqualTo(0.086).Within(0.001d)); + Assert.That(result[1][1], Is.Zero); + }); result = Calculator.CalculateAll(Chains[18], Link.End); - Assert.AreEqual(0, result[0][0]); - Assert.AreEqual(0.1352, Math.Round(result[0][1], 4)); - Assert.AreEqual(0.066, Math.Round(result[0][2], 3)); - Assert.AreEqual(0.0729, Math.Round(result[1][0], 4)); - Assert.AreEqual(0, result[1][1]); - Assert.AreEqual(0.174, Math.Round(result[1][2], 3)); - Assert.AreEqual(0.062, Math.Round(result[2][0], 3)); - Assert.AreEqual(0.129, Math.Round(result[2][1], 3)); - Assert.AreEqual(0, result[2][2]); + Assert.Multiple(() => + { + Assert.That(result[0][0], Is.Zero); + Assert.That(result[0][1], Is.EqualTo(0.1352).Within(0.0001d)); + Assert.That(result[0][2], Is.EqualTo(0.066).Within(0.001d)); + Assert.That(result[1][0], Is.EqualTo(0.0729).Within(0.0001d)); + Assert.That(result[1][1], Is.Zero); + Assert.That(result[1][2], Is.EqualTo(0.174).Within(0.001d)); + Assert.That(result[2][0], Is.EqualTo(0.062).Within(0.001d)); + Assert.That(result[2][1], Is.EqualTo(0.129).Within(0.001d)); + Assert.That(result[2][2], Is.Zero); + }); } } diff --git a/Libiada.Core.Tests/Core/Characteristics/Calculators/BinaryCalculators/PartialDependenceCoefficientTests.cs b/Libiada.Core.Tests/Core/Characteristics/Calculators/BinaryCalculators/PartialDependenceCoefficientTests.cs index a97005b4..0eee0de3 100644 --- a/Libiada.Core.Tests/Core/Characteristics/Calculators/BinaryCalculators/PartialDependenceCoefficientTests.cs +++ b/Libiada.Core.Tests/Core/Characteristics/Calculators/BinaryCalculators/PartialDependenceCoefficientTests.cs @@ -51,28 +51,37 @@ public void GetK1Test() { List> result = Calculator.CalculateAll(Chains[1], Link.End); - Assert.AreEqual(0, result[0][0]); - Assert.AreEqual(0, result[0][1]); - Assert.AreEqual(0, result[1][0]); - Assert.AreEqual(0, result[1][1]); + Assert.Multiple(() => + { + Assert.That(result[0][0], Is.Zero); + Assert.That(result[0][1], Is.Zero); + Assert.That(result[1][0], Is.Zero); + Assert.That(result[1][1], Is.Zero); + }); result = Calculator.CalculateAll(Chains[10], Link.End); - Assert.AreEqual(0, result[0][0]); - Assert.AreEqual(0.614, Math.Round(result[0][1], 3)); - Assert.AreEqual(0.402, Math.Round(result[1][0], 3)); - Assert.AreEqual(0, result[1][1]); + Assert.Multiple(() => + { + Assert.That(result[0][0], Is.Zero); + Assert.That(result[0][1], Is.EqualTo(0.614).Within(0.001d)); + Assert.That(result[1][0], Is.EqualTo(0.402).Within(0.001d)); + Assert.That(result[1][1], Is.Zero); + }); result = Calculator.CalculateAll(Chains[18], Link.End); - Assert.AreEqual(0, result[0][0]); - Assert.AreEqual(0.4055, Math.Round(result[0][1], 4)); - Assert.AreEqual(0.197, Math.Round(result[0][2], 3)); - Assert.AreEqual(0.4375, Math.Round(result[1][0], 4)); - Assert.AreEqual(0, result[1][1]); - Assert.AreEqual(0.349, Math.Round(result[1][2], 3)); - Assert.AreEqual(0.375, Math.Round(result[2][0], 3)); - Assert.AreEqual(0.388, Math.Round(result[2][1], 3)); - Assert.AreEqual(0, result[2][2]); + Assert.Multiple(() => + { + Assert.That(result[0][0], Is.Zero); + Assert.That(result[0][1], Is.EqualTo(0.4055).Within(0.0001d)); + Assert.That(result[0][2], Is.EqualTo(0.197).Within(0.001d)); + Assert.That(result[1][0], Is.EqualTo(0.4375).Within(0.0001d)); + Assert.That(result[1][1], Is.Zero); + Assert.That(result[1][2], Is.EqualTo(0.349).Within(0.001d)); + Assert.That(result[2][0], Is.EqualTo(0.375).Within(0.001d)); + Assert.That(result[2][1], Is.EqualTo(0.388).Within(0.001d)); + Assert.That(result[2][2], Is.Zero); + }); } } diff --git a/Libiada.Core.Tests/Core/Characteristics/Calculators/CongenericCalculators/CongenericCalculatorsFactoryTests.cs b/Libiada.Core.Tests/Core/Characteristics/Calculators/CongenericCalculators/CongenericCalculatorsFactoryTests.cs index 90b9956f..13f7e078 100644 --- a/Libiada.Core.Tests/Core/Characteristics/Calculators/CongenericCalculators/CongenericCalculatorsFactoryTests.cs +++ b/Libiada.Core.Tests/Core/Characteristics/Calculators/CongenericCalculators/CongenericCalculatorsFactoryTests.cs @@ -39,7 +39,7 @@ public class CongenericCalculatorsFactoryTests [TestCase(CongenericCharacteristic.Volume, typeof(Volume))] public void CreateCalculatorTest(CongenericCharacteristic type, Type calculator) { - Assert.IsInstanceOf(calculator, CongenericCalculatorsFactory.CreateCalculator(type)); + Assert.That(CongenericCalculatorsFactory.CreateCalculator(type), Is.TypeOf(calculator)); } /// diff --git a/Libiada.Core.Tests/Core/Characteristics/Calculators/CongenericCalculators/CongenericCalculatorsTests.cs b/Libiada.Core.Tests/Core/Characteristics/Calculators/CongenericCalculators/CongenericCalculatorsTests.cs index 063df3f1..0a905d80 100644 --- a/Libiada.Core.Tests/Core/Characteristics/Calculators/CongenericCalculators/CongenericCalculatorsTests.cs +++ b/Libiada.Core.Tests/Core/Characteristics/Calculators/CongenericCalculators/CongenericCalculatorsTests.cs @@ -19,7 +19,7 @@ /// /// Gets or sets the calculator. /// - private readonly T calculator = new T(); + private readonly T calculator = new(); /// /// The congeneric chain characteristic test. @@ -35,6 +35,6 @@ /// protected void CongenericChainCharacteristicTest(int index, Link link, double value) { - Assert.AreEqual(value, calculator.Calculate(congenericChains[index], link), 0.0001); + Assert.That(calculator.Calculate(congenericChains[index], link), Is.EqualTo(value).Within(0.0001d)); } } diff --git a/Libiada.Core.Tests/Core/Characteristics/Calculators/FullCalculators/AverageWordLengthTests.cs b/Libiada.Core.Tests/Core/Characteristics/Calculators/FullCalculators/AverageWordLengthTests.cs index ddde3e3c..fa2e6a37 100644 --- a/Libiada.Core.Tests/Core/Characteristics/Calculators/FullCalculators/AverageWordLengthTests.cs +++ b/Libiada.Core.Tests/Core/Characteristics/Calculators/FullCalculators/AverageWordLengthTests.cs @@ -45,7 +45,7 @@ public void CalculationTest() [4] = new ValueString("bla") }; double actual = Calculator.Calculate(sequence, Link.NotApplied); - Assert.AreEqual(5, actual, 0.0001); + Assert.That(actual, Is.EqualTo(5).Within(0.0001d)); sequence = new Chain(10) { @@ -61,7 +61,7 @@ public void CalculationTest() [9] = new ValueString("poiygtr") }; actual = Calculator.Calculate(sequence, Link.NotApplied); - Assert.AreEqual(5.6, actual, 0.0001); + Assert.That(actual, Is.EqualTo(5.6).Within(0.0001d)); sequence = new Chain(8) { @@ -75,6 +75,6 @@ public void CalculationTest() [7] = new ValueString("3456789012345") }; actual = Calculator.Calculate(sequence, Link.NotApplied); - Assert.AreEqual(6.875, actual, 0.0001); + Assert.That(actual, Is.EqualTo(6.875).Within(0.0001d)); } -} \ No newline at end of file +} diff --git a/Libiada.Core.Tests/Core/Characteristics/Calculators/FullCalculators/FullCalculatorsFactoryTests.cs b/Libiada.Core.Tests/Core/Characteristics/Calculators/FullCalculators/FullCalculatorsFactoryTests.cs index cc2ffadb..24400168 100644 --- a/Libiada.Core.Tests/Core/Characteristics/Calculators/FullCalculators/FullCalculatorsFactoryTests.cs +++ b/Libiada.Core.Tests/Core/Characteristics/Calculators/FullCalculators/FullCalculatorsFactoryTests.cs @@ -75,7 +75,7 @@ public class FullCalculatorsFactoryTests [TestCase(FullCharacteristic.Volume, typeof(Volume))] public void CreateCalculatorTest(FullCharacteristic type, Type calculator) { - Assert.IsInstanceOf(calculator, FullCalculatorsFactory.CreateCalculator(type)); + Assert.That(FullCalculatorsFactory.CreateCalculator(type), Is.TypeOf(calculator)); } /// diff --git a/Libiada.Core.Tests/Core/Characteristics/Calculators/FullCalculators/FullCalculatorsTests.cs b/Libiada.Core.Tests/Core/Characteristics/Calculators/FullCalculators/FullCalculatorsTests.cs index 3de7ef59..d4e3ca99 100644 --- a/Libiada.Core.Tests/Core/Characteristics/Calculators/FullCalculators/FullCalculatorsTests.cs +++ b/Libiada.Core.Tests/Core/Characteristics/Calculators/FullCalculators/FullCalculatorsTests.cs @@ -20,7 +20,7 @@ /// /// Gets or sets the calculator. /// - protected readonly T Calculator = new T(); + protected readonly T Calculator = new(); /// /// The chain characteristic test. @@ -36,7 +36,7 @@ /// protected void ChainCharacteristicTest(int index, Link link, double value) { - Assert.AreEqual(value, Calculator.Calculate(chains[index], link), 0.0001); + Assert.That(Calculator.Calculate(chains[index], link), Is.EqualTo(value).Within(0.0001d)); } /// @@ -54,6 +54,6 @@ protected void ChainCharacteristicTest(int index, Link link, double value) protected void SeriesCharacteristicTest(int index, Link link, double value) { chains[index].SetArrangementManagers(ArrangementType.Series); - Assert.AreEqual(value, Calculator.Calculate(chains[index], link), 0.0001); + Assert.That(Calculator.Calculate(chains[index], link), Is.EqualTo(value).Within(0.0001d)); } } diff --git a/Libiada.Core.Tests/Core/Characteristics/Calculators/FullCalculators/LinkedFullCalculatorTests.cs b/Libiada.Core.Tests/Core/Characteristics/Calculators/FullCalculators/LinkedFullCalculatorTests.cs index 7e314b6d..369f161f 100644 --- a/Libiada.Core.Tests/Core/Characteristics/Calculators/FullCalculators/LinkedFullCalculatorTests.cs +++ b/Libiada.Core.Tests/Core/Characteristics/Calculators/FullCalculators/LinkedFullCalculatorTests.cs @@ -41,6 +41,6 @@ public void CalculationTest(int sequenceIndex, FullCharacteristic type, Link lin { var calculator = new LinkedFullCalculator(type, link); double actual = calculator.Calculate(sequences[sequenceIndex]); - Assert.AreEqual(expected, actual, 0.0001); + Assert.That(actual, Is.EqualTo(expected).Within(0.0001d)); } } \ No newline at end of file diff --git a/Libiada.Core.Tests/Core/CongenericChainTests.cs b/Libiada.Core.Tests/Core/CongenericChainTests.cs index b0519709..dcb803c4 100644 --- a/Libiada.Core.Tests/Core/CongenericChainTests.cs +++ b/Libiada.Core.Tests/Core/CongenericChainTests.cs @@ -41,8 +41,8 @@ public void Initialization() [Test] public void ConstructorTest() { - Assert.AreEqual(10, congenericChain.Length); - Assert.AreEqual(message, congenericChain.Element); + Assert.That(congenericChain.Length, Is.EqualTo(10)); + Assert.That(congenericChain.Element, Is.EqualTo(message)); } /// @@ -55,7 +55,7 @@ public void IndependenceMessageTest() var newMessage = (ValueString)congenericChain.Element; - Assert.AreNotSame(congenericChain.Element, newMessage); + Assert.That(newMessage, Is.Not.SameAs(congenericChain.Element)); } /// @@ -65,7 +65,7 @@ public void IndependenceMessageTest() public void AddTest() { congenericChain.Set(message, 3); - Assert.AreEqual(message, congenericChain.Get(3)); + Assert.That(congenericChain.Get(3), Is.EqualTo(message)); } /// @@ -75,8 +75,8 @@ public void AddTest() public void WrongMessageTest() { congenericChain.Set(wrongMessage, 4); - Assert.AreNotEqual(wrongMessage, congenericChain.Get(4)); - Assert.AreEqual(NullValue.Instance(), congenericChain.Get(4)); + Assert.That(congenericChain.Get(4), Is.Not.EqualTo(wrongMessage)); + Assert.That(congenericChain.Get(4), Is.EqualTo(NullValue.Instance())); } /// @@ -87,8 +87,8 @@ public void RemoveTest() { congenericChain.Set(message, 3); congenericChain.RemoveAt(3); - Assert.AreNotEqual(message, congenericChain.Get(3)); - Assert.AreEqual(NullValue.Instance(), congenericChain.Get(3)); + Assert.That(congenericChain.Get(3), Is.Not.EqualTo(message)); + Assert.That(congenericChain.Get(3), Is.EqualTo(NullValue.Instance())); } /// @@ -99,8 +99,8 @@ public void DeleteTest() { congenericChain.Set(message, 3); congenericChain.DeleteAt(3); - Assert.AreNotEqual(message, congenericChain.Get(3)); - Assert.AreEqual(NullValue.Instance(), congenericChain.Get(3)); + Assert.That(congenericChain.Get(3), Is.Not.EqualTo(message)); + Assert.That(congenericChain.Get(3), Is.EqualTo(NullValue.Instance())); } /// @@ -111,8 +111,8 @@ public void ClearAndSetNewLengthTest() { const int newLength = 5; congenericChain.ClearAndSetNewLength(newLength); - Assert.AreEqual(newLength, congenericChain.Length); - Assert.IsEmpty(congenericChain.Positions); + Assert.That(congenericChain.Length, Is.EqualTo(newLength)); + Assert.That(congenericChain.Positions, Is.Empty); } /// @@ -123,9 +123,9 @@ public void CongenericChainTest() { var element = new ValueString("A"); var result = new CongenericChain(element); - Assert.AreEqual(element, result.Element); + Assert.That(result.Element, Is.EqualTo(element)); Assert.That(result.Length, Is.Zero); - Assert.IsEmpty(result.Positions); + Assert.That(result.Positions, Is.Empty); Assert.That(result.OccurrencesCount, Is.Zero); } @@ -135,11 +135,10 @@ public void CongenericChainTest() [Test] public void SetTest() { - List position = new List(); - position.Add(4); + List position = [4]; const int index = 5; congenericChain.Set(index); - Assert.AreNotEqual(position, congenericChain.Positions); + Assert.That(congenericChain.Positions, Is.Not.EqualTo(position)); } /// @@ -150,7 +149,7 @@ public void GetFirstAfterEmptyTest() { const int index = 3; const int expectedIndex = -1; - Assert.AreEqual(expectedIndex, congenericChain.GetFirstAfter(index)); + Assert.That(congenericChain.GetFirstAfter(index), Is.EqualTo(expectedIndex)); } /// @@ -163,26 +162,26 @@ public void GetFirstAfterTest() int expectedIndex = -1; congenericChain.Set(0); - Assert.AreEqual(expectedIndex, congenericChain.GetFirstAfter(index)); + Assert.That(congenericChain.GetFirstAfter(index), Is.EqualTo(expectedIndex)); congenericChain.Set(9); expectedIndex = 9; - Assert.AreEqual(expectedIndex, congenericChain.GetFirstAfter(index)); + Assert.That(congenericChain.GetFirstAfter(index), Is.EqualTo(expectedIndex)); index = 5; expectedIndex = 9; - Assert.AreEqual(expectedIndex, congenericChain.GetFirstAfter(index)); + Assert.That(congenericChain.GetFirstAfter(index), Is.EqualTo(expectedIndex)); congenericChain.Set(5); index = 0; expectedIndex = 5; - Assert.AreEqual(expectedIndex, congenericChain.GetFirstAfter(index)); + Assert.That(congenericChain.GetFirstAfter(index), Is.EqualTo(expectedIndex)); index = 4; - Assert.AreEqual(expectedIndex, congenericChain.GetFirstAfter(index)); + Assert.That(congenericChain.GetFirstAfter(index), Is.EqualTo(expectedIndex)); index = 5; expectedIndex = 9; - Assert.AreEqual(expectedIndex, congenericChain.GetFirstAfter(index)); + Assert.That(congenericChain.GetFirstAfter(index), Is.EqualTo(expectedIndex)); } } diff --git a/Libiada.Core.Tests/Core/CongenericScoreTrackTests.cs b/Libiada.Core.Tests/Core/CongenericScoreTrackTests.cs index fac9b821..3f635a16 100644 --- a/Libiada.Core.Tests/Core/CongenericScoreTrackTests.cs +++ b/Libiada.Core.Tests/Core/CongenericScoreTrackTests.cs @@ -18,32 +18,32 @@ public void ValueNoteOrderFirstTest() // создание и заполнения списка(ов) нот для такта(ов) монотрека var notes = new List { - new ValueNote(new Pitch(3, NoteSymbol.A, Accidental.DoubleSharp), new Duration(1, 16, false), false, Tie.None, 3), - new ValueNote(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), - new ValueNote(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), - new ValueNote(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 16, false), false, Tie.None, 1), - new ValueNote(new Pitch(3, NoteSymbol.A, Accidental.Flat), new Duration(1, 16, false), false, Tie.None, 3), - new ValueNote(new Pitch(3, NoteSymbol.D, Accidental.Bekar), new Duration(1, 16, false), false, Tie.None, 2), - new ValueNote(new Pitch(3, NoteSymbol.A, Accidental.DoubleSharp), new Duration(1, 16, false), false, Tie.None, 3), - new ValueNote(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 16, false), false, Tie.None, 1), - new ValueNote(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 16, false), false, Tie.None, 1) + new(new Pitch(3, NoteSymbol.A, Accidental.DoubleSharp), new Duration(1, 16, false), false, Tie.None, 3), + new(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), + new(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), + new(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 16, false), false, Tie.None, 1), + new(new Pitch(3, NoteSymbol.A, Accidental.Flat), new Duration(1, 16, false), false, Tie.None, 3), + new(new Pitch(3, NoteSymbol.D, Accidental.Bekar), new Duration(1, 16, false), false, Tie.None, 2), + new(new Pitch(3, NoteSymbol.A, Accidental.DoubleSharp), new Duration(1, 16, false), false, Tie.None, 3), + new(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 16, false), false, Tie.None, 1), + new(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 16, false), false, Tie.None, 1) }; var notes2 = new List { - new ValueNote(new Pitch(3, NoteSymbol.B, Accidental.Bekar), new Duration(1, 16, false), false, Tie.None, 1), - new ValueNote(new Pitch(3, NoteSymbol.A, Accidental.DoubleSharp), new Duration(1, 16, false), false, Tie.None, 3), - new ValueNote(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), - new ValueNote(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), - new ValueNote(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 16, false), false, Tie.None, 1), - new ValueNote(new Pitch(3, NoteSymbol.A, Accidental.Flat), new Duration(1, 16, false), false, Tie.None, 3), - new ValueNote(new Pitch(3, NoteSymbol.D, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 2), - new ValueNote(new Pitch(3, NoteSymbol.A, Accidental.DoubleSharp), new Duration(1, 16, false), false, Tie.None, 3), - new ValueNote(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 4, false), false, Tie.None, 1), - new ValueNote( new Duration(1, 4, false), false, Tie.None, 1), - new ValueNote(new Duration(1, 4, false), false, Tie.None, 1), - new ValueNote(new Duration(1, 16, false), false, Tie.None, 1), - new ValueNote(new Duration(1, 16, false), false, Tie.None, 1) + new(new Pitch(3, NoteSymbol.B, Accidental.Bekar), new Duration(1, 16, false), false, Tie.None, 1), + new(new Pitch(3, NoteSymbol.A, Accidental.DoubleSharp), new Duration(1, 16, false), false, Tie.None, 3), + new(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), + new(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), + new(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 16, false), false, Tie.None, 1), + new(new Pitch(3, NoteSymbol.A, Accidental.Flat), new Duration(1, 16, false), false, Tie.None, 3), + new(new Pitch(3, NoteSymbol.D, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 2), + new(new Pitch(3, NoteSymbol.A, Accidental.DoubleSharp), new Duration(1, 16, false), false, Tie.None, 3), + new(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 4, false), false, Tie.None, 1), + new( new Duration(1, 4, false), false, Tie.None, 1), + new(new Duration(1, 4, false), false, Tie.None, 1), + new(new Duration(1, 16, false), false, Tie.None, 1), + new(new Duration(1, 16, false), false, Tie.None, 1) }; var attr = new MeasureAttributes(new Size(4, 4), new Key(5)); @@ -55,36 +55,36 @@ public void ValueNoteOrderFirstTest() var uni = new CongenericScoreTrack(measuresList); - Assert.AreNotEqual(uni.NoteOrder()[0].Id, 1); + Assert.That(uni.NoteOrder()[0].Id, Is.Not.EqualTo(1)); - Assert.AreEqual(uni.NoteOrder()[0].Id, 0); - Assert.AreEqual(uni.NoteOrder()[1].Id, 1); - Assert.AreEqual(uni.NoteOrder()[2].Id, 1); + Assert.That(uni.NoteOrder()[0].Id, Is.EqualTo(0)); + Assert.That(uni.NoteOrder()[1].Id, Is.EqualTo(1)); + Assert.That(uni.NoteOrder()[2].Id, Is.EqualTo(1)); - Assert.AreEqual(uni.NoteOrder()[3].Id, 2); - Assert.AreEqual(uni.NoteOrder()[4].Id, 3); - Assert.AreEqual(uni.NoteOrder()[5].Id, 4); + Assert.That(uni.NoteOrder()[3].Id, Is.EqualTo(2)); + Assert.That(uni.NoteOrder()[4].Id, Is.EqualTo(3)); + Assert.That(uni.NoteOrder()[5].Id, Is.EqualTo(4)); - Assert.AreEqual(uni.NoteOrder()[6].Id, 0); - Assert.AreEqual(uni.NoteOrder()[7].Id, 2); - Assert.AreEqual(uni.NoteOrder()[8].Id, 2); + Assert.That(uni.NoteOrder()[6].Id, Is.EqualTo(0)); + Assert.That(uni.NoteOrder()[7].Id, Is.EqualTo(2)); + Assert.That(uni.NoteOrder()[8].Id, Is.EqualTo(2)); - Assert.AreEqual(uni.NoteOrder()[9].Id, 0); - Assert.AreEqual(uni.NoteOrder()[10].Id, 0); - Assert.AreEqual(uni.NoteOrder()[11].Id, 1); + Assert.That(uni.NoteOrder()[9].Id, Is.EqualTo(0)); + Assert.That(uni.NoteOrder()[10].Id, Is.EqualTo(0)); + Assert.That(uni.NoteOrder()[11].Id, Is.EqualTo(1)); - Assert.AreEqual(uni.NoteOrder()[12].Id, 1); - Assert.AreEqual(uni.NoteOrder()[13].Id, 2); - Assert.AreEqual(uni.NoteOrder()[14].Id, 3); + Assert.That(uni.NoteOrder()[12].Id, Is.EqualTo(1)); + Assert.That(uni.NoteOrder()[13].Id, Is.EqualTo(2)); + Assert.That(uni.NoteOrder()[14].Id, Is.EqualTo(3)); - Assert.AreEqual(uni.NoteOrder()[15].Id, 5); - Assert.AreEqual(uni.NoteOrder()[16].Id, 0); - Assert.AreEqual(uni.NoteOrder()[17].Id, 6); + Assert.That(uni.NoteOrder()[15].Id, Is.EqualTo(5)); + Assert.That(uni.NoteOrder()[16].Id, Is.EqualTo(0)); + Assert.That(uni.NoteOrder()[17].Id, Is.EqualTo(6)); - Assert.AreEqual(uni.NoteOrder()[18].Id, 7); - Assert.AreEqual(uni.NoteOrder()[19].Id, 7); - Assert.AreEqual(uni.NoteOrder()[20].Id, 8); - Assert.AreEqual(uni.NoteOrder()[21].Id, 8); + Assert.That(uni.NoteOrder()[18].Id, Is.EqualTo(7)); + Assert.That(uni.NoteOrder()[19].Id, Is.EqualTo(7)); + Assert.That(uni.NoteOrder()[20].Id, Is.EqualTo(8)); + Assert.That(uni.NoteOrder()[21].Id, Is.EqualTo(8)); } /// @@ -96,32 +96,32 @@ public void ValueNoteOrderSecondTest() // создание и заполнения списка(ов) нот для такта(ов) монотрека var notes = new List { - new ValueNote(new Pitch(3, NoteSymbol.A, Accidental.DoubleSharp), new Duration(1, 16, false), false, Tie.None, 3), - new ValueNote(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), - new ValueNote(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), - new ValueNote(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 16, false), false, Tie.None, 1), - new ValueNote(new Pitch(3, NoteSymbol.A, Accidental.Flat), new Duration(1, 16, false), false, Tie.None, 3), - new ValueNote(new Pitch(3, NoteSymbol.D, Accidental.Bekar), new Duration(1, 16, false), false, Tie.None, 2), - new ValueNote(new Pitch(3, NoteSymbol.A, Accidental.DoubleSharp), new Duration(1, 16, false), false, Tie.None, 3), - new ValueNote(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 16, false), false, Tie.None, 1), - new ValueNote(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 16, false), false, Tie.None, 1) + new(new Pitch(3, NoteSymbol.A, Accidental.DoubleSharp), new Duration(1, 16, false), false, Tie.None, 3), + new(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), + new(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), + new(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 16, false), false, Tie.None, 1), + new(new Pitch(3, NoteSymbol.A, Accidental.Flat), new Duration(1, 16, false), false, Tie.None, 3), + new(new Pitch(3, NoteSymbol.D, Accidental.Bekar), new Duration(1, 16, false), false, Tie.None, 2), + new(new Pitch(3, NoteSymbol.A, Accidental.DoubleSharp), new Duration(1, 16, false), false, Tie.None, 3), + new(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 16, false), false, Tie.None, 1), + new(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 16, false), false, Tie.None, 1) }; var notes2 = new List { - new ValueNote(new Pitch(3, NoteSymbol.B, Accidental.Bekar), new Duration(1, 16, false), false, Tie.None, 1), - new ValueNote(new Pitch(3, NoteSymbol.A, Accidental.DoubleSharp), new Duration(1, 16, false), false, Tie.None, 3), - new ValueNote(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), - new ValueNote(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), - new ValueNote(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 16, false), false, Tie.None, 1), - new ValueNote(new Pitch(3, NoteSymbol.A, Accidental.Flat), new Duration(1, 16, false), false, Tie.None, 3), - new ValueNote(new Pitch(3, NoteSymbol.D, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 2), - new ValueNote(new Pitch(3, NoteSymbol.A, Accidental.DoubleSharp), new Duration(1, 16, false), false, Tie.None, 3), - new ValueNote(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 4, false), false, Tie.None, 1), - new ValueNote(new Duration(1, 4, false), false, Tie.None, 1), - new ValueNote(new Duration(1, 4, false), false, Tie.None, 1), - new ValueNote(new Duration(1, 16, false), false, Tie.None, 1), - new ValueNote(new Duration(1, 16, false), false, Tie.None, 1) + new(new Pitch(3, NoteSymbol.B, Accidental.Bekar), new Duration(1, 16, false), false, Tie.None, 1), + new(new Pitch(3, NoteSymbol.A, Accidental.DoubleSharp), new Duration(1, 16, false), false, Tie.None, 3), + new(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), + new(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), + new(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 16, false), false, Tie.None, 1), + new(new Pitch(3, NoteSymbol.A, Accidental.Flat), new Duration(1, 16, false), false, Tie.None, 3), + new(new Pitch(3, NoteSymbol.D, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 2), + new(new Pitch(3, NoteSymbol.A, Accidental.DoubleSharp), new Duration(1, 16, false), false, Tie.None, 3), + new(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 4, false), false, Tie.None, 1), + new(new Duration(1, 4, false), false, Tie.None, 1), + new(new Duration(1, 4, false), false, Tie.None, 1), + new(new Duration(1, 16, false), false, Tie.None, 1), + new(new Duration(1, 16, false), false, Tie.None, 1) }; var attr = new MeasureAttributes(new Size(4, 4), new Key(5)); @@ -133,36 +133,36 @@ public void ValueNoteOrderSecondTest() var uni = new CongenericScoreTrack(measuresList); - Assert.AreNotEqual(uni.NoteIdOrder()[0], 1); + Assert.That(uni.NoteIdOrder()[0], Is.Not.EqualTo(1)); - Assert.AreEqual(uni.NoteIdOrder()[0], 0); - Assert.AreEqual(uni.NoteIdOrder()[1], 1); - Assert.AreEqual(uni.NoteIdOrder()[2], 1); + Assert.That(uni.NoteIdOrder()[0], Is.EqualTo(0)); + Assert.That(uni.NoteIdOrder()[1], Is.EqualTo(1)); + Assert.That(uni.NoteIdOrder()[2], Is.EqualTo(1)); - Assert.AreEqual(uni.NoteIdOrder()[3], 2); - Assert.AreEqual(uni.NoteIdOrder()[4], 3); - Assert.AreEqual(uni.NoteIdOrder()[5], 4); + Assert.That(uni.NoteIdOrder()[3], Is.EqualTo(2)); + Assert.That(uni.NoteIdOrder()[4], Is.EqualTo(3)); + Assert.That(uni.NoteIdOrder()[5], Is.EqualTo(4)); - Assert.AreEqual(uni.NoteIdOrder()[6], 0); - Assert.AreEqual(uni.NoteIdOrder()[7], 2); - Assert.AreEqual(uni.NoteIdOrder()[8], 2); + Assert.That(uni.NoteIdOrder()[6], Is.EqualTo(0)); + Assert.That(uni.NoteIdOrder()[7], Is.EqualTo(2)); + Assert.That(uni.NoteIdOrder()[8], Is.EqualTo(2)); - Assert.AreEqual(uni.NoteIdOrder()[9], 0); - Assert.AreEqual(uni.NoteIdOrder()[10], 0); - Assert.AreEqual(uni.NoteIdOrder()[11], 1); + Assert.That(uni.NoteIdOrder()[9], Is.EqualTo(0)); + Assert.That(uni.NoteIdOrder()[10], Is.EqualTo(0)); + Assert.That(uni.NoteIdOrder()[11], Is.EqualTo(1)); - Assert.AreEqual(uni.NoteIdOrder()[12], 1); - Assert.AreEqual(uni.NoteIdOrder()[13], 2); - Assert.AreEqual(uni.NoteIdOrder()[14], 3); + Assert.That(uni.NoteIdOrder()[12], Is.EqualTo(1)); + Assert.That(uni.NoteIdOrder()[13], Is.EqualTo(2)); + Assert.That(uni.NoteIdOrder()[14], Is.EqualTo(3)); - Assert.AreEqual(uni.NoteIdOrder()[15], 5); - Assert.AreEqual(uni.NoteIdOrder()[16], 0); - Assert.AreEqual(uni.NoteIdOrder()[17], 6); + Assert.That(uni.NoteIdOrder()[15], Is.EqualTo(5)); + Assert.That(uni.NoteIdOrder()[16], Is.EqualTo(0)); + Assert.That(uni.NoteIdOrder()[17], Is.EqualTo(6)); - Assert.AreEqual(uni.NoteIdOrder()[18], 7); - Assert.AreEqual(uni.NoteIdOrder()[19], 7); - Assert.AreEqual(uni.NoteIdOrder()[20], 8); - Assert.AreEqual(uni.NoteIdOrder()[21], 8); + Assert.That(uni.NoteIdOrder()[18], Is.EqualTo(7)); + Assert.That(uni.NoteIdOrder()[19], Is.EqualTo(7)); + Assert.That(uni.NoteIdOrder()[20], Is.EqualTo(8)); + Assert.That(uni.NoteIdOrder()[21], Is.EqualTo(8)); } /// @@ -174,47 +174,47 @@ public void MeasureOrderTest() // создание и заполнения списка(ов) нот для такта(ов) монотрека var notes = new List { - new ValueNote(new Pitch(3, NoteSymbol.A, Accidental.DoubleSharp), new Duration(1, 16, false), false, Tie.None, 3), - new ValueNote(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), - new ValueNote(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), - new ValueNote(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 16, false), false, Tie.None, 1) + new(new Pitch(3, NoteSymbol.A, Accidental.DoubleSharp), new Duration(1, 16, false), false, Tie.None, 3), + new(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), + new(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), + new(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 16, false), false, Tie.None, 1) }; var notes3 = new List { - new ValueNote(new Pitch(3, NoteSymbol.B, Accidental.Bekar), new Duration(1, 16, false), false, Tie.None, 3), - new ValueNote(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), - new ValueNote(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), - new ValueNote(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 16, false), false, Tie.None, 1) + new(new Pitch(3, NoteSymbol.B, Accidental.Bekar), new Duration(1, 16, false), false, Tie.None, 3), + new(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), + new(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), + new(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 16, false), false, Tie.None, 1) }; var notes2 = new List { - new ValueNote(new Pitch(3, NoteSymbol.B, Accidental.Bekar), new Duration(1, 16, false), false, Tie.None, 1), - new ValueNote(new Pitch(3, NoteSymbol.A, Accidental.DoubleSharp), new Duration(1, 16, false), false, Tie.None, 3), - new ValueNote(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), - new ValueNote(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), - new ValueNote(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 16, false), false, Tie.None, 1) + new(new Pitch(3, NoteSymbol.B, Accidental.Bekar), new Duration(1, 16, false), false, Tie.None, 1), + new(new Pitch(3, NoteSymbol.A, Accidental.DoubleSharp), new Duration(1, 16, false), false, Tie.None, 3), + new(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), + new(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), + new(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 16, false), false, Tie.None, 1) }; var notes4 = new List { - new ValueNote(new Pitch(3, NoteSymbol.A, Accidental.Flat), new Duration(1, 16, false), false, Tie.None, 3), - new ValueNote(new Pitch(3, NoteSymbol.D, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 2), - new ValueNote(new Pitch(3, NoteSymbol.A, Accidental.DoubleSharp), new Duration(1, 16, false), false, Tie.None, 3), - new ValueNote(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 4, false), false, Tie.None, 1) + new(new Pitch(3, NoteSymbol.A, Accidental.Flat), new Duration(1, 16, false), false, Tie.None, 3), + new(new Pitch(3, NoteSymbol.D, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 2), + new(new Pitch(3, NoteSymbol.A, Accidental.DoubleSharp), new Duration(1, 16, false), false, Tie.None, 3), + new(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 4, false), false, Tie.None, 1) }; var notes5 = new List { - new ValueNote(new Duration(1, 4, false), false, Tie.None, 1), - new ValueNote(new Duration(1, 4, false), false, Tie.None, 1) + new(new Duration(1, 4, false), false, Tie.None, 1), + new(new Duration(1, 4, false), false, Tie.None, 1) }; var notes6 = new List { - new ValueNote(new Duration(1, 16, false), false, Tie.None, 1), - new ValueNote(new Duration(1, 16, false), false, Tie.None, 1) + new(new Duration(1, 16, false), false, Tie.None, 1), + new(new Duration(1, 16, false), false, Tie.None, 1) }; var attr = new MeasureAttributes(new Size(4, 4), new Key(5)); @@ -230,24 +230,24 @@ public void MeasureOrderTest() var uni = new CongenericScoreTrack(measuresList); - Assert.AreEqual(uni.MeasureOrder()[0].Id, 0); - Assert.AreEqual(uni.MeasureOrder()[1].Id, 1); - Assert.AreEqual(uni.MeasureOrder()[2].Id, 0); - Assert.AreEqual(uni.MeasureOrder()[3].Id, 2); - Assert.AreEqual(uni.MeasureOrder()[4].Id, 3); - Assert.AreEqual(uni.MeasureOrder()[5].Id, 3); - Assert.AreEqual(uni.MeasureOrder()[6].Id, 1); - Assert.AreEqual(uni.MeasureOrder()[7].Id, 0); - Assert.AreEqual(uni.MeasureOrder()[8].Id, 4); - - Assert.AreEqual(uni.MeasureIdOrder()[0], 0); - Assert.AreEqual(uni.MeasureIdOrder()[1], 1); - Assert.AreEqual(uni.MeasureIdOrder()[2], 0); - Assert.AreEqual(uni.MeasureIdOrder()[3], 2); - Assert.AreEqual(uni.MeasureIdOrder()[4], 3); - Assert.AreEqual(uni.MeasureIdOrder()[5], 3); - Assert.AreEqual(uni.MeasureIdOrder()[6], 1); - Assert.AreEqual(uni.MeasureIdOrder()[7], 0); - Assert.AreEqual(uni.MeasureIdOrder()[8], 4); + Assert.That(uni.MeasureOrder()[0].Id, Is.EqualTo(0)); + Assert.That(uni.MeasureOrder()[1].Id, Is.EqualTo(1)); + Assert.That(uni.MeasureOrder()[2].Id, Is.EqualTo(0)); + Assert.That(uni.MeasureOrder()[3].Id, Is.EqualTo(2)); + Assert.That(uni.MeasureOrder()[4].Id, Is.EqualTo(3)); + Assert.That(uni.MeasureOrder()[5].Id, Is.EqualTo(3)); + Assert.That(uni.MeasureOrder()[6].Id, Is.EqualTo(1)); + Assert.That(uni.MeasureOrder()[7].Id, Is.EqualTo(0)); + Assert.That(uni.MeasureOrder()[8].Id, Is.EqualTo(4)); + + Assert.That(uni.MeasureIdOrder()[0], Is.EqualTo(0)); + Assert.That(uni.MeasureIdOrder()[1], Is.EqualTo(1)); + Assert.That(uni.MeasureIdOrder()[2], Is.EqualTo(0)); + Assert.That(uni.MeasureIdOrder()[3], Is.EqualTo(2)); + Assert.That(uni.MeasureIdOrder()[4], Is.EqualTo(3)); + Assert.That(uni.MeasureIdOrder()[5], Is.EqualTo(3)); + Assert.That(uni.MeasureIdOrder()[6], Is.EqualTo(1)); + Assert.That(uni.MeasureIdOrder()[7], Is.EqualTo(0)); + Assert.That(uni.MeasureIdOrder()[8], Is.EqualTo(4)); } } diff --git a/Libiada.Core.Tests/Core/FmotifChainTests.cs b/Libiada.Core.Tests/Core/FmotifChainTests.cs index 25c94c6d..ec6e7a4f 100644 --- a/Libiada.Core.Tests/Core/FmotifChainTests.cs +++ b/Libiada.Core.Tests/Core/FmotifChainTests.cs @@ -20,9 +20,9 @@ public void FmotifChainTest() chain.FmotifsList.Add(new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0)); chain.FmotifsList[0].NoteList.Add(new ValueNote(new Pitch(0, NoteSymbol.A, 0), new Duration(1, 4, false), false, Tie.None)); chain.FmotifsList[0].NoteList.Add(new ValueNote(new Pitch(0, NoteSymbol.B, 0), new Duration(1, 2, false), false, Tie.None)); - Assert.AreEqual(0, chain.FmotifsList[0].Id); - Assert.AreEqual(NoteSymbol.A, chain.FmotifsList[0].NoteList[0].Pitches[0].Step); - Assert.AreEqual(NoteSymbol.B, chain.FmotifsList[0].NoteList[1].Pitches[0].Step); + Assert.That(chain.FmotifsList[0].Id, Is.EqualTo(0)); + Assert.That(chain.FmotifsList[0].NoteList[0].Pitches[0].Step, Is.EqualTo(NoteSymbol.A)); + Assert.That(chain.FmotifsList[0].NoteList[1].Pitches[0].Step, Is.EqualTo(NoteSymbol.B)); } /// @@ -47,17 +47,17 @@ public void FmotifChainEqualsTest() var secondChain = new FmotifChain(); secondChain.FmotifsList.Add(fmotif1); secondChain.FmotifsList.Add(fmotif2); - Assert.IsTrue(firstChain.Equals(secondChain)); + Assert.That(firstChain, Is.EqualTo(secondChain)); secondChain = new FmotifChain(); secondChain.FmotifsList.Add(fmotif2); secondChain.FmotifsList.Add(fmotif1); - Assert.IsFalse(firstChain.Equals(secondChain)); + Assert.That(firstChain, Is.Not.EqualTo(secondChain)); secondChain = new FmotifChain(); secondChain.FmotifsList.Add(fmotif2); secondChain.FmotifsList.Add(fmotif2); - Assert.IsFalse(firstChain.Equals(secondChain)); + Assert.That(firstChain, Is.Not.EqualTo(secondChain)); firstChain = new FmotifChain(); firstChain.FmotifsList.Add(fmotif1); @@ -70,6 +70,6 @@ public void FmotifChainEqualsTest() secondChain.FmotifsList.Add(fmotif1); secondChain.FmotifsList.Add(fmotif2); secondChain.FmotifsList.Add(fmotif1); - Assert.IsTrue(firstChain.Equals(secondChain)); + Assert.That(firstChain, Is.EqualTo(secondChain)); } } diff --git a/Libiada.Core.Tests/Core/LinkTests.cs b/Libiada.Core.Tests/Core/LinkTests.cs index 9e90bd78..3ee1cc34 100644 --- a/Libiada.Core.Tests/Core/LinkTests.cs +++ b/Libiada.Core.Tests/Core/LinkTests.cs @@ -21,7 +21,7 @@ public class LinkTests public void LinkCountTest() { var actualCount = EnumExtensions.ToArray().Length; - Assert.AreEqual(LinksCount, actualCount); + Assert.That(EnumExtensions.ToArray(), Has.Length.EqualTo(LinksCount)); } /// @@ -33,7 +33,7 @@ public void LinkValuesTest() var links = EnumExtensions.ToArray(); for (int i = 0; i < LinksCount; i++) { - Assert.IsTrue(links.Contains((Link)i)); + Assert.That(links, Does.Contain((Link)i)); } } @@ -56,7 +56,7 @@ public void LinkValuesTest() [TestCase((Link)7, "CycleEnd")] public void LinkNamesTest(Link link, string name) { - Assert.AreEqual(name, link.GetName()); + Assert.That(link.GetName(), Is.EqualTo(name)); } /// @@ -68,7 +68,7 @@ public void LinkNamesTest(Link link, string name) [Test] public void LinkHasDisplayValueTest([Values]Link link) { - Assert.IsFalse(string.IsNullOrEmpty(link.GetDisplayValue())); + Assert.That(link.GetDisplayValue(), Is.Not.Empty); } /// @@ -80,7 +80,7 @@ public void LinkHasDisplayValueTest([Values]Link link) [Test] public void LinkHasDescriptionTest([Values]Link link) { - Assert.IsFalse(string.IsNullOrEmpty(link.GetDescription())); + Assert.That(link.GetDescription(), Is.Not.Empty); } /// diff --git a/Libiada.Core.Tests/Core/SimpleTypes/AccidentalTests.cs b/Libiada.Core.Tests/Core/SimpleTypes/AccidentalTests.cs index 2caeaafc..e9666af9 100644 --- a/Libiada.Core.Tests/Core/SimpleTypes/AccidentalTests.cs +++ b/Libiada.Core.Tests/Core/SimpleTypes/AccidentalTests.cs @@ -20,8 +20,7 @@ public class AccidentalTests [Test] public void AccidentalCountTest() { - var actualCount = EnumExtensions.ToArray().Length; - Assert.AreEqual(AccidentalsCount, actualCount); + Assert.That(EnumExtensions.ToArray(), Has.Length.EqualTo(AccidentalsCount)); } /// @@ -33,7 +32,7 @@ public void AccidentalValuesTest() var accidentals = EnumExtensions.ToArray(); for (int i = -2; i < AccidentalsCount - 2; i++) { - Assert.IsTrue(accidentals.Contains((Accidental)i)); + Assert.That(accidentals, Does.Contain((Accidental)i)); } } @@ -53,7 +52,7 @@ public void AccidentalValuesTest() [TestCase((Accidental)2, "DoubleSharp")] public void AccidentalNamesTest(Accidental accidental, string name) { - Assert.AreEqual(name, accidental.GetName()); + Assert.That(accidental.GetName(), Is.EqualTo(name)); } /// @@ -65,7 +64,7 @@ public void AccidentalNamesTest(Accidental accidental, string name) [Test] public void AccidentalHasDisplayValueTest([Values]Accidental accidental) { - Assert.IsFalse(string.IsNullOrEmpty(accidental.GetDisplayValue())); + Assert.That(accidental.GetDisplayValue(), Is.Not.Empty); } /// @@ -77,7 +76,7 @@ public void AccidentalHasDisplayValueTest([Values]Accidental accidental) [Test] public void AccidentalHasDescriptionTest([Values]Accidental accidental) { - Assert.IsFalse(string.IsNullOrEmpty(accidental.GetDescription())); + Assert.That(accidental.GetDescription(), Is.Not.Empty); } /// diff --git a/Libiada.Core.Tests/Core/SimpleTypes/DurationTests.cs b/Libiada.Core.Tests/Core/SimpleTypes/DurationTests.cs index 59a0fe2b..044ab91b 100644 --- a/Libiada.Core.Tests/Core/SimpleTypes/DurationTests.cs +++ b/Libiada.Core.Tests/Core/SimpleTypes/DurationTests.cs @@ -18,22 +18,28 @@ public void AddDurationTest() var duration2 = new Duration(1, 4, false); var duration3 = duration1.AddDuration(duration2); - // duration1 - Assert.AreEqual(1, duration1.Numerator); - Assert.AreEqual(2, duration1.Denominator); + Assert.Multiple(() => + { + // duration1 + Assert.That(duration1.Numerator, Is.EqualTo(1)); + Assert.That(duration1.Denominator, Is.EqualTo(2)); - // duration2 - Assert.AreEqual(1, duration2.Numerator); - Assert.AreEqual(4, duration2.Denominator); + // duration2 + Assert.That(duration2.Numerator, Is.EqualTo(1)); + Assert.That(duration2.Denominator, Is.EqualTo(4)); - // duration3 - Assert.AreEqual(3, duration3.Numerator); - Assert.AreEqual(4, duration3.Denominator); + // duration3 + Assert.That(duration3.Numerator, Is.EqualTo(3)); + Assert.That(duration3.Denominator, Is.EqualTo(4)); + }); duration3 = duration3.AddDuration(duration1); - // duration3' - Assert.AreEqual(5, duration3.Numerator); - Assert.AreEqual(4, duration3.Denominator); + Assert.Multiple(() => + { + // duration3' + Assert.That(duration3.Numerator, Is.EqualTo(5)); + Assert.That(duration3.Denominator, Is.EqualTo(4)); + }); } } diff --git a/Libiada.Core.Tests/Core/SimpleTypes/FmotifTests.cs b/Libiada.Core.Tests/Core/SimpleTypes/FmotifTests.cs index 2ee54942..c9443ea2 100644 --- a/Libiada.Core.Tests/Core/SimpleTypes/FmotifTests.cs +++ b/Libiada.Core.Tests/Core/SimpleTypes/FmotifTests.cs @@ -12,12 +12,12 @@ public class FmotifTests /// /// The note. /// - private readonly ValueNote note = new ValueNote(new Pitch(1, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None); + private readonly ValueNote note = new(new Pitch(1, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None); /// /// The a note. /// - private readonly ValueNote aNote = new ValueNote(new Pitch(1, NoteSymbol.B, Accidental.Bekar), new Duration(1, 2, false), false, 0); + private readonly ValueNote aNote = new(new Pitch(1, NoteSymbol.B, Accidental.Bekar), new Duration(1, 2, false), false, 0); /// /// The fmotif test. @@ -25,22 +25,22 @@ public class FmotifTests [Test] public void FmotifTest() { - var fmotif = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); - var notelist = new List { (ValueNote)note.Clone(), (ValueNote)aNote.Clone(), (ValueNote)note.Clone() }; + Fmotif fmotif = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); + List notelist = [(ValueNote)note.Clone(), (ValueNote)aNote.Clone(), (ValueNote)note.Clone()]; fmotif.NoteList.Add((ValueNote)note.Clone()); fmotif.NoteList.Add((ValueNote)aNote.Clone()); fmotif.NoteList.Add((ValueNote)note.Clone()); - Assert.AreEqual(notelist[0], fmotif.NoteList[0]); - Assert.AreEqual(notelist[1], fmotif.NoteList[1]); - Assert.AreEqual(notelist[2], fmotif.NoteList[2]); - Assert.AreEqual(FmotifType.CompleteMinimalMeasure, fmotif.Type); + Assert.That(fmotif.NoteList[0], Is.EqualTo(notelist[0])); + Assert.That(fmotif.NoteList[1], Is.EqualTo(notelist[1])); + Assert.That(fmotif.NoteList[2], Is.EqualTo(notelist[2])); + Assert.That(fmotif.Type, Is.EqualTo(FmotifType.CompleteMinimalMeasure)); fmotif.Type = FmotifType.CompleteMinimalMetrorhythmicGroup; - Assert.AreEqual(FmotifType.CompleteMinimalMetrorhythmicGroup, fmotif.Type); - Assert.AreEqual(0, fmotif.Id); + Assert.That(fmotif.Type, Is.EqualTo(FmotifType.CompleteMinimalMetrorhythmicGroup)); + Assert.That(fmotif.Id, Is.EqualTo(0)); fmotif.Id = 1; - Assert.AreEqual(1, fmotif.Id); + Assert.That(fmotif.Id, Is.EqualTo(1)); // проверка на идентичность нот проверяется только высота звучания и реальная длительность, не сравнивая приоритеты, лиги, триоли } @@ -52,16 +52,19 @@ public void FmotifTest() public void FmotifWithoutPausesFirstTest() { // проверка работы метода, который возвращает копию объекта (Fmotif), только без пауз. - var fmotif = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); + Fmotif fmotif = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); fmotif.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 2, false), false, Tie.None)); fmotif.NoteList.Add(new ValueNote(new Duration(1, 4, false), false, Tie.None)); fmotif.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 2, false), false, Tie.None)); fmotif.NoteList.Add(new ValueNote(new Duration(1, 4, false), false, Tie.None)); fmotif.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 2, false), false, Tie.None)); - Assert.AreEqual(fmotif.PauseTreatmentProcedure(PauseTreatment.Ignore).NoteList[0].Pitches[0].Step, NoteSymbol.A); - Assert.AreEqual(fmotif.PauseTreatmentProcedure(PauseTreatment.Ignore).NoteList[1].Pitches[0].Step, NoteSymbol.A); - Assert.AreEqual(fmotif.PauseTreatmentProcedure(PauseTreatment.Ignore).NoteList[2].Pitches[0].Step, NoteSymbol.A); - Assert.AreEqual(fmotif.PauseTreatmentProcedure(PauseTreatment.Ignore).NoteList.Count, 3); + Assert.Multiple(() => + { + Assert.That(fmotif.PauseTreatmentProcedure(PauseTreatment.Ignore).NoteList[0].Pitches[0].Step, Is.EqualTo(NoteSymbol.A)); + Assert.That(fmotif.PauseTreatmentProcedure(PauseTreatment.Ignore).NoteList[1].Pitches[0].Step, Is.EqualTo(NoteSymbol.A)); + Assert.That(fmotif.PauseTreatmentProcedure(PauseTreatment.Ignore).NoteList[2].Pitches[0].Step, Is.EqualTo(NoteSymbol.A)); + Assert.That(fmotif.PauseTreatmentProcedure(PauseTreatment.Ignore).NoteList, Has.Count.EqualTo(3)); + }); } /// @@ -71,17 +74,20 @@ public void FmotifWithoutPausesFirstTest() public void FmotifWithoutPausesSecondTest() { // проверка работы метода, который возвращает копию объекта (Fmotif), только без пауз. - var fmotif = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); + Fmotif fmotif = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); fmotif.NoteList.Add(new ValueNote(new Duration(1, 4, false), false, Tie.None)); fmotif.NoteList.Add(new ValueNote(new Duration(1, 4, false), false, Tie.None)); fmotif.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 2, false), false, Tie.None)); fmotif.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 2, false), false, Tie.None)); fmotif.NoteList.Add(new ValueNote(new Duration(1, 4, false), false, Tie.None)); fmotif.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 2, false), false, Tie.None)); - Assert.AreEqual(fmotif.PauseTreatmentProcedure(PauseTreatment.Ignore).NoteList[0].Pitches[0].Step, NoteSymbol.A); - Assert.AreEqual(fmotif.PauseTreatmentProcedure(PauseTreatment.Ignore).NoteList[1].Pitches[0].Step, NoteSymbol.A); - Assert.AreEqual(fmotif.PauseTreatmentProcedure(PauseTreatment.Ignore).NoteList[2].Pitches[0].Step, NoteSymbol.A); - Assert.AreEqual(fmotif.PauseTreatmentProcedure(PauseTreatment.Ignore).NoteList.Count, 3); + Assert.Multiple(() => + { + Assert.That(fmotif.PauseTreatmentProcedure(PauseTreatment.Ignore).NoteList[0].Pitches[0].Step, Is.EqualTo(NoteSymbol.A)); + Assert.That(fmotif.PauseTreatmentProcedure(PauseTreatment.Ignore).NoteList[1].Pitches[0].Step, Is.EqualTo(NoteSymbol.A)); + Assert.That(fmotif.PauseTreatmentProcedure(PauseTreatment.Ignore).NoteList[2].Pitches[0].Step, Is.EqualTo(NoteSymbol.A)); + Assert.That(fmotif.PauseTreatmentProcedure(PauseTreatment.Ignore).NoteList, Has.Count.EqualTo(3)); + }); } /// @@ -91,7 +97,7 @@ public void FmotifWithoutPausesSecondTest() public void FmotifTieGatheredFirstTest() { // проверка работы метода, который возвращает копию объекта (Fmotif), c собранными залигованными нотами. - var fmotif = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); + Fmotif fmotif = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); fmotif.NoteList.Add(new ValueNote(new Duration(1, 2, false), false, Tie.None, 0)); fmotif.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 8, false), false, Tie.Start, 2)); fmotif.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 8, false), false, Tie.Continue, 4)); @@ -100,10 +106,14 @@ public void FmotifTieGatheredFirstTest() fmotif.NoteList.Add(new ValueNote(new Duration(1, 4, false), false, Tie.None, 3)); fmotif.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 2, false), false, Tie.None, 4)); - Assert.AreEqual(4, fmotif.TieGathered().NoteList.Count); - Assert.AreEqual(1, fmotif.TieGathered().NoteList[1].Duration.Numerator); - Assert.AreEqual(2, fmotif.TieGathered().NoteList[1].Duration.Denominator); - Assert.AreEqual(2, fmotif.TieGathered().NoteList[1].Priority); + + Assert.Multiple(() => + { + Assert.That(fmotif.TieGathered().NoteList, Has.Count.EqualTo(4)); + Assert.That(fmotif.TieGathered().NoteList[1].Duration.Numerator, Is.EqualTo(1)); + Assert.That(fmotif.TieGathered().NoteList[1].Duration.Denominator, Is.EqualTo(2)); + Assert.That(fmotif.TieGathered().NoteList[1].Priority, Is.EqualTo(2)); + }); } /// @@ -113,7 +123,7 @@ public void FmotifTieGatheredFirstTest() public void FmotifTieGatheredSecondTest() { // проверка работы метода, который возвращает копию объекта (Fmotif), c собранными залигованными нотами. - var fmotif = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); + Fmotif fmotif = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); fmotif.NoteList.Add(new ValueNote(new Duration(1, 2, false), false, Tie.None, 0)); fmotif.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 8, 2, 3, false), false, Tie.Start, 2)); fmotif.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 8, 2, 3, false), false, Tie.Continue, 4)); @@ -121,11 +131,13 @@ public void FmotifTieGatheredSecondTest() fmotif.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 8, false), false, Tie.End, 1)); fmotif.NoteList.Add(new ValueNote(new Duration(1, 4, false), false, Tie.None, 3)); fmotif.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 2, false), false, Tie.None, 4)); - - Assert.AreEqual(4, fmotif.TieGathered().NoteList.Count); - Assert.AreEqual(3, fmotif.TieGathered().NoteList[1].Duration.Numerator); - Assert.AreEqual(8, fmotif.TieGathered().NoteList[1].Duration.Denominator); - Assert.AreEqual(2, fmotif.TieGathered().NoteList[1].Priority); + Assert.Multiple(() => + { + Assert.That(fmotif.TieGathered().NoteList, Has.Count.EqualTo(4)); + Assert.That(fmotif.TieGathered().NoteList[1].Duration.Numerator, Is.EqualTo(3)); + Assert.That(fmotif.TieGathered().NoteList[1].Duration.Denominator, Is.EqualTo(8)); + Assert.That(fmotif.TieGathered().NoteList[1].Priority, Is.EqualTo(2)); + }); } /// @@ -136,7 +148,7 @@ public void FmotifTieGatheredThirdTest() { // проверка работы метода, который возвращает копию объекта (Fmotif), c собранными залигованными нотами. // старт лиги, потом опять старт лиги - var fmotif = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); + Fmotif fmotif = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); fmotif.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 8, false), false, Tie.Start, 2)); fmotif.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 8, false), false, Tie.Start, 2)); try @@ -170,7 +182,7 @@ public void FmotifTieGatheredThirdTest() } // лига без старта - var fmotif1 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); + Fmotif fmotif1 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); fmotif1.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 8, false), false, Tie.Continue, 4)); fmotif1.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 8, false), false, Tie.Continue, 3)); fmotif1.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 8, false), false, Tie.End, 1)); @@ -188,7 +200,7 @@ public void FmotifTieGatheredThirdTest() } // в знаке лиги не {-1,0,1,2} - var fmotif2 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); + Fmotif fmotif2 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); fmotif2.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 8, false), false, (Tie)9, 1)); try { @@ -204,7 +216,7 @@ public void FmotifTieGatheredThirdTest() } // в знаке лиги не {-1,0,1,2} - var fmotif3 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); + Fmotif fmotif3 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); fmotif3.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 8, false), false, Tie.Start, 1)); fmotif3.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.B, Accidental.Bekar), new Duration(1, 8, false), false, Tie.End, 1)); try @@ -228,9 +240,9 @@ public void FmotifTieGatheredThirdTest() public void FmotifEqualsFirstTest() { // проверка работы метода, который возвращает копию объекта (Fmotif), c собранными залигованными нотами. - var fmotif1 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); - var fmotif2 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); - var fmotif3 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); + Fmotif fmotif1 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); + Fmotif fmotif2 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); + Fmotif fmotif3 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); fmotif1.NoteList.Add(new ValueNote(new Duration(1, 2, false), false, Tie.None, 0)); fmotif1.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 8, false), false, Tie.Start, 2)); @@ -251,15 +263,15 @@ public void FmotifEqualsFirstTest() fmotif3.NoteList.Add(new ValueNote(new Duration(1, 4, false), false, Tie.None, 3)); fmotif3.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.DoubleSharp), new Duration(1, 2, false), false, Tie.None, 4)); - Assert.IsTrue(fmotif1.Equals(fmotif2)); - Assert.IsTrue(fmotif1.Equals(fmotif3)); - Assert.IsTrue(fmotif2.Equals(fmotif3)); - Assert.IsTrue(fmotif3.Equals(fmotif2)); - Assert.IsTrue(fmotif3.Equals(fmotif1)); - Assert.IsTrue(fmotif2.Equals(fmotif1)); + Assert.That(fmotif1, Is.EqualTo(fmotif2)); + Assert.That(fmotif1, Is.EqualTo(fmotif3)); + Assert.That(fmotif2, Is.EqualTo(fmotif3)); + Assert.That(fmotif3, Is.EqualTo(fmotif2)); + Assert.That(fmotif3, Is.EqualTo(fmotif1)); + Assert.That(fmotif2, Is.EqualTo(fmotif1)); fmotif2.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 2, false), false, Tie.None, 4)); - Assert.IsTrue(!fmotif1.Equals(fmotif2)); + Assert.That(fmotif1, Is.Not.EqualTo(fmotif2)); } /// @@ -268,7 +280,7 @@ public void FmotifEqualsFirstTest() [Test] public void FmotifEqualsSecondTest() { - var fmotif = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); + Fmotif fmotif = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); fmotif.NoteList.Add(new ValueNote(new Duration(1, 2, false), false, Tie.None, 0)); fmotif.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 8, 2, 3, false), false, Tie.Start, 2)); fmotif.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 8, 2, 3, false), false, Tie.Continue, 4)); @@ -277,7 +289,7 @@ public void FmotifEqualsSecondTest() fmotif.NoteList.Add(new ValueNote(new Duration(1, 4, false), false, Tie.None, 3)); fmotif.NoteList.Add(new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 2, false), false, Tie.None, 4)); - Assert.IsTrue(fmotif.Equals(fmotif)); + Assert.That(fmotif, Is.EqualTo(fmotif)); } /// @@ -286,7 +298,7 @@ public void FmotifEqualsSecondTest() [Test] public void FmotifEqualsThirdTest() { - var fmotif = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); + Fmotif fmotif = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); fmotif.NoteList.Add(new ValueNote(new Duration(1, 2, false), false, Tie.None, 0)); fmotif.NoteList.Add(new ValueNote(new Pitch(2, NoteSymbol.A, Accidental.Bekar), new Duration(1, 8, 2, 3, false), false, Tie.Start, 2)); fmotif.NoteList.Add(new ValueNote(new Pitch(2, NoteSymbol.A, Accidental.Bekar), new Duration(1, 8, 2, 3, false), false, Tie.Continue, 4)); @@ -295,13 +307,13 @@ public void FmotifEqualsThirdTest() fmotif.NoteList.Add(new ValueNote(new Duration(1, 4, false), false, Tie.None, 3)); fmotif.NoteList.Add(new ValueNote(new Pitch(2, NoteSymbol.A, Accidental.Bekar), new Duration(1, 2, false), false, Tie.None, 4)); - var fmotif1 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); + Fmotif fmotif1 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); fmotif1.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.A, Accidental.Bekar), new Duration(1, 8, 2, 3, false), false, Tie.Start, 0)); fmotif1.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.A, Accidental.Bekar), new Duration(1, 8, 2, 3, false), false, Tie.Continue, 1)); fmotif1.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.A, Accidental.Bekar), new Duration(1, 8, 2, 3, false), false, Tie.Continue, 3)); fmotif1.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.A, Accidental.Bekar), new Duration(1, 8, false), false, Tie.End, 2)); fmotif1.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.B, Accidental.DoubleFlat), new Duration(1, 2, false), false, Tie.None, 5)); - Assert.IsTrue(fmotif.FmEquals(fmotif1, PauseTreatment.Ignore, true)); + Assert.That(fmotif.FmEquals(fmotif1, PauseTreatment.Ignore, true), Is.True); } } diff --git a/Libiada.Core.Tests/Core/SimpleTypes/FmotifTypeTests.cs b/Libiada.Core.Tests/Core/SimpleTypes/FmotifTypeTests.cs index 8267b432..091b23a4 100644 --- a/Libiada.Core.Tests/Core/SimpleTypes/FmotifTypeTests.cs +++ b/Libiada.Core.Tests/Core/SimpleTypes/FmotifTypeTests.cs @@ -21,7 +21,7 @@ public class FmotifTypeTests public void FmotifTypeCountTest() { var actualCount = EnumExtensions.ToArray().Length; - Assert.AreEqual(FmotifTypesCount, actualCount); + Assert.That(actualCount, Is.EqualTo(FmotifTypesCount)); } /// @@ -33,7 +33,7 @@ public void FmotifTypeValuesTest() var fmotifTypes = EnumExtensions.ToArray(); for (int i = 0; i < FmotifTypesCount; i++) { - Assert.IsTrue(fmotifTypes.Contains((FmotifType)i)); + Assert.That(fmotifTypes, Does.Contain((FmotifType)i)); } } @@ -54,7 +54,7 @@ public void FmotifTypeValuesTest() [TestCase((FmotifType)5, "PartialMinimalMetrorhythmicGroup")] public void FmotifTypeNamesTest(FmotifType fmotifType, string name) { - Assert.AreEqual(name, fmotifType.GetName()); + Assert.That(fmotifType.GetName(), Is.EqualTo(name)); } /// @@ -66,7 +66,7 @@ public void FmotifTypeNamesTest(FmotifType fmotifType, string name) [Test] public void FmotifTypeHasDisplayValueTest([Values]FmotifType fmotifType) { - Assert.IsFalse(string.IsNullOrEmpty(fmotifType.GetDisplayValue())); + Assert.That(fmotifType.GetDisplayValue(), Is.Not.Empty); } /// @@ -78,7 +78,7 @@ public void FmotifTypeHasDisplayValueTest([Values]FmotifType fmotifType) [Test] public void FmotifTypeHasDescriptionTest([Values]FmotifType fmotifType) { - Assert.IsFalse(string.IsNullOrEmpty(fmotifType.GetDescription())); + Assert.That(fmotifType.GetDescription(), Is.Not.Empty); } /// diff --git a/Libiada.Core.Tests/Core/SimpleTypes/InstrumentTests.cs b/Libiada.Core.Tests/Core/SimpleTypes/InstrumentTests.cs index 2e92db1a..d6a5f6cf 100644 --- a/Libiada.Core.Tests/Core/SimpleTypes/InstrumentTests.cs +++ b/Libiada.Core.Tests/Core/SimpleTypes/InstrumentTests.cs @@ -21,7 +21,7 @@ public class InstrumentTests public void InstrumentCountTest() { var actualCount = EnumExtensions.ToArray().Length; - Assert.AreEqual(InstrumentsCount, actualCount); + Assert.That(actualCount, Is.EqualTo(InstrumentsCount)); } /// @@ -33,7 +33,7 @@ public void InstrumentValuesTest() var instruments = EnumExtensions.ToArray(); for (int i = 0; i < InstrumentsCount; i++) { - Assert.IsTrue(instruments.Contains((Instrument)i)); + Assert.That(instruments, Does.Contain((Instrument)i)); } } @@ -49,7 +49,7 @@ public void InstrumentValuesTest() [TestCase((Instrument)0, "AnyOrUnknown")] public void InstrumentNamesTest(Instrument instrument, string name) { - Assert.AreEqual(name, instrument.GetName()); + Assert.That(instrument.GetName(), Is.EqualTo(name)); } /// @@ -61,7 +61,7 @@ public void InstrumentNamesTest(Instrument instrument, string name) [Test] public void InstrumentHasDisplayValueTest([Values]Instrument instrument) { - Assert.IsFalse(string.IsNullOrEmpty(instrument.GetDisplayValue())); + Assert.That(instrument.GetDisplayValue(), Is.Not.Empty); } /// @@ -73,7 +73,7 @@ public void InstrumentHasDisplayValueTest([Values]Instrument instrument) [Test] public void InstrumentHasDescriptionTest([Values]Instrument instrument) { - Assert.IsFalse(string.IsNullOrEmpty(instrument.GetDescription())); + Assert.That(instrument.GetDescription(), Is.Not.Empty); } /// diff --git a/Libiada.Core.Tests/Core/SimpleTypes/MeasureTests.cs b/Libiada.Core.Tests/Core/SimpleTypes/MeasureTests.cs index 2b00db79..216bbaeb 100644 --- a/Libiada.Core.Tests/Core/SimpleTypes/MeasureTests.cs +++ b/Libiada.Core.Tests/Core/SimpleTypes/MeasureTests.cs @@ -29,7 +29,7 @@ public void MeasureFirstTest() var m1 = new Measure(notes, attributes); var m2 = new Measure(notes2, attributes); - Assert.IsTrue(m1.Equals(m2)); + Assert.That(m1, Is.EqualTo(m2)); } /// @@ -55,7 +55,7 @@ public void MeasureSecondTest() var m2 = new Measure(notes2, attributes); var m3 = new Measure(notes2, attributes2); - Assert.IsFalse(m1.Equals(m2)); - Assert.IsFalse(m2.Equals(m3)); + Assert.That(m1, Is.Not.EqualTo(m2)); + Assert.That(m2, Is.Not.EqualTo(m3)); } } diff --git a/Libiada.Core.Tests/Core/SimpleTypes/NoteSymbolTests.cs b/Libiada.Core.Tests/Core/SimpleTypes/NoteSymbolTests.cs index 6a359fc3..057e8df3 100644 --- a/Libiada.Core.Tests/Core/SimpleTypes/NoteSymbolTests.cs +++ b/Libiada.Core.Tests/Core/SimpleTypes/NoteSymbolTests.cs @@ -20,8 +20,7 @@ public class NoteSymbolTests [Test] public void NoteSymbolCountTest() { - var actualCount = EnumExtensions.ToArray().Length; - Assert.AreEqual(NoteSymbolsCount, actualCount); + Assert.That(EnumExtensions.ToArray(), Has.Length.EqualTo(NoteSymbolsCount)); } /// @@ -31,13 +30,13 @@ public void NoteSymbolCountTest() public void NoteSymbolValuesTest() { var noteSymbols = EnumExtensions.ToArray(); - Assert.IsTrue(noteSymbols.Contains((NoteSymbol)0)); - Assert.IsTrue(noteSymbols.Contains((NoteSymbol)2)); - Assert.IsTrue(noteSymbols.Contains((NoteSymbol)4)); - Assert.IsTrue(noteSymbols.Contains((NoteSymbol)5)); - Assert.IsTrue(noteSymbols.Contains((NoteSymbol)7)); - Assert.IsTrue(noteSymbols.Contains((NoteSymbol)9)); - Assert.IsTrue(noteSymbols.Contains((NoteSymbol)11)); + Assert.That(noteSymbols, Does.Contain((NoteSymbol)0)); + Assert.That(noteSymbols, Does.Contain((NoteSymbol)2)); + Assert.That(noteSymbols, Does.Contain((NoteSymbol)4)); + Assert.That(noteSymbols, Does.Contain((NoteSymbol)5)); + Assert.That(noteSymbols, Does.Contain((NoteSymbol)7)); + Assert.That(noteSymbols, Does.Contain((NoteSymbol)9)); + Assert.That(noteSymbols, Does.Contain((NoteSymbol)11)); } /// @@ -58,7 +57,7 @@ public void NoteSymbolValuesTest() [TestCase((NoteSymbol)11, "B")] public void NoteSymbolNamesTest(NoteSymbol noteSymbol, string name) { - Assert.AreEqual(name, noteSymbol.GetName()); + Assert.That(noteSymbol.GetName(), Is.EqualTo(name)); } /// @@ -70,7 +69,7 @@ public void NoteSymbolNamesTest(NoteSymbol noteSymbol, string name) [Test] public void NoteSymbolHasDisplayValueTest([Values]NoteSymbol noteSymbol) { - Assert.IsFalse(string.IsNullOrEmpty(noteSymbol.GetDisplayValue())); + Assert.That(noteSymbol.GetDisplayValue(), Is.Not.Empty); } /// @@ -82,7 +81,7 @@ public void NoteSymbolHasDisplayValueTest([Values]NoteSymbol noteSymbol) [Test] public void NoteSymbolHasDescriptionTest([Values]NoteSymbol noteSymbol) { - Assert.IsFalse(string.IsNullOrEmpty(noteSymbol.GetDescription())); + Assert.That(noteSymbol.GetDescription(), Is.Not.Empty); } /// diff --git a/Libiada.Core.Tests/Core/SimpleTypes/NullValueTests.cs b/Libiada.Core.Tests/Core/SimpleTypes/NullValueTests.cs index b3a8d686..56a0f6d2 100644 --- a/Libiada.Core.Tests/Core/SimpleTypes/NullValueTests.cs +++ b/Libiada.Core.Tests/Core/SimpleTypes/NullValueTests.cs @@ -14,7 +14,7 @@ public class NullValueTests [Test] public void InstanceNotNullTest() { - Assert.IsNotNull(NullValue.Instance()); + Assert.That(NullValue.Instance(), Is.Not.Null); } /// @@ -23,6 +23,6 @@ public void InstanceNotNullTest() [Test] public void InstanceSingleToneTest() { - Assert.AreSame(NullValue.Instance(), NullValue.Instance()); + Assert.That(NullValue.Instance(), Is.SameAs(NullValue.Instance())); } } diff --git a/Libiada.Core.Tests/Core/SimpleTypes/PitchTests.cs b/Libiada.Core.Tests/Core/SimpleTypes/PitchTests.cs index 417ea36e..37b92a53 100644 --- a/Libiada.Core.Tests/Core/SimpleTypes/PitchTests.cs +++ b/Libiada.Core.Tests/Core/SimpleTypes/PitchTests.cs @@ -14,11 +14,11 @@ public class PitchTests [Test] public void PitchConstructorTest() { - var initialPitch = new Pitch(1, NoteSymbol.A, Accidental.Bekar); - var midiNumberPitch = new Pitch(initialPitch.MidiNumber); - Assert.AreEqual(initialPitch.MidiNumber, midiNumberPitch.MidiNumber); + Pitch initialPitch = new(1, NoteSymbol.A, Accidental.Bekar); + Pitch midiNumberPitch = new(initialPitch.MidiNumber); + Assert.That(midiNumberPitch.MidiNumber, Is.EqualTo(initialPitch.MidiNumber)); initialPitch = new Pitch(5, NoteSymbol.C, Accidental.Sharp); midiNumberPitch = new Pitch(initialPitch.MidiNumber); - Assert.AreEqual(initialPitch.MidiNumber, midiNumberPitch.MidiNumber); + Assert.That(midiNumberPitch.MidiNumber, Is.EqualTo(initialPitch.MidiNumber)); } } diff --git a/Libiada.Core.Tests/Core/SimpleTypes/TieTests.cs b/Libiada.Core.Tests/Core/SimpleTypes/TieTests.cs index 720c34de..a9b31d42 100644 --- a/Libiada.Core.Tests/Core/SimpleTypes/TieTests.cs +++ b/Libiada.Core.Tests/Core/SimpleTypes/TieTests.cs @@ -21,7 +21,7 @@ public class TieTests public void TieCountTest() { var actualCount = EnumExtensions.ToArray().Length; - Assert.AreEqual(TiesCount, actualCount); + Assert.That(actualCount, Is.EqualTo(TiesCount)); } /// @@ -33,7 +33,7 @@ public void TieValuesTest() var ties = EnumExtensions.ToArray(); for (int i = 0; i < TiesCount; i++) { - Assert.IsTrue(ties.Contains((Tie)i)); + Assert.That(ties, Does.Contain((Tie)i)); } } @@ -52,7 +52,7 @@ public void TieValuesTest() [TestCase((Tie)3, "Continue")] public void TieNamesTest(Tie tie, string name) { - Assert.AreEqual(name, tie.GetName()); + Assert.That(tie.GetName(), Is.EqualTo(name)); } /// @@ -64,7 +64,7 @@ public void TieNamesTest(Tie tie, string name) [Test] public void TieHasDisplayValueTest([Values]Tie tie) { - Assert.IsFalse(string.IsNullOrEmpty(tie.GetDisplayValue())); + Assert.That(tie.GetDisplayValue(), Is.Not.Empty); } /// @@ -76,7 +76,7 @@ public void TieHasDisplayValueTest([Values]Tie tie) [Test] public void TieHasDescriptionTest([Values]Tie tie) { - Assert.IsFalse(string.IsNullOrEmpty(tie.GetDescription())); + Assert.That(tie.GetDescription(), Is.Not.Empty); } /// diff --git a/Libiada.Core.Tests/Core/SimpleTypes/ValueIntTests.cs b/Libiada.Core.Tests/Core/SimpleTypes/ValueIntTests.cs index 18eac9eb..4b449a49 100644 --- a/Libiada.Core.Tests/Core/SimpleTypes/ValueIntTests.cs +++ b/Libiada.Core.Tests/Core/SimpleTypes/ValueIntTests.cs @@ -15,9 +15,9 @@ public class ValueIntTests public void SumTest() { int x = new ValueInt(1) + new ValueInt(3); - Assert.AreEqual(4, x); + Assert.That(x, Is.EqualTo(4)); ValueInt y = new ValueInt(1) + new ValueInt(3); - Assert.AreEqual(4, (int)y); - Assert.IsTrue(4.Equals(y)); + Assert.That((int)y, Is.EqualTo(4)); + Assert.That(4.Equals(y), Is.True); } } diff --git a/Libiada.Core.Tests/Core/SimpleTypes/ValueNoteTests.cs b/Libiada.Core.Tests/Core/SimpleTypes/ValueNoteTests.cs index 5095c4d4..da5b9839 100644 --- a/Libiada.Core.Tests/Core/SimpleTypes/ValueNoteTests.cs +++ b/Libiada.Core.Tests/Core/SimpleTypes/ValueNoteTests.cs @@ -14,11 +14,11 @@ public class ValueNoteTests [Test] public void ValueNoteEqualsFirstTest() { - var note1 = new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None); + ValueNote note1 = new(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None); - var note2 = new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 4, false), false, Tie.Start); + ValueNote note2 = new(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 4, false), false, Tie.Start); - Assert.IsTrue(!note1.Equals(note2)); + Assert.That(note1, Is.Not.EqualTo(note2)); } /// @@ -27,11 +27,11 @@ public void ValueNoteEqualsFirstTest() [Test] public void ValueNoteEqualsSecondTest() { - var note1 = new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None); + ValueNote note1 = new(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None); - var note2 = new ValueNote(new Pitch(1, NoteSymbol.B, Accidental.DoubleFlat), new Duration(1, 4, false), false, Tie.None); + ValueNote note2 = new(new Pitch(1, NoteSymbol.B, Accidental.DoubleFlat), new Duration(1, 4, false), false, Tie.None); - Assert.IsTrue(note1.Equals(note2)); + Assert.That(note1, Is.EqualTo(note2)); } /// @@ -40,13 +40,13 @@ public void ValueNoteEqualsSecondTest() [Test] public void MultiNoteEqualsTest() { - var note1 = new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None); + ValueNote note1 = new(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None); note1.AddPitch(new Pitch(1, NoteSymbol.B, Accidental.Bekar)); - var note2 = new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None); + ValueNote note2 = new(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None); note2.AddPitch(new Pitch(1, NoteSymbol.B, Accidental.Bekar)); - Assert.IsTrue(note1.Equals(note2)); + Assert.That(note1, Is.EqualTo(note2)); } /// @@ -55,12 +55,12 @@ public void MultiNoteEqualsTest() [Test] public void ValueNoteCloneTest() { - var note1 = new ValueNote(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 4, false), false, Tie.End); + ValueNote note1 = new(new Pitch(1, NoteSymbol.A, Accidental.Bekar), new Duration(1, 4, false), false, Tie.End); - var note2 = (ValueNote)note1.Clone(); + ValueNote note2 = (ValueNote)note1.Clone(); - Assert.IsTrue(note1.Equals(note2)); + Assert.That(note1, Is.EqualTo(note2)); - Assert.AreNotSame(note1, note2); + Assert.That(note1, Is.Not.SameAs(note2)); } } diff --git a/Libiada.Core.Tests/Core/SimpleTypes/ValuePhantomTests.cs b/Libiada.Core.Tests/Core/SimpleTypes/ValuePhantomTests.cs index 26b89beb..13bed77d 100644 --- a/Libiada.Core.Tests/Core/SimpleTypes/ValuePhantomTests.cs +++ b/Libiada.Core.Tests/Core/SimpleTypes/ValuePhantomTests.cs @@ -14,9 +14,9 @@ public class ValuePhantomTests [Test] public void EqualsTest() { - var m1 = new ValuePhantom { new ValueString('1'), new ValueString('2'), new ValueString('3') }; + ValuePhantom m1 = [new ValueString('1'), new ValueString('2'), new ValueString('3')]; - Assert.IsTrue(m1.Equals(new ValueString('3'))); + Assert.That(m1.Equals(new ValueString('3'))); } /// @@ -25,14 +25,14 @@ public void EqualsTest() [Test] public void AddMessagePhantomTest() { - var m2 = new ValuePhantom { new ValueString('4'), new ValueString('2'), new ValueString('5') }; - var m1 = new ValuePhantom { new ValueString('1'), new ValueString('2'), new ValueString('3'), m2 }; + ValuePhantom m2 = [new ValueString('4'), new ValueString('2'), new ValueString('5')]; + ValuePhantom m1 = [new ValueString('1'), new ValueString('2'), new ValueString('3'), m2]; - Assert.IsTrue(m1.Equals(new ValueString('1'))); - Assert.IsTrue(m1.Equals(new ValueString('2'))); - Assert.IsTrue(m1.Equals(new ValueString('3'))); - Assert.IsTrue(m1.Equals(new ValueString('4'))); - Assert.IsTrue(m1.Equals(new ValueString('5'))); + Assert.That(m1.Equals(new ValueString('1'))); + Assert.That(m1.Equals(new ValueString('2'))); + Assert.That(m1.Equals(new ValueString('3'))); + Assert.That(m1.Equals(new ValueString('4'))); + Assert.That(m1.Equals(new ValueString('5'))); } /// @@ -41,9 +41,9 @@ public void AddMessagePhantomTest() [Test] public void CloneTest() { - var m1 = new ValuePhantom { new ValueString('1'), new ValueString('2'), new ValueString('3') }; + ValuePhantom m1 = [new ValueString('1'), new ValueString('2'), new ValueString('3')]; + var clone = (ValuePhantom)m1.Clone(); - var itsClone = (ValuePhantom)m1.Clone(); - Assert.AreEqual(m1, itsClone); + Assert.That(clone, Is.EqualTo(m1)); } } diff --git a/Libiada.Core.Tests/Core/SimpleTypes/ValueStringTests.cs b/Libiada.Core.Tests/Core/SimpleTypes/ValueStringTests.cs index cc984cac..7353b8eb 100644 --- a/Libiada.Core.Tests/Core/SimpleTypes/ValueStringTests.cs +++ b/Libiada.Core.Tests/Core/SimpleTypes/ValueStringTests.cs @@ -32,7 +32,10 @@ public void EmptyStringValueTest() [Test] public void EqualsTest() { - Assert.AreEqual(new ValueString("1"), new ValueString("1")); - Assert.AreEqual(new ValueString("abc"), new ValueString("abc")); + Assert.Multiple(() => + { + Assert.That(new ValueString("1"), Is.EqualTo(new ValueString('1'))); + Assert.That(new ValueString("abc"), Is.EqualTo(new ValueString("abc"))); + }); } } diff --git a/Libiada.Core.Tests/DataTransformers/DissimilarChainFactoryTests.cs b/Libiada.Core.Tests/DataTransformers/DissimilarChainFactoryTests.cs index 1035ac1b..d53d2b2d 100644 --- a/Libiada.Core.Tests/DataTransformers/DissimilarChainFactoryTests.cs +++ b/Libiada.Core.Tests/DataTransformers/DissimilarChainFactoryTests.cs @@ -25,7 +25,7 @@ public void DissimilarOrderTest(int chainIndex, int resultIndex) { var result = DissimilarChainFactory.Create(ChainsStorage.Chains[chainIndex]); var expected = ChainsStorage.DissimilarChains[resultIndex]; - Assert.AreEqual(expected, result); + Assert.That(result, Is.EqualTo(expected)); } /// @@ -45,6 +45,6 @@ public void DissimilarSecondOrderTest(int chainIndex, int resultIndex) var result = DissimilarChainFactory.Create(ChainsStorage.Chains[chainIndex]); result = DissimilarChainFactory.Create(result); var expected = ChainsStorage.DissimilarChains[resultIndex]; - Assert.AreEqual(expected, result); + Assert.That(result, Is.EqualTo(expected)); } } diff --git a/Libiada.Core.Tests/DataTransformers/DnaTransformerTests.cs b/Libiada.Core.Tests/DataTransformers/DnaTransformerTests.cs index 5d709423..51bcee83 100644 --- a/Libiada.Core.Tests/DataTransformers/DnaTransformerTests.cs +++ b/Libiada.Core.Tests/DataTransformers/DnaTransformerTests.cs @@ -13,21 +13,21 @@ public class DnaTransformerTests [Test] public void UnexpectedStopCodonTest() { - var input = new BaseChain("TAGTGA"); + BaseChain input = new("TAGTGA"); Assert.Throws(() => DnaTransformer.EncodeAmino(input)); } [Test] public void NoStopCodonTest() { - var input = new BaseChain("AAAAAA"); + BaseChain input = new("AAAAAA"); Assert.Throws(() => DnaTransformer.EncodeAmino(input)); } [Test] public void WrongCodingTableNumberTest() { - var input = new BaseChain("TAGTGA"); + BaseChain input = new("TAGTGA"); Assert.Throws(() => DnaTransformer.EncodeAmino(input, 58)); } @@ -89,11 +89,11 @@ public void WrongCodingTableNumberTest() [TestCase(33, "FFLLSSSSYYYCCWWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSSKVVVVAAAADDEEGGGG", "TTTTTCTTATTGTCTTCCTCATCGTATTACTAATGTTGCTGATGGCTTCTCCTACTGCCTCCCCCACCGCATCACCAACAGCGTCGCCGACGGATTATCATAATGACTACCACAACGAATAACAAAAAGAGTAGCAGAAGGGTTGTCGTAGTGGCTGCCGCAGCGGATGACGAAGAGGGTGGCGGAGGGTAG")] public void EncodeWithCodingTableTest(byte codingTable, string aminoSequence, string nucleotideSequcne) { - var input = new BaseChain(nucleotideSequcne); + BaseChain input = new(nucleotideSequcne); BaseChain result = DnaTransformer.EncodeAmino(input, codingTable); - var expected = new BaseChain(aminoSequence); + BaseChain expected = new(aminoSequence); - Assert.AreEqual(expected, result); + Assert.That(result, Is.EqualTo(expected)); } /// @@ -102,10 +102,10 @@ public void EncodeWithCodingTableTest(byte codingTable, string aminoSequence, st [Test] public void SimpleDecodeTest() { - var input = new BaseChain("F"); + BaseChain input = new("F"); BaseChain result = DnaTransformer.Decode(input); - var mes = new ValuePhantom { new ValueString("TTT"), new ValueString("TTC") }; - Assert.IsTrue(mes.Equals(result[0])); + ValuePhantom mes = [new ValueString("TTT"), new ValueString("TTC")]; + Assert.That(mes, Is.EqualTo(result[0])); } /// @@ -114,101 +114,91 @@ public void SimpleDecodeTest() [Test] public void DecodeTest() { - var input = new BaseChain("FLSYXCWPHQRIMTNKVADEG"); + BaseChain input = new("FLSYXCWPHQRIMTNKVADEG"); - var message = new List - { - new ValuePhantom { new ValueString("TTT"), new ValueString("TTC") }, - new ValuePhantom - { - new ValueString("TTA"), - new ValueString("TTG"), - new ValueString("CTT"), - new ValueString("CTC"), - new ValueString("CTA"), - new ValueString("CTG") - }, - new ValuePhantom - { - new ValueString("TCT"), - new ValueString("TCC"), - new ValueString("TCA"), - new ValueString("TCG"), - new ValueString("AGT"), - new ValueString("AGC") - }, - new ValuePhantom { new ValueString("TAT"), new ValueString("TAC") }, - new ValuePhantom - { - new ValueString("TAA"), - new ValueString("TAG"), - new ValueString("TGA") - }, - new ValuePhantom { new ValueString("TGT"), new ValueString("TGC") }, - new ValuePhantom { new ValueString("TGG") }, - new ValuePhantom - { - new ValueString("CCT"), - new ValueString("CCC"), - new ValueString("CCA"), - new ValueString("CCG") - }, - new ValuePhantom { new ValueString("CAT"), new ValueString("CAC") }, - new ValuePhantom { new ValueString("CAA"), new ValueString("CAG") }, - new ValuePhantom - { - new ValueString("CGT"), - new ValueString("CGC"), - new ValueString("CGA"), - new ValueString("CGG"), - new ValueString("AGA"), - new ValueString("AGG") - }, - new ValuePhantom - { - new ValueString("ATT"), - new ValueString("ATC"), - new ValueString("ATA") - }, - new ValuePhantom { new ValueString("ATG") }, - new ValuePhantom - { - new ValueString("ACT"), - new ValueString("ACC"), - new ValueString("ACA"), - new ValueString("ACG") - }, - new ValuePhantom { new ValueString("AAT"), new ValueString("AAC") }, - new ValuePhantom { new ValueString("AAA"), new ValueString("AAG") }, - new ValuePhantom - { - new ValueString("GTT"), - new ValueString("GTC"), - new ValueString("GTA"), - new ValueString("GTG") - }, - new ValuePhantom - { - new ValueString("GCT"), - new ValueString("GCC"), - new ValueString("GCA"), - new ValueString("GCG") - }, - new ValuePhantom { new ValueString("GAT"), new ValueString("GAC") }, - new ValuePhantom { new ValueString("GAA"), new ValueString("GAG") }, - new ValuePhantom - { - new ValueString("GGT"), - new ValueString("GGC"), - new ValueString("GGA"), - new ValueString("GGG") - } - }; + List message = + [ + [new ValueString("TTT"), new ValueString("TTC")], + [ + new ValueString("TTA"), + new ValueString("TTG"), + new ValueString("CTT"), + new ValueString("CTC"), + new ValueString("CTA"), + new ValueString("CTG") + ], + [ + new ValueString("TCT"), + new ValueString("TCC"), + new ValueString("TCA"), + new ValueString("TCG"), + new ValueString("AGT"), + new ValueString("AGC") + ], + [new ValueString("TAT"), new ValueString("TAC")], + [ + new ValueString("TAA"), + new ValueString("TAG"), + new ValueString("TGA") + ], + [new ValueString("TGT"), new ValueString("TGC")], + [new ValueString("TGG")], + [ + new ValueString("CCT"), + new ValueString("CCC"), + new ValueString("CCA"), + new ValueString("CCG") + ], + [new ValueString("CAT"), new ValueString("CAC")], + [new ValueString("CAA"), new ValueString("CAG")], + [ + new ValueString("CGT"), + new ValueString("CGC"), + new ValueString("CGA"), + new ValueString("CGG"), + new ValueString("AGA"), + new ValueString("AGG") + ], + [ + new ValueString("ATT"), + new ValueString("ATC"), + new ValueString("ATA") + ], + [new ValueString("ATG")], + [ + new ValueString("ACT"), + new ValueString("ACC"), + new ValueString("ACA"), + new ValueString("ACG") + ], + [new ValueString("AAT"), new ValueString("AAC")], + [new ValueString("AAA"), new ValueString("AAG")], + [ + new ValueString("GTT"), + new ValueString("GTC"), + new ValueString("GTA"), + new ValueString("GTG") + ], + [ + new ValueString("GCT"), + new ValueString("GCC"), + new ValueString("GCA"), + new ValueString("GCG") + ], + [new ValueString("GAT"), new ValueString("GAC")], + [new ValueString("GAA"), new ValueString("GAG")], + [ + new ValueString("GGT"), + new ValueString("GGC"), + new ValueString("GGA"), + new ValueString("GGG") + ] + ]; BaseChain result = DnaTransformer.Decode(input); for (int i = 0; i < message.Count; i++) { - Assert.IsTrue(result[i].Equals(message[i])); + Assert.That(result[i], Is.EqualTo(message[i])); } } @@ -284,17 +274,15 @@ public void DecodeTest() [TestCase("GGG")] public void EncodeTripletsTest(string triplet) { - var input = new BaseChain(triplet.Length); + Assert.That(triplet, Has.Length.EqualTo(3)); + BaseChain input = new(triplet.Length); for (int i = 0; i < triplet.Length; i++) { input[i] = new ValueString(triplet[i]); } BaseChain result = DnaTransformer.EncodeTriplets(input); - - for (int i = 0; i < result.Length; i++) - { - Assert.AreEqual(new ValueString(triplet.Substring(i * 3, 3)), result[i]); - } + Assert.That(result, Has.Length.EqualTo(1)); + Assert.That(result[0], Is.EqualTo(new ValueString(triplet))); } } diff --git a/Libiada.Core.Tests/DataTransformers/HighOrderFactoryTests.cs b/Libiada.Core.Tests/DataTransformers/HighOrderFactoryTests.cs index 781f0275..fdd0a50a 100644 --- a/Libiada.Core.Tests/DataTransformers/HighOrderFactoryTests.cs +++ b/Libiada.Core.Tests/DataTransformers/HighOrderFactoryTests.cs @@ -32,7 +32,7 @@ public void SecondOrderTest(int chainIndex, int resultIndex, Link link) { var result = HighOrderFactory.Create(ChainsStorage.Chains[chainIndex], link); var expected = ChainsStorage.HighOrderChains[resultIndex]; - Assert.AreEqual(expected, result); + Assert.That(result, Is.EqualTo(expected)); } /// @@ -44,6 +44,6 @@ public void ThirdOrderTest() var result = HighOrderFactory.Create(ChainsStorage.Chains[0], Link.End); result = HighOrderFactory.Create(result, Link.End); var expected = ChainsStorage.HighOrderChains[6]; - Assert.AreEqual(expected, result); + Assert.That(result, Is.EqualTo(expected)); } } diff --git a/Libiada.Core.Tests/DataTransformers/PermutationGeneratorTests.cs b/Libiada.Core.Tests/DataTransformers/PermutationGeneratorTests.cs index 647bba78..4bea5e6f 100644 --- a/Libiada.Core.Tests/DataTransformers/PermutationGeneratorTests.cs +++ b/Libiada.Core.Tests/DataTransformers/PermutationGeneratorTests.cs @@ -6,20 +6,20 @@ public class PermutationGeneratorTests { private static readonly int[][] Expected1 = - { - new int[] { 0, 1 }, - new int[] { 1, 0 }, - }; + [ + [0, 1], + [1, 0], + ]; private static readonly int[][] Expected2 = - { - new int[] { 0, 1, 2 }, - new int[] { 0, 2, 1 }, - new int[] { 1, 0, 2 }, - new int[] { 1, 2, 0 }, - new int[] { 2, 0, 1 }, - new int[] { 2, 1, 0 }, - }; + [ + [0, 1, 2], + [0, 2, 1], + [1, 0, 2], + [1, 2, 0], + [2, 0, 1], + [2, 1, 0], + ]; [Test] public void GetOrdersForTwoElementsTest() diff --git a/Libiada.Core.Tests/DataTransformers/SequenceConcatenatorTests.cs b/Libiada.Core.Tests/DataTransformers/SequenceConcatenatorTests.cs index 9ad60fa4..593107da 100644 --- a/Libiada.Core.Tests/DataTransformers/SequenceConcatenatorTests.cs +++ b/Libiada.Core.Tests/DataTransformers/SequenceConcatenatorTests.cs @@ -10,18 +10,18 @@ public class SequenceConcatenatorTests [Test] public void ConcatenateTest() { - var sequencesIndexes = new[] { 0, 2, 1 }; + int[] sequencesIndexes = [0, 2, 1]; var sourceChains = ChainsStorage.ConcatinationChains; - var result = SequenceConcatenator.Concatenate(new[] { sourceChains[0], sourceChains[1], sourceChains[2] }, sequencesIndexes); - Assert.AreEqual(sourceChains[4], result); + var result = SequenceConcatenator.Concatenate([sourceChains[0], sourceChains[1], sourceChains[2]], sequencesIndexes); + Assert.That(result, Is.EqualTo(sourceChains[4])); } [Test] public void ConcatenateAsOrderedTest() { var sourceChains = ChainsStorage.ConcatinationChains; - var result = SequenceConcatenator.ConcatenateAsOrdered(new[] { sourceChains[0], sourceChains[1], sourceChains[2] }); - Assert.AreEqual(sourceChains[3], result); + var result = SequenceConcatenator.ConcatenateAsOrdered([sourceChains[0], sourceChains[1], sourceChains[2]]); + Assert.That(result, Is.EqualTo(sourceChains[3])); } [Test] @@ -29,16 +29,16 @@ public void GenerateConcatenationsTest() { var sourceChains = ChainsStorage.ConcatinationChains; Chain[] expectedChains = - { + [ sourceChains[3], sourceChains[4], sourceChains[5], sourceChains[6], sourceChains[7], sourceChains[8] - }; + ]; - var result = SequenceConcatenator.GenerateConcatenations(new[] { sourceChains[0], sourceChains[1], sourceChains[2] }); - Assert.AreEqual(expectedChains, result); + var result = SequenceConcatenator.GenerateConcatenations([sourceChains[0], sourceChains[1], sourceChains[2]]); + Assert.That(result, Is.EqualTo(expectedChains)); } } diff --git a/Libiada.Core.Tests/Exceptions/TypeArgumentExceptionTests.cs b/Libiada.Core.Tests/Exceptions/TypeArgumentExceptionTests.cs index c3aa67fa..655ecfdb 100644 --- a/Libiada.Core.Tests/Exceptions/TypeArgumentExceptionTests.cs +++ b/Libiada.Core.Tests/Exceptions/TypeArgumentExceptionTests.cs @@ -14,8 +14,8 @@ public class TypeArgumentExceptionTests [Test] public void TypeArgumentExceptionMessageTest() { - var exception = new TypeArgumentException("test message"); - Assert.AreEqual("test message", exception.Message); + TypeArgumentException exception = new("test message"); + Assert.That(exception.Message, Is.EqualTo("test message")); } /// @@ -24,8 +24,8 @@ public void TypeArgumentExceptionMessageTest() [Test] public void TypeArgumentExceptionActualTypeTest() { - var exception = new TypeArgumentException("test message", typeof(object)); - Assert.IsNotNull(exception.ActualTypeArgument); - Assert.AreEqual(typeof(object).Name, exception.ActualTypeArgument.Name); + TypeArgumentException exception = new("test message", typeof(object)); + Assert.That(exception.ActualTypeArgument, Is.Not.Null); + Assert.That(exception.ActualTypeArgument.Name, Is.EqualTo(typeof(object).Name)); } -} \ No newline at end of file +} diff --git a/Libiada.Core.Tests/Extensions/ArrayExtensionsTests.cs b/Libiada.Core.Tests/Extensions/ArrayExtensionsTests.cs index 94dcda67..0a3a4766 100644 --- a/Libiada.Core.Tests/Extensions/ArrayExtensionsTests.cs +++ b/Libiada.Core.Tests/Extensions/ArrayExtensionsTests.cs @@ -14,19 +14,19 @@ public class ArrayExtensionsTests [Test] public void DeleteAtIntArrayTest() { - var source = new[] { 1, 2, 2, 4, 4, 2, 7, 2, 3, 1 }; + int[] source = [1, 2, 2, 4, 4, 2, 7, 2, 3, 1]; int[] result = source.DeleteAt(6); - var expected = new[] { 1, 2, 2, 4, 4, 2, 2, 3, 1 }; - Assert.AreEqual(expected, result); + int[] expected = [1, 2, 2, 4, 4, 2, 2, 3, 1]; + Assert.That(result, Is.EqualTo(expected)); result = result.DeleteAt(4); - expected = new[] { 1, 2, 2, 4, 2, 2, 3, 1 }; - Assert.AreEqual(expected, result); + expected = [1, 2, 2, 4, 2, 2, 3, 1]; + Assert.That(result, Is.EqualTo(expected)); result = result.DeleteAt(0); - expected = new[] { 2, 2, 4, 2, 2, 3, 1 }; - Assert.AreEqual(expected, result); + expected = [2, 2, 4, 2, 2, 3, 1]; + Assert.That(result, Is.EqualTo(expected)); } /// @@ -35,19 +35,19 @@ public void DeleteAtIntArrayTest() [Test] public void DeleteAtTest() { - var source = new[] { "test", "a", "a", "test", "test", "b", "1" }; + string[] source = ["test", "a", "a", "test", "test", "b", "1"]; string[] result = source.DeleteAt(6); - var expected = new[] { "test", "a", "a", "test", "test", "b" }; - Assert.AreEqual(expected, result); + string[] expected = ["test", "a", "a", "test", "test", "b"]; + Assert.That(result, Is.EqualTo(expected)); result = result.DeleteAt(4); - expected = new[] { "test", "a", "a", "test", "b" }; - Assert.AreEqual(expected, result); + expected = ["test", "a", "a", "test", "b"]; + Assert.That(result, Is.EqualTo(expected)); result = result.DeleteAt(0); - expected = new[] { "a", "a", "test", "b" }; - Assert.AreEqual(expected, result); + expected = ["a", "a", "test", "b"]; + Assert.That(result, Is.EqualTo(expected)); } /// @@ -56,16 +56,16 @@ public void DeleteAtTest() [Test] public void AllIndexesOfIntArrayTest() { - var source = new[] { 1, 2, 2, 4, 4, 2, 7, 2, 3, 1 }; + int[] source = [1, 2, 2, 4, 4, 2, 7, 2, 3, 1]; - var expected = new[] { 1, 2, 5, 7 }; - Assert.AreEqual(expected, source.AllIndexesOf(2)); + int[] expected = [1, 2, 5, 7]; + Assert.That(source.AllIndexesOf(2), Is.EqualTo(expected)); - expected = new[] { 6 }; - Assert.AreEqual(expected, source.AllIndexesOf(7)); + expected = [6]; + Assert.That(source.AllIndexesOf(7), Is.EqualTo(expected)); - expected = Array.Empty(); - Assert.AreEqual(expected, source.AllIndexesOf(11)); + expected = []; + Assert.That(source.AllIndexesOf(11), Is.EqualTo(expected)); } /// @@ -74,19 +74,19 @@ public void AllIndexesOfIntArrayTest() [Test] public void AllIndexesOfTest() { - var source = new[] { "a", "test", "a", "aa", "test", "test", "c" }; + string[] source = ["a", "test", "a", "aa", "test", "test", "c"]; - var expected = new[] { 0, 2 }; - Assert.AreEqual(expected, source.AllIndexesOf("a")); + int[] expected = [0, 2]; + Assert.That(source.AllIndexesOf("a"), Is.EqualTo(expected)); - expected = new[] { 6 }; - Assert.AreEqual(expected, source.AllIndexesOf("c")); + expected = [6]; + Assert.That(source.AllIndexesOf("c"), Is.EqualTo(expected)); - expected = new[] { 1, 4, 5 }; - Assert.AreEqual(expected, source.AllIndexesOf("test")); + expected = [1, 4, 5]; + Assert.That(source.AllIndexesOf("test"), Is.EqualTo(expected)); - expected = Array.Empty(); - Assert.AreEqual(expected, source.AllIndexesOf("another test")); + expected = []; + Assert.That(source.AllIndexesOf("another test"), Is.EqualTo(expected)); } /// @@ -95,13 +95,13 @@ public void AllIndexesOfTest() [Test] public void ToStringTest() { - var source = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + int[] source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - var expected = "1 2 3 4 5 6 7 8 9 10"; - Assert.AreEqual(expected, source.ToString(" ")); + string expected = "1 2 3 4 5 6 7 8 9 10"; + Assert.That(source.ToString(" "), Is.EqualTo(expected)); expected = "1, 2, 3, 4, 5, 6, 7, 8, 9, 10"; - Assert.AreEqual(expected, source.ToString(", ")); + Assert.That(source.ToString(", "), Is.EqualTo(expected)); } /// @@ -110,10 +110,10 @@ public void ToStringTest() [Test] public void ToStringWithDefaultDelimiterTest() { - var source = new[] { 1, 2, 3 }; + int[] source = [1, 2, 3]; string expected = "1" + Environment.NewLine + "2" + Environment.NewLine + "3"; - Assert.AreEqual(expected, source.ToStringWithDefaultDelimiter()); + Assert.That(source.ToStringWithDefaultDelimiter(), Is.EqualTo(expected)); } /// @@ -122,10 +122,10 @@ public void ToStringWithDefaultDelimiterTest() [Test] public void ToStringWithoutDelimiterTest() { - var source = new[] { 1, 2, 3, 2, 2 }; + int[] source = [1, 2, 3, 2, 2]; - var expected = "12322"; - Assert.AreEqual(expected, source.ToStringWithoutDelimiter()); + const string expected = "12322"; + Assert.That(source.ToStringWithoutDelimiter(), Is.EqualTo(expected)); } /// @@ -134,18 +134,18 @@ public void ToStringWithoutDelimiterTest() [Test] public void RotateTest() { - var source = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; - var result = source.Rotate(1); - var expected = new[] { 2, 3, 4, 5, 6, 7, 8, 9, 10, 1 }; - Assert.AreEqual(expected, result); + int[] source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + int[] result = source.Rotate(1); + int[] expected = [2, 3, 4, 5, 6, 7, 8, 9, 10, 1]; + Assert.That(result, Is.EqualTo(expected)); result = source.Rotate(2); - expected = new[] { 3, 4, 5, 6, 7, 8, 9, 10, 1, 2 }; - Assert.AreEqual(expected, result); + expected = [3, 4, 5, 6, 7, 8, 9, 10, 1, 2]; + Assert.That(result, Is.EqualTo(expected)); result = source.Rotate(10); - expected = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; - Assert.AreEqual(expected, result); + expected = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + Assert.That(result, Is.EqualTo(expected)); } /// @@ -154,21 +154,33 @@ public void RotateTest() [Test] public void IsSortedTest() { - var source = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; - Assert.IsTrue(source.IsSorted()); - Assert.IsTrue(source.ToList().IsSorted()); - - source = new[] { 1 }; - Assert.IsTrue(source.IsSorted()); - Assert.IsTrue(source.ToList().IsSorted()); - - source = new[] { 1, 2, 2, 2, 2, 10, 100, 10000 }; - Assert.IsTrue(source.IsSorted()); - Assert.IsTrue(source.ToList().IsSorted()); - - source = new[] { 1, 2, 1, 3, 4, 10 }; - Assert.IsFalse(source.IsSorted()); - Assert.IsFalse(source.ToList().IsSorted()); + int[] source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + Assert.Multiple(() => + { + Assert.That(source.IsSorted()); + Assert.That(source.ToList().IsSorted()); + }); + + source = [1]; + Assert.Multiple(() => + { + Assert.That(source.IsSorted()); + Assert.That(source.ToList().IsSorted()); + }); + + source = [1, 2, 2, 2, 2, 10, 100, 10000]; + Assert.Multiple(() => + { + Assert.That(source.IsSorted()); + Assert.That(source.ToList().IsSorted()); + }); + + source = [1, 2, 1, 3, 4, 10]; + Assert.Multiple(() => + { + Assert.That(source.IsSorted(), Is.False); + Assert.That(source.ToList().IsSorted(), Is.False); + }); } /// @@ -177,11 +189,16 @@ public void IsSortedTest() [Test] public void SubArrayTest() { - var source = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; - Assert.AreEqual(new[] { 1 }, source.SubArray(0, 1)); - Assert.AreEqual(new[] { 1, 2 }, source.SubArray(0, 2)); - Assert.AreEqual(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, source.SubArray(0, 10)); - Assert.AreEqual(new[] { 2 }, source.SubArray(1, 1)); - Assert.AreEqual(new[] { 2, 3, 4, 5, 6, 7, 8, 9, 10 }, source.SubArray(1, 9)); + int[] source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + int[] expected = [1]; + Assert.That(source.SubArray(0, 1), Is.EqualTo(expected)); + expected = [1, 2]; + Assert.That(source.SubArray(0, 2), Is.EqualTo(expected)); + expected = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + Assert.That(source.SubArray(0, 10), Is.EqualTo(expected)); + expected = [2]; + Assert.That(source.SubArray(1, 1), Is.EqualTo(expected)); + expected = [2, 3, 4, 5, 6, 7, 8, 9, 10]; + Assert.That(source.SubArray(1, 9), Is.EqualTo(expected)); } } diff --git a/Libiada.Core.Tests/Extensions/EnumExtensionsTests.cs b/Libiada.Core.Tests/Extensions/EnumExtensionsTests.cs index b040ee08..95b145ea 100644 --- a/Libiada.Core.Tests/Extensions/EnumExtensionsTests.cs +++ b/Libiada.Core.Tests/Extensions/EnumExtensionsTests.cs @@ -38,6 +38,6 @@ public void ToArrayTest() TestEnum[] actual = EnumExtensions.ToArray(); var expected = new[] { TestEnum.First, TestEnum.Second, TestEnum.Third }; - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } -} \ No newline at end of file +} diff --git a/Libiada.Core.Tests/Extensions/StringExtensionsTests.cs b/Libiada.Core.Tests/Extensions/StringExtensionsTests.cs index f6e2f830..6170de73 100644 --- a/Libiada.Core.Tests/Extensions/StringExtensionsTests.cs +++ b/Libiada.Core.Tests/Extensions/StringExtensionsTests.cs @@ -14,11 +14,11 @@ public class StringExtensionsTests [Test] public void TrimEndTest() { - var source = "Chaoyang virus strain Deming polyprotein gene, complete cds."; - var expected = "Chaoyang virus strain Deming polyprotein gene"; + const string source = "Chaoyang virus strain Deming polyprotein gene, complete cds."; + const string expected = "Chaoyang virus strain Deming polyprotein gene"; string actual = source.TrimEnd(", complete cds."); - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); actual = source.TrimEnd(", complete genome.") .TrimEnd(", complete sequence.") @@ -30,7 +30,7 @@ public void TrimEndTest() .TrimEnd(" complete CDS.") .TrimEnd(" complete cds.") .TrimEnd(" genome."); - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } /// @@ -43,27 +43,27 @@ public void TrimEndWithTrashTest() var expected = "Bagaza virus isolate BAGV/Spain/RLP-Hcc2/2010, complete genome."; string actual = source.TrimEnd(", complete cds"); - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); actual = source.TrimEnd(", complete genome") .TrimEnd(", complete sequence") .TrimEnd(", complete CDS") .TrimEnd(", complete cds") .TrimEnd(", genome"); - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); source = "Bagaza virus isolate BAGV/Spain/RLP-Hcc2/2010, complete genome"; expected = "Bagaza virus isolate BAGV/Spain/RLP-Hcc2/2010, complete genome"; actual = source.TrimEnd(", complete cds."); - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); actual = source.TrimEnd(", complete genome.") .TrimEnd(", complete sequence.") .TrimEnd(", complete CDS.") .TrimEnd(", complete cds.") .TrimEnd(", genome."); - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } /// @@ -72,10 +72,10 @@ public void TrimEndWithTrashTest() [Test] public void GetLargestRepeatingSubstringTest() { - string source = " abc abc abc abc "; - string expected = "abc"; + const string source = " abc abc abc abc "; + const string expected = "abc"; string actual = source.GetLargestRepeatingSubstring(); - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } /// @@ -85,10 +85,10 @@ public void GetLargestRepeatingSubstringTest() [Test] public void GetLargestRepeatingSubstringNoSubstringTest() { - string source = " abc abc abc abf "; - string expected = " abc abc abc abf "; + const string source = " abc abc abc abf "; + const string expected = " abc abc abc abf "; string actual = source.GetLargestRepeatingSubstring(); - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } /// @@ -97,13 +97,17 @@ public void GetLargestRepeatingSubstringNoSubstringTest() [Test] public void IsSubsetOfTest() { - var firstSource = "Salmonella enterica subsp. enterica serovar Paratyphi C str. RKS4594"; - var secondSource = "enterica subsp. enterica serovar Paratyphi C str. Salmonella enterica subsp. enterica serovar Paratyphi C str."; - Assert.IsTrue(secondSource.IsSubsetOf(firstSource)); - Assert.IsFalse(firstSource.IsSubsetOf(secondSource)); + const string firstSource = "Salmonella enterica subsp. enterica serovar Paratyphi C str. RKS4594"; + string secondSource = "enterica subsp. enterica serovar Paratyphi C str. Salmonella enterica subsp. enterica serovar Paratyphi C str."; + + Assert.Multiple(() => + { + Assert.That(secondSource.IsSubsetOf(firstSource)); + Assert.That(firstSource.IsSubsetOf(secondSource), Is.False); + }); secondSource = secondSource.GetLargestRepeatingSubstring(); - Assert.IsTrue(secondSource.IsSubsetOf(firstSource)); + Assert.That(secondSource.IsSubsetOf(firstSource)); } /// @@ -117,9 +121,9 @@ public void IsSubsetOfTest() [TestCase("Salmonella enterica subsp. enterica serovar Paratyphi C strain RKS4594")] public void IsSubsetOfItselfTest(string source) { - Assert.IsTrue(source.IsSubsetOf(source)); + Assert.That(source.IsSubsetOf(source)); source = source.GetLargestRepeatingSubstring(); - Assert.IsTrue(source.IsSubsetOf(source)); + Assert.That(source.IsSubsetOf(source)); } } diff --git a/Libiada.Core.Tests/Images/ImageProcessorTests.cs b/Libiada.Core.Tests/Images/ImageProcessorTests.cs index 5f69ae29..a9997954 100644 --- a/Libiada.Core.Tests/Images/ImageProcessorTests.cs +++ b/Libiada.Core.Tests/Images/ImageProcessorTests.cs @@ -13,7 +13,7 @@ public class ImageProcessorTests [Test] public void SimpleTest() { - Image image = new Image(2, 3); + Image image = new(2, 3); image[0, 0] = Color.Black; image[0, 1] = Color.White; image[0, 2] = Color.Black; @@ -21,12 +21,12 @@ public void SimpleTest() image[1, 1] = Color.Black; image[1, 2] = Color.White; - BaseChain actual = ImageProcessor.ProcessImage(image, new IImageTransformer[0], new IMatrixTransformer[0], new LineOrderExtractor()); + BaseChain actual = ImageProcessor.ProcessImage(image, [], [], new LineOrderExtractor()); - ValuePixel black = new ValuePixel(Color.Black); - ValuePixel white = new ValuePixel(Color.White); + ValuePixel black = new(Color.Black); + ValuePixel white = new(Color.White); - BaseChain expected = new BaseChain(6); + BaseChain expected = new(6); expected[0] = black; expected[1] = white; @@ -35,88 +35,87 @@ public void SimpleTest() expected[4] = black; expected[5] = white; - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } [Test] public void SecondSimpleTest() { - Image image = new Image(2, 2); + Image image = new(2, 2); image[0, 0] = Color.Gray; image[0, 1] = Color.Blue; image[1, 0] = Color.Red; image[1, 1] = Color.Brown; - BaseChain actual = ImageProcessor.ProcessImage(image, new IImageTransformer[0], new IMatrixTransformer[0], new LineOrderExtractor()); + BaseChain actual = ImageProcessor.ProcessImage(image, [], [], new LineOrderExtractor()); - ValuePixel gray = new ValuePixel(Color.Gray); - ValuePixel blue = new ValuePixel(Color.Blue); - ValuePixel red = new ValuePixel(Color.Red); - ValuePixel brown = new ValuePixel(Color.Brown); + ValuePixel gray = new(Color.Gray); + ValuePixel blue = new(Color.Blue); + ValuePixel red = new(Color.Red); + ValuePixel brown = new(Color.Brown); - BaseChain expected = new BaseChain(4); + BaseChain expected = new(4); expected[0] = gray; expected[1] = blue; expected[2] = red; expected[3] = brown; - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } [Test] public void ThirdSimpleTest() { - Image image = new Image(1, 4); + Image image = new(1, 4); image[0, 0] = Color.Gray; image[0, 1] = Color.Blue; image[0, 2] = Color.Red; image[0, 3] = Color.Brown; - BaseChain actual = ImageProcessor.ProcessImage(image, new IImageTransformer[0], new IMatrixTransformer[0], new LineOrderExtractor()); + BaseChain actual = ImageProcessor.ProcessImage(image, [], [], new LineOrderExtractor()); - ValuePixel gray = new ValuePixel(Color.Gray); - ValuePixel blue = new ValuePixel(Color.Blue); - ValuePixel red = new ValuePixel(Color.Red); - ValuePixel brown = new ValuePixel(Color.Brown); + ValuePixel gray = new(Color.Gray); + ValuePixel blue = new(Color.Blue); + ValuePixel red = new(Color.Red); + ValuePixel brown = new(Color.Brown); - BaseChain expected = new BaseChain(4); + BaseChain expected = new(4); expected[0] = gray; expected[1] = blue; expected[2] = red; expected[3] = brown; - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } [Test] public void FourthSimpleTest() { - Image image = new Image(4, 1); + Image image = new(4, 1); image[0, 0] = Color.Gray; image[1, 0] = Color.Blue; image[2, 0] = Color.Red; image[3, 0] = Color.Brown; - BaseChain actual = ImageProcessor.ProcessImage(image, new IImageTransformer[0], new IMatrixTransformer[0], new LineOrderExtractor()); + BaseChain actual = ImageProcessor.ProcessImage(image, [], [], new LineOrderExtractor()); - ValuePixel gray = new ValuePixel(Color.Gray); - ValuePixel blue = new ValuePixel(Color.Blue); - ValuePixel red = new ValuePixel(Color.Red); - ValuePixel brown = new ValuePixel(Color.Brown); + ValuePixel gray = new(Color.Gray); + ValuePixel blue = new(Color.Blue); + ValuePixel red = new(Color.Red); + ValuePixel brown = new(Color.Brown); - BaseChain expected = new BaseChain(4); + BaseChain expected = new(4); expected[0] = gray; expected[1] = blue; expected[2] = red; expected[3] = brown; - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } } - diff --git a/Libiada.Core.Tests/Images/ZigzagOrderExtractorTests.cs b/Libiada.Core.Tests/Images/ZigzagOrderExtractorTests.cs index 8c5b6395..0ddd0099 100644 --- a/Libiada.Core.Tests/Images/ZigzagOrderExtractorTests.cs +++ b/Libiada.Core.Tests/Images/ZigzagOrderExtractorTests.cs @@ -14,7 +14,7 @@ public class ZigzagOrderExtractorTests [Test] public void ZigzagSimpleTest() { - Image image = new Image(2, 3); + Image image = new(2, 3); image[0, 0] = Color.Black; image[0, 1] = Color.White; image[0, 2] = Color.Black; @@ -22,12 +22,12 @@ public void ZigzagSimpleTest() image[1, 1] = Color.Black; image[1, 2] = Color.White; - BaseChain actual = ImageProcessor.ProcessImage(image, new IImageTransformer[0], new IMatrixTransformer[0], new ZigzagOrderExtractor()); + BaseChain actual = ImageProcessor.ProcessImage(image, [], [], new ZigzagOrderExtractor()); - ValuePixel black = new ValuePixel(Color.Black); - ValuePixel white = new ValuePixel(Color.White); + ValuePixel black = new(Color.Black); + ValuePixel white = new(Color.White); - BaseChain expected = new BaseChain(6); + BaseChain expected = new(6); expected[0] = black; expected[1] = white; @@ -36,85 +36,84 @@ public void ZigzagSimpleTest() expected[4] = black; expected[5] = white; - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } [Test] public void ZigzagSecondSimpleTest() { - Image image = new Image(2, 2); + Image image = new(2, 2); image[0, 0] = Color.Black; image[0, 1] = Color.Blue; image[1, 0] = Color.Red; image[1, 1] = Color.White; - BaseChain actual = ImageProcessor.ProcessImage(image, new IImageTransformer[0], new IMatrixTransformer[0], new ZigzagOrderExtractor()); + BaseChain actual = ImageProcessor.ProcessImage(image, [], [], new ZigzagOrderExtractor()); - ValuePixel black = new ValuePixel(Color.Black); - ValuePixel blue = new ValuePixel(Color.Blue); - ValuePixel red = new ValuePixel(Color.Red); - ValuePixel white = new ValuePixel(Color.White); + ValuePixel black = new(Color.Black); + ValuePixel blue = new(Color.Blue); + ValuePixel red = new(Color.Red); + ValuePixel white = new(Color.White); - BaseChain expected = new BaseChain(4); + BaseChain expected = new(4); expected[0] = black; expected[1] = blue; expected[2] = white; expected[3] = red; - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } [Test] public void ZigzagThirdSimpleTest() { - Image image = new Image(1, 4); + Image image = new(1, 4); image[0, 0] = Color.Black; image[0, 1] = Color.Blue; image[0, 2] = Color.Red; image[0, 3] = Color.White; - BaseChain actual = ImageProcessor.ProcessImage(image, new IImageTransformer[0], new IMatrixTransformer[0], new ZigzagOrderExtractor()); + BaseChain actual = ImageProcessor.ProcessImage(image, [], [], new ZigzagOrderExtractor()); - ValuePixel black = new ValuePixel(Color.Black); - ValuePixel blue = new ValuePixel(Color.Blue); - ValuePixel red = new ValuePixel(Color.Red); - ValuePixel white = new ValuePixel(Color.White); + ValuePixel black = new(Color.Black); + ValuePixel blue = new(Color.Blue); + ValuePixel red = new(Color.Red); + ValuePixel white = new(Color.White); - BaseChain expected = new BaseChain(4); + BaseChain expected = new(4); expected[0] = black; expected[1] = blue; expected[2] = red; expected[3] = white; - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } [Test] public void ZigzagFourthSimpleTest() { - Image image = new Image(4, 1); + Image image = new(4, 1); image[0, 0] = Color.Black; image[1, 0] = Color.Blue; image[2, 0] = Color.Red; image[3, 0] = Color.White; - BaseChain actual = ImageProcessor.ProcessImage(image, new IImageTransformer[0], new IMatrixTransformer[0], new ZigzagOrderExtractor()); + BaseChain actual = ImageProcessor.ProcessImage(image, [], [], new ZigzagOrderExtractor()); - ValuePixel black = new ValuePixel(Color.Black); - ValuePixel blue = new ValuePixel(Color.Blue); - ValuePixel red = new ValuePixel(Color.Red); - ValuePixel white = new ValuePixel(Color.White); + ValuePixel black = new(Color.Black); + ValuePixel blue = new(Color.Blue); + ValuePixel red = new(Color.Red); + ValuePixel white = new(Color.White); - BaseChain expected = new BaseChain(4); + BaseChain expected = new(4); expected[0] = black; expected[1] = blue; expected[2] = red; expected[3] = white; - Assert.AreEqual(expected, actual); - + Assert.That(actual, Is.EqualTo(expected)); } -} \ No newline at end of file +} diff --git a/Libiada.Core.Tests/Iterators/CustomIteratorTests.cs b/Libiada.Core.Tests/Iterators/CustomIteratorTests.cs index 9d274f19..3276dfd4 100644 --- a/Libiada.Core.Tests/Iterators/CustomIteratorTests.cs +++ b/Libiada.Core.Tests/Iterators/CustomIteratorTests.cs @@ -15,20 +15,20 @@ public class CustomIteratorTests [Test] public void CustomIteratorTest() { - var starts = new List> { new List { 0 }, new List { 3 }, new List { 5, 9 } }; - var lengthes = new List> { new List { 2 }, new List { 3 }, new List { 2, 1 } }; + List> starts = [[0], [3], [5, 9]]; + List> lengthes = [[2], [3], [2, 1]]; - var source = new Chain("abcdefghij"); + Chain source = new("abcdefghij"); - List expected = new List { new Chain("ab"), new Chain("def"), new Chain("fgj") }; + List expected = [new Chain("ab"), new Chain("def"), new Chain("fgj")]; - var iterator = new CustomIterator(source, starts, lengthes); + CustomIterator iterator = new(source, starts, lengthes); for (int i = 0; iterator.Next(); i++) { Chain result = (Chain)iterator.Current(); - Assert.AreEqual(expected[i], result); + Assert.That(result, Is.EqualTo(expected[i])); } } } diff --git a/Libiada.Core.Tests/Iterators/CutRuleWithFixedStartTests.cs b/Libiada.Core.Tests/Iterators/CutRuleWithFixedStartTests.cs index 4b8990c7..57995196 100644 --- a/Libiada.Core.Tests/Iterators/CutRuleWithFixedStartTests.cs +++ b/Libiada.Core.Tests/Iterators/CutRuleWithFixedStartTests.cs @@ -14,16 +14,19 @@ public class CutRuleWithFixedStartTests [Test] public void CutRuleTest() { - int length = 12; - int step = 3; + const int length = 12; + const int step = 3; var rule = new CutRuleWithFixedStart(length, step); CutRuleIterator iterator = rule.GetIterator(); for (int i = step; i <= length; i += step) { iterator.Next(); - Assert.AreEqual(0, iterator.GetStartPosition()); - Assert.AreEqual(i, iterator.GetEndPosition()); + Assert.Multiple(() => + { + Assert.That(iterator.GetStartPosition(), Is.EqualTo(0)); + Assert.That(iterator.GetEndPosition(), Is.EqualTo(i)); + }); } } } diff --git a/Libiada.Core.Tests/Iterators/CutRuleWithShiftedAndFixedStartTests.cs b/Libiada.Core.Tests/Iterators/CutRuleWithShiftedAndFixedStartTests.cs index 39ea3c16..16f10e78 100644 --- a/Libiada.Core.Tests/Iterators/CutRuleWithShiftedAndFixedStartTests.cs +++ b/Libiada.Core.Tests/Iterators/CutRuleWithShiftedAndFixedStartTests.cs @@ -21,8 +21,11 @@ public void CutRuleTest() for (int i = 8; i <= 17; i += 3) { iterator.Next(); - Assert.AreEqual(5, iterator.GetStartPosition()); - Assert.AreEqual(i, iterator.GetEndPosition()); + Assert.Multiple(() => + { + Assert.That(iterator.GetStartPosition(), Is.EqualTo(5)); + Assert.That(iterator.GetEndPosition(), Is.EqualTo(i)); + }); } } } diff --git a/Libiada.Core.Tests/Iterators/DiffCutterTests.cs b/Libiada.Core.Tests/Iterators/DiffCutterTests.cs index 65ab8cb2..071ba750 100644 --- a/Libiada.Core.Tests/Iterators/DiffCutterTests.cs +++ b/Libiada.Core.Tests/Iterators/DiffCutterTests.cs @@ -14,12 +14,12 @@ public class DiffCutterTests [Test] public void DiffTest() { - string source = "reegwvwvw"; + const string source = "reegwvwvw"; var rule = new CutRuleWithFixedStart(source.Length, 3); List cuts = DiffCutter.Cut(source, rule); - Assert.AreEqual("ree", cuts[0]); - Assert.AreEqual("reegwv", cuts[1]); - Assert.AreEqual("reegwvwvw", cuts[2]); + Assert.That(cuts[0], Is.EqualTo("ree")); + Assert.That(cuts[1], Is.EqualTo("reegwv")); + Assert.That(cuts[2], Is.EqualTo("reegwvwvw")); } } diff --git a/Libiada.Core.Tests/Iterators/IteratorEndTests.cs b/Libiada.Core.Tests/Iterators/IteratorEndTests.cs index 1fae90df..0037baf0 100644 --- a/Libiada.Core.Tests/Iterators/IteratorEndTests.cs +++ b/Libiada.Core.Tests/Iterators/IteratorEndTests.cs @@ -29,52 +29,52 @@ public void Initialization() [Test] public void ReadWindowModeTest() { - int length = 3; - int step = 1; + const int length = 3; + const int step = 1; var iterator = new IteratorEnd(chainToIterate, length, step); // 12 - 3 + 1 - var message2 = new List - { + List message2 = + [ // 121331212|231| - new Chain("231"), + new("231"), // 12133121|223|1 - new Chain("223"), + new("223"), // 1213312|122|31 - new Chain("122"), + new("122"), // 121331|212|231 - new Chain("212"), + new("212"), // 12133|121|2231 - new Chain("121"), + new("121"), // 1213|312|12231 - new Chain("312"), + new("312"), // 121|331|212231 - new Chain("331"), + new("331"), // 12|133|1212231 - new Chain("133"), + new("133"), // 1|213|31212231 - new Chain("213"), + new("213"), // |121|331212231 - new Chain("121") - }; + new("121") + ]; int i = 0; while (iterator.Next()) { var message1 = iterator.Current(); - Assert.AreEqual(message1, message2[i++]); + Assert.That(message2[i++], Is.EqualTo(message1)); } - Assert.AreEqual(--i, 9); + Assert.That(--i, Is.EqualTo(9)); } /// @@ -83,32 +83,32 @@ public void ReadWindowModeTest() [Test] public void ReadBlockModeTest() { - int length = 3; - int step = 3; + const int length = 3; + const int step = 3; var iterator = new IteratorEnd(chainToIterate, length, step); - var message2 = new List - { + List message2 = + [ // 121331212|231| - new Chain("231"), + new("231"), // 121331|212|231 - new Chain("212"), + new("212"), // 121|331|212231 - new Chain("331"), + new("331"), // |121|331212231 - new Chain("121") - }; + new("121") + ]; int i = 0; while (iterator.Next()) { var message1 = iterator.Current(); - Assert.AreEqual(message1, message2[i++]); + Assert.That(message2[i++], Is.EqualTo(message1)); } - Assert.AreEqual(--i, 3); + Assert.That(--i, Is.EqualTo(3)); } } diff --git a/Libiada.Core.Tests/Iterators/IteratorStartTests.cs b/Libiada.Core.Tests/Iterators/IteratorStartTests.cs index d97ec185..560b06f3 100644 --- a/Libiada.Core.Tests/Iterators/IteratorStartTests.cs +++ b/Libiada.Core.Tests/Iterators/IteratorStartTests.cs @@ -29,31 +29,31 @@ public void Initialization() [Test] public void ReadWindowModeTest() { - int length = 3; - int step = 1; - var iterator = new IteratorStart(chainToIterate, length, step); - var message2 = new List - { - new Chain("121"), - new Chain("213"), - new Chain("133"), - new Chain("331"), - new Chain("312"), - new Chain("121"), - new Chain("212"), - new Chain("122"), - new Chain("223"), - new Chain("231") - }; + const int length = 3; + const int step = 1; + IteratorStart iterator = new(chainToIterate, length, step); + List message2 = + [ + new("121"), + new("213"), + new("133"), + new("331"), + new("312"), + new("121"), + new("212"), + new("122"), + new("223"), + new("231") + ]; int i = 0; while (iterator.Next()) { - var message1 = iterator.Current(); - Assert.AreEqual(message1, message2[i++]); + AbstractChain message1 = iterator.Current(); + Assert.That(message2[i++], Is.EqualTo(message1)); } - Assert.AreEqual(--i, 9); + Assert.That(--i, Is.EqualTo(9)); } /// @@ -62,18 +62,18 @@ public void ReadWindowModeTest() [Test] public void ReadBlockModeTest() { - int length = 3; - int step = 3; - var iterator = new IteratorStart(chainToIterate, length, step); - var message2 = new List { new Chain("121"), new Chain("331"), new Chain("212"), new Chain("231") }; + const int length = 3; + const int step = 3; + IteratorStart iterator = new(chainToIterate, length, step); + List message2 = [new("121"), new("331"), new("212"), new("231")]; int i = 0; while (iterator.Next()) { - var message1 = iterator.Current(); - Assert.AreEqual(message1, message2[i++]); + AbstractChain message1 = iterator.Current(); + Assert.That(message2[i++], Is.EqualTo(message1)); } - Assert.AreEqual(--i, 3); + Assert.That(--i, Is.EqualTo(3)); } } diff --git a/Libiada.Core.Tests/Iterators/IteratorWritableEndTests.cs b/Libiada.Core.Tests/Iterators/IteratorWritableEndTests.cs index 55fa0ac4..0989913c 100644 --- a/Libiada.Core.Tests/Iterators/IteratorWritableEndTests.cs +++ b/Libiada.Core.Tests/Iterators/IteratorWritableEndTests.cs @@ -30,7 +30,7 @@ public void Initialization() [Test] public void WriteTest() { - var messages = new List { '1', '3', '2', '2', '1', '2', '1', '3', '3', '1', '2', '1' }; + List messages = ['1', '3', '2', '2', '1', '2', '1', '3', '3', '1', '2', '1']; var toWrite = new Chain(12); var iteratorWrite = new IteratorWritableEnd(toWrite); @@ -40,6 +40,6 @@ public void WriteTest() iteratorWrite.WriteValue(messages[i++]); } - Assert.AreEqual(chainToIterate, toWrite); + Assert.That(toWrite, Is.EqualTo(chainToIterate)); } } diff --git a/Libiada.Core.Tests/Iterators/IteratorWritableStartTests.cs b/Libiada.Core.Tests/Iterators/IteratorWritableStartTests.cs index 65f294ce..0c413515 100644 --- a/Libiada.Core.Tests/Iterators/IteratorWritableStartTests.cs +++ b/Libiada.Core.Tests/Iterators/IteratorWritableStartTests.cs @@ -30,21 +30,8 @@ public void Initialization() [Test] public void WriteTest() { - var messages = new List(12) - { - new ValueString('1'), - new ValueString('2'), - new ValueString('1'), - new ValueString('3'), - new ValueString('3'), - new ValueString('1'), - new ValueString('2'), - new ValueString('1'), - new ValueString('2'), - new ValueString('2'), - new ValueString('3'), - new ValueString('1') - }; + List messages = + ['1', '2', '1', '3', '3', '1', '2', '1', '2', '2', '3', '1']; var toWrite = new Chain(12); var iteratorWrite = new IteratorWritableStart(toWrite); @@ -54,6 +41,6 @@ public void WriteTest() iteratorWrite.WriteValue(messages[i++]); } - Assert.AreEqual(chainToIterate, toWrite); + Assert.That(toWrite, Is.EqualTo(chainToIterate)); } } diff --git a/Libiada.Core.Tests/Iterators/SimpleCutRuleTests.cs b/Libiada.Core.Tests/Iterators/SimpleCutRuleTests.cs index dc5a7285..495e8a5f 100644 --- a/Libiada.Core.Tests/Iterators/SimpleCutRuleTests.cs +++ b/Libiada.Core.Tests/Iterators/SimpleCutRuleTests.cs @@ -14,14 +14,17 @@ public class SimpleCutRuleTests [Test] public void CutRuleTest() { - var rule = new SimpleCutRule(100, 3, 3); + SimpleCutRule rule = new(100, 3, 3); CutRuleIterator iterator = rule.GetIterator(); for (int i = 0; i <= 12; i += 3) { iterator.Next(); - Assert.AreEqual(i, iterator.GetStartPosition()); - Assert.AreEqual(i + 3, iterator.GetEndPosition()); + Assert.Multiple(() => + { + Assert.That(iterator.GetStartPosition(), Is.EqualTo(i)); + Assert.That(iterator.GetEndPosition(), Is.EqualTo(i + 3)); + }); } } } diff --git a/Libiada.Core.Tests/Iterators/SimpleCutRuleWithShiftedStartTests.cs b/Libiada.Core.Tests/Iterators/SimpleCutRuleWithShiftedStartTests.cs index 68ad074f..635e406a 100644 --- a/Libiada.Core.Tests/Iterators/SimpleCutRuleWithShiftedStartTests.cs +++ b/Libiada.Core.Tests/Iterators/SimpleCutRuleWithShiftedStartTests.cs @@ -14,14 +14,17 @@ public class SimpleCutRuleWithShiftedStartTests [Test] public void CutRuleTest() { - var rule = new SimpleCutRuleWithShiftedStart(18, 3, 5, 5); + SimpleCutRuleWithShiftedStart rule = new(18, 3, 5, 5); CutRuleIterator iterator = rule.GetIterator(); for (int i = 5; i <= 11; i += 3) { iterator.Next(); - Assert.AreEqual(i, iterator.GetStartPosition()); - Assert.AreEqual(i + 5, iterator.GetEndPosition()); + Assert.Multiple(() => + { + Assert.That(iterator.GetStartPosition(), Is.EqualTo(i)); + Assert.That(iterator.GetEndPosition(), Is.EqualTo(i + 5)); + }); } } } diff --git a/Libiada.Core.Tests/Libiada.Core.Tests.csproj b/Libiada.Core.Tests/Libiada.Core.Tests.csproj index 1a8fb71d..b871bc2d 100644 --- a/Libiada.Core.Tests/Libiada.Core.Tests.csproj +++ b/Libiada.Core.Tests/Libiada.Core.Tests.csproj @@ -19,9 +19,13 @@ - - - + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/Libiada.Core.Tests/Music/FmotifDividerTests.cs b/Libiada.Core.Tests/Music/FmotifDividerTests.cs index 0a93db50..f099fe7f 100644 --- a/Libiada.Core.Tests/Music/FmotifDividerTests.cs +++ b/Libiada.Core.Tests/Music/FmotifDividerTests.cs @@ -19,34 +19,34 @@ public class FmotifDividerTests public void FmotifDividerFirstTest() { // создание и заполнения списка(ов) нот для такта(ов) монотрека - var notes = new List - { - new ValueNote(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 4, false), false, Tie.None, 0), - new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 4, false), false, Tie.None, 1), - new ValueNote(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 4, false), false, Tie.None, 0), - new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 4, false), false, Tie.None, 1) - }; + List notes = + [ + new(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 4, false), false, Tie.None, 0), + new(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 4, false), false, Tie.None, 1), + new(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 4, false), false, Tie.None, 0), + new(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 4, false), false, Tie.None, 1) + ]; // создание атрибутов для такта(ов) - var attributes = new MeasureAttributes(new Size(2, 4), new Key(0, "major")); + MeasureAttributes attributes = new(new Size(2, 4), new Key(0, "major")); // создание и заполнение такта(ов) списками нот и атрибутами - var measures = new List { new Measure(notes, (MeasureAttributes)attributes.Clone()) }; + List measures = [new(notes, (MeasureAttributes)attributes.Clone())]; // создание моно трека - var unitrack = new CongenericScoreTrack(measures); + CongenericScoreTrack unitrack = new(measures); // создание объекта для деления монотрека на фмотивы - var fmdivider = new FmotifDivider(); + FmotifDivider fmdivider = new(); // создание результирующей цепочки фмотивов // вычисление, опрделение, разбиение на ф-мотивы данного монотрека - var chain = fmdivider.GetDivision(unitrack, PauseTreatment.Ignore); + FmotifChain chain = fmdivider.GetDivision(unitrack, PauseTreatment.Ignore); // создание аналогов ф-мотивов, которые должны получиться, после разбиения // процедура определения одинаковых на данном этапе не производится - var fmotif1 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); - var fmotif2 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 1); + Fmotif fmotif1 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); + Fmotif fmotif2 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 1); fmotif1.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 4, false), false, Tie.None)); fmotif1.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 4, false), false, Tie.None)); @@ -55,11 +55,11 @@ public void FmotifDividerFirstTest() fmotif2.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 4, false), false, Tie.None)); // записываем ф-мотивы в цепь ф-мотивов, которая будет сравниваться с получившейся - var secondChain = new FmotifChain(); + FmotifChain secondChain = new(); secondChain.FmotifsList.Add(fmotif1); secondChain.FmotifsList.Add(fmotif2); - Assert.IsTrue(secondChain.Equals(chain)); + Assert.That(secondChain, Is.EqualTo(chain)); } /// @@ -69,25 +69,25 @@ public void FmotifDividerFirstTest() public void FmotifDividerSecondTest() { // создание и заполнения списка(ов) нот для такта(ов) монотрека - var notes = new List - { - new ValueNote(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 8, false), false, Tie.None, 0), - new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 8, false), false, Tie.None, 2), - new ValueNote(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 8, false), false, Tie.None, 1), - new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 8, false), false, Tie.None, 2) - }; + List notes = + [ + new(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 8, false), false, Tie.None, 0), + new(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 8, false), false, Tie.None, 2), + new(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 8, false), false, Tie.None, 1), + new(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 8, false), false, Tie.None, 2) + ]; // создание атрибутов для такта(ов) - var attributes = new MeasureAttributes(new Size(2, 4), new Key(0, "major")); + MeasureAttributes attributes = new(new Size(2, 4), new Key(0, "major")); // создание и заполнение такта(ов) списками нот и атрибутами - var measures = new List { new Measure(notes, (MeasureAttributes)attributes.Clone()) }; + List measures = [new(notes, (MeasureAttributes)attributes.Clone())]; // создание моно трека - var unitrack = new CongenericScoreTrack(measures); + CongenericScoreTrack unitrack = new(measures); // создание объекта для деления монотрека на фмотивы - var fmdivider = new FmotifDivider(); + FmotifDivider fmdivider = new(); // создание результирующей цепочки фмотивов // вычисление, опрделение, разбиение на ф-мотивы данного монотрека @@ -95,8 +95,8 @@ public void FmotifDividerSecondTest() // создание аналогов ф-мотивов, которые должны получиться, после разбиения // процедура определения одинаковых на данном этапе не производится - var fmotif1 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); - var fmotif2 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 1); + Fmotif fmotif1 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); + Fmotif fmotif2 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 1); fmotif1.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 8, false), false, Tie.None)); fmotif1.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 8, false), false, Tie.None)); @@ -105,11 +105,11 @@ public void FmotifDividerSecondTest() fmotif2.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 8, false), false, Tie.None)); // записываем ф-мотивы в цепь ф-мотивов, которая будет сравниваться с получившейся - var fmchain1 = new FmotifChain(); + FmotifChain fmchain1 = new(); fmchain1.FmotifsList.Add(fmotif1); fmchain1.FmotifsList.Add(fmotif2); - Assert.IsTrue(fmchain1.Equals(fmchain)); + Assert.That(fmchain1, Is.EqualTo(fmchain)); } /// @@ -119,44 +119,44 @@ public void FmotifDividerSecondTest() public void TestFmotifThirdDivider() { // создание и заполнения списка(ов) нот для такта(ов) монотрека - var notes = new List - { - new ValueNote(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 4, false), false, Tie.None, 0), - new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 8, false), false, Tie.None, 1), - new ValueNote(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 8, false), false, Tie.None, 2) - }; - - var notes1 = new List - { - new ValueNote(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 4, false), false, Tie.None, 0), - new ValueNote(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 4, false), false, Tie.None, 1) - }; + List notes = + [ + new(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 4, false), false, Tie.None, 0), + new(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 8, false), false, Tie.None, 1), + new(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 8, false), false, Tie.None, 2) + ]; + + List notes1 = + [ + new(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 4, false), false, Tie.None, 0), + new(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 4, false), false, Tie.None, 1) + ]; // создание атрибутов для такта(ов) - var attributes = new MeasureAttributes(new Size(2, 4), new Key(0, "major")); + MeasureAttributes attributes = new(new Size(2, 4), new Key(0, "major")); // создание и заполнение такта(ов) списками нот и атрибутами - var measures = new List - { - new Measure(notes, (MeasureAttributes)attributes.Clone()), - new Measure(notes1, (MeasureAttributes)attributes.Clone()) - }; + List measures = + [ + new(notes, (MeasureAttributes)attributes.Clone()), + new(notes1, (MeasureAttributes)attributes.Clone()) + ]; // создание моно трека - var unitrack = new CongenericScoreTrack(measures); + CongenericScoreTrack unitrack = new(measures); // создание объекта для деления монотрека на фмотивы - var fmdivider = new FmotifDivider(); + FmotifDivider fmdivider = new(); // создание результирующей цепочки фмотивов // вычисление, опрделение, разбиение на ф-мотивы данного монотрека - var fmchain = fmdivider.GetDivision(unitrack, PauseTreatment.Ignore); + FmotifChain fmchain = fmdivider.GetDivision(unitrack, PauseTreatment.Ignore); // создание аналогов ф-мотивов, которые должны получиться, после разбиения // процедура определения одинаковых на данном этапе не производится - var fmotif1 = new Fmotif(FmotifType.PartialMinimalMeasure, PauseTreatment.Ignore, 0); - var fmotif2 = new Fmotif(FmotifType.CompleteMinimalMetrorhythmicGroup, PauseTreatment.Ignore, 1); - var fmotif3 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 3); + Fmotif fmotif1 = new(FmotifType.PartialMinimalMeasure, PauseTreatment.Ignore, 0); + Fmotif fmotif2 = new(FmotifType.CompleteMinimalMetrorhythmicGroup, PauseTreatment.Ignore, 1); + Fmotif fmotif3 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 3); fmotif1.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 4, false), false, Tie.None)); @@ -167,12 +167,12 @@ public void TestFmotifThirdDivider() fmotif3.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 4, false), false, Tie.None)); // записываем ф-мотивы в цепь ф-мотивов, которая будет сравниваться с получившейся - var fmchain1 = new FmotifChain(); + FmotifChain fmchain1 = new(); fmchain1.FmotifsList.Add(fmotif1); fmchain1.FmotifsList.Add(fmotif2); fmchain1.FmotifsList.Add(fmotif3); - Assert.IsTrue(fmchain1.Equals(fmchain)); + Assert.That(fmchain1, Is.EqualTo(fmchain)); } /// @@ -182,42 +182,42 @@ public void TestFmotifThirdDivider() public void FmotifDividerFourthTest() { // создание и заполнения списка(ов) нот для такта(ов) монотрека - var notes = new List - { - new ValueNote(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 8, false), false, Tie.Start, 0), - new ValueNote(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 8, false), false, Tie.End, 2), - new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 4, false), false, Tie.None, 1) - }; + List notes = + [ + new(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 8, false), false, Tie.Start, 0), + new(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 8, false), false, Tie.End, 2), + new(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 4, false), false, Tie.None, 1) + ]; // создание атрибутов для такта(ов) - var attributes = new MeasureAttributes(new Size(2, 4), new Key(0, "major")); + MeasureAttributes attributes = new(new Size(2, 4), new Key(0, "major")); // создание и заполнение такта(ов) списками нот и атрибутами - var measures = new List { new Measure(notes, (MeasureAttributes)attributes.Clone()) }; + List measures = [new(notes, (MeasureAttributes)attributes.Clone())]; // создание моно трека - var unitrack = new CongenericScoreTrack(measures); + CongenericScoreTrack unitrack = new(measures); // создание объекта для деления монотрека на фмотивы - var fmdivider = new FmotifDivider(); + FmotifDivider fmdivider = new(); // создание результирующей цепочки фмотивов // вычисление, опрделение, разбиение на ф-мотивы данного монотрека - var fmchain = fmdivider.GetDivision(unitrack, PauseTreatment.Ignore); + FmotifChain fmchain = fmdivider.GetDivision(unitrack, PauseTreatment.Ignore); // создание аналогов ф-мотивов, которые должны получиться, после разбиения // процедура определения одинаковых на данном этапе не производится - var fmotif1 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); + Fmotif fmotif1 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); fmotif1.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 8, false), false, Tie.Start)); fmotif1.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 8, false), false, Tie.End)); fmotif1.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 4, false), false, Tie.None)); // записываем ф-мотивы в цепь ф-мотивов, которая будет сравниваться с получившейся - var fmchain1 = new FmotifChain(); + FmotifChain fmchain1 = new(); fmchain1.FmotifsList.Add(fmotif1); - Assert.IsTrue(fmchain1.Equals(fmchain)); + Assert.That(fmchain1, Is.EqualTo(fmchain)); } /// @@ -227,35 +227,35 @@ public void FmotifDividerFourthTest() public void FmotifDividerFifthTest() { // создание и заполнения списка(ов) нот для такта(ов) монотрека - var notes = new List - { - new ValueNote(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 8, 2, 3, false), false, Tie.None, 0), - new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 8, 2, 3, false), false, Tie.None, 1), - new ValueNote(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 8, 2, 3, false), false, Tie.None, 1), - new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 8, false), false, Tie.None, 0), - new ValueNote(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 8, false), false, Tie.None, 1) - }; + List notes = + [ + new(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 8, 2, 3, false), false, Tie.None, 0), + new(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 8, 2, 3, false), false, Tie.None, 1), + new(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 8, 2, 3, false), false, Tie.None, 1), + new(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 8, false), false, Tie.None, 0), + new(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 8, false), false, Tie.None, 1) + ]; // создание атрибутов для такта(ов) - var attributes = new MeasureAttributes(new Size(2, 4), new Key(0, "major")); + MeasureAttributes attributes = new(new Size(2, 4), new Key(0, "major")); // создание и заполнение такта(ов) списками нот и атрибутами - var measures = new List { new Measure(notes, (MeasureAttributes)attributes.Clone()) }; + List measures = [new(notes, (MeasureAttributes)attributes.Clone())]; // создание моно трека - var unitrack = new CongenericScoreTrack(measures); + CongenericScoreTrack unitrack = new(measures); // создание объекта для деления монотрека на фмотивы - var fmdivider = new FmotifDivider(); + FmotifDivider fmdivider = new(); // создание результирующей цепочки фмотивов // вычисление, опрделение, разбиение на ф-мотивы данного монотрека - var fmchain = fmdivider.GetDivision(unitrack, PauseTreatment.Ignore); + FmotifChain fmchain = fmdivider.GetDivision(unitrack, PauseTreatment.Ignore); // создание аналогов ф-мотивов, которые должны получиться, после разбиения // процедура определения одинаковых на данном этапе не производится - var fmotif1 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); - var fmotif2 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 1); + Fmotif fmotif1 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); + Fmotif fmotif2 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 1); fmotif1.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 8, 2, 3, false), false, Tie.None)); fmotif1.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 8, 2, 3, false), false, Tie.None)); @@ -265,11 +265,11 @@ public void FmotifDividerFifthTest() fmotif2.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 8, false), false, Tie.None)); // записываем ф-мотивы в цепь ф-мотивов, которая будет сравниваться с получившейся - var fmchain1 = new FmotifChain(); + FmotifChain fmchain1 = new(); fmchain1.FmotifsList.Add(fmotif1); fmchain1.FmotifsList.Add(fmotif2); - Assert.IsTrue(fmchain1.Equals(fmchain)); + Assert.That(fmchain1, Is.EqualTo(fmchain)); } /// @@ -279,36 +279,36 @@ public void FmotifDividerFifthTest() public void FmotifDividerSixthTest() { // создание и заполнения списка(ов) нот для такта(ов) монотрека - var notes = new List - { - new ValueNote(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), - new ValueNote(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 16, false), false, Tie.None, 1), - new ValueNote(new Pitch(3, NoteSymbol.A, Accidental.Flat), new Duration(1, 16, false), false, Tie.None, 3), - new ValueNote(new Pitch(3, NoteSymbol.D, Accidental.Bekar), new Duration(1, 16, false), false, Tie.None, 2), - new ValueNote(new Pitch(3, NoteSymbol.A, Accidental.DoubleSharp), new Duration(1, 16, false), false, Tie.None, 3) - }; + List notes = + [ + new(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None, 0), + new(new Pitch(3, NoteSymbol.C, Accidental.Sharp), new Duration(1, 16, false), false, Tie.None, 1), + new(new Pitch(3, NoteSymbol.A, Accidental.Flat), new Duration(1, 16, false), false, Tie.None, 3), + new(new Pitch(3, NoteSymbol.D, Accidental.Bekar), new Duration(1, 16, false), false, Tie.None, 2), + new(new Pitch(3, NoteSymbol.A, Accidental.DoubleSharp), new Duration(1, 16, false), false, Tie.None, 3) + ]; // создание атрибутов для такта(ов) - var attributes = new MeasureAttributes(new Size(2, 4), new Key(0, "major")); + MeasureAttributes attributes = new(new Size(2, 4), new Key(0, "major")); // создание и заполнение такта(ов) списками нот и атрибутами - var measures = new List { new Measure(notes, (MeasureAttributes)attributes.Clone()) }; + List measures = [new(notes, (MeasureAttributes)attributes.Clone())]; // создание моно трека - var unitrack = new CongenericScoreTrack(measures); + CongenericScoreTrack unitrack = new(measures); // создание объекта для деления монотрека на фмотивы - var fmdivider = new FmotifDivider(); + FmotifDivider fmdivider = new(); // создание результирующей цепочки фмотивов // вычисление, опрделение, разбиение на ф-мотивы данного монотрека - var fmchain = fmdivider.GetDivision(unitrack, PauseTreatment.Ignore); + FmotifChain fmchain = fmdivider.GetDivision(unitrack, PauseTreatment.Ignore); // создание аналогов ф-мотивов, которые должны получиться, после разбиения // процедура определения одинаковых на данном этапе не производится - var fmotif1 = new Fmotif(FmotifType.PartialMinimalMeasure, PauseTreatment.Ignore, 0); - var fmotif2 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 1); - var fmotif3 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 2); + Fmotif fmotif1 = new(FmotifType.PartialMinimalMeasure, PauseTreatment.Ignore, 0); + Fmotif fmotif2 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 1); + Fmotif fmotif3 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 2); fmotif1.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.E, Accidental.Bekar), new Duration(1, 4, false), false, Tie.None)); @@ -319,12 +319,12 @@ public void FmotifDividerSixthTest() fmotif3.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.A, Accidental.DoubleSharp), new Duration(1, 16, false), false, Tie.None)); // записываем ф-мотивы в цепь ф-мотивов, которая будет сравниваться с получившейся - var fmchain1 = new FmotifChain(); + FmotifChain fmchain1 = new(); fmchain1.FmotifsList.Add(fmotif1); fmchain1.FmotifsList.Add(fmotif2); fmchain1.FmotifsList.Add(fmotif3); - Assert.IsTrue(fmchain1.Equals(fmchain)); + Assert.That(fmchain1, Is.EqualTo(fmchain)); } /// @@ -334,24 +334,24 @@ public void FmotifDividerSixthTest() public void FmotifDividerSeventhTest() { // создание и заполнения списка(ов) нот для такта(ов) монотрека - var notes = new List - { - new ValueNote(new Duration(1, 4, false), false, Tie.None, 0), - new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 8, false), false, Tie.None, 1), - new ValueNote(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 8, false), false, Tie.None, 2) - }; + List notes = + [ + new(new Duration(1, 4, false), false, Tie.None, 0), + new(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 8, false), false, Tie.None, 1), + new(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 8, false), false, Tie.None, 2) + ]; // создание атрибутов для такта(ов) - var attributes = new MeasureAttributes(new Size(2, 4), new Key(0, "major")); + MeasureAttributes attributes = new(new Size(2, 4), new Key(0, "major")); // создание и заполнение такта(ов) списками нот и атрибутами - var measures = new List { new Measure(notes, (MeasureAttributes)attributes.Clone()) }; + List measures = [new(notes, (MeasureAttributes)attributes.Clone())]; // создание моно трека - var unitrack = new CongenericScoreTrack(measures); + CongenericScoreTrack unitrack = new(measures); // создание объекта для деления монотрека на фмотивы - var fmdivider = new FmotifDivider(); + FmotifDivider fmdivider = new(); // создание результирующей цепочки фмотивов // вычисление, опрделение, разбиение на ф-мотивы данного монотрека @@ -359,16 +359,16 @@ public void FmotifDividerSeventhTest() // создание аналогов ф-мотивов, которые должны получиться, после разбиения // процедура определения одинаковых на данном этапе не производится - var fmotif1 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); + Fmotif fmotif1 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); fmotif1.NoteList.Add(new ValueNote(new Duration(1, 4, false), false, Tie.None)); fmotif1.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 8, false), false, Tie.None)); fmotif1.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 8, false), false, Tie.None)); // записываем ф-мотивы в цепь ф-мотивов, которая будет сравниваться с получившейся - var fmchain1 = new FmotifChain(); + FmotifChain fmchain1 = new(); fmchain1.FmotifsList.Add(fmotif1); - Assert.IsTrue(fmchain1.Equals(fmchain)); + Assert.That(fmchain1, Is.EqualTo(fmchain)); } /// @@ -378,25 +378,25 @@ public void FmotifDividerSeventhTest() public void FmotifDividerEighthTest() { // создание и заполнения списка(ов) нот для такта(ов) монотрека - var notes = new List - { - new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 8, false), false, Tie.None, 0), - new ValueNote(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 8, false), false, Tie.None, 2), - new ValueNote(new Duration(1, 8, false), false, Tie.None, 1), - new ValueNote(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 8, false), false, Tie.None, 2) - }; + List notes = + [ + new(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 8, false), false, Tie.None, 0), + new(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 8, false), false, Tie.None, 2), + new(new Duration(1, 8, false), false, Tie.None, 1), + new(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 8, false), false, Tie.None, 2) + ]; // создание атрибутов для такта(ов) - var attributes = new MeasureAttributes(new Size(2, 4), new Key(0, "major")); + MeasureAttributes attributes = new(new Size(2, 4), new Key(0, "major")); // создание и заполнение такта(ов) списками нот и атрибутами - var measures = new List { new Measure(notes, (MeasureAttributes)attributes.Clone()) }; + List measures = [new(notes, (MeasureAttributes)attributes.Clone())]; // создание моно трека - var unitrack = new CongenericScoreTrack(measures); + CongenericScoreTrack unitrack = new(measures); // создание объекта для деления монотрека на фмотивы - var fmdivider = new FmotifDivider(); + FmotifDivider fmdivider = new(); // создание результирующей цепочки фмотивов // вычисление, опрделение, разбиение на ф-мотивы данного монотрека @@ -404,17 +404,17 @@ public void FmotifDividerEighthTest() // создание аналогов ф-мотивов, которые должны получиться, после разбиения // процедура определения одинаковых на данном этапе не производится - var fmotif1 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); + Fmotif fmotif1 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); fmotif1.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 8, false), false, Tie.None)); fmotif1.NoteList.Add(new ValueNote(new Duration(1, 8, false), false, Tie.None)); fmotif1.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 8, false), false, Tie.None)); fmotif1.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 8, false), false, Tie.None)); // записываем ф-мотивы в цепь ф-мотивов, которая будет сравниваться с получившейся - var fmchain1 = new FmotifChain(); + FmotifChain fmchain1 = new(); fmchain1.FmotifsList.Add(fmotif1); - Assert.IsTrue(fmchain1.Equals(fmchain)); + Assert.That(fmchain1, Is.EqualTo(fmchain)); } /// @@ -424,25 +424,25 @@ public void FmotifDividerEighthTest() public void FmotifDividerPauseSilenceTest() { // создание и заполнения списка(ов) нот для такта(ов) монотрека - var notes = new List - { - new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 8, false), false, Tie.None, 0), - new ValueNote(new Duration(1, 8, false), false, Tie.None, 2), - new ValueNote(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 8, false), false, Tie.None, 1), - new ValueNote(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 8, false), false, Tie.None, 2) - }; + List notes = + [ + new(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 8, false), false, Tie.None, 0), + new(new Duration(1, 8, false), false, Tie.None, 2), + new(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 8, false), false, Tie.None, 1), + new(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 8, false), false, Tie.None, 2) + ]; // создание атрибутов для такта(ов) - var attributes = new MeasureAttributes(new Size(2, 4), new Key(0, "major")); + MeasureAttributes attributes = new(new Size(2, 4), new Key(0, "major")); // создание и заполнение такта(ов) списками нот и атрибутами - var measures = new List { new Measure(notes, (MeasureAttributes)attributes.Clone()) }; + List measures = [new(notes, (MeasureAttributes)attributes.Clone())]; // создание моно трека - var unitrack = new CongenericScoreTrack(measures); + CongenericScoreTrack unitrack = new(measures); // создание объекта для деления монотрека на фмотивы - var fmdivider = new FmotifDivider(); + FmotifDivider fmdivider = new(); // создание результирующей цепочки фмотивов // вычисление, опрделение, разбиение на ф-мотивы данного монотрека @@ -450,22 +450,22 @@ public void FmotifDividerPauseSilenceTest() // создание аналогов ф-мотивов, которые должны получиться, после разбиения // процедура определения одинаковых на данном этапе не производится - var fmotif1 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); + Fmotif fmotif1 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); fmotif1.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 8, false), false, Tie.None)); fmotif1.NoteList.Add(new ValueNote(new Duration(1, 8, false), false, Tie.None)); - var fmotif2 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 1); + Fmotif fmotif2 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 1); fmotif2.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 8, false), false, Tie.None)); fmotif2.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 8, false), false, Tie.None)); // записываем ф-мотивы в цепь ф-мотивов, которая будет сравниваться с получившейся - var fmchain1 = new FmotifChain(); + FmotifChain fmchain1 = new(); fmchain1.FmotifsList.Add(fmotif1); fmchain1.FmotifsList.Add(fmotif2); - Assert.IsTrue(fmotif1.FmEquals(fmotif1, PauseTreatment.SilenceNote, true)); - Assert.IsTrue(fmotif2.FmEquals(fmotif2, PauseTreatment.SilenceNote, true)); - Assert.IsTrue(fmchain.FmotifsList[0].FmEquals(fmotif1, PauseTreatment.SilenceNote, true)); - Assert.IsTrue(fmchain.FmotifsList[1].FmEquals(fmotif2, PauseTreatment.SilenceNote, true)); - Assert.IsTrue(fmchain1.Equals(fmchain)); + Assert.That(fmotif1.FmEquals(fmotif1, PauseTreatment.SilenceNote, true)); + Assert.That(fmotif2.FmEquals(fmotif2, PauseTreatment.SilenceNote, true)); + Assert.That(fmchain.FmotifsList[0].FmEquals(fmotif1, PauseTreatment.SilenceNote, true)); + Assert.That(fmchain.FmotifsList[1].FmEquals(fmotif2, PauseTreatment.SilenceNote, true)); + Assert.That(fmchain1, Is.EqualTo(fmchain)); } } diff --git a/Libiada.Core.Tests/Music/FmotifIdentifierTests.cs b/Libiada.Core.Tests/Music/FmotifIdentifierTests.cs index b550b364..66e76eab 100644 --- a/Libiada.Core.Tests/Music/FmotifIdentifierTests.cs +++ b/Libiada.Core.Tests/Music/FmotifIdentifierTests.cs @@ -52,12 +52,12 @@ public void FmotifIdentificationFirstTest() fmchain1.FmotifsList.Add(fmotif6); var fmid = new FmotifIdentifier(); - Assert.AreEqual(0, fmid.GetIdentification(fmchain1, true).FmotifsList[0].Id); - Assert.AreEqual(1, fmid.GetIdentification(fmchain1, true).FmotifsList[1].Id); - Assert.AreEqual(1, fmid.GetIdentification(fmchain1, true).FmotifsList[2].Id); - Assert.AreEqual(1, fmid.GetIdentification(fmchain1, true).FmotifsList[3].Id); - Assert.AreEqual(0, fmid.GetIdentification(fmchain1, true).FmotifsList[4].Id); - Assert.AreEqual(0, fmid.GetIdentification(fmchain1, true).FmotifsList[5].Id); + Assert.That(fmid.GetIdentification(fmchain1, true).FmotifsList[0].Id, Is.EqualTo(0)); + Assert.That(fmid.GetIdentification(fmchain1, true).FmotifsList[1].Id, Is.EqualTo(1)); + Assert.That(fmid.GetIdentification(fmchain1, true).FmotifsList[2].Id, Is.EqualTo(1)); + Assert.That(fmid.GetIdentification(fmchain1, true).FmotifsList[3].Id, Is.EqualTo(1)); + Assert.That(fmid.GetIdentification(fmchain1, true).FmotifsList[4].Id, Is.EqualTo(0)); + Assert.That(fmid.GetIdentification(fmchain1, true).FmotifsList[5].Id, Is.EqualTo(0)); } /// @@ -103,11 +103,11 @@ public void FmotifIdentificationSecondTest() var fmid = new FmotifIdentifier(); - Assert.AreEqual(0, fmid.GetIdentification(fmchain1, true).FmotifsList[0].Id); - Assert.AreEqual(0, fmid.GetIdentification(fmchain1, true).FmotifsList[1].Id); - Assert.AreEqual(0, fmid.GetIdentification(fmchain1, true).FmotifsList[2].Id); - Assert.AreEqual(1, fmid.GetIdentification(fmchain1, true).FmotifsList[3].Id); - Assert.AreEqual(2, fmid.GetIdentification(fmchain1, true).FmotifsList[4].Id); - Assert.AreEqual(3, fmid.GetIdentification(fmchain1, true).FmotifsList[5].Id); + Assert.That(fmid.GetIdentification(fmchain1, true).FmotifsList[0].Id, Is.EqualTo(0)); + Assert.That(fmid.GetIdentification(fmchain1, true).FmotifsList[1].Id, Is.EqualTo(0)); + Assert.That(fmid.GetIdentification(fmchain1, true).FmotifsList[2].Id, Is.EqualTo(0)); + Assert.That(fmid.GetIdentification(fmchain1, true).FmotifsList[3].Id, Is.EqualTo(1)); + Assert.That(fmid.GetIdentification(fmchain1, true).FmotifsList[4].Id, Is.EqualTo(2)); + Assert.That(fmid.GetIdentification(fmchain1, true).FmotifsList[5].Id, Is.EqualTo(3)); } } diff --git a/Libiada.Core.Tests/Music/MidiNumberManagerTests.cs b/Libiada.Core.Tests/Music/MidiNumberManagerTests.cs index 1f6153e3..836f25cd 100644 --- a/Libiada.Core.Tests/Music/MidiNumberManagerTests.cs +++ b/Libiada.Core.Tests/Music/MidiNumberManagerTests.cs @@ -15,13 +15,13 @@ public class MidiNumberManagerTests [Test] public void GetOctaveFromMidiNumberTest() { - var initialPitch = new Pitch(1, NoteSymbol.A, 0); + Pitch initialPitch = new(1, NoteSymbol.A, 0); var octave = MidiNumberManager.GetOctaveFromMidiNumber(initialPitch.MidiNumber); - Assert.AreEqual(initialPitch.Octave, octave); + Assert.That(octave, Is.EqualTo(initialPitch.Octave)); initialPitch = new Pitch(5, NoteSymbol.C, Accidental.Sharp); octave = MidiNumberManager.GetOctaveFromMidiNumber(initialPitch.MidiNumber); - Assert.AreEqual(initialPitch.Octave, octave); + Assert.That(octave, Is.EqualTo(initialPitch.Octave)); } /// @@ -30,13 +30,13 @@ public void GetOctaveFromMidiNumberTest() [Test] public void GetNoteSymbolFromMidiNumberTest() { - var initialPitch = new Pitch(1, NoteSymbol.A, Accidental.Bekar); + Pitch initialPitch = new(1, NoteSymbol.A, Accidental.Bekar); var step = MidiNumberManager.GetNoteSymbolFromMidiNumber(initialPitch.MidiNumber); - Assert.AreEqual(initialPitch.Step, step); + Assert.That(step, Is.EqualTo(initialPitch.Step)); initialPitch = new Pitch(5, NoteSymbol.C, Accidental.Sharp); step = MidiNumberManager.GetNoteSymbolFromMidiNumber(initialPitch.MidiNumber); - Assert.AreEqual(initialPitch.Step, step); + Assert.That(step, Is.EqualTo(initialPitch.Step)); } /// @@ -45,12 +45,12 @@ public void GetNoteSymbolFromMidiNumberTest() [Test] public void GetAlterFromMidiNumberTest() { - var initialPitch = new Pitch(1, NoteSymbol.A, Accidental.Bekar); + Pitch initialPitch = new(1, NoteSymbol.A, Accidental.Bekar); var alter = MidiNumberManager.GetAlterFromMidiNumber(initialPitch.MidiNumber); - Assert.AreEqual(initialPitch.Alter, alter); + Assert.That(alter, Is.EqualTo(initialPitch.Alter)); initialPitch = new Pitch(5, NoteSymbol.C, Accidental.Sharp); alter = MidiNumberManager.GetAlterFromMidiNumber(initialPitch.MidiNumber); - Assert.AreEqual(initialPitch.Alter, alter); + Assert.That(alter, Is.EqualTo(initialPitch.Alter)); } } diff --git a/Libiada.Core.Tests/Music/MusicXml/MusicXmlParserTests.cs b/Libiada.Core.Tests/Music/MusicXml/MusicXmlParserTests.cs index f24bc75a..5df2a332 100644 --- a/Libiada.Core.Tests/Music/MusicXml/MusicXmlParserTests.cs +++ b/Libiada.Core.Tests/Music/MusicXml/MusicXmlParserTests.cs @@ -22,67 +22,67 @@ public class MusicXmlParserTests public void MusicXmlParserSetUp() { // Measures attributes - var attributes = new MeasureAttributes(new Size(7, 8), new Key(0, "major")); + MeasureAttributes attributes = new(new Size(7, 8), new Key(0, "major")); // notes lists for each measure - var notes1 = new List - { - new ValueNote(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 2, false), false, Tie.None), - new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 8, false), false, Tie.None), - new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 8, false), false, Tie.None), - new ValueNote(new Pitch(3, NoteSymbol.F, 0), new Duration(1, 8, false), false, Tie.Start) - }; - var notes2 = new List - { - new ValueNote(new Pitch(3, NoteSymbol.F, 0), new Duration(1, 8, false), false, Tie.End), - new ValueNote(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 8, false), false, Tie.None), - new ValueNote(new Pitch(3, NoteSymbol.G, 0), new Duration(1, 8, false), false, Tie.None), - new ValueNote(new Pitch(4, NoteSymbol.C, 0), new Duration(1, 8, false), false, Tie.None), - new ValueNote(new Pitch(3, NoteSymbol.G, 0), new Duration(1, 8, false), false, Tie.None), - new ValueNote(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 8, false), false, Tie.None), - new ValueNote(new Pitch(2, NoteSymbol.A, 0), new Duration(1, 8, false), false, Tie.None) - }; - var notes3 = new List - { - new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 16, false), false, Tie.None), - new ValueNote(new Pitch(3, NoteSymbol.G, 0), new Duration(1, 16, false), false, Tie.None), - new ValueNote(new Pitch(4, NoteSymbol.E, 0), new Duration(1, 16, false), false, Tie.None), - new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 16, false), false, Tie.None), - new ValueNote(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 16, false), false, Tie.None), - new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 16, false), false, Tie.None), - new ValueNote(new Pitch(4, NoteSymbol.D, 0), new Duration(1, 8, true), false, Tie.None), - new ValueNote(new Pitch(4, NoteSymbol.C, 0), new Duration(1, 8, true), false, Tie.None), - new ValueNote(new Duration(1, 8, false), false, Tie.None) - }; - var notes4 = new List - { - new ValueNote(new Pitch(4, NoteSymbol.C, 0), new Duration(1, 16, false), false, Tie.None), - new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 16, false), false, Tie.None), - new ValueNote(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 16, false), false, Tie.None), - new ValueNote(new Pitch(4, NoteSymbol.C, 0), new Duration(1, 16, false), false, Tie.None), - new ValueNote(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 16, false), false, Tie.None), - new ValueNote(new Pitch(2, NoteSymbol.A, 0), new Duration(1, 16, false), false, Tie.None), - new ValueNote(new Pitch(4, NoteSymbol.D, 0), new Duration(1, 16, false), false, Tie.None), - new ValueNote(new Pitch(4, NoteSymbol.C, 0), new Duration(1, 16, false), false, Tie.None), - new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 16, false), false, Tie.None), - new ValueNote(new Pitch(2, NoteSymbol.E, 0), new Duration(1, 16, false), false, Tie.None), - new ValueNote(new Pitch(4, NoteSymbol.C, 0), new Duration(1, 16, false), false, Tie.None), - new ValueNote(new Pitch(3, NoteSymbol.G, 0), new Duration(1, 16, false), false, Tie.None), - new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 16, false), false, Tie.None), - new ValueNote(new Pitch(4, NoteSymbol.C, 0), new Duration(1, 16, false), false, Tie.None) - }; + List notes1 = + [ + new(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 2, false), false, Tie.None), + new(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 8, false), false, Tie.None), + new(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 8, false), false, Tie.None), + new(new Pitch(3, NoteSymbol.F, 0), new Duration(1, 8, false), false, Tie.Start) + ]; + List notes2 = + [ + new(new Pitch(3, NoteSymbol.F, 0), new Duration(1, 8, false), false, Tie.End), + new(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 8, false), false, Tie.None), + new(new Pitch(3, NoteSymbol.G, 0), new Duration(1, 8, false), false, Tie.None), + new(new Pitch(4, NoteSymbol.C, 0), new Duration(1, 8, false), false, Tie.None), + new(new Pitch(3, NoteSymbol.G, 0), new Duration(1, 8, false), false, Tie.None), + new(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 8, false), false, Tie.None), + new(new Pitch(2, NoteSymbol.A, 0), new Duration(1, 8, false), false, Tie.None) + ]; + List notes3 = + [ + new(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 16, false), false, Tie.None), + new(new Pitch(3, NoteSymbol.G, 0), new Duration(1, 16, false), false, Tie.None), + new(new Pitch(4, NoteSymbol.E, 0), new Duration(1, 16, false), false, Tie.None), + new(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 16, false), false, Tie.None), + new(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 16, false), false, Tie.None), + new(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 16, false), false, Tie.None), + new(new Pitch(4, NoteSymbol.D, 0), new Duration(1, 8, true), false, Tie.None), + new(new Pitch(4, NoteSymbol.C, 0), new Duration(1, 8, true), false, Tie.None), + new(new Duration(1, 8, false), false, Tie.None) + ]; + List notes4 = + [ + new(new Pitch(4, NoteSymbol.C, 0), new Duration(1, 16, false), false, Tie.None), + new(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 16, false), false, Tie.None), + new(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 16, false), false, Tie.None), + new(new Pitch(4, NoteSymbol.C, 0), new Duration(1, 16, false), false, Tie.None), + new(new Pitch(3, NoteSymbol.E, 0), new Duration(1, 16, false), false, Tie.None), + new(new Pitch(2, NoteSymbol.A, 0), new Duration(1, 16, false), false, Tie.None), + new(new Pitch(4, NoteSymbol.D, 0), new Duration(1, 16, false), false, Tie.None), + new(new Pitch(4, NoteSymbol.C, 0), new Duration(1, 16, false), false, Tie.None), + new(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 16, false), false, Tie.None), + new(new Pitch(2, NoteSymbol.E, 0), new Duration(1, 16, false), false, Tie.None), + new(new Pitch(4, NoteSymbol.C, 0), new Duration(1, 16, false), false, Tie.None), + new(new Pitch(3, NoteSymbol.G, 0), new Duration(1, 16, false), false, Tie.None), + new(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 16, false), false, Tie.None), + new(new Pitch(4, NoteSymbol.C, 0), new Duration(1, 16, false), false, Tie.None) + ]; // measures list for congeneric score track - var measures1 = new List - { - new Measure(notes1, (MeasureAttributes)attributes.Clone()), - new Measure(notes2, (MeasureAttributes)attributes.Clone()), - new Measure(notes3, (MeasureAttributes)attributes.Clone()), - new Measure(notes4, (MeasureAttributes)attributes.Clone()) - }; + List measures1 = + [ + new(notes1, (MeasureAttributes)attributes.Clone()), + new(notes2, (MeasureAttributes)attributes.Clone()), + new(notes3, (MeasureAttributes)attributes.Clone()), + new(notes4, (MeasureAttributes)attributes.Clone()) + ]; // single uniform score track - var uniformTracks = new List { new CongenericScoreTrack(measures1) }; + List uniformTracks = [new(measures1)]; // whole music sequence scoreTrack = new ScoreTrack(uniformTracks); @@ -94,18 +94,24 @@ public void MusicXmlParserSetUp() [Test] public void XmlParserTest() { - var xmlReader = new MusicXmlReader($"{SystemData.ProjectFolderPath}LibiadaMusicExample7Liga.xml"); - var parser = new MusicXmlParser(); + MusicXmlReader xmlReader = new($"{SystemData.ProjectFolderPath}LibiadaMusicExample7Liga.xml"); + MusicXmlParser parser = new(); parser.Execute(xmlReader.MusicXmlDocument); - Assert.AreEqual(scoreTrack.CongenericScoreTracks[0].MeasureList[0].Attributes, parser.ScoreModel.CongenericScoreTracks[0].MeasureList[0].Attributes); - Assert.AreEqual(scoreTrack.CongenericScoreTracks[0].MeasureList[0].NoteList[0], parser.ScoreModel.CongenericScoreTracks[0].MeasureList[0].NoteList[0]); - Assert.AreEqual(scoreTrack.CongenericScoreTracks[0].MeasureList[0], parser.ScoreModel.CongenericScoreTracks[0].MeasureList[0]); - Assert.AreEqual(scoreTrack.CongenericScoreTracks[0].MeasureList[1], parser.ScoreModel.CongenericScoreTracks[0].MeasureList[1]); - Assert.AreEqual(scoreTrack.CongenericScoreTracks[0].MeasureList[2], parser.ScoreModel.CongenericScoreTracks[0].MeasureList[2]); - Assert.AreEqual(scoreTrack.CongenericScoreTracks[0].MeasureList[3], parser.ScoreModel.CongenericScoreTracks[0].MeasureList[3]); - Assert.AreEqual(scoreTrack.CongenericScoreTracks[0], parser.ScoreModel.CongenericScoreTracks[0]); - Assert.AreEqual(scoreTrack, parser.ScoreModel); + CongenericScoreTrack actual = parser.ScoreModel.CongenericScoreTracks[0]; + CongenericScoreTrack expected = scoreTrack.CongenericScoreTracks[0]; + + Assert.Multiple(() => + { + Assert.That(actual.MeasureList[0].Attributes, Is.EqualTo(expected.MeasureList[0].Attributes)); + Assert.That(actual.MeasureList[0].NoteList[0], Is.EqualTo(expected.MeasureList[0].NoteList[0])); + Assert.That(actual.MeasureList[0], Is.EqualTo(expected.MeasureList[0])); + Assert.That(actual.MeasureList[1], Is.EqualTo(expected.MeasureList[1])); + Assert.That(actual.MeasureList[2], Is.EqualTo(expected.MeasureList[2])); + Assert.That(actual.MeasureList[3], Is.EqualTo(expected.MeasureList[3])); + Assert.That(actual, Is.EqualTo(expected)); + Assert.That(parser.ScoreModel, Is.EqualTo(scoreTrack)); + }); } /// @@ -114,24 +120,32 @@ public void XmlParserTest() [Test] public void PolyXmlParserTest() { - var xmlReader = new MusicXmlReader($"{SystemData.ProjectFolderPath}polytest.xml"); - var parser = new MusicXmlParser(); + MusicXmlReader xmlReader = new($"{SystemData.ProjectFolderPath}polytest.xml"); + MusicXmlParser parser = new(); parser.Execute(xmlReader.MusicXmlDocument); - Assert.AreEqual(parser.ScoreModel.CongenericScoreTracks.Count, 1); - Assert.AreEqual(parser.ScoreModel.CongenericScoreTracks[0].MeasureList.Count, 3); - Assert.AreEqual(parser.ScoreModel.CongenericScoreTracks[0].MeasureList[0].NoteList.Count, 5); - Assert.AreEqual(parser.ScoreModel.CongenericScoreTracks[0].MeasureList[1].NoteList.Count, 6); - Assert.AreEqual(parser.ScoreModel.CongenericScoreTracks[0].MeasureList[2].NoteList.Count, 4); - Assert.AreEqual(parser.ScoreModel.CongenericScoreTracks[0].MeasureList[0].NoteList[0].Pitches.Count, 2); - Assert.AreEqual(parser.ScoreModel.CongenericScoreTracks[0].MeasureList[2].NoteList[0].Pitches.Count, 3); - Assert.AreEqual(parser.ScoreModel.CongenericScoreTracks[0].MeasureList[0].NoteList[0].Duration.Denominator, 4); - Assert.AreEqual(parser.ScoreModel.CongenericScoreTracks[0].MeasureList[0].NoteList[0].Pitches[0].Step.ToString(), "A"); - Assert.AreEqual(parser.ScoreModel.CongenericScoreTracks[0].MeasureList[0].NoteList[0].Pitches[1].Step.ToString(), "C"); - Assert.AreEqual(parser.ScoreModel.CongenericScoreTracks[0].MeasureList[2].NoteList[0].Duration.Denominator, 8); - Assert.AreEqual(parser.ScoreModel.CongenericScoreTracks[0].MeasureList[2].NoteList[0].Pitches[0].Step.ToString(), "G"); - Assert.AreEqual(parser.ScoreModel.CongenericScoreTracks[0].MeasureList[2].NoteList[0].Pitches[1].Step.ToString(), "G"); - Assert.AreEqual(parser.ScoreModel.CongenericScoreTracks[0].MeasureList[2].NoteList[0].Pitches[2].Step.ToString(), "C"); + CongenericScoreTrack actual = parser.ScoreModel.CongenericScoreTracks[0]; + + Assert.Multiple(() => + { + Assert.That(parser.ScoreModel.CongenericScoreTracks, Has.Count.EqualTo(1)); + Assert.That(actual.MeasureList, Has.Count.EqualTo(3)); + }); + Assert.Multiple(() => + { + Assert.That(actual.MeasureList[0].NoteList, Has.Count.EqualTo(5)); + Assert.That(actual.MeasureList[1].NoteList, Has.Count.EqualTo(6)); + Assert.That(actual.MeasureList[2].NoteList, Has.Count.EqualTo(4)); + Assert.That(actual.MeasureList[0].NoteList[0].Pitches, Has.Count.EqualTo(2)); + Assert.That(actual.MeasureList[2].NoteList[0].Pitches, Has.Count.EqualTo(3)); + Assert.That(actual.MeasureList[0].NoteList[0].Duration.Denominator, Is.EqualTo(4)); + Assert.That(actual.MeasureList[0].NoteList[0].Pitches[0].Step.ToString(), Is.EqualTo("A")); + Assert.That(actual.MeasureList[0].NoteList[0].Pitches[1].Step.ToString(), Is.EqualTo("C")); + Assert.That(actual.MeasureList[2].NoteList[0].Duration.Denominator, Is.EqualTo(8)); + Assert.That(actual.MeasureList[2].NoteList[0].Pitches[0].Step.ToString(), Is.EqualTo("G")); + Assert.That(actual.MeasureList[2].NoteList[0].Pitches[1].Step.ToString(), Is.EqualTo("G")); + Assert.That(actual.MeasureList[2].NoteList[0].Pitches[2].Step.ToString(), Is.EqualTo("C")); + }); } /// @@ -140,15 +154,17 @@ public void PolyXmlParserTest() [Test] public void RepeaterTest() { - var xmlReader = new MusicXmlReader($"{SystemData.ProjectFolderPath}repeatertest.xml"); - var parser = new MusicXmlParser(); + MusicXmlReader xmlReader = new($"{SystemData.ProjectFolderPath}repeatertest.xml"); + MusicXmlParser parser = new(); parser.Execute(xmlReader.MusicXmlDocument); - Assert.AreEqual(parser.ScoreModel.CongenericScoreTracks.Count, 1); - Assert.AreEqual(parser.ScoreModel.CongenericScoreTracks[0].MeasureList.Count, 8); - Assert.AreEqual(parser.ScoreModel.CongenericScoreTracks[0].MeasureList[0].NoteList.Count, 1); - Assert.IsTrue(parser.ScoreModel.CongenericScoreTracks[0].MeasureList[0].Equals(parser.ScoreModel.CongenericScoreTracks[0].MeasureList[4])); - Assert.IsTrue(parser.ScoreModel.CongenericScoreTracks[0].MeasureList[1].Equals(parser.ScoreModel.CongenericScoreTracks[0].MeasureList[5])); + CongenericScoreTrack actual = parser.ScoreModel.CongenericScoreTracks[0]; + + Assert.That(parser.ScoreModel.CongenericScoreTracks, Has.Count.EqualTo(1)); + Assert.That(actual.MeasureList, Has.Count.EqualTo(8)); + Assert.That(actual.MeasureList[0].NoteList, Has.Count.EqualTo(1)); + Assert.That(actual.MeasureList[0], Is.EqualTo(actual.MeasureList[4])); + Assert.That(actual.MeasureList[1], Is.EqualTo(actual.MeasureList[5])); } /// @@ -157,11 +173,11 @@ public void RepeaterTest() [Test] public void XmlParserScoreTrackTest() { - var xmlReader = new MusicXmlReader($"{SystemData.ProjectFolderPath}LibiadaMusicExample7Liga.xml"); - var parser = new MusicXmlParser(); + MusicXmlReader xmlReader = new($"{SystemData.ProjectFolderPath}LibiadaMusicExample7Liga.xml"); + MusicXmlParser parser = new(); parser.Execute(xmlReader.MusicXmlDocument); - Assert.AreEqual(scoreTrack, parser.ScoreModel); + Assert.That(parser.ScoreModel, Is.EqualTo(scoreTrack)); } /// @@ -170,11 +186,11 @@ public void XmlParserScoreTrackTest() [Test] public void XmlParserCongenericScoreTrackTest() { - var xmlReader = new MusicXmlReader($"{SystemData.ProjectFolderPath}LibiadaMusicExample7Liga.xml"); - var parser = new MusicXmlParser(); + MusicXmlReader xmlReader = new($"{SystemData.ProjectFolderPath}LibiadaMusicExample7Liga.xml"); + MusicXmlParser parser = new(); parser.Execute(xmlReader.MusicXmlDocument); - - Assert.AreEqual(scoreTrack.CongenericScoreTracks[0], parser.ScoreModel.CongenericScoreTracks[0]); + CongenericScoreTrack actual = parser.ScoreModel.CongenericScoreTracks[0]; + Assert.That(actual, Is.EqualTo(scoreTrack.CongenericScoreTracks[0])); } /// @@ -183,16 +199,16 @@ public void XmlParserCongenericScoreTrackTest() [Test] public void XmlParserMeasureTest() { - var xmlReader = new MusicXmlReader($"{SystemData.ProjectFolderPath}LibiadaMusicExample7Liga.xml"); - var parser = new MusicXmlParser(); + MusicXmlReader xmlReader = new($"{SystemData.ProjectFolderPath}LibiadaMusicExample7Liga.xml"); + MusicXmlParser parser = new(); parser.Execute(xmlReader.MusicXmlDocument); - + CongenericScoreTrack actual = parser.ScoreModel.CongenericScoreTracks[0]; List expectedMeasures = scoreTrack.CongenericScoreTracks[0].MeasureList; - List actualMeasures = parser.ScoreModel.CongenericScoreTracks[0].MeasureList; - Assert.AreEqual(expectedMeasures.Count, actualMeasures.Count); + List actualMeasures = actual.MeasureList; + Assert.That(actualMeasures, Has.Count.EqualTo(expectedMeasures.Count)); for (int i = 0; i < expectedMeasures.Count; i++) { - Assert.AreEqual(scoreTrack.CongenericScoreTracks[0].MeasureList[i], parser.ScoreModel.CongenericScoreTracks[0].MeasureList[i]); + Assert.That(actual.MeasureList[i], Is.EqualTo(scoreTrack.CongenericScoreTracks[0].MeasureList[i])); } } @@ -202,21 +218,21 @@ public void XmlParserMeasureTest() [Test] public void XmlParserNoteTest() { - var xmlReader = new MusicXmlReader($"{SystemData.ProjectFolderPath}LibiadaMusicExample7Liga.xml"); - var parser = new MusicXmlParser(); + MusicXmlReader xmlReader = new($"{SystemData.ProjectFolderPath}LibiadaMusicExample7Liga.xml"); + MusicXmlParser parser = new(); parser.Execute(xmlReader.MusicXmlDocument); - + CongenericScoreTrack actual = parser.ScoreModel.CongenericScoreTracks[0]; List expectedMeasures = scoreTrack.CongenericScoreTracks[0].MeasureList; - List actualMeasures = parser.ScoreModel.CongenericScoreTracks[0].MeasureList; - Assert.AreEqual(expectedMeasures.Count, actualMeasures.Count); + List actualMeasures = actual.MeasureList; + Assert.That(actualMeasures, Has.Count.EqualTo(expectedMeasures.Count)); for (int i = 0; i < expectedMeasures.Count; i++) { List expectedNotes = expectedMeasures[i].NoteList; List actualNotes = actualMeasures[i].NoteList; - Assert.AreEqual(expectedNotes.Count, actualNotes.Count); + Assert.That(actualNotes, Has.Count.EqualTo(expectedNotes.Count)); for (int j = 0; j < expectedNotes.Count; j++) { - Assert.AreEqual(expectedNotes[j], actualNotes[j]); + Assert.That(actualNotes[j], Is.EqualTo(expectedNotes[j])); } } } @@ -227,20 +243,20 @@ public void XmlParserNoteTest() [Test] public void XmlParserAttributesTest() { - var xmlReader = new MusicXmlReader($"{SystemData.ProjectFolderPath}LibiadaMusicExample7Liga.xml"); - var parser = new MusicXmlParser(); + MusicXmlReader xmlReader = new($"{SystemData.ProjectFolderPath}LibiadaMusicExample7Liga.xml"); + MusicXmlParser parser = new(); parser.Execute(xmlReader.MusicXmlDocument); - + CongenericScoreTrack actual = parser.ScoreModel.CongenericScoreTracks[0]; List expectedMeasures = scoreTrack.CongenericScoreTracks[0].MeasureList; - List actualMeasures = parser.ScoreModel.CongenericScoreTracks[0].MeasureList; - Assert.AreEqual(expectedMeasures.Count, actualMeasures.Count); + List actualMeasures = actual.MeasureList; + Assert.That(actualMeasures, Has.Count.EqualTo(expectedMeasures.Count)); for (int i = 0; i < expectedMeasures.Count; i++) { MeasureAttributes expectedAttributes = scoreTrack.CongenericScoreTracks[0].MeasureList[i].Attributes; - MeasureAttributes actualAttributes = parser.ScoreModel.CongenericScoreTracks[0].MeasureList[i].Attributes; - Assert.AreEqual(expectedAttributes, actualAttributes); - Assert.AreEqual(expectedAttributes.Key, actualAttributes.Key); - Assert.AreEqual(expectedAttributes.Size, actualAttributes.Size); + MeasureAttributes actualAttributes = actual.MeasureList[i].Attributes; + Assert.That(actualAttributes, Is.EqualTo(expectedAttributes)); + Assert.That(actualAttributes.Key, Is.EqualTo(expectedAttributes.Key)); + Assert.That(actualAttributes.Size, Is.EqualTo(expectedAttributes.Size)); } } @@ -250,24 +266,24 @@ public void XmlParserAttributesTest() [Test] public void XmlParserPitchTest() { - var xmlReader = new MusicXmlReader($"{SystemData.ProjectFolderPath}LibiadaMusicExample7Liga.xml"); - var parser = new MusicXmlParser(); + MusicXmlReader xmlReader = new($"{SystemData.ProjectFolderPath}LibiadaMusicExample7Liga.xml"); + MusicXmlParser parser = new(); parser.Execute(xmlReader.MusicXmlDocument); - + CongenericScoreTrack actual = parser.ScoreModel.CongenericScoreTracks[0]; List expectedMeasures = scoreTrack.CongenericScoreTracks[0].MeasureList; - List actualMeasures = parser.ScoreModel.CongenericScoreTracks[0].MeasureList; - Assert.AreEqual(expectedMeasures.Count, actualMeasures.Count); + List actualMeasures = actual.MeasureList; + Assert.That(actualMeasures, Has.Count.EqualTo(expectedMeasures.Count)); for (int i = 0; i < expectedMeasures.Count; i++) { List expectedNotes = expectedMeasures[i].NoteList; List actualNotes = actualMeasures[i].NoteList; - Assert.AreEqual(expectedNotes.Count, actualNotes.Count); + Assert.That(actualNotes, Has.Count.EqualTo(expectedNotes.Count)); for (int j = 0; j < expectedNotes.Count; j++) { - Assert.AreEqual(expectedNotes[j].Pitches.Count, actualNotes[j].Pitches.Count); + Assert.That(actualNotes[j].Pitches, Has.Count.EqualTo(expectedNotes[j].Pitches.Count)); for (int k = 0; k < expectedNotes[j].Pitches.Count; k++) { - Assert.AreEqual(expectedNotes[j].Pitches[k], actualNotes[j].Pitches[k]); + Assert.That(actualNotes[j].Pitches[k], Is.EqualTo(expectedNotes[j].Pitches[k])); } } } @@ -279,21 +295,21 @@ public void XmlParserPitchTest() [Test] public void XmlParserDurationTest() { - var xmlReader = new MusicXmlReader($"{SystemData.ProjectFolderPath}LibiadaMusicExample7Liga.xml"); - var parser = new MusicXmlParser(); + MusicXmlReader xmlReader = new($"{SystemData.ProjectFolderPath}LibiadaMusicExample7Liga.xml"); + MusicXmlParser parser = new(); parser.Execute(xmlReader.MusicXmlDocument); - + CongenericScoreTrack actual = parser.ScoreModel.CongenericScoreTracks[0]; List expectedMeasures = scoreTrack.CongenericScoreTracks[0].MeasureList; - List actualMeasures = parser.ScoreModel.CongenericScoreTracks[0].MeasureList; - Assert.AreEqual(expectedMeasures.Count, actualMeasures.Count); + List actualMeasures = actual.MeasureList; + Assert.That(actualMeasures, Has.Count.EqualTo(expectedMeasures.Count)); for (int i = 0; i < expectedMeasures.Count; i++) { List expectedNotes = expectedMeasures[i].NoteList; List actualNotes = actualMeasures[i].NoteList; - Assert.AreEqual(expectedNotes.Count, actualNotes.Count); + Assert.That(actualNotes, Has.Count.EqualTo(expectedNotes.Count)); for (int j = 0; j < expectedNotes.Count; j++) { - Assert.AreEqual(expectedNotes[j].Duration, actualNotes[j].Duration); + Assert.That(actualNotes[j].Duration, Is.EqualTo(expectedNotes[j].Duration)); } } } @@ -304,21 +320,21 @@ public void XmlParserDurationTest() [Test] public void XmlParserTieTest() { - var xmlReader = new MusicXmlReader($"{SystemData.ProjectFolderPath}LibiadaMusicExample7Liga.xml"); - var parser = new MusicXmlParser(); + MusicXmlReader xmlReader = new($"{SystemData.ProjectFolderPath}LibiadaMusicExample7Liga.xml"); + MusicXmlParser parser = new(); parser.Execute(xmlReader.MusicXmlDocument); - + CongenericScoreTrack actual = parser.ScoreModel.CongenericScoreTracks[0]; List expectedMeasures = scoreTrack.CongenericScoreTracks[0].MeasureList; - List actualMeasures = parser.ScoreModel.CongenericScoreTracks[0].MeasureList; - Assert.AreEqual(expectedMeasures.Count, actualMeasures.Count); + List actualMeasures = actual.MeasureList; + Assert.That(actualMeasures, Has.Count.EqualTo(expectedMeasures.Count)); for (int i = 0; i < expectedMeasures.Count; i++) { List expectedNotes = expectedMeasures[i].NoteList; List actualNotes = actualMeasures[i].NoteList; - Assert.AreEqual(expectedNotes.Count, actualNotes.Count); + Assert.That(actualNotes, Has.Count.EqualTo(expectedNotes.Count)); for (int j = 0; j < expectedNotes.Count; j++) { - Assert.AreEqual(expectedNotes[j].Tie, actualNotes[j].Tie); + Assert.That(actualNotes[j].Tie, Is.EqualTo(expectedNotes[j].Tie)); } } } @@ -329,21 +345,21 @@ public void XmlParserTieTest() [Test] public void XmlParserTripletTest() { - var xmlReader = new MusicXmlReader($"{SystemData.ProjectFolderPath}LibiadaMusicExample7Liga.xml"); - var parser = new MusicXmlParser(); + MusicXmlReader xmlReader = new($"{SystemData.ProjectFolderPath}LibiadaMusicExample7Liga.xml"); + MusicXmlParser parser = new(); parser.Execute(xmlReader.MusicXmlDocument); - + CongenericScoreTrack actual = parser.ScoreModel.CongenericScoreTracks[0]; List expectedMeasures = scoreTrack.CongenericScoreTracks[0].MeasureList; - List actualMeasures = parser.ScoreModel.CongenericScoreTracks[0].MeasureList; - Assert.AreEqual(expectedMeasures.Count, actualMeasures.Count); + List actualMeasures = actual.MeasureList; + Assert.That(actualMeasures, Has.Count.EqualTo(expectedMeasures.Count)); for (int i = 0; i < expectedMeasures.Count; i++) { List expectedNotes = expectedMeasures[i].NoteList; List actualNotes = actualMeasures[i].NoteList; - Assert.AreEqual(expectedNotes.Count, actualNotes.Count); + Assert.That(actualNotes, Has.Count.EqualTo(expectedNotes.Count)); for (int j = 0; j < expectedNotes.Count; j++) { - Assert.AreEqual(expectedNotes[j].Triplet, actualNotes[j].Triplet); + Assert.That(actualNotes[j].Triplet, Is.EqualTo(expectedNotes[j].Triplet)); } } } diff --git a/Libiada.Core.Tests/Music/MusicXml/XmlReaderTests.cs b/Libiada.Core.Tests/Music/MusicXml/XmlReaderTests.cs index 4ef3645b..b11d9205 100644 --- a/Libiada.Core.Tests/Music/MusicXml/XmlReaderTests.cs +++ b/Libiada.Core.Tests/Music/MusicXml/XmlReaderTests.cs @@ -15,6 +15,6 @@ public class XmlReaderTests public void XmlReaderFirstTest() { var xr = new MusicXmlReader($"{SystemData.ProjectFolderPath}LibiadaMusicExample7Liga.xml"); - Assert.IsNotNull(xr.MusicXmlDocument); + Assert.That(xr.MusicXmlDocument, Is.Not.Null); } } diff --git a/Libiada.Core.Tests/Music/PauseTreatmentTests.cs b/Libiada.Core.Tests/Music/PauseTreatmentTests.cs index b89f4993..05a32079 100644 --- a/Libiada.Core.Tests/Music/PauseTreatmentTests.cs +++ b/Libiada.Core.Tests/Music/PauseTreatmentTests.cs @@ -14,8 +14,9 @@ public class PauseTreatmentTests [Test] public void ParamPauseTest() { - Assert.AreEqual((int)PauseTreatment.Ignore, 1); - Assert.AreEqual((int)PauseTreatment.NoteTrace, 2); - Assert.AreEqual((int)PauseTreatment.SilenceNote, 3); + // TODO: Rewrite this as other enum tests + Assert.That((int)PauseTreatment.Ignore, Is.EqualTo(1)); + Assert.That((int)PauseTreatment.NoteTrace, Is.EqualTo(2)); + Assert.That((int)PauseTreatment.SilenceNote, Is.EqualTo(3)); } } diff --git a/Libiada.Core.Tests/Music/PriorityDiscoverTests.cs b/Libiada.Core.Tests/Music/PriorityDiscoverTests.cs index 1a01de4e..f3326532 100644 --- a/Libiada.Core.Tests/Music/PriorityDiscoverTests.cs +++ b/Libiada.Core.Tests/Music/PriorityDiscoverTests.cs @@ -12,57 +12,57 @@ public class PriorityDiscoverTests /// /// The note. /// - private readonly ValueNote note = new ValueNote(new Pitch(1, NoteSymbol.E, 0), new Duration(1, 4, false), false, Tie.None); + private readonly ValueNote note = new(new Pitch(1, NoteSymbol.E, 0), new Duration(1, 4, false), false, Tie.None); /// /// The a note. /// - private readonly ValueNote aNote = new ValueNote(new Pitch(1, NoteSymbol.B, 0), new Duration(1, 2, false), false, 0); + private readonly ValueNote aNote = new(new Pitch(1, NoteSymbol.B, 0), new Duration(1, 2, false), false, 0); /// /// The b note. /// - private readonly ValueNote bNote = new ValueNote(new Duration(1, 4, false), false, 0); + private readonly ValueNote bNote = new(new Duration(1, 4, false), false, 0); /// /// The с note. /// - private readonly ValueNote сNote = new ValueNote(new Pitch(1, NoteSymbol.A, 0), new Duration(1, 4, 2, 3, false), true, 0); + private readonly ValueNote сNote = new(new Pitch(1, NoteSymbol.A, 0), new Duration(1, 4, 2, 3, false), true, 0); /// /// The cc note. /// - private readonly ValueNote ccNote = new ValueNote(new Pitch(1, NoteSymbol.A, 0), new Duration(1, 8, 2, 3, false), true, 0); + private readonly ValueNote ccNote = new(new Pitch(1, NoteSymbol.A, 0), new Duration(1, 8, 2, 3, false), true, 0); /// /// The сcc note. /// - private readonly ValueNote сccNote = new ValueNote(new Pitch(1, NoteSymbol.A, 0), new Duration(1, 8, 4, 7, false), true, 0); + private readonly ValueNote сccNote = new(new Pitch(1, NoteSymbol.A, 0), new Duration(1, 8, 4, 7, false), true, 0); /// /// The d note. /// - private readonly ValueNote dNote = new ValueNote(new Pitch(1, NoteSymbol.B, 0), new Duration(1, 16, false), false, 0); + private readonly ValueNote dNote = new(new Pitch(1, NoteSymbol.B, 0), new Duration(1, 16, false), false, 0); /// /// The attributes. /// - private readonly MeasureAttributes attributes = new MeasureAttributes(new Size(4, 4), new Key(0, "minor")); + private readonly MeasureAttributes attributes = new(new Size(4, 4), new Key(0, "minor")); /// /// The attributes 1. /// - private readonly MeasureAttributes attributes1 = new MeasureAttributes(new Size(3, 4), new Key(0, "minor")); + private readonly MeasureAttributes attributes1 = new(new Size(3, 4), new Key(0, "minor")); /// /// The attributes 2. /// - private readonly MeasureAttributes attributes2 = new MeasureAttributes(new Size(12, 8), new Key(0, "minor")); + private readonly MeasureAttributes attributes2 = new(new Size(12, 8), new Key(0, "minor")); /// /// The attributes 3. /// - private readonly MeasureAttributes attributes3 = new MeasureAttributes(new Size(13, 16), new Key(0, "minor")); + private readonly MeasureAttributes attributes3 = new(new Size(13, 16), new Key(0, "minor")); /// /// The priority get set test. @@ -74,9 +74,9 @@ public void PriorityGetSetTest() aNote.Priority = -1; bNote.Priority = 3; - Assert.AreEqual(0, note.Priority); - Assert.AreEqual(3, bNote.Priority); - Assert.AreEqual(-1, aNote.Priority); + Assert.That(note.Priority, Is.EqualTo(0)); + Assert.That(bNote.Priority, Is.EqualTo(3)); + Assert.That(aNote.Priority, Is.EqualTo(-1)); } /// @@ -85,13 +85,13 @@ public void PriorityGetSetTest() [Test] public void PriorityMinDurationTest() { - var pd = new PriorityDiscover(); + PriorityDiscover pd = new(); - var notes = new List { note, bNote, dNote, aNote }; - var measure = new Measure(notes, attributes); + List notes = [note, bNote, dNote, aNote]; + Measure measure = new(notes, attributes); // minimal note duration in measure is 1/16 = 0.0625 (dNote) - Assert.IsTrue(Math.Abs(pd.MinDuration(measure) - 0.0625) < 0.00001); + Assert.That(pd.MinDuration(measure), Is.EqualTo(0.0625).Within(0.00001d)); measure.NoteList.Clear(); Assert.Throws(() => pd.MinDuration(measure)); @@ -103,51 +103,51 @@ public void PriorityMinDurationTest() [Test] public void PriorityMaskCalculationFirstTest() { - var pd = new PriorityDiscover(); + PriorityDiscover pd = new(); - var notes = new List { note, bNote, dNote, aNote }; - var measure = new Measure(notes, attributes); - var priorityMask = pd.CalculatePriorityMask(measure); + List notes = [note, bNote, dNote, aNote]; + Measure measure = new(notes, attributes); + Measure priorityMask = pd.CalculatePriorityMask(measure); // так как минимальная длительность ноты в такте 1/16 то маска приоритетов должна разложиться (посчитаться) до 1/32 - Assert.AreEqual(0, priorityMask.NoteList[0].Priority); - Assert.AreEqual(5, priorityMask.NoteList[1].Priority); - Assert.AreEqual(4, priorityMask.NoteList[2].Priority); - Assert.AreEqual(5, priorityMask.NoteList[3].Priority); - Assert.AreEqual(3, priorityMask.NoteList[4].Priority); - Assert.AreEqual(5, priorityMask.NoteList[5].Priority); - Assert.AreEqual(4, priorityMask.NoteList[6].Priority); - Assert.AreEqual(5, priorityMask.NoteList[7].Priority); - Assert.AreEqual(2, priorityMask.NoteList[8].Priority); - Assert.AreEqual(5, priorityMask.NoteList[9].Priority); - Assert.AreEqual(4, priorityMask.NoteList[10].Priority); - Assert.AreEqual(5, priorityMask.NoteList[11].Priority); - Assert.AreEqual(3, priorityMask.NoteList[12].Priority); - Assert.AreEqual(5, priorityMask.NoteList[13].Priority); - Assert.AreEqual(4, priorityMask.NoteList[14].Priority); - Assert.AreEqual(5, priorityMask.NoteList[15].Priority); - Assert.AreEqual(1, priorityMask.NoteList[16].Priority); - Assert.AreEqual(5, priorityMask.NoteList[17].Priority); - Assert.AreEqual(4, priorityMask.NoteList[18].Priority); - Assert.AreEqual(5, priorityMask.NoteList[19].Priority); - Assert.AreEqual(3, priorityMask.NoteList[20].Priority); - Assert.AreEqual(5, priorityMask.NoteList[21].Priority); - Assert.AreEqual(4, priorityMask.NoteList[22].Priority); - Assert.AreEqual(5, priorityMask.NoteList[23].Priority); - Assert.AreEqual(2, priorityMask.NoteList[24].Priority); - Assert.AreEqual(5, priorityMask.NoteList[25].Priority); - Assert.AreEqual(4, priorityMask.NoteList[26].Priority); - Assert.AreEqual(5, priorityMask.NoteList[27].Priority); - Assert.AreEqual(3, priorityMask.NoteList[28].Priority); - Assert.AreEqual(5, priorityMask.NoteList[29].Priority); - Assert.AreEqual(4, priorityMask.NoteList[30].Priority); - Assert.AreEqual(5, priorityMask.NoteList[31].Priority); + Assert.That(priorityMask.NoteList[0].Priority, Is.EqualTo(0)); + Assert.That(priorityMask.NoteList[1].Priority, Is.EqualTo(5)); + Assert.That(priorityMask.NoteList[2].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[3].Priority, Is.EqualTo(5)); + Assert.That(priorityMask.NoteList[4].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[5].Priority, Is.EqualTo(5)); + Assert.That(priorityMask.NoteList[6].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[7].Priority, Is.EqualTo(5)); + Assert.That(priorityMask.NoteList[8].Priority, Is.EqualTo(2)); + Assert.That(priorityMask.NoteList[9].Priority, Is.EqualTo(5)); + Assert.That(priorityMask.NoteList[10].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[11].Priority, Is.EqualTo(5)); + Assert.That(priorityMask.NoteList[12].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[13].Priority, Is.EqualTo(5)); + Assert.That(priorityMask.NoteList[14].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[15].Priority, Is.EqualTo(5)); + Assert.That(priorityMask.NoteList[16].Priority, Is.EqualTo(1)); + Assert.That(priorityMask.NoteList[17].Priority, Is.EqualTo(5)); + Assert.That(priorityMask.NoteList[18].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[19].Priority, Is.EqualTo(5)); + Assert.That(priorityMask.NoteList[20].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[21].Priority, Is.EqualTo(5)); + Assert.That(priorityMask.NoteList[22].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[23].Priority, Is.EqualTo(5)); + Assert.That(priorityMask.NoteList[24].Priority, Is.EqualTo(2)); + Assert.That(priorityMask.NoteList[25].Priority, Is.EqualTo(5)); + Assert.That(priorityMask.NoteList[26].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[27].Priority, Is.EqualTo(5)); + Assert.That(priorityMask.NoteList[28].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[29].Priority, Is.EqualTo(5)); + Assert.That(priorityMask.NoteList[30].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[31].Priority, Is.EqualTo(5)); // проверка длительностей - foreach (var lnote in priorityMask.NoteList) + foreach (ValueNote lnote in priorityMask.NoteList) { - Assert.AreEqual(1, lnote.Duration.Numerator); - Assert.AreEqual(32, lnote.Duration.Denominator); + Assert.That(lnote.Duration.Numerator, Is.EqualTo(1)); + Assert.That(lnote.Duration.Denominator, Is.EqualTo(32)); } } @@ -157,68 +157,68 @@ public void PriorityMaskCalculationFirstTest() [Test] public void PriorityMaskCalculationSecondTest() { - var pd = new PriorityDiscover(); + PriorityDiscover pd = new(); - var notes = new List { note, bNote, dNote, aNote }; - var measure = new Measure(notes, attributes2); - var priorityMask = pd.CalculatePriorityMask(measure); + List notes = [note, bNote, dNote, aNote]; + Measure measure = new(notes, attributes2); + Measure priorityMask = pd.CalculatePriorityMask(measure); // так как минимальная длительность ноты в такте 1/16 то маска приоритетов должна разложиться (посчитаться) до 1/32 // размер 12/8, поэтому будет считаться приоритет для 48/32 нот - Assert.AreEqual(0, priorityMask.NoteList[0].Priority); - Assert.AreEqual(4, priorityMask.NoteList[1].Priority); - Assert.AreEqual(3, priorityMask.NoteList[2].Priority); - Assert.AreEqual(4, priorityMask.NoteList[3].Priority); - Assert.AreEqual(2, priorityMask.NoteList[4].Priority); - Assert.AreEqual(4, priorityMask.NoteList[5].Priority); - Assert.AreEqual(3, priorityMask.NoteList[6].Priority); - Assert.AreEqual(4, priorityMask.NoteList[7].Priority); - Assert.AreEqual(1, priorityMask.NoteList[8].Priority); - Assert.AreEqual(4, priorityMask.NoteList[9].Priority); - Assert.AreEqual(3, priorityMask.NoteList[10].Priority); - Assert.AreEqual(4, priorityMask.NoteList[11].Priority); - Assert.AreEqual(2, priorityMask.NoteList[12].Priority); - Assert.AreEqual(4, priorityMask.NoteList[13].Priority); - Assert.AreEqual(3, priorityMask.NoteList[14].Priority); - Assert.AreEqual(4, priorityMask.NoteList[15].Priority); - Assert.AreEqual(1, priorityMask.NoteList[16].Priority); - Assert.AreEqual(4, priorityMask.NoteList[17].Priority); - Assert.AreEqual(3, priorityMask.NoteList[18].Priority); - Assert.AreEqual(4, priorityMask.NoteList[19].Priority); - Assert.AreEqual(2, priorityMask.NoteList[20].Priority); - Assert.AreEqual(4, priorityMask.NoteList[21].Priority); - Assert.AreEqual(3, priorityMask.NoteList[22].Priority); - Assert.AreEqual(4, priorityMask.NoteList[23].Priority); - Assert.AreEqual(1, priorityMask.NoteList[24].Priority); - Assert.AreEqual(4, priorityMask.NoteList[25].Priority); - Assert.AreEqual(3, priorityMask.NoteList[26].Priority); - Assert.AreEqual(4, priorityMask.NoteList[27].Priority); - Assert.AreEqual(2, priorityMask.NoteList[28].Priority); - Assert.AreEqual(4, priorityMask.NoteList[29].Priority); - Assert.AreEqual(3, priorityMask.NoteList[30].Priority); - Assert.AreEqual(4, priorityMask.NoteList[31].Priority); - Assert.AreEqual(1, priorityMask.NoteList[32].Priority); - Assert.AreEqual(4, priorityMask.NoteList[33].Priority); - Assert.AreEqual(3, priorityMask.NoteList[34].Priority); - Assert.AreEqual(4, priorityMask.NoteList[35].Priority); - Assert.AreEqual(2, priorityMask.NoteList[36].Priority); - Assert.AreEqual(4, priorityMask.NoteList[37].Priority); - Assert.AreEqual(3, priorityMask.NoteList[38].Priority); - Assert.AreEqual(4, priorityMask.NoteList[39].Priority); - Assert.AreEqual(1, priorityMask.NoteList[40].Priority); - Assert.AreEqual(4, priorityMask.NoteList[41].Priority); - Assert.AreEqual(3, priorityMask.NoteList[42].Priority); - Assert.AreEqual(4, priorityMask.NoteList[43].Priority); - Assert.AreEqual(2, priorityMask.NoteList[44].Priority); - Assert.AreEqual(4, priorityMask.NoteList[45].Priority); - Assert.AreEqual(3, priorityMask.NoteList[46].Priority); - Assert.AreEqual(4, priorityMask.NoteList[47].Priority); + Assert.That(priorityMask.NoteList[0].Priority, Is.EqualTo(0)); + Assert.That(priorityMask.NoteList[1].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[2].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[3].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[4].Priority, Is.EqualTo(2)); + Assert.That(priorityMask.NoteList[5].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[6].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[7].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[8].Priority, Is.EqualTo(1)); + Assert.That(priorityMask.NoteList[9].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[10].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[11].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[12].Priority, Is.EqualTo(2)); + Assert.That(priorityMask.NoteList[13].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[14].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[15].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[16].Priority, Is.EqualTo(1)); + Assert.That(priorityMask.NoteList[17].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[18].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[19].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[20].Priority, Is.EqualTo(2)); + Assert.That(priorityMask.NoteList[21].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[22].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[23].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[24].Priority, Is.EqualTo(1)); + Assert.That(priorityMask.NoteList[25].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[26].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[27].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[28].Priority, Is.EqualTo(2)); + Assert.That(priorityMask.NoteList[29].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[30].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[31].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[32].Priority, Is.EqualTo(1)); + Assert.That(priorityMask.NoteList[33].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[34].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[35].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[36].Priority, Is.EqualTo(2)); + Assert.That(priorityMask.NoteList[37].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[38].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[39].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[40].Priority, Is.EqualTo(1)); + Assert.That(priorityMask.NoteList[41].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[42].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[43].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[44].Priority, Is.EqualTo(2)); + Assert.That(priorityMask.NoteList[45].Priority, Is.EqualTo(4)); + Assert.That(priorityMask.NoteList[46].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[47].Priority, Is.EqualTo(4)); // проверка длительностей - foreach (var lnote in priorityMask.NoteList) + foreach (ValueNote lnote in priorityMask.NoteList) { - Assert.AreEqual(1, lnote.Duration.Numerator); - Assert.AreEqual(32, lnote.Duration.Denominator); + Assert.That(lnote.Duration.Numerator, Is.EqualTo(1)); + Assert.That(lnote.Duration.Denominator, Is.EqualTo(32)); } } @@ -228,46 +228,46 @@ public void PriorityMaskCalculationSecondTest() [Test] public void PriorityMaskCalculationThirdTest() { - var pd = new PriorityDiscover(); + PriorityDiscover pd = new(); - var notes = new List { note, bNote, dNote, aNote }; - var measure = new Measure(notes, attributes3); - var priorityMask = pd.CalculatePriorityMask(measure); + List notes = [note, bNote, dNote, aNote]; + Measure measure = new(notes, attributes3); + Measure priorityMask = pd.CalculatePriorityMask(measure); // так как минимальная длительность ноты в такте 1/16 то маска приоритетов должна разложиться (посчитаться) до 1/32 // размер 13/16, поэтому будет считаться приоритет для 26/32 нот - Assert.AreEqual(0, priorityMask.NoteList[0].Priority); - Assert.AreEqual(3, priorityMask.NoteList[1].Priority); - Assert.AreEqual(2, priorityMask.NoteList[2].Priority); - Assert.AreEqual(3, priorityMask.NoteList[3].Priority); - Assert.AreEqual(1, priorityMask.NoteList[4].Priority); - Assert.AreEqual(3, priorityMask.NoteList[5].Priority); - Assert.AreEqual(2, priorityMask.NoteList[6].Priority); - Assert.AreEqual(3, priorityMask.NoteList[7].Priority); - Assert.AreEqual(1, priorityMask.NoteList[8].Priority); - Assert.AreEqual(3, priorityMask.NoteList[9].Priority); - Assert.AreEqual(2, priorityMask.NoteList[10].Priority); - Assert.AreEqual(3, priorityMask.NoteList[11].Priority); - Assert.AreEqual(1, priorityMask.NoteList[12].Priority); - Assert.AreEqual(3, priorityMask.NoteList[13].Priority); - Assert.AreEqual(2, priorityMask.NoteList[14].Priority); - Assert.AreEqual(3, priorityMask.NoteList[15].Priority); - Assert.AreEqual(1, priorityMask.NoteList[16].Priority); - Assert.AreEqual(3, priorityMask.NoteList[17].Priority); - Assert.AreEqual(2, priorityMask.NoteList[18].Priority); - Assert.AreEqual(3, priorityMask.NoteList[19].Priority); - Assert.AreEqual(1, priorityMask.NoteList[20].Priority); - Assert.AreEqual(3, priorityMask.NoteList[21].Priority); - Assert.AreEqual(2, priorityMask.NoteList[22].Priority); - Assert.AreEqual(3, priorityMask.NoteList[23].Priority); - Assert.AreEqual(2, priorityMask.NoteList[24].Priority); - Assert.AreEqual(3, priorityMask.NoteList[25].Priority); + Assert.That(priorityMask.NoteList[0].Priority, Is.EqualTo(0)); + Assert.That(priorityMask.NoteList[1].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[2].Priority, Is.EqualTo(2)); + Assert.That(priorityMask.NoteList[3].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[4].Priority, Is.EqualTo(1)); + Assert.That(priorityMask.NoteList[5].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[6].Priority, Is.EqualTo(2)); + Assert.That(priorityMask.NoteList[7].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[8].Priority, Is.EqualTo(1)); + Assert.That(priorityMask.NoteList[9].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[10].Priority, Is.EqualTo(2)); + Assert.That(priorityMask.NoteList[11].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[12].Priority, Is.EqualTo(1)); + Assert.That(priorityMask.NoteList[13].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[14].Priority, Is.EqualTo(2)); + Assert.That(priorityMask.NoteList[15].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[16].Priority, Is.EqualTo(1)); + Assert.That(priorityMask.NoteList[17].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[18].Priority, Is.EqualTo(2)); + Assert.That(priorityMask.NoteList[19].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[20].Priority, Is.EqualTo(1)); + Assert.That(priorityMask.NoteList[21].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[22].Priority, Is.EqualTo(2)); + Assert.That(priorityMask.NoteList[23].Priority, Is.EqualTo(3)); + Assert.That(priorityMask.NoteList[24].Priority, Is.EqualTo(2)); + Assert.That(priorityMask.NoteList[25].Priority, Is.EqualTo(3)); // проверка длительностей - foreach (var lnote in priorityMask.NoteList) + foreach (ValueNote lnote in priorityMask.NoteList) { - Assert.AreEqual(1, lnote.Duration.Numerator); - Assert.AreEqual(32, lnote.Duration.Denominator); + Assert.That(lnote.Duration.Numerator, Is.EqualTo(1)); + Assert.That(lnote.Duration.Denominator, Is.EqualTo(32)); } } @@ -277,26 +277,26 @@ public void PriorityMaskCalculationThirdTest() [Test] public void PriorityMaskCalculationFourthTest() { - var pd = new PriorityDiscover(); + PriorityDiscover pd = new(); - var notes = new List { note, aNote }; - var measure = new Measure(notes, attributes1); - var priorityMask = pd.CalculatePriorityMask(measure); + List notes = [note, aNote]; + Measure measure = new(notes, attributes1); + Measure priorityMask = pd.CalculatePriorityMask(measure); // так как минимальная длительность ноты в такте 1/4 то маска приоритетов должна разложиться (посчитаться) до 1/4 // размер 3/4, поэтому будет считаться приоритет для 3/4 нот - Assert.AreEqual(0, priorityMask.NoteList[0].Priority); - Assert.AreEqual(2, priorityMask.NoteList[1].Priority); - Assert.AreEqual(1, priorityMask.NoteList[2].Priority); - Assert.AreEqual(2, priorityMask.NoteList[3].Priority); - Assert.AreEqual(1, priorityMask.NoteList[4].Priority); - Assert.AreEqual(2, priorityMask.NoteList[5].Priority); + Assert.That(priorityMask.NoteList[0].Priority, Is.EqualTo(0)); + Assert.That(priorityMask.NoteList[1].Priority, Is.EqualTo(2)); + Assert.That(priorityMask.NoteList[2].Priority, Is.EqualTo(1)); + Assert.That(priorityMask.NoteList[3].Priority, Is.EqualTo(2)); + Assert.That(priorityMask.NoteList[4].Priority, Is.EqualTo(1)); + Assert.That(priorityMask.NoteList[5].Priority, Is.EqualTo(2)); // проверка длительностей - foreach (var lnote in priorityMask.NoteList) + foreach (ValueNote lnote in priorityMask.NoteList) { - Assert.AreEqual(1, lnote.Duration.Numerator); - Assert.AreEqual(8, lnote.Duration.Denominator); + Assert.That(lnote.Duration.Numerator, Is.EqualTo(1)); + Assert.That(lnote.Duration.Denominator, Is.EqualTo(8)); } } @@ -306,25 +306,25 @@ public void PriorityMaskCalculationFourthTest() [Test] public void PriorityDiscoverTest() { - var notes = new List { note, bNote, aNote }; - var notes1 = new List { note, note, note }; - var notes2 = new List { aNote, note, bNote, note, bNote }; - var notes3 = new List { note, dNote, note, note }; - var notes4 = new List { сNote, сNote, сNote, ccNote, ccNote, ccNote }; - var notes5 = new List { сccNote, сccNote, сccNote, сccNote, сccNote, сccNote, сccNote, note, note }; - - var measure = new Measure(notes, attributes); - var measure1 = new Measure(notes1, attributes1); - var measure2 = new Measure(notes2, attributes2); - var measure3 = new Measure(notes3, attributes3); - var measure4 = new Measure(notes4, attributes1); - var measure5 = new Measure(notes5, attributes); - - var prioritydiscover = new PriorityDiscover(); - - Assert.AreEqual(-1, measure.NoteList[0].Priority); - Assert.AreEqual(-1, measure.NoteList[1].Priority); - Assert.AreEqual(-1, measure.NoteList[2].Priority); + List notes = [note, bNote, aNote]; + List notes1 = [note, note, note]; + List notes2 = [aNote, note, bNote, note, bNote]; + List notes3 = [note, dNote, note, note]; + List notes4 = [сNote, сNote, сNote, ccNote, ccNote, ccNote]; + List notes5 = [сccNote, сccNote, сccNote, сccNote, сccNote, сccNote, сccNote, note, note]; + + Measure measure = new(notes, attributes); + Measure measure1 = new(notes1, attributes1); + Measure measure2 = new(notes2, attributes2); + Measure measure3 = new(notes3, attributes3); + Measure measure4 = new(notes4, attributes1); + Measure measure5 = new(notes5, attributes); + + PriorityDiscover prioritydiscover = new(); + + Assert.That(measure.NoteList[0].Priority, Is.EqualTo(-1)); + Assert.That(measure.NoteList[1].Priority, Is.EqualTo(-1)); + Assert.That(measure.NoteList[2].Priority, Is.EqualTo(-1)); prioritydiscover.Calculate(measure); prioritydiscover.Calculate(measure1); @@ -333,44 +333,44 @@ public void PriorityDiscoverTest() prioritydiscover.Calculate(measure4); prioritydiscover.Calculate(measure5); - Assert.AreEqual(0, measure.NoteList[0].Priority); - Assert.AreEqual(2, measure.NoteList[1].Priority); - Assert.AreEqual(1, measure.NoteList[2].Priority); - - Assert.AreEqual(0, measure1.NoteList[0].Priority); - Assert.AreEqual(1, measure1.NoteList[1].Priority); - Assert.AreEqual(1, measure1.NoteList[2].Priority); - - Assert.AreEqual(0, measure2.NoteList[0].Priority); - Assert.AreEqual(1, measure2.NoteList[1].Priority); - Assert.AreEqual(1, measure2.NoteList[2].Priority); - Assert.AreEqual(1, measure2.NoteList[3].Priority); - Assert.AreEqual(1, measure2.NoteList[4].Priority); - - Assert.AreEqual(0, measure3.NoteList[0].Priority); - Assert.AreEqual(1, measure3.NoteList[1].Priority); - Assert.AreEqual(2, measure3.NoteList[2].Priority); - Assert.AreEqual(2, measure3.NoteList[3].Priority); - - Assert.AreEqual(0, measure4.NoteList[0].Priority); - Assert.AreEqual(1, measure4.NoteList[1].Priority); - Assert.AreEqual(1, measure4.NoteList[2].Priority); - Assert.AreEqual(1, measure4.NoteList[3].Priority); - Assert.AreEqual(2, measure4.NoteList[4].Priority); - Assert.AreEqual(2, measure4.NoteList[5].Priority); - - Assert.AreEqual(0, measure5.NoteList[0].Priority); - Assert.AreEqual(3, measure5.NoteList[1].Priority); - Assert.AreEqual(2, measure5.NoteList[2].Priority); - Assert.AreEqual(3, measure5.NoteList[3].Priority); - Assert.AreEqual(3, measure5.NoteList[4].Priority); - Assert.AreEqual(3, measure5.NoteList[5].Priority); - Assert.AreEqual(3, measure5.NoteList[6].Priority); - Assert.AreEqual(1, measure5.NoteList[7].Priority); - Assert.AreEqual(2, measure5.NoteList[8].Priority); - - Assert.AreEqual(-1, note.Priority); - Assert.AreEqual(-1, bNote.Priority); - Assert.AreEqual(-1, aNote.Priority); + Assert.That(measure.NoteList[0].Priority, Is.EqualTo(0)); + Assert.That(measure.NoteList[1].Priority, Is.EqualTo(2)); + Assert.That(measure.NoteList[2].Priority, Is.EqualTo(1)); + + Assert.That(measure1.NoteList[0].Priority, Is.EqualTo(0)); + Assert.That(measure1.NoteList[1].Priority, Is.EqualTo(1)); + Assert.That(measure1.NoteList[2].Priority, Is.EqualTo(1)); + + Assert.That(measure2.NoteList[0].Priority, Is.EqualTo(0)); + Assert.That(measure2.NoteList[1].Priority, Is.EqualTo(1)); + Assert.That(measure2.NoteList[2].Priority, Is.EqualTo(1)); + Assert.That(measure2.NoteList[3].Priority, Is.EqualTo(1)); + Assert.That(measure2.NoteList[4].Priority, Is.EqualTo(1)); + + Assert.That(measure3.NoteList[0].Priority, Is.EqualTo(0)); + Assert.That(measure3.NoteList[1].Priority, Is.EqualTo(1)); + Assert.That(measure3.NoteList[2].Priority, Is.EqualTo(2)); + Assert.That(measure3.NoteList[3].Priority, Is.EqualTo(2)); + + Assert.That(measure4.NoteList[0].Priority, Is.EqualTo(0)); + Assert.That(measure4.NoteList[1].Priority, Is.EqualTo(1)); + Assert.That(measure4.NoteList[2].Priority, Is.EqualTo(1)); + Assert.That(measure4.NoteList[3].Priority, Is.EqualTo(1)); + Assert.That(measure4.NoteList[4].Priority, Is.EqualTo(2)); + Assert.That(measure4.NoteList[5].Priority, Is.EqualTo(2)); + + Assert.That(measure5.NoteList[0].Priority, Is.EqualTo(0)); + Assert.That(measure5.NoteList[1].Priority, Is.EqualTo(3)); + Assert.That(measure5.NoteList[2].Priority, Is.EqualTo(2)); + Assert.That(measure5.NoteList[3].Priority, Is.EqualTo(3)); + Assert.That(measure5.NoteList[4].Priority, Is.EqualTo(3)); + Assert.That(measure5.NoteList[5].Priority, Is.EqualTo(3)); + Assert.That(measure5.NoteList[6].Priority, Is.EqualTo(3)); + Assert.That(measure5.NoteList[7].Priority, Is.EqualTo(1)); + Assert.That(measure5.NoteList[8].Priority, Is.EqualTo(2)); + + Assert.That(note.Priority, Is.EqualTo(-1)); + Assert.That(bNote.Priority, Is.EqualTo(-1)); + Assert.That(aNote.Priority, Is.EqualTo(-1)); } } diff --git a/Libiada.Core.Tests/SpaceReorganizers/NullCycleSpaceReorganizerTests.cs b/Libiada.Core.Tests/SpaceReorganizers/NullCycleSpaceReorganizerTests.cs index 386cf4c0..d5ca4d96 100644 --- a/Libiada.Core.Tests/SpaceReorganizers/NullCycleSpaceReorganizerTests.cs +++ b/Libiada.Core.Tests/SpaceReorganizers/NullCycleSpaceReorganizerTests.cs @@ -33,7 +33,7 @@ public void LevelOneTest() var rebulder = new NullCycleSpaceReorganizer(1); var result = rebulder.Reorganize(testChain); - Assert.AreEqual(cycleTestChainLevel1, result); + Assert.That(result, Is.EqualTo(cycleTestChainLevel1)); } /// @@ -46,6 +46,6 @@ public void LevelFiveTest() var reorganizer = new NullCycleSpaceReorganizer(5); var result = reorganizer.Reorganize(testChain); - Assert.AreEqual(cycleTestChainLevel5, result); + Assert.That(result, Is.EqualTo(cycleTestChainLevel5)); } } diff --git a/Libiada.Core.Tests/SpaceReorganizers/NullReorganizerTests.cs b/Libiada.Core.Tests/SpaceReorganizers/NullReorganizerTests.cs index 3978ecdb..03e99841 100644 --- a/Libiada.Core.Tests/SpaceReorganizers/NullReorganizerTests.cs +++ b/Libiada.Core.Tests/SpaceReorganizers/NullReorganizerTests.cs @@ -38,7 +38,7 @@ public void FromParentToChildTest() { var reorganizer = new NullReorganizer(); var result = reorganizer.Reorganize(chain); - Assert.AreEqual(baseChain, result); + Assert.That(result, Is.EqualTo(baseChain)); } /// @@ -50,6 +50,6 @@ public void FromChildToParentTest() { var reorganizer = new NullReorganizer(); var result = reorganizer.Reorganize(baseChain); - Assert.AreEqual(chain, result); + Assert.That(result, Is.EqualTo(chain)); } } diff --git a/Libiada.Core.Tests/TimeSeries/Aggregators/AverageTests.cs b/Libiada.Core.Tests/TimeSeries/Aggregators/AverageTests.cs index 78280b40..2f7dac53 100644 --- a/Libiada.Core.Tests/TimeSeries/Aggregators/AverageTests.cs +++ b/Libiada.Core.Tests/TimeSeries/Aggregators/AverageTests.cs @@ -11,10 +11,7 @@ public class AverageTests /// /// The distances list. /// - private static readonly List distances = new List() - { - 1, 2, 3, 4, 5 - }; + private static readonly List distances = [1, 2, 3, 4, 5]; /// /// The expected average result. @@ -29,6 +26,6 @@ public void AverageTest() { var aggregator = new Average(); double result = aggregator.Aggregate(distances); - Assert.AreEqual(average, result); + Assert.That(result, Is.EqualTo(average)); } -} \ No newline at end of file +} diff --git a/Libiada.Core.Tests/TimeSeries/Aggregators/DifferenceModuleTests.cs b/Libiada.Core.Tests/TimeSeries/Aggregators/DifferenceModuleTests.cs index a11900f8..14367044 100644 --- a/Libiada.Core.Tests/TimeSeries/Aggregators/DifferenceModuleTests.cs +++ b/Libiada.Core.Tests/TimeSeries/Aggregators/DifferenceModuleTests.cs @@ -11,10 +11,7 @@ public class DifferenceModuleTests /// /// The distances list. /// - private static readonly List distances = new List() - { - 1, 2, 3, 4, 5 - }; + private static readonly List distances = [1, 2, 3, 4, 5]; /// /// The expected difference module value. @@ -29,6 +26,6 @@ public void DifferenceModuleTest() { var aggregator = new DifferenceModule(); double result = aggregator.Aggregate(distances); - Assert.AreEqual(diffMod, result); + Assert.That(result, Is.EqualTo(diffMod)); } -} \ No newline at end of file +} diff --git a/Libiada.Core.Tests/TimeSeries/Aggregators/DifferenceSquareRootTests.cs b/Libiada.Core.Tests/TimeSeries/Aggregators/DifferenceSquareRootTests.cs index b075e16b..8b8d221f 100644 --- a/Libiada.Core.Tests/TimeSeries/Aggregators/DifferenceSquareRootTests.cs +++ b/Libiada.Core.Tests/TimeSeries/Aggregators/DifferenceSquareRootTests.cs @@ -11,10 +11,7 @@ public class DifferenceSquareRootTests /// /// The distances list. /// - private static readonly List distances = new List() - { - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 - }; + private static readonly List distances = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]; /// /// The expected difference square root value. @@ -29,6 +26,6 @@ public void DifferenceSquareRootTest() { var aggregator = new DifferenceSquareRoot(); double result = aggregator.Aggregate(distances); - Assert.AreEqual(diffSqrt, result); + Assert.That(result, Is.EqualTo(diffSqrt)); } -} \ No newline at end of file +} diff --git a/Libiada.Core.Tests/TimeSeries/Aggregators/MaxTests.cs b/Libiada.Core.Tests/TimeSeries/Aggregators/MaxTests.cs index cf0d6198..bab748aa 100644 --- a/Libiada.Core.Tests/TimeSeries/Aggregators/MaxTests.cs +++ b/Libiada.Core.Tests/TimeSeries/Aggregators/MaxTests.cs @@ -11,10 +11,7 @@ public class MaxTests /// /// The distances list. /// - private static readonly List distances = new List() - { - 1, 2, 3, 4, 5 - }; + private static readonly List distances = [1, 2, 3, 4, 5]; /// /// The expected max value. @@ -29,6 +26,6 @@ public void MaxTest() { var aggregator = new Max(); double result = aggregator.Aggregate(distances); - Assert.AreEqual(max, result); + Assert.That(result, Is.EqualTo(max)); } -} \ No newline at end of file +} diff --git a/Libiada.Core.Tests/TimeSeries/Aggregators/MinTests.cs b/Libiada.Core.Tests/TimeSeries/Aggregators/MinTests.cs index 2d89121b..5b86a93d 100644 --- a/Libiada.Core.Tests/TimeSeries/Aggregators/MinTests.cs +++ b/Libiada.Core.Tests/TimeSeries/Aggregators/MinTests.cs @@ -11,10 +11,7 @@ public class MinTests /// /// The distances list. /// - private static readonly List distances = new List() - { - 1, 2, 3, 4, 5 - }; + private static readonly List distances = [1, 2, 3, 4, 5]; /// /// The expected min value. @@ -29,6 +26,6 @@ public void MinTest() { var aggregator = new Min(); double result = aggregator.Aggregate(distances); - Assert.AreEqual(min, result); + Assert.That(result, Is.EqualTo(min)); } -} \ No newline at end of file +} diff --git a/Libiada.Core.Tests/TimeSeries/Aggregators/SumModuleTests.cs b/Libiada.Core.Tests/TimeSeries/Aggregators/SumModuleTests.cs index 1b5bf28b..68ba55ea 100644 --- a/Libiada.Core.Tests/TimeSeries/Aggregators/SumModuleTests.cs +++ b/Libiada.Core.Tests/TimeSeries/Aggregators/SumModuleTests.cs @@ -2,7 +2,6 @@ using Libiada.Core.TimeSeries.Aggregators; - /// /// The sum module aggregator tests. /// @@ -12,10 +11,7 @@ public class SumModuleTests /// /// The distances list. /// - private static readonly List distances = new List() - { - 1, 2, 3, 4, 5 - }; + private static readonly List distances = [1, 2, 3, 4, 5]; /// /// The expected sum mod value. @@ -30,6 +26,6 @@ public void SumModuleTest() { var aggregator = new SumModule(); double result = aggregator.Aggregate(distances); - Assert.AreEqual(sumMod, result); + Assert.That(result, Is.EqualTo(sumMod)); } -} \ No newline at end of file +} diff --git a/Libiada.Core.Tests/TimeSeries/Aggregators/SumSquareRootTests.cs b/Libiada.Core.Tests/TimeSeries/Aggregators/SumSquareRootTests.cs index 26334f57..1a19e07f 100644 --- a/Libiada.Core.Tests/TimeSeries/Aggregators/SumSquareRootTests.cs +++ b/Libiada.Core.Tests/TimeSeries/Aggregators/SumSquareRootTests.cs @@ -11,10 +11,7 @@ public class SumSquareRootTests /// /// The distances list. /// - private static readonly List distances = new List() - { - 1, 2, 3, 4, 5, 6, 7, 8 - }; + private static readonly List distances = [1, 2, 3, 4, 5, 6, 7, 8]; /// /// The expected sum sqrt. @@ -29,6 +26,6 @@ public void SumSquareRootTest() { var aggregator = new SumSquareRoot(); double result = aggregator.Aggregate(distances); - Assert.AreEqual(sumSqrt, result); + Assert.That(result, Is.EqualTo(sumSqrt)); } -} \ No newline at end of file +} diff --git a/Libiada.Core.Tests/TimeSeries/Aligners/AllOffsetsAlignerTests.cs b/Libiada.Core.Tests/TimeSeries/Aligners/AllOffsetsAlignerTests.cs index e3626423..edba6e77 100644 --- a/Libiada.Core.Tests/TimeSeries/Aligners/AllOffsetsAlignerTests.cs +++ b/Libiada.Core.Tests/TimeSeries/Aligners/AllOffsetsAlignerTests.cs @@ -11,20 +11,18 @@ public class AllOffsetsAlignerTests /// The combination tests. /// private static readonly object[][] CombinationTests = - { - new object[] - { + [ + [ new double[] { 1, 2, 3 }, new double[] { 1, 2, 3, 4, 5 }, - new[] { new double[] { 1, 2, 3 }, new double[] { 1, 2, 3 }, new double[] { 1, 2, 3 } }, - new[] { new double[] { 1, 2, 3 }, new double[] { 2, 3, 4 }, new double[] { 3, 4, 5 } } - }, - new object[] - { + new[] { new double[] { 1, 2, 3 }, [1, 2, 3], [1, 2, 3] }, + new[] { new double[] { 1, 2, 3 }, [2, 3, 4], [3, 4, 5] } + ], + [ new double[] { 1, 2, 3, 4, 5, 6 }, new double[] { 1, 2, 3 }, - new[] { new double[] { 1, 2, 3 }, new double[] { 2, 3, 4 }, new double[] { 3, 4, 5 }, new double[] { 4, 5, 6 } }, - new[] { new double[] { 1, 2, 3 }, new double[] { 1, 2, 3 }, new double[] { 1, 2, 3 }, new double[] { 1, 2, 3 } } - } - }; + new[] { new double[] { 1, 2, 3 }, [2, 3, 4], [3, 4, 5], [4, 5, 6] }, + new[] { new double[] { 1, 2, 3 }, [1, 2, 3], [1, 2, 3], [1, 2, 3] } + ] + ]; /// /// The all offsets align test. @@ -41,13 +39,16 @@ public class AllOffsetsAlignerTests /// /// The second Expected. /// - [TestCaseSource("CombinationTests")] + [TestCaseSource(nameof(CombinationTests))] public void AllOffsetsAlignTest(double[] firstSeries, double[] secondSeries, double[][] firstExpected, double[][] secondExpected) { var aligner = new AllOffsetsAligner(); - var result = aligner.AlignSeries(firstSeries, secondSeries); - Assert.AreEqual(firstExpected, result.first); - Assert.AreEqual(secondExpected, result.second); + var (first, second) = aligner.AlignSeries(firstSeries, secondSeries); + Assert.Multiple(() => + { + Assert.That(first, Is.EqualTo(firstExpected)); + Assert.That(second, Is.EqualTo(secondExpected)); + }); } -} \ No newline at end of file +} diff --git a/Libiada.Core.Tests/TimeSeries/Aligners/ByShortestAlignerTests.cs b/Libiada.Core.Tests/TimeSeries/Aligners/ByShortestAlignerTests.cs index 8256830a..4590234b 100644 --- a/Libiada.Core.Tests/TimeSeries/Aligners/ByShortestAlignerTests.cs +++ b/Libiada.Core.Tests/TimeSeries/Aligners/ByShortestAlignerTests.cs @@ -11,17 +11,17 @@ public class ByShortestAlignerTests /// /// The short time series. /// - private readonly double[] shortTimeSeries = { 1.01, 2, 5, 17.3 }; + private readonly double[] shortTimeSeries = [1.01, 2, 5, 17.3]; /// /// The long time series. /// - private readonly double[] longTimeSeries = { 1.3, 2, 5, 17.4, 12, 23 }; + private readonly double[] longTimeSeries = [1.3, 2, 5, 17.4, 12, 23]; /// /// The expected sub array. /// - private readonly double[] expectedSubArray = { 1.3, 2, 5, 17.4 }; + private readonly double[] expectedSubArray = [1.3, 2, 5, 17.4]; /// /// The shortest align test. @@ -31,8 +31,8 @@ public void ShortestAlignTest() { var aligner = new ByShortestAligner(); var result = aligner.AlignSeries(shortTimeSeries, longTimeSeries); - Assert.AreEqual(result.first[0].Length, result.second[0].Length); - Assert.AreEqual(shortTimeSeries, result.first[0]); - Assert.AreEqual(expectedSubArray, result.second[0]); + Assert.That(result.second[0], Has.Length.EqualTo(result.first[0].Length)); + Assert.That(result.first[0], Is.EqualTo(shortTimeSeries)); + Assert.That(result.second[0], Is.EqualTo(expectedSubArray)); } -} \ No newline at end of file +} diff --git a/Libiada.Core.Tests/TimeSeries/Aligners/ByShortestFromRightAlignerTests.cs b/Libiada.Core.Tests/TimeSeries/Aligners/ByShortestFromRightAlignerTests.cs index 1c58caf1..27c3ce4f 100644 --- a/Libiada.Core.Tests/TimeSeries/Aligners/ByShortestFromRightAlignerTests.cs +++ b/Libiada.Core.Tests/TimeSeries/Aligners/ByShortestFromRightAlignerTests.cs @@ -11,22 +11,22 @@ public class ByShortestFromRightAlignerTests /// /// The shortest time series. /// - private readonly double[] shortTimeSeries = { 1, 2, 3 }; + private readonly double[] shortTimeSeries = [1, 2, 3]; /// /// The longest time series. /// - private readonly double[] longTimeSeries = { 1, 2, 3, 4, 5 }; + private readonly double[] longTimeSeries = [1, 2, 3, 4, 5]; /// /// The first. /// - private readonly double[] first = { 1, 2, 3 }; + private readonly double[] first = [1, 2, 3]; /// /// The expected sub array. /// - private readonly double[] second = { 3, 4, 5 }; + private readonly double[] second = [3, 4, 5]; /// /// The shortest from right align test. @@ -37,7 +37,7 @@ public void ShortestFromRightAlignTest() var aligner = new ByShortestFromRightAligner(); var result = aligner.AlignSeries(shortTimeSeries, longTimeSeries); - Assert.AreEqual(shortTimeSeries, result.first[0]); - Assert.AreEqual(second, result.second[0]); + Assert.That(result.first[0], Is.EqualTo(shortTimeSeries)); + Assert.That(result.second[0], Is.EqualTo(second)); } -} \ No newline at end of file +} diff --git a/Libiada.Core.Tests/TimeSeries/Aligners/FirstElementDuplicatorTests.cs b/Libiada.Core.Tests/TimeSeries/Aligners/FirstElementDuplicatorTests.cs index eda23289..2029883e 100644 --- a/Libiada.Core.Tests/TimeSeries/Aligners/FirstElementDuplicatorTests.cs +++ b/Libiada.Core.Tests/TimeSeries/Aligners/FirstElementDuplicatorTests.cs @@ -1,7 +1,5 @@ namespace Libiada.Core.Tests.TimeSeries.Aligners; -using System.Diagnostics; - using Libiada.Core.TimeSeries.Aligners; @@ -15,10 +13,10 @@ public class FirstElementDuplicatorTests /// The combination tests. /// private static readonly object[][] CombinationTests = - { - new object[] { new double[] { 1, 2, 3 }, new double[] { 1, 2, 3, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6 }, new double[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3 } }, - new object[] { new double[] { 1, 2, 3, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6 }, new double[] { 1, 2, 3 }, new double[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3 } } - }; + [ + [new double[] { 1, 2, 3 }, new double[] { 1, 2, 3, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6 }, new double[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3 }], + [new double[] { 1, 2, 3, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6 }, new double[] { 1, 2, 3 }, new double[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3 }] + ]; /// /// The first element duplication aligner test. @@ -32,18 +30,13 @@ public class FirstElementDuplicatorTests /// /// The expected. /// - [TestCaseSource("CombinationTests")] + [TestCaseSource(nameof(CombinationTests))] public void FirstElementDuplicationAlignerTest(double[] firstTimeSeries, double[] secondTimeSeries, double[] expected) { - Stopwatch timer = new Stopwatch(); - timer.Start(); var aligner = new FirstElementDuplicator(); - var result = aligner.AlignSeries(firstTimeSeries, secondTimeSeries); - timer.Stop(); - Console.WriteLine("Time elapsed: (ms) : {0}", timer.Elapsed.TotalMilliseconds); - Assert.AreEqual( - expected, - firstTimeSeries.Length < secondTimeSeries.Length ? result.first[0] : result.second[0]); + var (first, second) = aligner.AlignSeries(firstTimeSeries, secondTimeSeries); + var actual = firstTimeSeries.Length < secondTimeSeries.Length ? first[0] : second[0]; + Assert.That(actual, Is.EqualTo(expected)); } -} \ No newline at end of file +} diff --git a/Libiada.Core.Tests/TimeSeries/Aligners/LastElementDuplicatorTests.cs b/Libiada.Core.Tests/TimeSeries/Aligners/LastElementDuplicatorTests.cs index 8181354b..48259f33 100644 --- a/Libiada.Core.Tests/TimeSeries/Aligners/LastElementDuplicatorTests.cs +++ b/Libiada.Core.Tests/TimeSeries/Aligners/LastElementDuplicatorTests.cs @@ -1,7 +1,5 @@ namespace Libiada.Core.Tests.TimeSeries.Aligners; -using System.Diagnostics; - using Libiada.Core.TimeSeries.Aligners; /// @@ -13,10 +11,10 @@ public class LastElementDuplicatorTests /// The combination tests. /// private static readonly object[][] CombinationTests = - { - new object[] { new double[] { 1, 2, 3 }, new double[] { 1, 2, 3, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6 }, new double[] { 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 } }, - new object[] { new double[] { 1, 2, 3, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6 }, new double[] { 1, 2, 3 }, new double[] { 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 } } - }; + [ + [new double[] { 1, 2, 3 }, new double[] { 1, 2, 3, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6 }, new double[] { 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }], + [new double[] { 1, 2, 3, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6 }, new double[] { 1, 2, 3 }, new double[] { 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }] + ]; /// /// The last element duplication aligner test. @@ -30,18 +28,13 @@ public class LastElementDuplicatorTests /// /// The expected. /// - [TestCaseSource("CombinationTests")] + [TestCaseSource(nameof(CombinationTests))] public void LastElementDuplicationAlignerTest(double[] firstTimeSeries, double[] secondTimeSeries, double[] expected) { - Stopwatch timer = new Stopwatch(); - timer.Start(); var aligner = new LastElementDuplicator(); - var result = aligner.AlignSeries(firstTimeSeries, secondTimeSeries); - timer.Stop(); - Console.WriteLine("Time elapsed: (ms) : {0}", timer.Elapsed.TotalMilliseconds); - Assert.AreEqual( - expected, - firstTimeSeries.Length < secondTimeSeries.Length ? result.first[0] : result.second[0]); + var (first, second) = aligner.AlignSeries(firstTimeSeries, secondTimeSeries); + var actual = firstTimeSeries.Length < secondTimeSeries.Length ? first[0] : second[0]; + Assert.That(actual, Is.EqualTo(expected)); } -} \ No newline at end of file +} diff --git a/Libiada.Core.Tests/TimeSeries/OneDimensional/ComparersTests/OneDimensionalTimeSeriesComparerTests.cs b/Libiada.Core.Tests/TimeSeries/OneDimensional/ComparersTests/OneDimensionalTimeSeriesComparerTests.cs index 62e17ee0..98179747 100644 --- a/Libiada.Core.Tests/TimeSeries/OneDimensional/ComparersTests/OneDimensionalTimeSeriesComparerTests.cs +++ b/Libiada.Core.Tests/TimeSeries/OneDimensional/ComparersTests/OneDimensionalTimeSeriesComparerTests.cs @@ -15,314 +15,272 @@ public class OneDimensionalTimeSeriesComparerTests /// The combination_tests sources. /// private static readonly object[][] CombinationTests = - { + [ // ByShortestAligner tests with Euclidean distance calculator - new object[] - { + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new ByShortestAligner(), new EuclideanDistanceBetweenOneDimensionalPointsCalculator(), new Average() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new ByShortestAligner(), new EuclideanDistanceBetweenOneDimensionalPointsCalculator(), new DifferenceModule() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new ByShortestAligner(), new EuclideanDistanceBetweenOneDimensionalPointsCalculator(), new DifferenceSquareRoot() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new ByShortestAligner(), new EuclideanDistanceBetweenOneDimensionalPointsCalculator(), new Max(), - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new ByShortestAligner(), new EuclideanDistanceBetweenOneDimensionalPointsCalculator(), new Min() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new ByShortestAligner(), new EuclideanDistanceBetweenOneDimensionalPointsCalculator(), new SumModule() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new ByShortestAligner(), new EuclideanDistanceBetweenOneDimensionalPointsCalculator(), new SumSquareRoot() - }, + ], // ByShortestAligner tests with Hamming distance calculator - new object[] - { + [ new double[] { -1, -2, -3, -4, -5 }, new double[] { 1, 2, 3, 4, 5 }, 1, new ByShortestAligner(), new HammingDistanceBetweenOneDimensionalPointsCalculator(), new Average() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new ByShortestAligner(), new HammingDistanceBetweenOneDimensionalPointsCalculator(), new DifferenceModule() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new ByShortestAligner(), new HammingDistanceBetweenOneDimensionalPointsCalculator(), new DifferenceSquareRoot() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new[] { 1.12345, 2.12345, 3.12345, 4.12345, 5.123456 }, 6, new ByShortestAligner(), new HammingDistanceBetweenOneDimensionalPointsCalculator(), new Max() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new ByShortestAligner(), new HammingDistanceBetweenOneDimensionalPointsCalculator(), new Min() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new ByShortestAligner(), new HammingDistanceBetweenOneDimensionalPointsCalculator(), new SumModule() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new ByShortestAligner(), new HammingDistanceBetweenOneDimensionalPointsCalculator(), new SumSquareRoot() - }, + ], // ByShortestFromRightAligner tests with Euclidean distance calculator - new object[] - { + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 2, 3, 4, 5, 6 }, 1, new ByShortestFromRightAligner(), new EuclideanDistanceBetweenOneDimensionalPointsCalculator(), new Average() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new ByShortestFromRightAligner(), new EuclideanDistanceBetweenOneDimensionalPointsCalculator(), new DifferenceModule() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new ByShortestFromRightAligner(), new EuclideanDistanceBetweenOneDimensionalPointsCalculator(), new DifferenceSquareRoot() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new ByShortestFromRightAligner(), new EuclideanDistanceBetweenOneDimensionalPointsCalculator(), new Max() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new ByShortestFromRightAligner(), new EuclideanDistanceBetweenOneDimensionalPointsCalculator(), new Min() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new ByShortestFromRightAligner(), new EuclideanDistanceBetweenOneDimensionalPointsCalculator(), new SumModule() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new ByShortestFromRightAligner(), new EuclideanDistanceBetweenOneDimensionalPointsCalculator(), new SumSquareRoot() - }, + ], // ByShortestFromRightAligner tests with Hamming distance calculator - new object[] - { + [ new double[] { 1, 2, 3, 4, 5 }, new[] { 1.01234, 2.01234, 3.01234, 4.01234, 5.01234 }, 4, new ByShortestFromRightAligner(), new HammingDistanceBetweenOneDimensionalPointsCalculator(), new Average() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new ByShortestFromRightAligner(), new HammingDistanceBetweenOneDimensionalPointsCalculator(), new DifferenceModule() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new ByShortestFromRightAligner(), new HammingDistanceBetweenOneDimensionalPointsCalculator(), new DifferenceSquareRoot() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new ByShortestFromRightAligner(), new HammingDistanceBetweenOneDimensionalPointsCalculator(), new Max() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new ByShortestFromRightAligner(), new HammingDistanceBetweenOneDimensionalPointsCalculator(), new Min() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new ByShortestFromRightAligner(), new HammingDistanceBetweenOneDimensionalPointsCalculator(), new SumModule() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new ByShortestFromRightAligner(), new HammingDistanceBetweenOneDimensionalPointsCalculator(), new SumSquareRoot() - }, + ], // AllOffsetsAligner tests with Euclidean distance calculator - new object[] - { + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new AllOffsetsAligner(), new EuclideanDistanceBetweenOneDimensionalPointsCalculator(), new Average() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new AllOffsetsAligner(), new EuclideanDistanceBetweenOneDimensionalPointsCalculator(), new DifferenceModule() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new AllOffsetsAligner(), new EuclideanDistanceBetweenOneDimensionalPointsCalculator(), new DifferenceSquareRoot() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new AllOffsetsAligner(), new EuclideanDistanceBetweenOneDimensionalPointsCalculator(), new Max() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new AllOffsetsAligner(), new EuclideanDistanceBetweenOneDimensionalPointsCalculator(), new Min() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new AllOffsetsAligner(), new EuclideanDistanceBetweenOneDimensionalPointsCalculator(), new SumModule() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new AllOffsetsAligner(), new EuclideanDistanceBetweenOneDimensionalPointsCalculator(), new SumSquareRoot() - }, + ], // AllOffsetsAligner tests with Hamming distance calculator - new object[] - { + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new AllOffsetsAligner(), new HammingDistanceBetweenOneDimensionalPointsCalculator(), new Average() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new AllOffsetsAligner(), new HammingDistanceBetweenOneDimensionalPointsCalculator(), new DifferenceModule() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new AllOffsetsAligner(), new HammingDistanceBetweenOneDimensionalPointsCalculator(), new DifferenceSquareRoot() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new AllOffsetsAligner(), new HammingDistanceBetweenOneDimensionalPointsCalculator(), new Max() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new AllOffsetsAligner(), new HammingDistanceBetweenOneDimensionalPointsCalculator(), new Min() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new AllOffsetsAligner(), new HammingDistanceBetweenOneDimensionalPointsCalculator(), new SumModule() - }, - new object[] - { + ], + [ new double[] { 1, 2, 3, 4, 5 }, new double[] { 1, 2, 3, 4, 5 }, 0, new AllOffsetsAligner(), new HammingDistanceBetweenOneDimensionalPointsCalculator(), new SumSquareRoot() - } - }; + ] + ]; /// /// The time series compare generalized test. @@ -345,7 +303,7 @@ public class OneDimensionalTimeSeriesComparerTests /// /// The aggregator. /// - [TestCaseSource("CombinationTests")] + [TestCaseSource(nameof(CombinationTests))] public void CompareTest( double[] firstSeries, @@ -357,6 +315,6 @@ public void CompareTest( { var comparer = new OneDimensionalTimeSeriesComparer(aligner, calculator, aggregator); double result = comparer.GetDistance(firstSeries, secondSeries); - Assert.AreEqual(result, expected); + Assert.That(result, Is.EqualTo(expected)); } -} \ No newline at end of file +} diff --git a/Libiada.Core.Tests/TimeSeries/OneDimensional/DistanceCalculatorsTests/EuclideanDistanceBetweenOneDimensionalPointsTests.cs b/Libiada.Core.Tests/TimeSeries/OneDimensional/DistanceCalculatorsTests/EuclideanDistanceBetweenOneDimensionalPointsTests.cs index 8b7ac7c4..41fd4654 100644 --- a/Libiada.Core.Tests/TimeSeries/OneDimensional/DistanceCalculatorsTests/EuclideanDistanceBetweenOneDimensionalPointsTests.cs +++ b/Libiada.Core.Tests/TimeSeries/OneDimensional/DistanceCalculatorsTests/EuclideanDistanceBetweenOneDimensionalPointsTests.cs @@ -28,6 +28,6 @@ public void EuclideanDistanceTest(double firstPoint, double secondPoint, double { var calculator = new EuclideanDistanceBetweenOneDimensionalPointsCalculator(); double result = calculator.GetDistance(firstPoint, secondPoint); - Assert.AreEqual(result, expectedDistance); + Assert.That(result, Is.EqualTo(expectedDistance)); } -} \ No newline at end of file +} diff --git a/Libiada.Core.Tests/TimeSeries/OneDimensional/DistanceCalculatorsTests/HammingDistanceBetweenOneDimensionalPointsTests.cs b/Libiada.Core.Tests/TimeSeries/OneDimensional/DistanceCalculatorsTests/HammingDistanceBetweenOneDimensionalPointsTests.cs index 8d7865aa..4314f3e2 100644 --- a/Libiada.Core.Tests/TimeSeries/OneDimensional/DistanceCalculatorsTests/HammingDistanceBetweenOneDimensionalPointsTests.cs +++ b/Libiada.Core.Tests/TimeSeries/OneDimensional/DistanceCalculatorsTests/HammingDistanceBetweenOneDimensionalPointsTests.cs @@ -30,6 +30,6 @@ public void HammingDistanceTest(double firstPoint, double secondPoint, int expec { var calculator = new HammingDistanceBetweenOneDimensionalPointsCalculator(); double result = calculator.GetDistance(firstPoint, secondPoint); - Assert.AreEqual(result, expectedDistance); + Assert.That(result, Is.EqualTo(expectedDistance)); } -} \ No newline at end of file +} diff --git a/Libiada.Core/Core/ArrangementManagers/NullArrangementManager.cs b/Libiada.Core/Core/ArrangementManagers/NullArrangementManager.cs index b45ce839..11d2a8ad 100644 --- a/Libiada.Core/Core/ArrangementManagers/NullArrangementManager.cs +++ b/Libiada.Core/Core/ArrangementManagers/NullArrangementManager.cs @@ -16,6 +16,6 @@ public class NullArrangementManager : IArrangementManager /// public int[] GetArrangement(Link link) { - return Array.Empty(); + return []; } } diff --git a/Libiada.Core/Core/BaseChain.cs b/Libiada.Core/Core/BaseChain.cs index 1a79bd4d..7817dbb4 100644 --- a/Libiada.Core/Core/BaseChain.cs +++ b/Libiada.Core/Core/BaseChain.cs @@ -216,7 +216,7 @@ public override void Set(IBaseObject item, int index) IBaseObject[] chain = ToArray(); chain[index] = item; - alphabet = new Alphabet { NullValue.Instance() }; + alphabet = [NullValue.Instance()]; FillAlphabetAndOrder(chain); } @@ -231,6 +231,8 @@ public override void RemoveAt(int index) { order[index] = 0; + if (VerifyOrder()) return; + throw new NotImplementedException(); // TODO: remove element from alphabet if last entry is removed. } @@ -244,6 +246,8 @@ public override void DeleteAt(int index) { order = order.DeleteAt(index); + if (VerifyOrder()) return; + throw new NotImplementedException(); // TODO: remove element from alphabet if last entry is removed. } @@ -264,7 +268,7 @@ public override void ClearAndSetNewLength(int length) } order = new int[length]; - alphabet = new Alphabet { NullValue.Instance() }; + alphabet = [NullValue.Instance()]; } /// @@ -352,4 +356,16 @@ private void FillAlphabetAndOrder(IReadOnlyList elements) order[i] = elementIndex; } } + + private bool VerifyOrder() + { + int counter = 0; + for(int i = 0; i < order.Length; i++) + { + if (counter + 1 < order[i]) return false; + if (counter + 1 == order[i]) counter++; + } + + return true; + } } diff --git a/Libiada.Core/Libiada.Core.csproj b/Libiada.Core/Libiada.Core.csproj index d86e6af0..ccb53084 100644 --- a/Libiada.Core/Libiada.Core.csproj +++ b/Libiada.Core/Libiada.Core.csproj @@ -7,7 +7,7 @@ - + diff --git a/Libiada.MarkovChains.Tests/Libiada.MarkovChains.Tests.csproj b/Libiada.MarkovChains.Tests/Libiada.MarkovChains.Tests.csproj index c20b2d88..30db7ee1 100644 --- a/Libiada.MarkovChains.Tests/Libiada.MarkovChains.Tests.csproj +++ b/Libiada.MarkovChains.Tests/Libiada.MarkovChains.Tests.csproj @@ -7,9 +7,13 @@ - - - + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/Libiada.MarkovChains.Tests/MarkovChain/MarkovChainNotCongenericStaticTests.cs b/Libiada.MarkovChains.Tests/MarkovChain/MarkovChainNotCongenericStaticTests.cs index 9cf9c34d..0e3255b3 100644 --- a/Libiada.MarkovChains.Tests/MarkovChain/MarkovChainNotCongenericStaticTests.cs +++ b/Libiada.MarkovChains.Tests/MarkovChain/MarkovChainNotCongenericStaticTests.cs @@ -111,7 +111,7 @@ public void MarkovChainNotCongenericZeroRankTwoTest() // "a" 0.71; // "a" 0.2; - Assert.AreEqual(resultTheory, temp); + Assert.That(resultTheory, Is.EqualTo(temp)); } /// @@ -213,7 +213,7 @@ public void MarkovChainNotCongenericOneRangTwoTest() // 1 chain. . 0.77 // 2 chain. . 0.15 b - Assert.AreEqual(result, temp); + Assert.That(result, Is.EqualTo(temp)); } /// diff --git a/Libiada.MarkovChains.Tests/MarkovChain/Matrices/Probability/ProbabilityMatrixTests.cs b/Libiada.MarkovChains.Tests/MarkovChain/Matrices/Probability/ProbabilityMatrixTests.cs index 6f5d905b..64cbbe47 100644 --- a/Libiada.MarkovChains.Tests/MarkovChain/Matrices/Probability/ProbabilityMatrixTests.cs +++ b/Libiada.MarkovChains.Tests/MarkovChain/Matrices/Probability/ProbabilityMatrixTests.cs @@ -65,7 +65,7 @@ public class ProbabilityMatrixTests [SetUp] public void Initialize() { - alphabet = new Alphabet(); + alphabet = []; a = new ValueString('a'); b = new ValueString('b'); c = new ValueString('c'); @@ -81,7 +81,7 @@ public void Initialize() [Test] public void AddLengthMoreThanChainRankTest() { - alphabet = new Alphabet { a, b, c, d }; + alphabet = [a, b, c, d]; baseChain = new BaseChain("abb"); @@ -148,24 +148,24 @@ public void GetWithIndexesTest() arrayToTeach = new int[2]; arrayToTeach[0] = alphabet.IndexOf(ch1[0]); arrayToTeach[1] = alphabet.IndexOf(ch1[1]); - Assert.AreEqual(2, matrix.FrequencyFromObject(arrayToTeach)); + Assert.That(matrix.FrequencyFromObject(arrayToTeach), Is.EqualTo(2)); arrayToTeach = new int[2]; arrayToTeach[0] = alphabet.IndexOf(ch4[0]); arrayToTeach[1] = alphabet.IndexOf(ch4[1]); - Assert.AreEqual(0, matrix.FrequencyFromObject(arrayToTeach)); + Assert.That(matrix.FrequencyFromObject(arrayToTeach), Is.EqualTo(0)); arrayToTeach = new int[1]; arrayToTeach[0] = alphabet.IndexOf(ch5[0]); - Assert.AreEqual(3, matrix.FrequencyFromObject(arrayToTeach)); + Assert.That(matrix.FrequencyFromObject(arrayToTeach), Is.EqualTo(3)); arrayToTeach = new int[1]; arrayToTeach[0] = alphabet.IndexOf(ch6[0]); - Assert.AreEqual(1, matrix.FrequencyFromObject(arrayToTeach)); + Assert.That(matrix.FrequencyFromObject(arrayToTeach), Is.EqualTo(1)); arrayToTeach = new int[1]; arrayToTeach[0] = alphabet.IndexOf(ch7[0]); - Assert.AreEqual(2, matrix.FrequencyFromObject(arrayToTeach)); + Assert.That(matrix.FrequencyFromObject(arrayToTeach), Is.EqualTo(2)); } /// @@ -195,204 +195,204 @@ public void GetThirdLevelChainTest() var toGet = new int[1]; toGet[0] = testChain.Alphabet.IndexOf((ValueString)"a"); - Assert.AreEqual(6, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(6)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(3, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(3)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"c"); - Assert.AreEqual(2, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(2)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"d"); - Assert.AreEqual(1, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(1)); toGet = new int[2]; toGet[0] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"a"); - Assert.AreEqual(3, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(3)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(0, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"c"); - Assert.AreEqual(2, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(2)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"d"); - Assert.AreEqual(1, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(1)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"a"); - Assert.AreEqual(2, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(2)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(1, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(1)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"c"); - Assert.AreEqual(0, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"d"); - Assert.AreEqual(0, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"a"); - Assert.AreEqual(1, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(1)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(1, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(1)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"c"); - Assert.AreEqual(0, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"d"); - Assert.AreEqual(0, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"a"); - Assert.AreEqual(0, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(1, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(1)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"c"); - Assert.AreEqual(0, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"d"); - Assert.AreEqual(0, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet = new int[3]; toGet[0] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"c"); - Assert.AreEqual(2, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(2)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"d"); - Assert.AreEqual(1, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(1)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"a"); - Assert.AreEqual(1, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(1)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(1, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(1)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(1, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(1)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(0, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"a"); - Assert.AreEqual(2, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(2)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"c"); - Assert.AreEqual(0, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"a"); - Assert.AreEqual(1, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(1)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(0, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(0, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(0, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"a"); - Assert.AreEqual(1, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(1)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(1, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(1)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"a"); - Assert.AreEqual(0, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(0, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(0, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"c"); - Assert.AreEqual(0, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"a"); - Assert.AreEqual(1, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(1)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(0, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"a"); - Assert.AreEqual(0, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(0, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(0, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(0, matrix.FrequencyFromObject(toGet)); + Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(0)); } /// @@ -424,204 +424,204 @@ public void GetProbabilityMatrixTest() var toGet = new int[1]; toGet[0] = testChain.Alphabet.IndexOf((ValueString)"a"); - Assert.AreEqual(0.5, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0.5)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(0.25, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0.25)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"c"); - Assert.AreEqual(1 / (double)6, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0.1666666667d).Within(0.0000000001d)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"d"); - Assert.AreEqual(1 / (double)12, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0.0833333333).Within(0.0000000001d)); toGet = new int[2]; toGet[0] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"a"); - Assert.AreEqual(0.5, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0.5)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(0, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"c"); - Assert.AreEqual(1 / (double)3, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0.3333333333).Within(0.0000000001d)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"d"); - Assert.AreEqual(1 / (double)6, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0.1666666667d).Within(0.0000000001d)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"a"); - Assert.AreEqual(2 / (double)3, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0.6666666667).Within(0.0000000001d)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(1 / (double)3, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0.3333333333).Within(0.0000000001d)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"c"); - Assert.AreEqual(0, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"d"); - Assert.AreEqual(0, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"a"); - Assert.AreEqual(0.5, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0.5)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(0.5, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0.5)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"c"); - Assert.AreEqual(0, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"d"); - Assert.AreEqual(0, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"a"); - Assert.AreEqual(0, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(1, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(1)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"c"); - Assert.AreEqual(0, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"d"); - Assert.AreEqual(0, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet = new int[3]; toGet[0] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"c"); - Assert.AreEqual(2 / (double)3, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0.6666666667).Within(0.0000000001d)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"d"); - Assert.AreEqual(1 / (double)3, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0.3333333333).Within(0.0000000001d)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"a"); - Assert.AreEqual(0.5, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0.5)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(0.5, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0.5)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(1, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(1)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(0, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"a"); - Assert.AreEqual(1, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(1)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"c"); - Assert.AreEqual(0, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"a"); - Assert.AreEqual(1, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(1)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(0, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(0, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(0, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"a"); - Assert.AreEqual(1, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(1)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(1, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(1)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"a"); - Assert.AreEqual(0, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(0, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(0, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"c"); - Assert.AreEqual(0, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"a"); - Assert.AreEqual(1, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(1)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(0, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"a"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"a"); - Assert.AreEqual(0, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"c"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(0, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(0, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"d"); toGet[1] = testChain.Alphabet.IndexOf((ValueString)"b"); toGet[2] = testChain.Alphabet.IndexOf((ValueString)"b"); - Assert.AreEqual(0, probabilityMatrix.FrequencyFromObject(toGet)); + Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0)); } /// diff --git a/Libiada.MarkovChains.Tests/MarkovCompare/MarkovMetricsTests.cs b/Libiada.MarkovChains.Tests/MarkovCompare/MarkovMetricsTests.cs index 2944f38e..90c27049 100644 --- a/Libiada.MarkovChains.Tests/MarkovCompare/MarkovMetricsTests.cs +++ b/Libiada.MarkovChains.Tests/MarkovCompare/MarkovMetricsTests.cs @@ -35,6 +35,6 @@ public void CompareSameChainTest() var markov = new MarkovChainNotCongenericStatic(2, 0, new MockGenerator()); markov.Teach(testChain, TeachingMethod.Cycle); var ma = new MarkovMetrics(); - Assert.AreEqual(ma.GetArithmeticalMean(markov), ma.GetArithmeticalMean(markov)); + Assert.That(ma.GetArithmeticalMean(markov), Is.EqualTo(ma.GetArithmeticalMean(markov))); } } diff --git a/Libiada.PhantomChains.Tests/Libiada.PhantomChains.Tests.csproj b/Libiada.PhantomChains.Tests/Libiada.PhantomChains.Tests.csproj index 048e7565..aa5ceee8 100644 --- a/Libiada.PhantomChains.Tests/Libiada.PhantomChains.Tests.csproj +++ b/Libiada.PhantomChains.Tests/Libiada.PhantomChains.Tests.csproj @@ -7,9 +7,13 @@ - - - + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/Libiada.PhantomChains.Tests/PhantomChainGeneratorTests.cs b/Libiada.PhantomChains.Tests/PhantomChainGeneratorTests.cs index 3d51c19e..09831f15 100644 --- a/Libiada.PhantomChains.Tests/PhantomChainGeneratorTests.cs +++ b/Libiada.PhantomChains.Tests/PhantomChainGeneratorTests.cs @@ -34,13 +34,12 @@ public void Initialize() [Test] public void FirstTest() { - var resultChain = new BaseChain(new[] { 1, 2, 2, 1, 2, 1, 2, 1, 2, 2 }, - new Alphabet() { NullValue.Instance(), mother.PhantomMessageBc[1], mother.PhantomMessageA[0] }); + var resultChain = new BaseChain([1, 2, 2, 1, 2, 1, 2, 1, 2, 2], [NullValue.Instance(), mother.PhantomMessageBc[1], mother.PhantomMessageA[0]]); var gen = new PhantomChainGenerator(mother.SourceChain, new MockGenerator()); - List res = gen.Generate(1); - Assert.AreEqual(res.Count, 1); - Assert.AreEqual(resultChain, res[0]); + List result = gen.Generate(1); + Assert.That(result, Has.Count.EqualTo(1)); + Assert.That(result[0], Is.EqualTo(resultChain)); } /// @@ -50,12 +49,12 @@ public void FirstTest() public void SecondTest() { var resultChain = new BaseChain( - new [] { 1, 2, 1, 2, 3 }, - new Alphabet(){NullValue.Instance(), mother.PhantomMessageBc[1], mother.PhantomMessageA[0], mother.PhantomMessageBc[0] }); + [1, 2, 1, 2, 3], + [NullValue.Instance(), mother.PhantomMessageBc[1], mother.PhantomMessageA[0], mother.PhantomMessageBc[0]]); var gen = new PhantomChainGenerator(mother.UnnormalizedChain, new MockGenerator()); - List res = gen.Generate(1); - Assert.AreEqual(1, res.Count); - Assert.AreEqual(resultChain, res[0]); + List result = gen.Generate(1); + Assert.That(result, Has.Count.EqualTo(1)); + Assert.That(result[0], Is.EqualTo(resultChain)); } /// @@ -73,8 +72,8 @@ public void ThirdTest() } var gen = new PhantomChainGenerator(resultChain, new SimpleGenerator()); - List res = gen.Generate(3000); - Assert.AreEqual(res.Count, 3000); + List result = gen.Generate(3000); + Assert.That(result, Has.Count.EqualTo(3000)); } /// @@ -105,7 +104,7 @@ public void FourthTest() } } - Assert.AreEqual(0, counter); + Assert.That(counter, Is.EqualTo(0)); } /// @@ -117,7 +116,7 @@ public void SixthTest() var sourceChain = new BaseChain(new List() { (ValueString)"X", (ValueString)"S", (ValueString)"C" }); BaseChain forBuild = DnaTransformer.Decode(sourceChain); var gen = new PhantomChainGenerator(forBuild, new SimpleGenerator()); - List res = gen.Generate(1); - Assert.AreEqual(9, res[0].Length); + List result = gen.Generate(1); + Assert.That(result[0].Length, Is.EqualTo(9)); } } diff --git a/Libiada.PhantomChains.Tests/PhantomTableTests.cs b/Libiada.PhantomChains.Tests/PhantomTableTests.cs index 3d08b8e0..5a95ce8e 100644 --- a/Libiada.PhantomChains.Tests/PhantomTableTests.cs +++ b/Libiada.PhantomChains.Tests/PhantomTableTests.cs @@ -15,18 +15,21 @@ public class PhantomTableTests [Test] public void VolumeTest() { - var m3 = new ValuePhantom { new ValueString('a') }; - var m1 = new ValuePhantom { new ValueString('1'), new ValueString('2'), new ValueString('3') }; - var m2 = new ValuePhantom { new ValueString('4'), new ValueString('3') }; + ValuePhantom m3 = [new ValueString('a')]; + ValuePhantom m1 = [new ValueString('1'), new ValueString('2'), new ValueString('3')]; + ValuePhantom m2 = [new ValueString('4'), new ValueString('3')]; - var test = new BaseChain(new List() { m1, m2, m2, m3 }); + BaseChain test = new(new List() { m1, m2, m2, m3 }); - var table = new PhantomTable(test); - Assert.AreEqual(12, table[0].Volume); - Assert.AreEqual(4, table[1].Volume); - Assert.AreEqual(2, table[2].Volume); - Assert.AreEqual(1, table[3].Volume); - Assert.AreEqual(1, table[4].Volume); + PhantomTable table = new(test); + Assert.Multiple(() => + { + Assert.That(table[0].Volume, Is.EqualTo(12)); + Assert.That(table[1].Volume, Is.EqualTo(4)); + Assert.That(table[2].Volume, Is.EqualTo(2)); + Assert.That(table[3].Volume, Is.EqualTo(1)); + Assert.That(table[4].Volume, Is.EqualTo(1)); + }); } /// @@ -35,14 +38,17 @@ public void VolumeTest() [Test] public void ContentTest() { - var m1 = new ValuePhantom { new ValueString('1'), new ValueString('2'), new ValueString('3') }; - var m2 = new ValuePhantom { new ValueString('4'), new ValueString('3') }; + ValuePhantom m1 = [new ValueString('1'), new ValueString('2'), new ValueString('3')]; + ValuePhantom m2 = [new ValueString('4'), new ValueString('3')]; - var test = new BaseChain(new List() { m1, m2, m2 }); + BaseChain test = new(new List() { m1, m2, m2 }); - var table = new PhantomTable(test); - Assert.AreEqual(m1, table[1].Content); - Assert.AreEqual(m2, table[2].Content); - Assert.AreEqual(m2, table[3].Content); + PhantomTable table = new(test); + Assert.Multiple(() => + { + Assert.That(table[1].Content, Is.EqualTo(m1)); + Assert.That(table[2].Content, Is.EqualTo(m2)); + Assert.That(table[3].Content, Is.EqualTo(m2)); + }); } } diff --git a/Libiada.PhantomChains.Tests/TestObject.cs b/Libiada.PhantomChains.Tests/TestObject.cs index 1afebec5..1f46d164 100644 --- a/Libiada.PhantomChains.Tests/TestObject.cs +++ b/Libiada.PhantomChains.Tests/TestObject.cs @@ -26,7 +26,7 @@ public class TestObject /// /// The alpha. /// - private readonly Alphabet alphabet = new Alphabet() { (ValueString)"a", (ValueString)"b", (ValueString)"c" }; + private readonly Alphabet alphabet = [(ValueString)"a", (ValueString)"b", (ValueString)"c"]; /// /// The chain 2. @@ -38,10 +38,10 @@ public class TestObject /// public TestObject() { - pm1 = new ValuePhantom { alphabet[2], alphabet[1] }; - pm2 = new ValuePhantom { alphabet[0] }; + pm1 = [alphabet[2], alphabet[1]]; + pm2 = [alphabet[0]]; - chain = new BaseChain(new [] { 1, 2, 2, 1, 2, 1, 2, 1, 2, 2 }, new Alphabet() { NullValue.Instance(), PhantomMessageBc, PhantomMessageA }); + chain = new BaseChain([1, 2, 2, 1, 2, 1, 2, 1, 2, 2], [NullValue.Instance(), PhantomMessageBc, PhantomMessageA]); chain2 = new BaseChain(new List(){ alphabet[1], PhantomMessageA, PhantomMessageBc, alphabet[0], PhantomMessageBc }); } diff --git a/Libiada.PhantomChains.Tests/TreeTests.cs b/Libiada.PhantomChains.Tests/TreeTests.cs index 23dd33c5..227aae3b 100644 --- a/Libiada.PhantomChains.Tests/TreeTests.cs +++ b/Libiada.PhantomChains.Tests/TreeTests.cs @@ -25,12 +25,12 @@ public void TreeVolumeTest() IGenerator generator = new SimpleGenerator(); var tree = new TreeTop(test, generator); - Assert.AreEqual(12, tree.Volume); + Assert.That(tree.Volume, Is.EqualTo(12)); TreeNode ch1 = tree.GetChild(0); - Assert.AreEqual(4, ch1.Volume); + Assert.That(ch1.Volume, Is.EqualTo(4)); TreeNode ch2 = tree.GetChild(1); - Assert.AreEqual(4, ch2.Volume); + Assert.That(ch2.Volume, Is.EqualTo(4)); TreeNode ch3 = tree.GetChild(2); - Assert.AreEqual(4, ch3.Volume); + Assert.That(ch3.Volume, Is.EqualTo(4)); } } diff --git a/Libiada.Segmenter.Tests/Base/Collectors/FrequencyDictionaryTests.cs b/Libiada.Segmenter.Tests/Base/Collectors/FrequencyDictionaryTests.cs index 8abb45ec..c932ced2 100644 --- a/Libiada.Segmenter.Tests/Base/Collectors/FrequencyDictionaryTests.cs +++ b/Libiada.Segmenter.Tests/Base/Collectors/FrequencyDictionaryTests.cs @@ -13,7 +13,7 @@ public class FrequencyDictionaryTests /// /// The chain. /// - private ComplexChain chain = new ComplexChain("AACAGGTGCCCCTTATTT"); + private readonly ComplexChain chain = new("AACAGGTGCCCCTTATTT"); /// /// The put test. @@ -22,13 +22,16 @@ public class FrequencyDictionaryTests public void PutTest() { var alphabet = new FrequencyDictionary(chain); - string word = "string"; - string unknown = "WOW"; - int pos = 20; + const string word = "string"; + const string unknown = "WOW"; + const int pos = 20; alphabet.Put(word, pos); - Assert.True(alphabet.Contains(word)); - Assert.True(!alphabet.Contains(unknown)); + Assert.Multiple(() => + { + Assert.That(alphabet.Contains(word)); + Assert.That(!alphabet.Contains(unknown)); + }); } /// @@ -38,13 +41,16 @@ public void PutTest() public void ContainsTest() { var alphabet = new FrequencyDictionary(chain); - string[] words = { "A", "G", "C", "T", "WORD", "AG" }; - Assert.True(alphabet.Contains(words[0])); - Assert.True(alphabet.Contains(words[1])); - Assert.True(alphabet.Contains(words[2])); - Assert.True(alphabet.Contains(words[3])); - Assert.True(!alphabet.Contains(words[4])); - Assert.True(!alphabet.Contains(words[5])); + string[] words = ["A", "G", "C", "T", "WORD", "AG"]; + Assert.Multiple(() => + { + Assert.That(alphabet.Contains(words[0])); + Assert.That(alphabet.Contains(words[1])); + Assert.That(alphabet.Contains(words[2])); + Assert.That(alphabet.Contains(words[3])); + Assert.That(!alphabet.Contains(words[4])); + Assert.That(!alphabet.Contains(words[5])); + }); } /// @@ -55,16 +61,19 @@ public void GetTest() { // AACAGGTGCCCCTTATTT var alphabet = new FrequencyDictionary(chain); - string[] words = { "A", "G", "C", "T", "WORD", "AG" }; - int[] positionsA = { 0, 1, 3, 14 }; - int[] positionsG = { 4, 5, 7 }; - int[] positionsC = { 2, 8, 9, 10, 11 }; - int[] positionsT = { 6, 12, 13, 15, 16, 17 }; - Helper.ArraysEqual(positionsA, alphabet[words[0]].ToArray()); - Assert.True(Helper.ArraysEqual(positionsA, alphabet[words[0]].ToArray())); - Assert.True(Helper.ArraysEqual(positionsG, alphabet[words[1]].ToArray())); - Assert.True(Helper.ArraysEqual(positionsC, alphabet[words[2]].ToArray())); - Assert.True(Helper.ArraysEqual(positionsT, alphabet[words[3]].ToArray())); + string[] words = ["A", "G", "C", "T", "WORD", "AG"]; + int[] positionsA = [0, 1, 3, 14]; + int[] positionsG = [4, 5, 7]; + int[] positionsC = [2, 8, 9, 10, 11]; + int[] positionsT = [6, 12, 13, 15, 16, 17]; + + Assert.Multiple(() => + { + Assert.That(Helper.ArraysEqual(positionsA, alphabet[words[0]].ToArray())); + Assert.That(Helper.ArraysEqual(positionsG, alphabet[words[1]].ToArray())); + Assert.That(Helper.ArraysEqual(positionsC, alphabet[words[2]].ToArray())); + Assert.That(Helper.ArraysEqual(positionsT, alphabet[words[3]].ToArray())); + }); } /// @@ -74,16 +83,16 @@ public void GetTest() public void RemoveTest() { var alphabet = new FrequencyDictionary(chain); - string[] words = { "A", "G", "C", "T", "WORD", "AG" }; + string[] words = ["A", "G", "C", "T", "WORD", "AG"]; alphabet.Remove(words[0]); - Assert.True(!alphabet.Contains(words[0])); + Assert.That(!alphabet.Contains(words[0])); alphabet.Remove(words[1]); - Assert.True(!alphabet.Contains(words[1])); + Assert.That(!alphabet.Contains(words[1])); alphabet.Remove(words[2]); - Assert.True(!alphabet.Contains(words[2])); + Assert.That(!alphabet.Contains(words[2])); alphabet.Remove(words[3]); - Assert.True(!alphabet.Contains(words[3])); - Assert.True(alphabet.Count == 0); + Assert.That(!alphabet.Contains(words[3])); + Assert.That(alphabet.Count, Is.EqualTo(0)); } /// @@ -93,9 +102,9 @@ public void RemoveTest() public void GetWordsTest() { var alphabet = new FrequencyDictionary(chain); - string[] words = { "A", "G", "C", "T" }; + string[] words = ["A", "G", "C", "T"]; List alphabetWords = alphabet.GetWords(); - Assert.True(!words.Except(alphabetWords).Any()); + Assert.That(!words.Except(alphabetWords).Any()); } /// @@ -107,7 +116,7 @@ public void FillOneTest() string str = chain.ToString(); var alphabet1 = new FrequencyDictionary(str); var alphabet2 = new FrequencyDictionary(chain); - Assert.True(alphabet1.Equals(alphabet2)); + Assert.That(alphabet1, Is.EqualTo(alphabet2)); } /// @@ -126,8 +135,8 @@ public void FillTwoTest() public void PowerTest() { var alphabetChain = new FrequencyDictionary(chain); - int power = 4; - Assert.True(alphabetChain.Count == power); + const int power = 4; + Assert.That(alphabetChain.Count, Is.EqualTo(power)); } /// @@ -138,7 +147,7 @@ public void ClearTest() { var alphabet = new FrequencyDictionary(chain); alphabet.Clear(); - Assert.True(alphabet.Count == 0); + Assert.That(alphabet.Count, Is.EqualTo(0)); } /// @@ -149,11 +158,15 @@ public void AddTest() { var alphabet = new FrequencyDictionary(); var alphabetTest = new FrequencyDictionary(chain); - string[] words = { "A", "G", "C", "T" }; - int power = 1; + string[] words = ["A", "G", "C", "T"]; + const int power = 1; alphabet.Add(words[0], alphabetTest[words[0]]); alphabet.Add(words[0], alphabetTest[words[0]]); - Assert.True(alphabet.Contains(words[0]) && alphabet.Count == power); + Assert.Multiple(() => + { + Assert.That(alphabet.Contains(words[0])); + Assert.That(alphabet.Count, Is.EqualTo(power)); + }); } /// @@ -166,7 +179,11 @@ public void CloneTest() var alphabet1 = new FrequencyDictionary(str); var alphabet2 = new FrequencyDictionary(chain); FrequencyDictionary alphabet3 = alphabet2.Clone(); - Assert.True(alphabet1.Equals(alphabet2) && alphabet3.Equals(alphabet1)); + Assert.Multiple(() => + { + Assert.That(alphabet1, Is.EqualTo(alphabet2)); + Assert.That(alphabet3, Is.EqualTo(alphabet1)); + }); } /// @@ -178,9 +195,9 @@ public void EqualsTest() string str = chain.ToString(); var alphabet1 = new FrequencyDictionary(str); var alphabet2 = new FrequencyDictionary(chain); - Assert.True(alphabet1.Equals(alphabet2)); + Assert.That(alphabet1, Is.EqualTo(alphabet2)); alphabet1.Remove(alphabet1.GetWord(1)); - Assert.True(!alphabet1.Equals(alphabet2)); + Assert.That(alphabet1, Is.Not.EqualTo(alphabet2)); } /// @@ -192,7 +209,7 @@ public void GetWordTest() var alphabet = new FrequencyDictionary(chain); for (int index = 0; index < alphabet.Count; index++) { - Assert.True(alphabet.Contains(alphabet.GetWord(index))); + Assert.That(alphabet.Contains(alphabet.GetWord(index))); } } } diff --git a/Libiada.Segmenter.Tests/Base/Iterators/EndIteratorTests.cs b/Libiada.Segmenter.Tests/Base/Iterators/EndIteratorTests.cs index bc66be9a..35a2b2c7 100644 --- a/Libiada.Segmenter.Tests/Base/Iterators/EndIteratorTests.cs +++ b/Libiada.Segmenter.Tests/Base/Iterators/EndIteratorTests.cs @@ -30,28 +30,28 @@ public void SetUp() [Test] public void HasNextTest() { - int lengthCut = 3; - int step = 1; + const int lengthCut = 3; + const int step = 1; int countSteps = 0; - var iterator = new EndIterator(complexChain, lengthCut, step); + EndIterator iterator = new(complexChain, lengthCut, step); while (iterator.HasNext()) { iterator.Next(); - countSteps = countSteps + 1; + countSteps++; } - Assert.AreEqual(countSteps, iterator.MaxShifts); + Assert.That(iterator.MaxShifts, Is.EqualTo(countSteps)); countSteps = 0; iterator = new EndIterator(complexChain, lengthCut, step + 1); while (iterator.HasNext()) { iterator.Next(); - countSteps = countSteps + 1; + countSteps++; } - Assert.True(countSteps == iterator.MaxShifts); + Assert.That(iterator.MaxShifts, Is.EqualTo(countSteps)); } /// @@ -62,22 +62,22 @@ public void NextTest() { List cut; string[] triplesForStepOne = - { + [ "AAC", "ACA", "CAG", "AGG", "GGT", "GTG", "TGC", "GCC", "CCC", "CCC", "CCT", "CTT", "TTA", "TAT", "ATT", "TTT" - }; - string[] triplesForStepTwo = { "AAC", "CAG", "GGT", "TGC", "CCC", "CCT", "TTA", "ATT" }; - int lengthCut = 3; - int step = 1; + ]; + string[] triplesForStepTwo = ["AAC", "CAG", "GGT", "TGC", "CCC", "CCT", "TTA", "ATT"]; + const int lengthCut = 3; + const int step = 1; - var iterator = new EndIterator(complexChain, lengthCut, step); + EndIterator iterator = new(complexChain, lengthCut, step); for (int i = iterator.MaxShifts - 1; i >= 0; i--) { cut = iterator.Next(); - Assert.True(Helper.ToString(cut).Equals(triplesForStepOne[i])); + Assert.That(Helper.ToString(cut), Is.EqualTo(triplesForStepOne[i])); } iterator = new EndIterator(complexChain, lengthCut, step + 1); @@ -85,7 +85,7 @@ public void NextTest() for (int i = iterator.MaxShifts - 1; i >= 0; i--) { cut = iterator.Next(); - Assert.True(Helper.ToString(cut).Equals(triplesForStepTwo[i])); + Assert.That(Helper.ToString(cut), Is.EqualTo(triplesForStepTwo[i])); } } @@ -95,12 +95,12 @@ public void NextTest() [Test] public void ResetTest() { - int lengthCut = 2; - int step = 1; + const int lengthCut = 2; + const int step = 1; int index = 0; - int position = 6; - var list1 = new List - { + const int position = 6; + List list1 = + [ "ABABAB", "ABATAT", "TABABAB", @@ -108,18 +108,18 @@ public void ResetTest() "ABABAB", "ABABAB", "ABABAB" - }; - var chain = new ComplexChain(list1); - var iterator = new EndIterator(chain, lengthCut, step); + ]; + ComplexChain chain = new(list1); + EndIterator iterator = new(chain, lengthCut, step); while (iterator.HasNext()) { iterator.Next(); - index = index + 1; + index++; } iterator.Reset(); - Assert.True(iterator.Position() == position); + Assert.That(iterator.Position(), Is.EqualTo(position)); } /// @@ -128,11 +128,11 @@ public void ResetTest() [Test] public void GetMaxShiftsTest() { - int lengthCut = 3; - int step = 1; - int maxShifts = 16; - EndIterator iterator = new EndIterator(complexChain, lengthCut, step); - Assert.True(iterator.MaxShifts == maxShifts); + const int lengthCut = 3; + const int step = 1; + const int maxShifts = 16; + EndIterator iterator = new(complexChain, lengthCut, step); + Assert.That(iterator.MaxShifts, Is.EqualTo(maxShifts)); } /// @@ -141,11 +141,11 @@ public void GetMaxShiftsTest() [Test] public void MoveTest() { - int len = 2; - int step = 1; - int from = 1, to = 3; - var list1 = new List - { + const int len = 2; + const int step = 1; + const int from = 1, to = 3; + List list1 = + [ "ABABAB", "ABATAT", "TABABAB", @@ -153,15 +153,15 @@ public void MoveTest() "ABABAB", "ABABAB", "ABABAB" - }; + ]; List list = list1.GetRange(@from, to - @from); - var chain = new ComplexChain(list1); - var iterator = new EndIterator(chain, len, step); + ComplexChain chain = new(list1); + EndIterator iterator = new(chain, len, step); iterator.Move(2); List result = iterator.Next(); for (int i = 0; i < list.Count; i++) { - Assert.True(list[i].Equals(result[i])); + Assert.That(list[i], Is.EqualTo(result[i])); } } } diff --git a/Libiada.Segmenter.Tests/Base/Iterators/StartIteratorTests.cs b/Libiada.Segmenter.Tests/Base/Iterators/StartIteratorTests.cs index 86426a33..deaf9234 100644 --- a/Libiada.Segmenter.Tests/Base/Iterators/StartIteratorTests.cs +++ b/Libiada.Segmenter.Tests/Base/Iterators/StartIteratorTests.cs @@ -30,8 +30,8 @@ public void SetUp() [Test] public void HasNextTest() { - int lengthCut = 3; - int step = 1; + const int lengthCut = 3; + const int step = 1; int countSteps = 0; var iterator = new StartIterator(chain, lengthCut, step); @@ -41,7 +41,7 @@ public void HasNextTest() countSteps++; } - Assert.True(countSteps == iterator.MaxShifts); + Assert.That(countSteps, Is.EqualTo(iterator.MaxShifts)); countSteps = 0; iterator = new StartIterator(chain, lengthCut, step + 1); @@ -51,7 +51,7 @@ public void HasNextTest() countSteps++; } - Assert.True(countSteps == iterator.MaxShifts); + Assert.That(countSteps, Is.EqualTo(iterator.MaxShifts)); } /// @@ -62,20 +62,20 @@ public void NextTest() { List cut; string[] triplesForStepOne = - { + [ "AAC", "ACA", "CAG", "AGG", "GGT", "GTG", "TGC", "GCC", "CCC", "CCC", "CCT", "CTT", "TTA", "TAT", "ATT", "TTT" - }; - string[] triplesForStepTwo = { "AAC", "CAG", "GGT", "TGC", "CCC", "CCT", "TTA", "ATT" }; - int lengthCut = 3; - int step = 1; + ]; + string[] triplesForStepTwo = ["AAC", "CAG", "GGT", "TGC", "CCC", "CCT", "TTA", "ATT"]; + const int lengthCut = 3; + const int step = 1; var iterator = new StartIterator(chain, lengthCut, step); for (int i = 0; i < iterator.MaxShifts; i++) { cut = iterator.Next(); - Assert.True(Helper.ToString(cut).Equals(triplesForStepOne[i])); + Assert.That(Helper.ToString(cut), Is.EqualTo(triplesForStepOne[i])); } iterator = new StartIterator(chain, lengthCut, step + 1); @@ -83,7 +83,7 @@ public void NextTest() for (int i = 0; i < iterator.MaxShifts; i++) { cut = iterator.Next(); - Assert.True(Helper.ToString(cut).Equals(triplesForStepTwo[i])); + Assert.That(Helper.ToString(cut), Is.EqualTo(triplesForStepTwo[i])); } } @@ -93,15 +93,15 @@ public void NextTest() [Test] public void ResetTest() { - int length = 2; - int step = 1; + const int length = 2; + const int step = 1; var iterator = new StartIterator(chain, length, step); if (iterator.Move(3)) { iterator.Reset(); } - Assert.True(iterator.CursorPosition == -step); + Assert.That(iterator.CursorPosition, Is.EqualTo(-step)); } /// @@ -115,28 +115,28 @@ public void MoveTest() int position = 3; var iterator = new StartIterator(chain, length, step); iterator.Move(position); - Assert.True(iterator.CursorPosition == position); + Assert.That(iterator.CursorPosition, Is.EqualTo(position)); position = 100; iterator.Move(position); - Assert.True(iterator.CursorPosition != position); + Assert.That(iterator.CursorPosition, Is.Not.EqualTo(position)); position = chain.Length / 2; iterator.Move(position); - Assert.True(iterator.CursorPosition == position); + Assert.That(iterator.CursorPosition, Is.EqualTo(position)); position = -1; iterator.Move(position); - Assert.True(iterator.CursorPosition != position); + Assert.That(iterator.CursorPosition, Is.Not.EqualTo(position)); length = 3; step = 2; position = 3; - string triple = "GTG"; + const string triple = "GTG"; iterator = new StartIterator(chain, length, step); iterator.Move(position); iterator.Next(); - Assert.AreEqual(triple, Helper.ToString(iterator.Current())); + Assert.That(Helper.ToString(iterator.Current()), Is.EqualTo(triple)); } /// @@ -145,11 +145,11 @@ public void MoveTest() [Test] public void GetMaxShiftsTest() { - int lengthCut = 3; - int step = 1; - int maxShifts = 16; + const int lengthCut = 3; + const int step = 1; + const int maxShifts = 16; var iterator = new StartIterator(chain, lengthCut, step); - Assert.True(iterator.MaxShifts == maxShifts); + Assert.That(iterator.MaxShifts, Is.EqualTo(maxShifts)); } /// @@ -158,18 +158,18 @@ public void GetMaxShiftsTest() [Test] public void GetPositionTest() { - int lengthCut = 2; - int step = 1; + const int lengthCut = 2; + const int step = 1; var iterator = new StartIterator(chain, lengthCut, step); iterator.Next(); - Assert.True(iterator.CursorPosition == 0); + Assert.That(iterator.CursorPosition, Is.EqualTo(0)); iterator.Next(); - Assert.True(iterator.CursorPosition == 1); + Assert.That(iterator.CursorPosition, Is.EqualTo(1)); for (int index = 2; index < iterator.MaxShifts; index++) { iterator.Next(); } - Assert.True(iterator.CursorPosition == 16); + Assert.That(iterator.CursorPosition, Is.EqualTo(16)); } } diff --git a/Libiada.Segmenter.Tests/Base/Seekers/Converters/FilterTests.cs b/Libiada.Segmenter.Tests/Base/Seekers/Converters/FilterTests.cs index dd139c62..3da8ab39 100644 --- a/Libiada.Segmenter.Tests/Base/Seekers/Converters/FilterTests.cs +++ b/Libiada.Segmenter.Tests/Base/Seekers/Converters/FilterTests.cs @@ -34,7 +34,7 @@ public void SetUp() { str1 = "A"; str2 = "TA"; - list = new List { "ABABAB", "ABATAT", "TABABAB", "ABTABAB", "ABABAB", "ABABAB", "ABABAB" }; + list = ["ABABAB", "ABATAT", "TABABAB", "ABTABAB", "ABABAB", "ABABAB", "ABABAB"]; } /// @@ -47,7 +47,8 @@ public void FilteroutTest() var filter = new Filter(chain); int hits = filter.FilterOut(str1); - var sb = new StringBuilder(); + // TODO: find out why this code is not used + var sb = new StringBuilder(list.Count); foreach (string s in list) { sb.Append(s); @@ -55,14 +56,14 @@ public void FilteroutTest() string result = filter.GetChain().ToString(); string buf = chain.ToString(); - Assert.True(buf.Length - result.Length == hits); + Assert.That(buf.Length - result.Length, Is.EqualTo(hits)); filter = new Filter(chain); hits = filter.FilterOut(str2); filter.GetChain().ToString(); chain.ToString(); - Assert.True(hits == 3); + Assert.That(hits, Is.EqualTo(3)); } /// @@ -75,7 +76,7 @@ public void ReplaceTest() var filter = new Filter(chain); int hits = filter.Replace(str2, "-"); - var sb = new StringBuilder(); + var sb = new StringBuilder(list.Count); foreach (string s in list) { sb.Append(s); @@ -83,6 +84,6 @@ public void ReplaceTest() string result = filter.GetChain().ToString(); string buf = chain.ToString(); - Assert.True(buf.Length - result.Length == hits); + Assert.That(buf.Length - result.Length, Is.EqualTo(hits)); } } diff --git a/Libiada.Segmenter.Tests/Base/Seekers/Converters/SequenceCleanerTests.cs b/Libiada.Segmenter.Tests/Base/Seekers/Converters/SequenceCleanerTests.cs index 2bc8534e..88c51993 100644 --- a/Libiada.Segmenter.Tests/Base/Seekers/Converters/SequenceCleanerTests.cs +++ b/Libiada.Segmenter.Tests/Base/Seekers/Converters/SequenceCleanerTests.cs @@ -15,8 +15,9 @@ public class SequenceCleanerTests [Test] public void FilteroutTest() { - var list1 = new List - { + // TODO: refactor this to use testcase + List list1 = + [ "ABABAB", "ABATAT", "TABABAB", @@ -24,24 +25,27 @@ public void FilteroutTest() "ABABAB", "ABABAB", "ABABAB" - }; - var listSequence1 = new List { "ABATAT", "TABABAB" }; - var listSequence2 = new List { "ABABAB", "ABABAB" }; - var listSequence3 = new List { "ABABAB" }; - var result1 = new List { "ABABAB", "ABTABAB", "ABABAB", "ABABAB", "ABABAB" }; - var result2 = new List { "ABABAB", "ABATAT", "TABABAB", "ABTABAB", "ABABAB" }; - var result3 = new List { "ABATAT", "TABABAB", "ABTABAB" }; + ]; + List listSequence1 = ["ABATAT", "TABABAB"]; + List listSequence2 = ["ABABAB", "ABABAB"]; + List listSequence3 = ["ABABAB"]; + List result1 = ["ABABAB", "ABTABAB", "ABABAB", "ABABAB", "ABABAB"]; + List result2 = ["ABABAB", "ABATAT", "TABABAB", "ABTABAB", "ABABAB"]; + List result3 = ["ABATAT", "TABABAB", "ABTABAB"]; - var firstCleaner = new SequenceCleaner(new ComplexChain(list1)); - var secondCleaner = new SequenceCleaner(new ComplexChain(list1)); - var thirdCleaner = new SequenceCleaner(new ComplexChain(list1)); + SequenceCleaner firstCleaner = new(new ComplexChain(list1)); + SequenceCleaner secondCleaner = new(new ComplexChain(list1)); + SequenceCleaner thirdCleaner = new(new ComplexChain(list1)); firstCleaner.FilterOut(listSequence1); secondCleaner.FilterOut(listSequence2); thirdCleaner.FilterOut(listSequence3); - Assert.True((new ComplexChain(result1)).Equals(firstCleaner.GetChain())); - Assert.True((new ComplexChain(result2)).Equals(secondCleaner.GetChain())); - Assert.True((new ComplexChain(result3)).Equals(thirdCleaner.GetChain())); + Assert.Multiple(() => + { + Assert.That(new ComplexChain(result1), Is.EqualTo(firstCleaner.GetChain())); + Assert.That(new ComplexChain(result2), Is.EqualTo(secondCleaner.GetChain())); + Assert.That(new ComplexChain(result3), Is.EqualTo(thirdCleaner.GetChain())); + }); } } diff --git a/Libiada.Segmenter.Tests/Base/Seekers/SeekerSequenceTests.cs b/Libiada.Segmenter.Tests/Base/Seekers/SeekerSequenceTests.cs index 96de307f..930f9795 100644 --- a/Libiada.Segmenter.Tests/Base/Seekers/SeekerSequenceTests.cs +++ b/Libiada.Segmenter.Tests/Base/Seekers/SeekerSequenceTests.cs @@ -16,12 +16,12 @@ public class SeekerSequenceTests [Test] public void SeekTest() { - int length = 2; - int step = 1; + const int length = 2; + const int step = 1; - var list1 = new List { "ABAC", "A", "A", "A", "ABAC", "A", "ABC", "AC", "ABC", "AG", "ABC", "A", "AB", "A", "ABC", "ABAC", "A" }; - var list2 = new List { "ABAC", "A" }; - var seek = new SeekerSequence(new StartIterator(new ComplexChain(list1), length, step)); - Assert.True(seek.Seek(list2) == 3); + List list1 = ["ABAC", "A", "A", "A", "ABAC", "A", "ABC", "AC", "ABC", "AG", "ABC", "A", "AB", "A", "ABC", "ABAC", "A"]; + List list2 = ["ABAC", "A"]; + SeekerSequence seek = new(new StartIterator(new ComplexChain(list1), length, step)); + Assert.That(seek.Seek(list2), Is.EqualTo(3)); } } diff --git a/Libiada.Segmenter.Tests/Base/Seekers/SeekerTests.cs b/Libiada.Segmenter.Tests/Base/Seekers/SeekerTests.cs index b1d6232e..d31c6e76 100644 --- a/Libiada.Segmenter.Tests/Base/Seekers/SeekerTests.cs +++ b/Libiada.Segmenter.Tests/Base/Seekers/SeekerTests.cs @@ -30,25 +30,25 @@ public void SetUp() [Test] public void SeekTest() { - int length = 1; - int step = 1; - string required1 = "A"; - string required2 = "C"; - string required3 = "T"; - string required4 = "G"; + const int length = 1; + const int step = 1; + const string required1 = "A"; + const string required2 = "C"; + const string required3 = "T"; + const string required4 = "G"; - var seek = new Seeker(new StartIterator(chain, length, step)); - seek.Seek(new List { required1 }); - Assert.True(seek.Arrangement.Count == 4); + Seeker seek = new(new StartIterator(chain, length, step)); + seek.Seek([required1]); + Assert.That(seek.Arrangement, Has.Count.EqualTo(4)); - seek.Seek(new List { required2 }); - Assert.True(seek.Arrangement.Count == 5); + seek.Seek([required2]); + Assert.That(seek.Arrangement, Has.Count.EqualTo(5)); - seek.Seek(new List { required3 }); - Assert.True(seek.Arrangement.Count == 6); + seek.Seek([required3]); + Assert.That(seek.Arrangement, Has.Count.EqualTo(6)); - seek.Seek(new List { required4 }); - Assert.True(seek.Arrangement.Count == 3); + seek.Seek([required4]); + Assert.That(seek.Arrangement, Has.Count.EqualTo(3)); } /// @@ -57,22 +57,22 @@ public void SeekTest() [Test] public void SeekTwoTest() { - int length = 1; - int step = 1; - string required1 = "AA"; - string required2 = "C"; - string required3 = "TTA"; - var list = new List { "AA", "AAAT", "AJJTTA" }; + const int length = 1; + const int step = 1; + const string required1 = "AA"; + const string required2 = "C"; + const string required3 = "TTA"; + List list = ["AA", "AAAT", "AJJTTA"]; - var seek = new Seeker(new StartIterator(new ComplexChain(list), length, step)); - seek.Seek(new List { required1 }); - Assert.True(seek.Arrangement.Count == 1); + Seeker seek = new(new StartIterator(new ComplexChain(list), length, step)); + seek.Seek([required1]); + Assert.That(seek.Arrangement, Has.Count.EqualTo(1)); - seek.Seek(new List { required2 }); - Assert.True(seek.Arrangement.Count == 0); + seek.Seek([required2]); + Assert.That(seek.Arrangement, Is.Empty); - seek.Seek(new List { required3 }); - Assert.True(seek.Arrangement.Count == 0); + seek.Seek([required3]); + Assert.That(seek.Arrangement, Is.Empty); } /// @@ -81,11 +81,11 @@ public void SeekTwoTest() [Test] public void GetMatchTest() { - int length = 1; - int step = 1; - string required1 = "A"; - var seek = new Seeker(new StartIterator(chain, length, step)); - seek.Seek(new List { required1 }); - Assert.True(seek.Arrangement.Count == 4); + const int length = 1; + const int step = 1; + const string required1 = "A"; + Seeker seek = new(new StartIterator(chain, length, step)); + seek.Seek([required1]); + Assert.That(seek.Arrangement, Has.Count.EqualTo(4)); } } diff --git a/Libiada.Segmenter.Tests/Base/Sequences/ComplexChainTests.cs b/Libiada.Segmenter.Tests/Base/Sequences/ComplexChainTests.cs index 4cf9736e..de6e7bd0 100644 --- a/Libiada.Segmenter.Tests/Base/Sequences/ComplexChainTests.cs +++ b/Libiada.Segmenter.Tests/Base/Sequences/ComplexChainTests.cs @@ -36,8 +36,8 @@ public void CloneTest() { ComplexChain foreignComplexChain = chain.Clone(); - Assert.AreNotSame(chain, foreignComplexChain); - Assert.True(chain.Equals(foreignComplexChain)); + Assert.That(foreignComplexChain, Is.Not.SameAs(chain)); + Assert.That(foreignComplexChain, Is.EqualTo(chain)); } /// @@ -48,10 +48,10 @@ public void EqualsTest() { ComplexChain foreignComplexChain = chain.Clone(); - Assert.True(foreignComplexChain.Equals(chain)); - foreignComplexChain.ClearAt(0); - foreignComplexChain.ClearAt(0); - Assert.True(!foreignComplexChain.Equals(chain)); + Assert.That(foreignComplexChain, Is.EqualTo(chain)); + foreignComplexChain.DeleteAt(0); + foreignComplexChain.DeleteAt(0); + Assert.That(foreignComplexChain, Is.Not.EqualTo(chain)); } /// @@ -60,13 +60,16 @@ public void EqualsTest() [Test] public void ElementAtTest() { - string str1 = "A"; - string str2 = "G"; - string str3 = "C"; - - Assert.True(str1.Equals(chain[0].ToString())); - Assert.True(str2.Equals(chain[4].ToString())); - Assert.True(str3.Equals(chain[2].ToString())); + const string str1 = "A"; + const string str2 = "G"; + const string str3 = "C"; + + Assert.Multiple(() => + { + Assert.That(chain[0].ToString(), Is.EqualTo(str1)); + Assert.That(chain[4].ToString(), Is.EqualTo(str2)); + Assert.That(chain[2].ToString(), Is.EqualTo(str3)); + }); } /// @@ -75,23 +78,23 @@ public void ElementAtTest() [Test] public void SubstringTest() { - int start = 0, end = 2; - var thirdComplexChain = new ComplexChain("AA"); - var foreignComplexChain = new ComplexChain(chain.Substring(start, end)); + const int start = 0, end = 2; + ComplexChain thirdComplexChain = new("AA"); + ComplexChain foreignComplexChain = new(chain.Substring(start, end)); - Assert.True(thirdComplexChain.Equals(foreignComplexChain)); + Assert.That(foreignComplexChain, Is.EqualTo(thirdComplexChain)); } /// /// The clear at test. /// [Test] - public void ClearAtTest() + public void DeleteAtTest() { - var secondComplexChain = new ComplexChain("AGTC"); - var firstComplexChain = new ComplexChain("ATC"); - secondComplexChain.ClearAt(1); - Assert.True(firstComplexChain.Equals(secondComplexChain)); + ComplexChain actual = new("AGTC"); + ComplexChain expected = new("ATC"); + actual.DeleteAt(1); + Assert.That(actual.Equals(expected)); } /// @@ -100,13 +103,13 @@ public void ClearAtTest() [Test] public void ConcatOneTest() { - int start = 0; + const int start = 0; int end = chain.Length; - var firstComplexChain = new ComplexChain(chain.Substring(start, end / 2)); - var secondComplexChain = new ComplexChain(chain.Substring(end / 2, end)); + ComplexChain firstComplexChain = new(chain.Substring(start, end / 2)); + ComplexChain secondComplexChain = new(chain.Substring(end / 2, end)); ComplexChain concatChain = firstComplexChain.Concat(secondComplexChain); - Assert.True(concatChain.Equals(chain)); + Assert.That(concatChain, Is.EqualTo(chain)); } /// @@ -115,13 +118,13 @@ public void ConcatOneTest() [Test] public void ConcatTwoTest() { - int start = 0; + const int start = 0; int end = chain.Length; - var firstComplexChain = new ComplexChain(chain.Substring(start, end - 1)); - var secondComplexChain = new ComplexChain(chain.Substring(end - 1, end)); + ComplexChain firstComplexChain = new(chain.Substring(start, end - 1)); + ComplexChain secondComplexChain = new(chain.Substring(end - 1, end)); ComplexChain concatChain = firstComplexChain.Concat(secondComplexChain.ToString()); - Assert.True(concatChain.Equals(chain)); + Assert.That(concatChain, Is.EqualTo(chain)); } /// @@ -132,10 +135,10 @@ public void LengthTest() { ComplexChain foreignComplexChain = chain.Clone(); - Assert.True(chain.Length != differentComplexChain.Length); - Assert.True(chain.Length == foreignComplexChain.Length); - foreignComplexChain.ClearAt(0); - Assert.True(chain.Length != foreignComplexChain.Length); + Assert.That(chain.Length, Is.Not.EqualTo(differentComplexChain.Length)); + Assert.That(foreignComplexChain.Length, Is.EqualTo(chain.Length)); + foreignComplexChain.DeleteAt(0); + Assert.That(foreignComplexChain.Length, Is.Not.EqualTo(chain.Length)); } /// @@ -144,13 +147,13 @@ public void LengthTest() [Test] public void IsEmptyTest() { - string str = "s"; - var emptyChain = new ComplexChain(string.Empty); - Assert.True(emptyChain.IsEmpty()); + const string str = "s"; + ComplexChain emptyChain = new(string.Empty); + Assert.That(emptyChain.IsEmpty()); emptyChain.Concat(str); - Assert.True(!emptyChain.IsEmpty()); - emptyChain.ClearAt(0); - Assert.True(emptyChain.IsEmpty()); + Assert.That(!emptyChain.IsEmpty()); + emptyChain.DeleteAt(0); + Assert.That(emptyChain.IsEmpty()); } /// @@ -161,9 +164,9 @@ public void UpdateCongenericsTest() { ComplexChain clonedComplexChain = chain.Clone(); - chain.ClearAt(0); - clonedComplexChain.ClearAt(0); - Assert.True(chain.Equals(clonedComplexChain)); + chain.DeleteAt(0); + clonedComplexChain.DeleteAt(0); + Assert.That(chain, Is.EqualTo(clonedComplexChain)); } /// @@ -172,23 +175,23 @@ public void UpdateCongenericsTest() [Test] public void JoinTest() { - ComplexChain clon = chain.Clone(); - var expected1 = new List { "AAC", "A", "G", "G", "T", "G", "C", "C", "C", "C", "T", "T", "A", "T", "T", "T" }; - var expected2 = new List { "AAC", "A", "G", "G", "TGC", "C", "C", "C", "T", "T", "A", "T", "T", "T" }; - var expected3 = new List { "AACAGGTGC", "C", "C", "C", "T", "T", "A", "T", "T", "T" }; - var expected4 = new List { "AACAGGTGC", "C", "C", "C", "T", "T", "A", "T", "TT" }; + ComplexChain clone = chain.Clone(); + List expected1 = ["AAC", "A", "G", "G", "T", "G", "C", "C", "C", "C", "T", "T", "A", "T", "T", "T"]; + List expected2 = ["AAC", "A", "G", "G", "TGC", "C", "C", "C", "T", "T", "A", "T", "T", "T"]; + List expected3 = ["AACAGGTGC", "C", "C", "C", "T", "T", "A", "T", "T", "T"]; + List expected4 = ["AACAGGTGC", "C", "C", "C", "T", "T", "A", "T", "TT"]; - clon.Join(0, 3); - Assert.True((new ComplexChain(expected1)).Equals(clon)); + clone.Join(0, 3); + Assert.That(new ComplexChain(expected1), Is.EqualTo(clone)); - clon.Join(4, 3); - Assert.True((new ComplexChain(expected2)).Equals(clon)); + clone.Join(4, 3); + Assert.That(new ComplexChain(expected2), Is.EqualTo(clone)); - clon.Join(0, 5); - Assert.True((new ComplexChain(expected3)).Equals(clon)); + clone.Join(0, 5); + Assert.That(new ComplexChain(expected3).Equals(clone)); - clon.Join(8, 2); - Assert.True((new ComplexChain(expected4)).Equals(clon)); + clone.Join(8, 2); + Assert.That(new ComplexChain(expected4).Equals(clone)); } /// @@ -197,9 +200,11 @@ public void JoinTest() [Test] public void JoinAllTest() { - var list1 = new List { "A", "A", "G", "G", "T", "G", "C", "A", "A", "A", "A", "T", "A", "T", "A", "A", "A" }; - var clon = new ComplexChain(list1); - var list2 = new List { "A", "A" }; - clon.JoinAll(list2); + List list1 = ["A", "A", "G", "G", "T", "G", "C", "A", "A", "A", "A", "T", "A", "T", "A", "A", "A"]; + ComplexChain clone = new(list1); + List list2 = ["A", "A"]; + clone.JoinAll(list2); + + //TODO: add asserts } } diff --git a/Libiada.Segmenter.Tests/Libiada.Segmenter.Tests.csproj b/Libiada.Segmenter.Tests/Libiada.Segmenter.Tests.csproj index d09f7611..508dc4fd 100644 --- a/Libiada.Segmenter.Tests/Libiada.Segmenter.Tests.csproj +++ b/Libiada.Segmenter.Tests/Libiada.Segmenter.Tests.csproj @@ -7,9 +7,13 @@ - - - + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/Libiada.Segmenter.Tests/Model/Threshold/ThresholdLinearTests.cs b/Libiada.Segmenter.Tests/Model/Threshold/ThresholdLinearTests.cs index 99cb6ba3..c5a1d17a 100644 --- a/Libiada.Segmenter.Tests/Model/Threshold/ThresholdLinearTests.cs +++ b/Libiada.Segmenter.Tests/Model/Threshold/ThresholdLinearTests.cs @@ -15,18 +15,18 @@ public class ThresholdLinearTests [Test] public void NextTest() { - double left = 0; - double right = 1; - double step = 0.10; + const double left = 0; + const double right = 1; + const double step = 0.10; double current; - double[] steps = { 1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, 0.0 }; + double[] steps = [1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, 0.0]; int index = 0; - Criterion criterion = null; + const Criterion? criterion = null; var threshold = new ThresholdLinear(left, right, step); while ((current = threshold.Next(criterion)) > 0) { - Assert.True((current - steps[index++]) < step); + Assert.That(current, Is.EqualTo(steps[index++]).Within(step)); } } } diff --git a/Libiada.Segmenter/Base/Collectors/FrequencyDictionary.cs b/Libiada.Segmenter/Base/Collectors/FrequencyDictionary.cs index bcb9e9b3..0f554cd7 100644 --- a/Libiada.Segmenter/Base/Collectors/FrequencyDictionary.cs +++ b/Libiada.Segmenter/Base/Collectors/FrequencyDictionary.cs @@ -292,4 +292,14 @@ public bool Equals(FrequencyDictionary other) return true; } + + public override bool Equals(object? obj) + { + if(ReferenceEquals(this, obj)) return true; + + if (obj == null) return false; + + if (obj is not FrequencyDictionary other) return false; + return Equals(other); + } } diff --git a/Libiada.Segmenter/Base/Sequences/ComplexChain.cs b/Libiada.Segmenter/Base/Sequences/ComplexChain.cs index 631b8536..08e606e5 100644 --- a/Libiada.Segmenter/Base/Sequences/ComplexChain.cs +++ b/Libiada.Segmenter/Base/Sequences/ComplexChain.cs @@ -89,7 +89,7 @@ public List Substring(int beginIndex, int endIndex) /// public List ToList() { - var result = new List(); + var result = new List(Length); for (int i = 0; i < Length; i++) { result.Add(this[i].ToString()); @@ -104,11 +104,11 @@ public List ToList() /// /// The index. /// - public void ClearAt(int index) + public override void DeleteAt(int index) { try { - DeleteAt(index); + base.DeleteAt(index); } catch (Exception) { diff --git a/Libiada.Segmenter/Model/Threshold/ThresholdLinear.cs b/Libiada.Segmenter/Model/Threshold/ThresholdLinear.cs index 08360a01..93fb8ff0 100644 --- a/Libiada.Segmenter/Model/Threshold/ThresholdLinear.cs +++ b/Libiada.Segmenter/Model/Threshold/ThresholdLinear.cs @@ -55,7 +55,7 @@ public override double Next(Criterion.Criterion criterion) if (current > leftBound) { current = rightBound; - rightBound = rightBound - step; + rightBound -= step; return current; } diff --git a/Libiada.SequenceGenerator.Tests/IntervalsDistributionExtractorTests.cs b/Libiada.SequenceGenerator.Tests/IntervalsDistributionExtractorTests.cs index 6d1ad793..fd04a721 100644 --- a/Libiada.SequenceGenerator.Tests/IntervalsDistributionExtractorTests.cs +++ b/Libiada.SequenceGenerator.Tests/IntervalsDistributionExtractorTests.cs @@ -19,14 +19,14 @@ public class IntervalsDistributionExtractorTests [TestCase(Link.CycleEnd)] public void GetIntervalsDistributionTest(Link link) { - var actualInternalsDistribution = new List(); + List actualInternalsDistribution = new(orders.Length); foreach (var order in orders) { actualInternalsDistribution.Add(IntervalsDistributionExtractor.GetIntervalsDistribution(order, link)); } for (int i = 0; i < actualInternalsDistribution.Count; i++) { - Assert.AreEqual(intervalsDistributions[link][i], actualInternalsDistribution[i]); + Assert.That(actualInternalsDistribution[i], Is.EqualTo(intervalsDistributions[link][i])); } } @@ -42,13 +42,13 @@ public void GetOrdersIntervalsDistributionsTest(Link link) var actualOrdersIntervalsDistributionsAccordance = IntervalsDistributionExtractor.GetOrdersIntervalsDistributionsAccordance(orders, link); foreach (var expected in ordersIntervalsDistributionsAccordance[link]) { - Assert.True(actualOrdersIntervalsDistributionsAccordance.ContainsKey(expected.Key)); - Assert.AreEqual(expected.Value.Count, actualOrdersIntervalsDistributionsAccordance[expected.Key].Count); + Assert.That(actualOrdersIntervalsDistributionsAccordance.ContainsKey(expected.Key)); + Assert.That(actualOrdersIntervalsDistributionsAccordance[expected.Key], Has.Count.EqualTo(expected.Value.Count)); for (int i = 0; i < expected.Value.Count; i++) { for (int j = 0; j < expected.Value[i].Length; j++) { - Assert.AreEqual(expected.Value[i][j], actualOrdersIntervalsDistributionsAccordance[expected.Key][i][j]); + Assert.That(actualOrdersIntervalsDistributionsAccordance[expected.Key][i][j], Is.EqualTo(expected.Value[i][j])); } } } diff --git a/Libiada.SequenceGenerator.Tests/IntervalsDistributionsStorage.cs b/Libiada.SequenceGenerator.Tests/IntervalsDistributionsStorage.cs index d8296edd..8f399462 100644 --- a/Libiada.SequenceGenerator.Tests/IntervalsDistributionsStorage.cs +++ b/Libiada.SequenceGenerator.Tests/IntervalsDistributionsStorage.cs @@ -4,26 +4,26 @@ public static class IntervalsDistributionsStorage { - public static int[][] Orders => new int[][] { - new [] { 1,1,1,1 }, - new [] { 1,1,1,2 }, - new [] { 1,1,2,1 }, - new [] { 1,1,2,2 }, - new [] { 1,1,2,3 }, - new [] { 1,2,1,1 }, - new [] { 1,2,1,2 }, - new [] { 1,2,1,3 }, - new [] { 1,2,2,1 }, - new [] { 1,2,2,2 }, - new [] { 1,2,2,3 }, - new [] { 1,2,3,1 }, - new [] { 1,2,3,2 }, - new [] { 1,2,3,3 }, - new [] { 1,2,3,4 } - }; + public static int[][] Orders => [ + [1,1,1,1], + [1,1,1,2], + [1,1,2,1], + [1,1,2,2], + [1,1,2,3], + [1,2,1,1], + [1,2,1,2], + [1,2,1,3], + [1,2,2,1], + [1,2,2,2], + [1,2,2,3], + [1,2,3,1], + [1,2,3,2], + [1,2,3,3], + [1,2,3,4] + ]; public static Dictionary IntervalsDistributions => - new Dictionary() + new() { { Link.None, new IntervalsDistribution[] { @@ -72,7 +72,7 @@ public static class IntervalsDistributionsStorage new IntervalsDistribution().SetDistribution(new Dictionary(){ {1,1 } }), - new IntervalsDistribution().SetDistribution(new Dictionary()), + new IntervalsDistribution().SetDistribution([]), } }, { Link.Start, new IntervalsDistribution[] @@ -511,7 +511,7 @@ public static class IntervalsDistributionsStorage }; public static Dictionary>> OrdersIntervalsDistributionsAccordance => - new Dictionary>>() + new() { { Link.None, new Dictionary>() { diff --git a/Libiada.SequenceGenerator.Tests/Libiada.SequenceGenerator.Tests.csproj b/Libiada.SequenceGenerator.Tests/Libiada.SequenceGenerator.Tests.csproj index 80a04c20..fee6bcec 100644 --- a/Libiada.SequenceGenerator.Tests/Libiada.SequenceGenerator.Tests.csproj +++ b/Libiada.SequenceGenerator.Tests/Libiada.SequenceGenerator.Tests.csproj @@ -7,9 +7,13 @@ - - - + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/Libiada.SequenceGenerator.Tests/NonredundantSequenceGeneratorTests.cs b/Libiada.SequenceGenerator.Tests/NonredundantSequenceGeneratorTests.cs index 4a8d4237..aef6f7f3 100644 --- a/Libiada.SequenceGenerator.Tests/NonredundantSequenceGeneratorTests.cs +++ b/Libiada.SequenceGenerator.Tests/NonredundantSequenceGeneratorTests.cs @@ -15,21 +15,21 @@ public class NonRedundantSequenceGeneratorTests [Test] public void GeneratorTest() { - var one = new ValueInt(1); - var two = new ValueInt(2); - var expected = new List - { - new BaseChain(new List { one, one, one }), - new BaseChain(new List { two, one, one }), - new BaseChain(new List { one, two, one }), - new BaseChain(new List { two, two, one }), - new BaseChain(new List { one, one, two }), - new BaseChain(new List { two, one, two }), - new BaseChain(new List { one, two, two }), - }; - var sequenceGenerator = new NonRedundantSequenceGenerator(); - var actual = sequenceGenerator.GenerateSequences(3, 2); - Assert.AreEqual(expected, actual); + ValueInt one = new(1); + ValueInt two = new(2); + List expected = + [ + new(new List { one, one, one }), + new(new List { two, one, one }), + new(new List { one, two, one }), + new(new List { two, two, one }), + new(new List { one, one, two }), + new(new List { two, one, two }), + new(new List { one, two, two }), + ]; + NonRedundantSequenceGenerator sequenceGenerator = new(); + List actual = sequenceGenerator.GenerateSequences(3, 2); + Assert.That(actual, Is.EqualTo(expected)); } /// @@ -38,27 +38,27 @@ public void GeneratorTest() [Test] public void CompleteGeneratorTest() { - var one = new ValueInt(1); - var two = new ValueInt(2); - var three = new ValueInt(3); - var expected = new List - { - new BaseChain(new List { one, one, one }), - new BaseChain(new List { two, one, one }), - new BaseChain(new List { one, two, one }), - new BaseChain(new List { two, two, one }), - new BaseChain(new List { three, two, one }), - new BaseChain(new List { two, three, one }), - new BaseChain(new List { one, one, two }), - new BaseChain(new List { two, one, two }), - new BaseChain(new List { three, one, two }), - new BaseChain(new List { one, two, two }), - new BaseChain(new List { one, three, two }), - new BaseChain(new List { two, one, three }), - new BaseChain(new List { one, two, three }), - }; - var sequenceGenerator = new NonRedundantSequenceGenerator(); - var actual = sequenceGenerator.GenerateSequences(3); - Assert.AreEqual(expected, actual); + ValueInt one = new(1); + ValueInt two = new(2); + ValueInt three = new(3); + List expected = + [ + new(new List { one, one, one }), + new(new List { two, one, one }), + new(new List { one, two, one }), + new(new List { two, two, one }), + new(new List { three, two, one }), + new(new List { two, three, one }), + new(new List { one, one, two }), + new(new List { two, one, two }), + new(new List { three, one, two }), + new(new List { one, two, two }), + new(new List { one, three, two }), + new(new List { two, one, three }), + new(new List { one, two, three }), + ]; + NonRedundantSequenceGenerator sequenceGenerator = new(); + List actual = sequenceGenerator.GenerateSequences(3); + Assert.That(actual, Is.EqualTo(expected)); } } diff --git a/Libiada.SequenceGenerator.Tests/NonredundantStrictSequenceGeneratorTests.cs b/Libiada.SequenceGenerator.Tests/NonredundantStrictSequenceGeneratorTests.cs index 5b35d0cc..34246603 100644 --- a/Libiada.SequenceGenerator.Tests/NonredundantStrictSequenceGeneratorTests.cs +++ b/Libiada.SequenceGenerator.Tests/NonredundantStrictSequenceGeneratorTests.cs @@ -15,38 +15,38 @@ public class NonRedundantStrictSequenceGeneratorTests [Test] public void GeneratorTest() { - var one = new ValueInt(1); - var two = new ValueInt(2); - var three = new ValueInt(3); - var expected = new List - { - new BaseChain(new List { two, one, one }), - new BaseChain(new List { one, two, one }), - new BaseChain(new List { two, two, one }), - new BaseChain(new List { one, one, two }), - new BaseChain(new List { two, one, two }), - new BaseChain(new List { one, two, two }) - }; - var strictSequenceGenerator = new NonRedundantStrictSequenceGenerator(); - var actual = strictSequenceGenerator.GenerateSequences(3, 2); - Assert.AreEqual(expected, actual); - expected = new List - { - new BaseChain(new List { one, one, one }) - }; + ValueInt one = new(1); + ValueInt two = new(2); + ValueInt three = new(3); + List expected = + [ + new(new List { two, one, one }), + new(new List { one, two, one }), + new(new List { two, two, one }), + new(new List { one, one, two }), + new(new List { two, one, two }), + new(new List { one, two, two }) + ]; + NonRedundantStrictSequenceGenerator strictSequenceGenerator = new(); + List actual = strictSequenceGenerator.GenerateSequences(3, 2); + Assert.That(actual, Is.EqualTo(expected)); + expected = + [ + new(new List { one, one, one }) + ]; actual = strictSequenceGenerator.GenerateSequences(3, 1); - Assert.AreEqual(expected, actual); - expected = new List - { - new BaseChain(new List { three, two, one }), - new BaseChain(new List { two, three, one }), - new BaseChain(new List { three, one, two }), - new BaseChain(new List { one, three, two }), - new BaseChain(new List { two, one, three }), - new BaseChain(new List { one, two, three }) - }; + Assert.That(actual, Is.EqualTo(expected)); + expected = + [ + new(new List { three, two, one }), + new(new List { two, three, one }), + new(new List { three, one, two }), + new(new List { one, three, two }), + new(new List { two, one, three }), + new(new List { one, two, three }) + ]; actual = strictSequenceGenerator.GenerateSequences(3, 3); - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } /// @@ -55,27 +55,27 @@ public void GeneratorTest() [Test] public void CompleteGeneratorTest() { - var one = new ValueInt(1); - var two = new ValueInt(2); - var three = new ValueInt(3); - var expected = new List - { - new BaseChain(new List { one, one, one }), - new BaseChain(new List { two, one, one }), - new BaseChain(new List { one, two, one }), - new BaseChain(new List { two, two, one }), - new BaseChain(new List { one, one, two }), - new BaseChain(new List { two, one, two }), - new BaseChain(new List { one, two, two }), - new BaseChain(new List { three, two, one }), - new BaseChain(new List { two, three, one }), - new BaseChain(new List { three, one, two }), - new BaseChain(new List { one, three, two }), - new BaseChain(new List { two, one, three }), - new BaseChain(new List { one, two, three }), - }; - var strictSequenceGenerator = new NonRedundantStrictSequenceGenerator(); - var actual = strictSequenceGenerator.GenerateSequences(3); - Assert.AreEqual(expected, actual); + ValueInt one = new(1); + ValueInt two = new(2); + ValueInt three = new(3); + List expected = + [ + new(new List { one, one, one }), + new(new List { two, one, one }), + new(new List { one, two, one }), + new(new List { two, two, one }), + new(new List { one, one, two }), + new(new List { two, one, two }), + new(new List { one, two, two }), + new(new List { three, two, one }), + new(new List { two, three, one }), + new(new List { three, one, two }), + new(new List { one, three, two }), + new(new List { two, one, three }), + new(new List { one, two, three }), + ]; + NonRedundantStrictSequenceGenerator strictSequenceGenerator = new(); + List actual = strictSequenceGenerator.GenerateSequences(3); + Assert.That(actual, Is.EqualTo(expected)); } } diff --git a/Libiada.SequenceGenerator.Tests/OrderEqualityComparerTests.cs b/Libiada.SequenceGenerator.Tests/OrderEqualityComparerTests.cs index 83f9b3e3..f7b3350c 100644 --- a/Libiada.SequenceGenerator.Tests/OrderEqualityComparerTests.cs +++ b/Libiada.SequenceGenerator.Tests/OrderEqualityComparerTests.cs @@ -30,7 +30,7 @@ public void EqualsTest(int[] first, int[] second, bool expected) { var comparer = new OrderEqualityComparer(); var actual = comparer.Equals(first, second); - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } /// @@ -54,6 +54,6 @@ public void GetHashCodeTest(int[] obj, int expected) { var comparer = new OrderEqualityComparer(); var actual = comparer.GetHashCode(obj); - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } } diff --git a/Libiada.SequenceGenerator.Tests/OrderGeneratorTests.cs b/Libiada.SequenceGenerator.Tests/OrderGeneratorTests.cs index 61c89292..6fc45a5e 100644 --- a/Libiada.SequenceGenerator.Tests/OrderGeneratorTests.cs +++ b/Libiada.SequenceGenerator.Tests/OrderGeneratorTests.cs @@ -12,17 +12,17 @@ public class OrderGeneratorTests [Test] public void GeneratorTest() { - var expected = new List - { - new[] { 1, 1, 1 }, - new[] { 1, 1, 2 }, - new[] { 1, 2, 1 }, - new[] { 1, 2, 2 } - }; + List expected = + [ + [1, 1, 1], + [1, 1, 2], + [1, 2, 1], + [1, 2, 2] + ]; - var orderGenerator = new OrderGenerator(); + OrderGenerator orderGenerator = new(); List actual = orderGenerator.GenerateOrders(3, 2); - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } /// @@ -31,18 +31,18 @@ public void GeneratorTest() [Test] public void CompleteGeneratorTest() { - var expected = new List - { - new[] { 1, 1, 1 }, - new[] { 1, 1, 2 }, - new[] { 1, 2, 1 }, - new[] { 1, 2, 2 }, - new[] { 1, 2, 3 } - }; + List expected = + [ + [1, 1, 1], + [1, 1, 2], + [1, 2, 1], + [1, 2, 2], + [1, 2, 3] + ]; - var orderGenerator = new OrderGenerator(); + OrderGenerator orderGenerator = new(); List actual = orderGenerator.GenerateOrders(3); - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } /// @@ -51,33 +51,33 @@ public void CompleteGeneratorTest() [Test] public void StrictGeneratorTest() { - var expected = new List - { - new[] { 1, 1, 2, 3 }, - new[] { 1, 2, 1, 3 }, - new[] { 1, 2, 2, 3 }, - new[] { 1, 2, 3, 1 }, - new[] { 1, 2, 3, 2 }, - new[] { 1, 2, 3, 3 } - }; + List expected = + [ + [1, 1, 2, 3], + [1, 2, 1, 3], + [1, 2, 2, 3], + [1, 2, 3, 1], + [1, 2, 3, 2], + [1, 2, 3, 3] + ]; - var orderGenerator = new OrderGenerator(); + OrderGenerator orderGenerator = new(); List actual = orderGenerator.StrictGenerateOrders(4, 3); - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } [Test] public void OrderValid() { - var expectedLength = 4; - var expectedAlphabetCardinality = 3; - var orderGenerator = new OrderGenerator(); + const int expectedLength = 4; + const int expectedAlphabetCardinality = 3; + OrderGenerator orderGenerator = new(); List actual = orderGenerator.StrictGenerateOrders(expectedLength, expectedAlphabetCardinality); - Assert.True(actual.All(o => o.Length == expectedLength),"Invalid length"); - Assert.True(actual.All(o => o.Max() == expectedAlphabetCardinality), "Invlaid alphabet cardinality"); - foreach (var order in actual) + Assert.That(actual.All(o => o.Length == expectedLength),"Invalid length"); + Assert.That(actual.All(o => o.Max() == expectedAlphabetCardinality), "Invlaid alphabet cardinality"); + foreach (int[] order in actual) { - var currentMax = 1; + int currentMax = 1; for (int i = 0; i < order.Length; i++) { if (order[i] > currentMax) diff --git a/Libiada.SequenceGenerator.Tests/OrderIteratorTests.cs b/Libiada.SequenceGenerator.Tests/OrderIteratorTests.cs index 5e2313d5..1154c289 100644 --- a/Libiada.SequenceGenerator.Tests/OrderIteratorTests.cs +++ b/Libiada.SequenceGenerator.Tests/OrderIteratorTests.cs @@ -21,14 +21,14 @@ public class OrderIteratorTests [TestCase(new[] { 1, 2, 2 }, 3)] public void IteratorTest(int[] expected, int iterations) { - var iterator = new OrderIterator(3, 2); + OrderIterator iterator = new(3, 2); for (int i = 0; i < iterations; i++) { iterator.IterateOrderCounter(); } int[] actual = iterator.Iterator; - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } /// @@ -37,22 +37,22 @@ public void IteratorTest(int[] expected, int iterations) [Test] public void EnumeratorTest() { - var iterator = new OrderIterator(3, 2); - var expected = new[] - { - new[] { 1, 1, 1 }, - new[] { 1, 1, 2 }, - new[] { 1, 2, 1 }, - new[] { 1, 2, 2 } - }; + OrderIterator iterator = new(3, 2); + int[][] expected = + [ + [1, 1, 1], + [1, 1, 2], + [1, 2, 1], + [1, 2, 2] + ]; int i = 0; foreach (var actual in iterator) { - Assert.AreEqual(expected[i], actual); + Assert.That(actual, Is.EqualTo(expected[i])); i++; } - Assert.AreEqual(expected.Length, i); + Assert.That(i, Is.EqualTo(expected.Length)); } } diff --git a/Libiada.SequenceGenerator.Tests/SequenceGeneratorTests.cs b/Libiada.SequenceGenerator.Tests/SequenceGeneratorTests.cs index 6fa3fa7e..154773d0 100644 --- a/Libiada.SequenceGenerator.Tests/SequenceGeneratorTests.cs +++ b/Libiada.SequenceGenerator.Tests/SequenceGeneratorTests.cs @@ -15,22 +15,22 @@ public class SequenceGeneratorTests [Test] public void GeneratorTest() { - var one = new ValueInt(1); - var two = new ValueInt(2); - var expected = new List - { - new BaseChain(new List { one, one, one }), - new BaseChain(new List { two, one, one }), - new BaseChain(new List { one, two, one }), - new BaseChain(new List { two, two, one }), - new BaseChain(new List { one, one, two }), - new BaseChain(new List { two, one, two }), - new BaseChain(new List { one, two, two }), - new BaseChain(new List { two, two, two }) - }; - var sequenceGenerator = new SequenceGenerator(); - var actual = sequenceGenerator.GenerateSequences(3, 2); - Assert.AreEqual(expected, actual); + ValueInt one = new(1); + ValueInt two = new(2); + List expected = + [ + new(new List { one, one, one }), + new(new List { two, one, one }), + new(new List { one, two, one }), + new(new List { two, two, one }), + new(new List { one, one, two }), + new(new List { two, one, two }), + new(new List { one, two, two }), + new(new List { two, two, two }) + ]; + SequenceGenerator sequenceGenerator = new(); + List actual = sequenceGenerator.GenerateSequences(3, 2); + Assert.That(actual, Is.EqualTo(expected)); } /// @@ -39,41 +39,41 @@ public void GeneratorTest() [Test] public void CompleteGeneratorTest() { - var one = new ValueInt(1); - var two = new ValueInt(2); - var three = new ValueInt(3); - var expected = new List - { - new BaseChain(new List { one, one, one }), - new BaseChain(new List { two, one, one }), - new BaseChain(new List { three, one, one }), - new BaseChain(new List { one, two, one }), - new BaseChain(new List { two, two, one }), - new BaseChain(new List { three, two, one }), - new BaseChain(new List { one, three, one }), - new BaseChain(new List { two, three, one }), - new BaseChain(new List { three, three, one }), - new BaseChain(new List { one, one, two }), - new BaseChain(new List { two, one, two }), - new BaseChain(new List { three, one, two }), - new BaseChain(new List { one, two, two }), - new BaseChain(new List { two, two, two }), - new BaseChain(new List { three, two, two }), - new BaseChain(new List { one, three, two }), - new BaseChain(new List { two, three, two }), - new BaseChain(new List { three, three, two }), - new BaseChain(new List { one, one, three }), - new BaseChain(new List { two, one, three }), - new BaseChain(new List { three, one, three }), - new BaseChain(new List { one, two, three }), - new BaseChain(new List { two, two, three }), - new BaseChain(new List { three, two, three }), - new BaseChain(new List { one, three, three }), - new BaseChain(new List { two, three, three }), - new BaseChain(new List { three, three, three }) - }; - var sequenceGenerator = new SequenceGenerator(); - var actual = sequenceGenerator.GenerateSequences(3); - Assert.AreEqual(expected, actual); + ValueInt one = new(1); + ValueInt two = new(2); + ValueInt three = new(3); + List expected = + [ + new(new List { one, one, one }), + new(new List { two, one, one }), + new(new List { three, one, one }), + new(new List { one, two, one }), + new(new List { two, two, one }), + new(new List { three, two, one }), + new(new List { one, three, one }), + new(new List { two, three, one }), + new(new List { three, three, one }), + new(new List { one, one, two }), + new(new List { two, one, two }), + new(new List { three, one, two }), + new(new List { one, two, two }), + new(new List { two, two, two }), + new(new List { three, two, two }), + new(new List { one, three, two }), + new(new List { two, three, two }), + new(new List { three, three, two }), + new(new List { one, one, three }), + new(new List { two, one, three }), + new(new List { three, one, three }), + new(new List { one, two, three }), + new(new List { two, two, three }), + new(new List { three, two, three }), + new(new List { one, three, three }), + new(new List { two, three, three }), + new(new List { three, three, three }) + ]; + SequenceGenerator sequenceGenerator = new(); + List actual = sequenceGenerator.GenerateSequences(3); + Assert.That(actual, Is.EqualTo(expected)); } } diff --git a/Libiada.SequenceGenerator.Tests/SequenceIteratorTests.cs b/Libiada.SequenceGenerator.Tests/SequenceIteratorTests.cs index 88fa42dc..f9bc7532 100644 --- a/Libiada.SequenceGenerator.Tests/SequenceIteratorTests.cs +++ b/Libiada.SequenceGenerator.Tests/SequenceIteratorTests.cs @@ -32,7 +32,7 @@ public void IteratorTest(int[] expected, int iterations) } var actual = iterator.Iterator; - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } /// @@ -43,21 +43,21 @@ public void EnumeratorTest() { var iterator = new SequenceIterator(3, 2); int[][] expected = - { - new[] { 1, 1, 1 }, - new[] { 2, 1, 1 }, - new[] { 1, 2, 1 }, - new[] { 2, 2, 1 }, - new[] { 1, 1, 2 }, - new[] { 2, 1, 2 }, - new[] { 1, 2, 2 }, - new[] { 2, 2, 2 } - }; + [ + [1, 1, 1], + [2, 1, 1], + [1, 2, 1], + [2, 2, 1], + [1, 1, 2], + [2, 1, 2], + [1, 2, 2], + [2, 2, 2] + ]; int i = 0; foreach (int[] actual in iterator) { - Assert.AreEqual(expected[i], actual); + Assert.That(actual, Is.EqualTo(expected[i])); i++; } } diff --git a/Libiada.SequenceGenerator.Tests/StrictSequenceGeneratorTests.cs b/Libiada.SequenceGenerator.Tests/StrictSequenceGeneratorTests.cs index d5eae843..7ac4fb04 100644 --- a/Libiada.SequenceGenerator.Tests/StrictSequenceGeneratorTests.cs +++ b/Libiada.SequenceGenerator.Tests/StrictSequenceGeneratorTests.cs @@ -15,38 +15,38 @@ public class StrictSequenceGeneratorTests [Test] public void GeneratorTest() { - var one = new ValueInt(1); - var two = new ValueInt(2); - var three = new ValueInt(3); - var expected = new List - { - new BaseChain(new List { two, one, one }), - new BaseChain(new List { one, two, one }), - new BaseChain(new List { two, two, one }), - new BaseChain(new List { one, one, two }), - new BaseChain(new List { two, one, two }), - new BaseChain(new List { one, two, two }) - }; - var strictSequenceGenerator = new StrictSequenceGenerator(); - var actual = strictSequenceGenerator.GenerateSequences(3, 2); - Assert.AreEqual(expected, actual); - expected = new List - { - new BaseChain(new List { one, one, one }) - }; + ValueInt one = new(1); + ValueInt two = new(2); + ValueInt three = new(3); + List expected = + [ + new(new List { two, one, one }), + new(new List { one, two, one }), + new(new List { two, two, one }), + new(new List { one, one, two }), + new(new List { two, one, two }), + new(new List { one, two, two }) + ]; + StrictSequenceGenerator strictSequenceGenerator = new(); + List actual = strictSequenceGenerator.GenerateSequences(3, 2); + Assert.That(actual, Is.EqualTo(expected)); + expected = + [ + new(new List { one, one, one }) + ]; actual = strictSequenceGenerator.GenerateSequences(3, 1); - Assert.AreEqual(expected, actual); - expected = new List - { - new BaseChain(new List { three, two, one }), - new BaseChain(new List { two, three, one }), - new BaseChain(new List { three, one, two }), - new BaseChain(new List { one, three, two }), - new BaseChain(new List { two, one, three }), - new BaseChain(new List { one, two, three }) - }; + Assert.That(actual, Is.EqualTo(expected)); + expected = + [ + new(new List { three, two, one }), + new(new List { two, three, one }), + new(new List { three, one, two }), + new(new List { one, three, two }), + new(new List { two, one, three }), + new(new List { one, two, three }) + ]; actual = strictSequenceGenerator.GenerateSequences(3, 3); - Assert.AreEqual(expected, actual); + Assert.That(actual, Is.EqualTo(expected)); } /// @@ -55,27 +55,27 @@ public void GeneratorTest() [Test] public void CompleteGeneratorTest() { - var one = new ValueInt(1); - var two = new ValueInt(2); - var three = new ValueInt(3); - var expected = new List - { - new BaseChain(new List { one, one, one }), - new BaseChain(new List { two, one, one }), - new BaseChain(new List { one, two, one }), - new BaseChain(new List { two, two, one }), - new BaseChain(new List { one, one, two }), - new BaseChain(new List { two, one, two }), - new BaseChain(new List { one, two, two }), - new BaseChain(new List { three, two, one }), - new BaseChain(new List { two, three, one }), - new BaseChain(new List { three, one, two }), - new BaseChain(new List { one, three, two }), - new BaseChain(new List { two, one, three }), - new BaseChain(new List { one, two, three }), - }; - var strictSequenceGenerator = new StrictSequenceGenerator(); - var actual = strictSequenceGenerator.GenerateSequences(3); - Assert.AreEqual(expected, actual); + ValueInt one = new(1); + ValueInt two = new(2); + ValueInt three = new(3); + List expected = + [ + new(new List { one, one, one }), + new(new List { two, one, one }), + new(new List { one, two, one }), + new(new List { two, two, one }), + new(new List { one, one, two }), + new(new List { two, one, two }), + new(new List { one, two, two }), + new(new List { three, two, one }), + new(new List { two, three, one }), + new(new List { three, one, two }), + new(new List { one, three, two }), + new(new List { two, one, three }), + new(new List { one, two, three }), + ]; + StrictSequenceGenerator strictSequenceGenerator = new(); + List actual = strictSequenceGenerator.GenerateSequences(3); + Assert.That(actual, Is.EqualTo(expected)); } }