From 80a455b1a4e974c371ccf8c36abc0b08de87162e Mon Sep 17 00:00:00 2001 From: Nikolay Pozdnichenko Date: Wed, 20 Mar 2024 15:30:11 +0600 Subject: [PATCH] Code style refactorings --- .../ClusterizatorsFactoryTests.cs | 6 +- .../FRiSCluster/FRiSClusterTests.cs | 8 +- .../Calculators/EquipotencyCalculatorTests.cs | 44 +- .../Krab/ConnectionTests.cs | 10 +- .../Krab/GraphElementTests.cs | 8 +- .../Krab/GraphManagerTests.cs | 26 +- .../Krab/KrabClusterizationTests.cs | 4 +- .../kMeans/KMeansClusterizationTests.cs | 8 +- .../ClusterizatorsFactory.cs | 4 +- .../FRiSCluster/FRiSCluster.cs | 20 +- .../Krab/Calculators/CommonCalculator.cs | 2 +- .../Krab/Calculators/EquipotencyCalculator.cs | 2 +- Libiada.Clusterizator/Krab/Connection.cs | 2 +- Libiada.Clusterizator/Krab/GraphElement.cs | 2 +- Libiada.Clusterizator/Krab/GraphManager.cs | 6 +- .../Krab/KrabClusterization.cs | 6 +- .../MeanShift/MeanShiftClusterization.cs | 4 +- .../kMeans/KMeansClusterization.cs | 6 +- Libiada.Core.Tests/Core/AbstractChainTests.cs | 16 +- Libiada.Core.Tests/Core/AlphabetTests.cs | 10 +- .../BinaryIntervalsManagerTests.cs | 9 +- .../IntervalsManagerTests.cs | 4 +- Libiada.Core.Tests/Core/BaseChainTests.cs | 30 +- Libiada.Core.Tests/Core/ChainTests.cs | 14 +- .../AccordanceCalculatorsTests.cs | 4 +- .../FullCalculators/AverageWordLengthTests.cs | 2 +- .../LinkedFullCalculatorTests.cs | 2 +- .../Core/CongenericChainTests.cs | 6 +- .../Core/CongenericScoreTrackTests.cs | 98 +-- Libiada.Core.Tests/Core/FmotifChainTests.cs | 10 +- Libiada.Core.Tests/Core/LinkTests.cs | 8 +- .../Core/SimpleTypes/AccidentalTests.cs | 6 +- .../Core/SimpleTypes/DurationTests.cs | 6 +- .../Core/SimpleTypes/FmotifTypeTests.cs | 8 +- .../Core/SimpleTypes/InstrumentTests.cs | 8 +- .../Core/SimpleTypes/MeasureTests.cs | 24 +- .../Core/SimpleTypes/NoteSymbolTests.cs | 6 +- .../Core/SimpleTypes/TieTests.cs | 8 +- .../Core/SimpleTypes/ValuePhantomTests.cs | 2 +- .../DissimilarChainFactoryTests.cs | 9 +- .../DataTransformers/HighOrderFactoryTests.cs | 8 +- .../PermutationGeneratorTests.cs | 16 +- .../SequenceConcatenatorTests.cs | 12 +- .../Extensions/EnumExtensionsTests.cs | 2 +- .../Extensions/StringExtensionsTests.cs | 4 +- .../Iterators/CutRuleWithFixedStartTests.cs | 2 +- .../CutRuleWithShiftedAndFixedStartTests.cs | 2 +- .../Iterators/DiffCutterTests.cs | 2 +- .../Iterators/IteratorEndTests.cs | 8 +- .../Iterators/IteratorWritableEndTests.cs | 4 +- .../Iterators/IteratorWritableStartTests.cs | 4 +- .../Music/FmotifIdentifierTests.cs | 32 +- .../Music/MidiNumberManagerTests.cs | 6 +- .../Music/MusicXml/XmlReaderTests.cs | 2 +- .../NullCycleSpaceReorganizerTests.cs | 12 +- .../SpaceReorganizers/NullReorganizerTests.cs | 8 +- .../TimeSeries/Aggregators/AverageTests.cs | 2 +- .../Aggregators/DifferenceModuleTests.cs | 2 +- .../Aggregators/DifferenceSquareRootTests.cs | 2 +- .../TimeSeries/Aggregators/MaxTests.cs | 2 +- .../TimeSeries/Aggregators/MinTests.cs | 2 +- .../TimeSeries/Aggregators/SumModuleTests.cs | 2 +- .../Aggregators/SumSquareRootTests.cs | 2 +- .../Aligners/AllOffsetsAlignerTests.cs | 4 +- .../Aligners/ByShortestAlignerTests.cs | 4 +- .../ByShortestFromRightAlignerTests.cs | 4 +- .../Aligners/FirstElementDuplicatorTests.cs | 6 +- .../Aligners/LastElementDuplicatorTests.cs | 6 +- .../OneDimensionalTimeSeriesComparerTests.cs | 2 +- ...istanceBetweenOneDimensionalPointsTests.cs | 2 +- ...istanceBetweenOneDimensionalPointsTests.cs | 2 +- Libiada.Core/Attributes/LinkAttribute.cs | 2 +- Libiada.Core/Core/AbstractChain.cs | 12 +- Libiada.Core/Core/Alphabet.cs | 18 +- .../AccordanceIntervalsManager.cs | 4 +- .../ArrangementManagers/ArrangementType.cs | 2 +- .../BinaryIntervalsManager.cs | 6 +- .../ArrangementManagers/IntervalsManager.cs | 10 +- .../Core/ArrangementManagers/SeriesManager.cs | 2 +- Libiada.Core/Core/BaseChain.cs | 8 +- Libiada.Core/Core/Chain.cs | 14 +- .../AccordanceCalculatorsFactory.cs | 13 +- .../MutualComplianceDegree.cs | 2 +- .../PartialComplianceDegree.cs | 2 +- .../BinaryCalculators/BinaryCalculator.cs | 6 +- .../BinaryCalculatorsFactory.cs | 25 +- .../InvolvedPartialDependenceCoefficient.cs | 2 +- .../MutualDependenceCoefficient.cs | 2 +- .../NormalizedPartialDependenceCoefficient.cs | 2 +- .../PartialDependenceCoefficient.cs | 2 +- .../BinaryCalculators/Redundancy.cs | 2 +- .../CongenericCalculators/ArithmeticMean.cs | 6 +- .../AverageRemoteness.cs | 6 +- .../CongenericCalculatorsFactory.cs | 82 +- .../CongenericCalculators/CuttingLength.cs | 4 +- .../CuttingLengthVocabularyEntropy.cs | 2 +- .../DescriptiveInformation.cs | 2 +- .../CongenericCalculators/GeometricMean.cs | 2 +- .../IdentificationInformation.cs | 2 +- .../InformationAmount.cs | 4 +- .../CongenericCalculators/Periodicity.cs | 4 +- .../CongenericCalculators/Probability.cs | 4 +- .../CongenericCalculators/Regularity.cs | 4 +- .../RemotenessDispersion.cs | 15 +- .../RemotenessKurtosis.cs | 17 +- .../RemotenessKurtosisCoefficient.cs | 4 +- .../RemotenessSkewness.cs | 17 +- .../RemotenessSkewnessCoefficient.cs | 4 +- .../RemotenessStandardDeviation.cs | 2 +- .../CongenericCalculators/Uniformity.cs | 4 +- .../Calculators/FullCalculators/ATSkew.cs | 6 +- .../AlphabeticAverageRemoteness.cs | 2 +- .../FullCalculators/ArithmeticMean.cs | 6 +- .../FullCalculators/AverageRemoteness.cs | 6 +- .../AverageRemotenessATSkew.cs | 2 +- .../AverageRemotenessDispersion.cs | 10 +- .../AverageRemotenessGCRatio.cs | 4 +- .../AverageRemotenessGCSkew.cs | 2 +- .../AverageRemotenessGCToATRatio.cs | 2 +- .../AverageRemotenessKurtosis.cs | 10 +- .../AverageRemotenessKurtosisCoefficient.cs | 4 +- .../AverageRemotenessMKSkew.cs | 4 +- .../AverageRemotenessRYSkew.cs | 4 +- .../AverageRemotenessSWSkew.cs | 4 +- .../AverageRemotenessSkewness.cs | 10 +- .../AverageRemotenessSkewnessCoefficient.cs | 4 +- .../AverageRemotenessStandardDeviation.cs | 2 +- .../FullCalculators/CuttingLength.cs | 4 +- .../CuttingLengthVocabularyEntropy.cs | 2 +- .../Calculators/FullCalculators/Depth.cs | 2 +- .../FullCalculators/DescriptiveInformation.cs | 2 +- .../FullCalculators/ElementsCount.cs | 2 +- .../FullCalculators/EntropyDispersion.cs | 10 +- .../FullCalculators/EntropyKurtosis.cs | 10 +- .../EntropyKurtosisCoefficient.cs | 4 +- .../FullCalculators/EntropySkewness.cs | 6 +- .../EntropySkewnessCoefficient.cs | 4 +- .../EntropyStandardDeviation.cs | 2 +- .../FullCalculators/FullCalculatorsFactory.cs | 172 ++-- .../Calculators/FullCalculators/GCRatio.cs | 10 +- .../Calculators/FullCalculators/GCSkew.cs | 6 +- .../FullCalculators/GCToATRatio.cs | 10 +- .../FullCalculators/GeometricMean.cs | 2 +- .../IdentificationInformation.cs | 2 +- .../FullCalculators/InformationAmount.cs | 2 +- .../FullCalculators/IntervalsCount.cs | 2 +- .../FullCalculators/IntervalsSum.cs | 2 +- .../Calculators/FullCalculators/MKSkew.cs | 14 +- .../FullCalculators/Probability.cs | 2 +- .../Calculators/FullCalculators/RYSkew.cs | 14 +- .../Calculators/FullCalculators/Regularity.cs | 4 +- .../FullCalculators/RemotenessDispersion.cs | 8 +- .../FullCalculators/RemotenessKurtosis.cs | 6 +- .../RemotenessKurtosisCoefficient.cs | 4 +- .../FullCalculators/RemotenessSkewness.cs | 6 +- .../RemotenessSkewnessCoefficient.cs | 4 +- .../RemotenessStandardDeviation.cs | 2 +- .../Calculators/FullCalculators/SWSkew.cs | 14 +- .../Calculators/FullCalculators/Uniformity.cs | 4 +- .../Calculators/FullCalculators/Volume.cs | 2 +- Libiada.Core/Core/CongenericChain.cs | 4 +- Libiada.Core/Core/CongenericScoreTrack.cs | 16 +- Libiada.Core/Core/FmotifChain.cs | 4 +- Libiada.Core/Core/ScoreTrack.cs | 10 +- Libiada.Core/Core/SimpleTypes/Duration.cs | 8 +- Libiada.Core/Core/SimpleTypes/Fmotif.cs | 12 +- Libiada.Core/Core/SimpleTypes/Measure.cs | 2 +- .../Core/SimpleTypes/MeasureAttributes.cs | 2 +- Libiada.Core/Core/SimpleTypes/NullValue.cs | 2 +- Libiada.Core/Core/SimpleTypes/ValueInt.cs | 2 +- Libiada.Core/Core/SimpleTypes/ValueNote.cs | 28 +- Libiada.Core/Core/SimpleTypes/ValuePhantom.cs | 6 +- Libiada.Core/Core/SimpleTypes/ValueString.cs | 4 +- .../DissimilarChainFactory.cs | 4 +- .../DataTransformers/DnaCodingTables.cs | 2 +- .../DataTransformers/DnaProcessing.cs | 6 +- .../DataTransformers/DnaTransformer.cs | 20 +- .../DataTransformers/HighOrderFactory.cs | 8 +- .../DataTransformers/SequenceConcatenator.cs | 14 +- Libiada.Core/Extensions/ArrayExtensions.cs | 16 +- Libiada.Core/Images/ColumnOrderExtractor.cs | 6 +- Libiada.Core/Images/ImageProcessor.cs | 2 +- Libiada.Core/Images/ImageResizer.cs | 2 +- Libiada.Core/Images/LineOrderExtractor.cs | 6 +- Libiada.Core/Images/ZigzagOrderExtractor.cs | 6 +- Libiada.Core/Iterators/CustomIterator.cs | 2 +- Libiada.Core/Iterators/CutRule.cs | 4 +- Libiada.Core/Iterators/DiffCutter.cs | 2 +- Libiada.Core/Iterators/IteratorBase.cs | 2 +- Libiada.Core/Music/BorodaDivider.cs | 10 +- Libiada.Core/Music/FmotifDivider.cs | 80 +- Libiada.Core/Music/FmotifIdentifier.cs | 4 +- Libiada.Core/Music/MidiNumberManager.cs | 2 +- Libiada.Core/Music/MusicXml/MusicXmlParser.cs | 28 +- Libiada.Core/Music/MusicXml/MusicXmlReader.cs | 37 +- Libiada.Core/Music/PriorityDiscover.cs | 26 +- .../NullCycleSpaceReorganizator.cs | 4 +- .../SpaceReorganizers/NullReorganizer.cs | 6 +- .../SpaceNotPhantomReorganizer.cs | 2 +- .../SpacePhantomReorganizer.cs | 4 +- ...SpaceReorganizerFromChainToChainByBlock.cs | 2 +- .../TimeSeries/Aggregators/Aggregator.cs | 2 +- .../Aggregators/AggregatorsFactory.cs | 30 +- .../TimeSeries/Aggregators/Average.cs | 2 +- .../Aggregators/DifferenceModule.cs | 2 +- .../Aggregators/DifferenceSquareRoot.cs | 2 +- .../Aggregators/IDistancesAggregator.cs | 2 +- Libiada.Core/TimeSeries/Aggregators/Max.cs | 2 +- Libiada.Core/TimeSeries/Aggregators/Min.cs | 2 +- .../TimeSeries/Aggregators/SumModule.cs | 2 +- .../TimeSeries/Aggregators/SumSquareRoot.cs | 2 +- Libiada.Core/TimeSeries/Aligners/Aligner.cs | 2 +- .../TimeSeries/Aligners/AlignersFactory.cs | 24 +- .../TimeSeries/Aligners/AllOffsetsAligner.cs | 2 +- .../TimeSeries/Aligners/ByShortestAligner.cs | 2 +- .../Aligners/ByShortestFromRightAligner.cs | 2 +- .../Aligners/FirstElementDuplicator.cs | 6 +- .../TimeSeries/Aligners/ITimeSeriesAligner.cs | 2 +- .../Aligners/LastElementDuplicator.cs | 4 +- .../IOneDimensionalTimeSeriesComparer.cs | 2 +- .../OneDimensionalTimeSeriesComparer.cs | 4 +- .../DistanceCalculators/DistanceCalculator.cs | 2 +- .../DistanceCalculatorsFactory.cs | 15 +- ...ceBetweenOneDimensionalPointsCalculator.cs | 2 +- ...ceBetweenOneDimensionalPointsCalculator.cs | 2 +- .../IOneDimensionalPointsDistance.cs | 2 +- .../Restrictions/IRestriction.cs | 2 +- .../Restrictions/SoftRestriction.cs | 2 +- .../MarkovChainNotCongenericStaticTests.cs | 12 +- .../Probability/ProbabilityMatrixTests.cs | 38 +- .../MarkovCompare/MarkovMetricsTests.cs | 4 +- .../MarkovChain/Builders/MatrixBuilder.cs | 13 +- .../Builders/ProbabilityMatrixBuilder.cs | 13 +- .../Generators/GeneratorFactory.cs | 10 +- .../MarkovChain/Generators/SimpleGenerator.cs | 2 +- .../MarkovChain/MarkovChainBase.cs | 21 +- .../MarkovChain/MarkovChainFactory.cs | 22 +- .../MarkovChainNotCongenericStatic.cs | 8 +- .../MarkovChain/MarkovChainRandom.cs | 8 +- .../Matrices/Absolute/IOpenMatrix.cs | 4 +- .../MarkovChain/Matrices/Absolute/Matrix.cs | 8 +- .../Matrices/Absolute/MatrixRow.cs | 8 +- .../MarkovChain/Matrices/Base/MatrixBase.cs | 6 +- .../MarkovChain/Matrices/Base/MatrixCommon.cs | 2 +- .../Matrices/Probability/ProbabilityMatrix.cs | 2 +- .../Probability/ProbabilityMatrixRow.cs | 4 +- .../MarkovCompare/MarkovMetrics.cs | 2 +- .../PhantomChainGeneratorTests.cs | 24 +- Libiada.PhantomChains.Tests/TreeTests.cs | 10 +- Libiada.PhantomChains/AbstractNode.cs | 2 +- .../PhantomChainGenerator.cs | 16 +- Libiada.PhantomChains/PhantomTable.cs | 6 +- Libiada.PhantomChains/TreeTop.cs | 2 +- .../Collectors/FrequencyDictionaryTests.cs | 32 +- .../Base/Iterators/StartIteratorTests.cs | 12 +- .../Base/Seekers/Converters/FilterTests.cs | 12 +- .../Model/Threshold/ThresholdLinearTests.cs | 2 +- .../Base/Collectors/DataCollector.cs | 4 +- .../Base/Collectors/FrequencyDictionary.cs | 10 +- .../Base/Iterators/BaseIterator.cs | 2 +- .../Base/Iterators/EndIterator.cs | 2 +- .../Base/Iterators/StartIterator.cs | 2 +- .../Seekers/Converters/SequenceCleaner.cs | 2 +- Libiada.Segmenter/Base/Seekers/Seeker.cs | 2 +- .../Base/Seekers/SeekerSequence.cs | 2 +- .../Base/Sequences/ComplexChain.cs | 6 +- Libiada.Segmenter/Extended/Helper.cs | 2 +- Libiada.Segmenter/Model/Algorithm.cs | 4 +- Libiada.Segmenter/Model/AlgorithmBase.cs | 12 +- Libiada.Segmenter/Model/AlgorithmFactory.cs | 13 +- .../CriterionAttitudeOfRemoteness.cs | 4 +- .../Criterion/CriterionEqualityOfDepths.cs | 2 +- .../Model/Criterion/CriterionFactory.cs | 28 +- .../Model/Criterion/CriterionMethod.cs | 20 +- .../CriterionMinSymmetryByShrader.cs | 2 +- .../Criterion/CriterionMinimumRegularity.cs | 2 +- .../Model/Criterion/CriterionPartialOrlov.cs | 4 +- Libiada.Segmenter/Model/MainOutputData.cs | 2 +- Libiada.Segmenter/Model/PositionFilter.cs | 2 +- .../DifferenceAverageIntervalExtractor.cs | 18 +- .../Model/Seekers/ProbabilityExtractor.cs | 8 +- .../Model/Seekers/SubwordExtractor.cs | 4 +- .../Model/Seekers/WordExtractor.cs | 9 +- .../Model/Seekers/WordExtractorFactory.cs | 20 +- .../Model/SimpleChainSplitter.cs | 2 +- .../Model/Threshold/ThresholdFactory.cs | 19 +- .../PoemsSegmenter/FrequencySegmenter.cs | 6 +- .../PoemsSegmenter/PoemSegmenter.cs | 14 +- .../IntervalsDistributionExtractorTests.cs | 2 +- .../IntervalsDistributionsStorage.cs | 750 +++++++++--------- .../OrderEqualityComparerTests.cs | 8 +- .../SequenceIteratorTests.cs | 6 +- .../IntervalsDistribution.cs | 8 +- .../IntervalsDistributionExtractor.cs | 18 +- .../NonredundantSequenceGenerator.cs | 10 +- .../NonredundantStrictSequenceGenerator.cs | 12 +- Libiada.SequenceGenerator/OrderGenerator.cs | 8 +- Libiada.SequenceGenerator/OrderIterator.cs | 2 +- .../SequenceGenerator.cs | 6 +- .../StrictSequenceGenerator.cs | 10 +- 300 files changed, 1539 insertions(+), 1736 deletions(-) diff --git a/Libiada.Clusterizator.Tests/ClusterizatorsFactoryTests.cs b/Libiada.Clusterizator.Tests/ClusterizatorsFactoryTests.cs index 674d1a3e..b6a7420b 100644 --- a/Libiada.Clusterizator.Tests/ClusterizatorsFactoryTests.cs +++ b/Libiada.Clusterizator.Tests/ClusterizatorsFactoryTests.cs @@ -23,13 +23,13 @@ public class ClusterizatorsFactoryTests [TestCase(ClusterizationType.Krab, typeof(KrabClusterization))] public void SelectionTest(ClusterizationType type, Type expected) { - var parameters = new Dictionary + Dictionary parameters = new() { { "powerWeight", 1 }, { "normalizedDistanceWeight", 1 }, { "distanceWeight", 4 } }; - var clusterizator = ClusterizatorsFactory.CreateClusterizator(type, parameters); + IClusterizator clusterizator = ClusterizatorsFactory.CreateClusterizator(type, parameters); Assert.That(clusterizator, Is.InstanceOf(expected)); } @@ -40,7 +40,7 @@ public void SelectionTest(ClusterizationType type, Type expected) [Test] public void SelectionErrorTest() { - var parameters = new Dictionary(); + Dictionary parameters = []; Assert.Throws(() => ClusterizatorsFactory.CreateClusterizator(0, parameters)); } } diff --git a/Libiada.Clusterizator.Tests/FRiSCluster/FRiSClusterTests.cs b/Libiada.Clusterizator.Tests/FRiSCluster/FRiSClusterTests.cs index e098ec4e..e3da7b80 100644 --- a/Libiada.Clusterizator.Tests/FRiSCluster/FRiSClusterTests.cs +++ b/Libiada.Clusterizator.Tests/FRiSCluster/FRiSClusterTests.cs @@ -14,7 +14,7 @@ public class FRiSClusterTests [Test] public void SimpleClusterTest() { - var cluster = new FRiSCluster(2, 2); + FRiSCluster cluster = new(2, 2); double[][] data = [[1], [2], [10]]; int[] actual = cluster.Cluster(2, data); Assert.That(actual, Is.EqualTo(new[] { 0, 0, 1 })); @@ -26,7 +26,7 @@ public void SimpleClusterTest() [Test] public void FourPointsClusterTest() { - var cluster = new FRiSCluster(2, 2); + FRiSCluster cluster = new(2, 2); double[][] data = [[-5], [-4], [4], [5]]; int[] actual = cluster.Cluster(2, data); Assert.That(actual, Is.EqualTo(new int[] { 0, 0, 1, 1 })); @@ -38,7 +38,7 @@ public void FourPointsClusterTest() [Test] public void TwoDimensionDataClusterTest() { - var cluster = new FRiSCluster(2, 2); + FRiSCluster cluster = new(2, 2); double[][] data = [[-5, 1], [-5, 2], [0, 0], [1, 1]]; int[] actual = cluster.Cluster(2, data); Assert.That(actual, Is.EqualTo(new int[] { 0, 0, 1, 1 })); @@ -51,7 +51,7 @@ public void TwoDimensionDataClusterTest() [Test] public void MultipleDataPointsClusterTest() { - var cluster = new FRiSCluster(2, 2); + FRiSCluster cluster = new(2, 2); double[][] data = [[-2.1], [-1.0], [0.3], [1.0], [1.1], [7.0], [9.0]]; int[] actual = cluster.Cluster(2, data); Assert.That(actual, Is.EqualTo(new int[] { 0, 0, 0, 0, 0, 1, 1 })); diff --git a/Libiada.Clusterizator.Tests/Krab/Calculators/EquipotencyCalculatorTests.cs b/Libiada.Clusterizator.Tests/Krab/Calculators/EquipotencyCalculatorTests.cs index d57293c2..7e41d575 100644 --- a/Libiada.Clusterizator.Tests/Krab/Calculators/EquipotencyCalculatorTests.cs +++ b/Libiada.Clusterizator.Tests/Krab/Calculators/EquipotencyCalculatorTests.cs @@ -20,23 +20,23 @@ public class EquipotencyCalculatorTests [SetUp] public void Initialization() { - var elements = new List - { + List elements = + [ new([0.0], "1"), new([2.0], "2"), new([5.0], "3"), new([6.0], "4") - }; + ]; - var connections = new List - { + List connections = + [ new(0, 1), new(0, 2), new(0, 3), new(1, 2), new(1, 3), new(2, 3) - }; + ]; manager = new GraphManager(connections, elements); } @@ -47,14 +47,14 @@ public void Initialization() [Test] public void FourPointsZeroTest() { - var connected = new[] { true, false, false, true, false, false }; + bool[] connected = [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, 2 }; + int[] taxonNumbers = [1, 1, 1, 2]; for (int i = 0; i < taxonNumbers.Length; i++) { @@ -70,14 +70,14 @@ public void FourPointsZeroTest() [Test] public void FourPointsOneTest() { - var connected = new[] { true, false, false, false, false, true }; + bool[] connected = [true, false, false, false, false, true]; for (int i = 0; i < connected.Length; i++) { manager.Connections[i].Connected = connected[i]; } - var taxonNumbers = new[] { 1, 1, 2, 2 }; + int[] taxonNumbers = [1, 1, 2, 2]; for (int i = 0; i < taxonNumbers.Length; i++) { @@ -93,14 +93,14 @@ public void FourPointsOneTest() [Test] public void FourPointsTwoTest() { - var connected = new[] { false, false, false, true, false, true }; + bool[] connected = [false, false, false, true, false, true]; for (int i = 0; i < connected.Length; i++) { manager.Connections[i].Connected = connected[i]; } - var taxonNumbers = new[] { 1, 2, 2, 2 }; + int[] taxonNumbers = [1, 2, 2, 2]; for (int i = 0; i < taxonNumbers.Length; i++) { @@ -116,14 +116,14 @@ public void FourPointsTwoTest() [Test] public void FourPointsThreeTest() { - var connected = new[] { true, false, false, false, false, false }; + bool[] connected = [true, false, false, false, false, false]; for (int i = 0; i < connected.Length; i++) { manager.Connections[i].Connected = connected[i]; } - var taxonNumbers = new[] { 1, 1, 2, 3 }; + int[] taxonNumbers = [1, 1, 2, 3]; for (int i = 0; i < taxonNumbers.Length; i++) { @@ -139,14 +139,14 @@ public void FourPointsThreeTest() [Test] public void FourPointsFourTest() { - var connected = new[] { false, false, false, true, false, false }; + bool[] connected = [false, false, false, true, false, false]; for (int i = 0; i < connected.Length; i++) { manager.Connections[i].Connected = connected[i]; } - var taxonNumbers = new[] { 1, 2, 2, 3 }; + int[] taxonNumbers = [1, 2, 2, 3]; for (int i = 0; i < taxonNumbers.Length; i++) { @@ -162,14 +162,14 @@ public void FourPointsFourTest() [Test] public void FourPointsFiveTest() { - var connected = new[] { false, false, false, true, false, true }; + bool[] connected = [false, false, false, true, false, true]; for (int i = 0; i < connected.Length; i++) { manager.Connections[i].Connected = connected[i]; } - var taxonNumbers = new[] { 1, 2, 3, 3 }; + int[] taxonNumbers = [1, 2, 3, 3]; for (int i = 0; i < taxonNumbers.Length; i++) { @@ -204,14 +204,14 @@ public void FourPointsSixTest() [Test] public void FourPointsSevenTest() { - var connected = new[] { false, true, false, false, true, false }; + bool[] connected = [false, true, false, false, true, false]; for (int i = 0; i < connected.Length; i++) { manager.Connections[i].Connected = connected[i]; } - var taxonNumbers = new[] { 1, 2, 1, 2 }; + int[] taxonNumbers = [1, 2, 1, 2]; for (int i = 0; i < taxonNumbers.Length; i++) { @@ -227,14 +227,14 @@ public void FourPointsSevenTest() [Test] public void FourPointsElevenTest() { - var connected = new[] { false, true, false, false, true, false }; + bool[] connected = [false, true, false, false, true, false]; for (int i = 0; i < connected.Length; i++) { manager.Connections[i].Connected = connected[i]; } - var taxonNumbers = new[] { 1, 2, 1, 2 }; + int[] taxonNumbers = [1, 2, 1, 2]; for (int i = 0; i < taxonNumbers.Length; i++) { diff --git a/Libiada.Clusterizator.Tests/Krab/ConnectionTests.cs b/Libiada.Clusterizator.Tests/Krab/ConnectionTests.cs index b1a7a92a..7c22404f 100644 --- a/Libiada.Clusterizator.Tests/Krab/ConnectionTests.cs +++ b/Libiada.Clusterizator.Tests/Krab/ConnectionTests.cs @@ -14,7 +14,7 @@ public class ConnectionTests [Test] public void ConnectionOneTest() { - var connection = new Connection(0, 1); + Connection connection = new(0, 1); Assert.That(connection.Connected, Is.False); } @@ -24,7 +24,7 @@ public void ConnectionOneTest() [Test] public void CloneOneTest() { - var connection = new Connection(2, 5) + Connection connection = new(2, 5) { Connected = false, Distance = 6, @@ -33,7 +33,7 @@ public void CloneOneTest() TauStar = 7, Lambda = 13 }; - var secondConnection = connection.Clone(); + Connection secondConnection = connection.Clone(); Assert.Multiple(() => { Assert.That(connection.Connected, Is.EqualTo(secondConnection.Connected)); @@ -56,7 +56,7 @@ public void CloneOneTest() [Test] public void CloneTwoTest() { - var connection = new Connection(2, 3) + Connection connection = new(2, 3) { Connected = true, Distance = 1, @@ -65,7 +65,7 @@ public void CloneTwoTest() TauStar = 0, Lambda = 5 }; - var secondConnection = connection.Clone(); + Connection secondConnection = connection.Clone(); Assert.Multiple(() => { Assert.That(connection.Connected, Is.EqualTo(secondConnection.Connected)); diff --git a/Libiada.Clusterizator.Tests/Krab/GraphElementTests.cs b/Libiada.Clusterizator.Tests/Krab/GraphElementTests.cs index 0e82ab4e..b2f82739 100644 --- a/Libiada.Clusterizator.Tests/Krab/GraphElementTests.cs +++ b/Libiada.Clusterizator.Tests/Krab/GraphElementTests.cs @@ -14,7 +14,7 @@ public class GraphElementTests [Test] public void NodeTest() { - var node = new GraphElement([15.0], "node"); + GraphElement node = new([15.0], "node"); Assert.That(node.Content[0], Is.EqualTo(15)); Assert.That(node.TaxonNumber, Is.Zero); @@ -26,7 +26,7 @@ public void NodeTest() [Test] public void NodeTwoTest() { - var node = new GraphElement([15.0], 1) { TaxonNumber = 5 }; + GraphElement node = new([15.0], 1) { TaxonNumber = 5 }; Assert.That(node.Content[0], Is.EqualTo(15)); @@ -45,8 +45,8 @@ public void NodeTwoTest() [Test] public void CloneTest() { - var node = new GraphElement([15.0], "node"); - var nodeClone = node.Clone(); + GraphElement node = new([15.0], "node"); + GraphElement nodeClone = node.Clone(); Assert.Multiple(() => { diff --git a/Libiada.Clusterizator.Tests/Krab/GraphManagerTests.cs b/Libiada.Clusterizator.Tests/Krab/GraphManagerTests.cs index 76ec70ba..3a37121a 100644 --- a/Libiada.Clusterizator.Tests/Krab/GraphManagerTests.cs +++ b/Libiada.Clusterizator.Tests/Krab/GraphManagerTests.cs @@ -65,7 +65,7 @@ public void Initialization() [Test] public void UnConnectedGraphsTest() { - var connector = new GraphManager(connectionsList, elementsList); + GraphManager connector = new(connectionsList, elementsList); connector.Connect(2, 3); Assert.That(connectionsList[9].Connected, Is.True); @@ -79,7 +79,7 @@ public void UnConnectedGraphsTest() [Test] public void SearchConnectionTest() { - var connector = new GraphManager(connectionsList, elementsList); + GraphManager connector = new(connectionsList, elementsList); 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); @@ -95,7 +95,7 @@ public void SearchConnectionTest() [Test] public void OneConnectedGraphTest() { - var connector = new GraphManager(connectionsList, elementsList); + GraphManager connector = new(connectionsList, elementsList); connector.Connect(0, 2); Assert.That(connectionsList[1].Connected, Is.True); @@ -110,7 +110,7 @@ public void OneConnectedGraphTest() [Test] public void BothConnectionGraphTest() { - var connector = new GraphManager(connectionsList, elementsList); + GraphManager connector = new(connectionsList, elementsList); connector.Connect(1, 5); Assert.That(connectionsList[8].Connected, Is.True); Assert.That(elementsList[0].TaxonNumber, Is.EqualTo(1)); @@ -125,7 +125,7 @@ public void BothConnectionGraphTest() [Test] public void UnBothConnectionGraphTest() { - var connector = new GraphManager(connectionsList, elementsList); + GraphManager connector = new(connectionsList, elementsList); connectionsList[1].Connected = true; elementsList[2].TaxonNumber = 1; connector.Connect(1, 2); @@ -142,7 +142,7 @@ public void UnBothConnectionGraphTest() [Test] public void CutGraphTest() { - var connector = new GraphManager(connectionsList, elementsList); + GraphManager connector = new(connectionsList, elementsList); connector.Cut(elementsList[0], elementsList[1]); Assert.That(connectionsList[0].Connected, Is.False); @@ -158,7 +158,7 @@ public void CutGraphTest() [Test] public void CutGraphTrioTest() { - var connector = new GraphManager(connectionsList, elementsList); + GraphManager connector = new(connectionsList, elementsList); connectionsList[1].Connected = true; elementsList[2].TaxonNumber = 1; connector.Cut(elementsList[0], elementsList[2]); @@ -175,8 +175,8 @@ public void CutGraphTrioTest() [Test] public void CloneTest() { - var connector = new GraphManager(connectionsList, elementsList); - var connector2 = connector.Clone(); + GraphManager connector = new(connectionsList, elementsList); + GraphManager connector2 = connector.Clone(); Assert.That(connector2, Is.TypeOf(typeof(GraphManager))); Assert.That(connector2.Connections[0], Is.TypeOf(typeof(Connection))); @@ -201,14 +201,14 @@ public void GraphConnectionTest() elementsList[connectionsList[i].SecondElementIndex].TaxonNumber = 0; } - var lambdas = new[] { 10, 20, 15, 21, 6, 11, 12, 27, 16, 9, 25, 26, 13, 21, 22 }; + int[] lambdas = [10, 20, 15, 21, 6, 11, 12, 27, 16, 9, 25, 26, 13, 21, 22]; for (int i = 0; i < lambdas.Length; i++) { connectionsList[i].Lambda = lambdas[i]; } - var connector = new GraphManager(connectionsList, elementsList); + GraphManager connector = new(connectionsList, elementsList); connector.ConnectGraph(); Assert.That(connectionsList[0].Connected, Is.True); @@ -234,7 +234,7 @@ public void GraphConnectionTest() [Test] public void CutConnectionTest() { - var connector = new GraphManager(connectionsList, elementsList); + GraphManager connector = new(connectionsList, elementsList); connector.Cut(connector.Connections[0]); Assert.That(connectionsList[0].Connected, Is.False); @@ -250,7 +250,7 @@ public void CutConnectionTest() [Test] public void CutConnectionTrioTest() { - var connector = new GraphManager(connectionsList, elementsList); + GraphManager connector = new(connectionsList, elementsList); connectionsList[1].Connected = true; elementsList[2].TaxonNumber = 1; connector.Cut(connector.Connections[1]); diff --git a/Libiada.Clusterizator.Tests/Krab/KrabClusterizationTests.cs b/Libiada.Clusterizator.Tests/Krab/KrabClusterizationTests.cs index dd9ab85b..09765e0e 100644 --- a/Libiada.Clusterizator.Tests/Krab/KrabClusterizationTests.cs +++ b/Libiada.Clusterizator.Tests/Krab/KrabClusterizationTests.cs @@ -14,7 +14,7 @@ public class KrabClusterizationTests [Test] public void ClusterizationTest() { - var krab = new KrabClusterization(4, 2, 1); + KrabClusterization krab = new(4, 2, 1); double[][] data = [ [2.0, 2.0], @@ -25,7 +25,7 @@ public void ClusterizationTest() [9.0, 7.0] ]; - var result = krab.Cluster(2, data); + int[] result = krab.Cluster(2, data); Assert.Multiple(() => { diff --git a/Libiada.Clusterizator.Tests/kMeans/KMeansClusterizationTests.cs b/Libiada.Clusterizator.Tests/kMeans/KMeansClusterizationTests.cs index 85f696c7..b566bc0e 100644 --- a/Libiada.Clusterizator.Tests/kMeans/KMeansClusterizationTests.cs +++ b/Libiada.Clusterizator.Tests/kMeans/KMeansClusterizationTests.cs @@ -14,7 +14,7 @@ public class KMeansClusterizationTests [Test] public void SimpleClusterTest() { - var cluster = new KMeansClusterization(); + KMeansClusterization cluster = new(); double[][] data = [[1], [2], [10]]; int[] actual = cluster.Cluster(2, data); Assert.That(actual[0], Is.EqualTo(actual[1])); @@ -27,7 +27,7 @@ public void SimpleClusterTest() [Test] public void FourPointsClusterTest() { - var cluster = new KMeansClusterization(); + KMeansClusterization cluster = new(); double[][] data = [[-5], [-4], [4], [5]]; int[] actual = cluster.Cluster(2, data); Assert.That(actual[0], Is.EqualTo(actual[1])); @@ -41,7 +41,7 @@ public void FourPointsClusterTest() [Test] public void TwoDimensionDataClusterTest() { - var cluster = new KMeansClusterization(); + KMeansClusterization cluster = new(); double[][] data = [[-5, 1], [-5, 2], [0, 0], [1, 1]]; int[] actual = cluster.Cluster(2, data); Assert.That(actual[0], Is.EqualTo(actual[1])); @@ -55,7 +55,7 @@ public void TwoDimensionDataClusterTest() [Test] public void MultipleDataPointsClusterTest() { - var cluster = new KMeansClusterization(); + KMeansClusterization cluster = new(); double[][] data = [[-2.1], [-1.0], [0.3], [1.0], [1.1], [7.0], [9.0]]; int[] actual = cluster.Cluster(2, data); Assert.That(actual[0], Is.EqualTo(actual[1])); diff --git a/Libiada.Clusterizator/ClusterizatorsFactory.cs b/Libiada.Clusterizator/ClusterizatorsFactory.cs index 3c81beca..e2581667 100644 --- a/Libiada.Clusterizator/ClusterizatorsFactory.cs +++ b/Libiada.Clusterizator/ClusterizatorsFactory.cs @@ -57,8 +57,8 @@ public static IClusterizator CreateClusterizator(ClusterizationType type, Dictio return new MeanShiftClusterization(bandwidth); case ClusterizationType.FRiSCluster: - var minimumClusters = (int)parameters["clustersCount"]; - var maximumClusters = (int)parameters["maximumClusters"]; + int minimumClusters = (int)parameters["clustersCount"]; + int maximumClusters = (int)parameters["maximumClusters"]; return new FRiSCluster.FRiSCluster(minimumClusters, maximumClusters); default: diff --git a/Libiada.Clusterizator/FRiSCluster/FRiSCluster.cs b/Libiada.Clusterizator/FRiSCluster/FRiSCluster.cs index dd03bc2d..4dd37888 100644 --- a/Libiada.Clusterizator/FRiSCluster/FRiSCluster.cs +++ b/Libiada.Clusterizator/FRiSCluster/FRiSCluster.cs @@ -72,7 +72,7 @@ public int[] Cluster(int clustersCount, double[][] data) CalculateDistances(); // average competitive similarity in comparison to virtual sample (set) B - var averageSimilarityFunction = new double[data.Length]; + double[] averageSimilarityFunction = new double[data.Length]; for (int i = 0; i < data.Length; i++) { @@ -85,7 +85,7 @@ public int[] Cluster(int clustersCount, double[][] data) averageSimilarityFunction[i] = localSimilarity / data.Length; } - var optimalClustersBelonging = Cluster(averageSimilarityFunction); + int[] optimalClustersBelonging = Cluster(averageSimilarityFunction); return optimalClustersBelonging; } @@ -93,7 +93,7 @@ public int[] Cluster(int clustersCount, double[][] data) private int[] Cluster(double[] averageSimilarityFunction) { // maximum of average similarity in competition with sample (set) B - var currentPillarIndexes = new List(); + List currentPillarIndexes = []; double maxSimilarity = averageSimilarityFunction.Max(); currentPillarIndexes.Add(Array.IndexOf(averageSimilarityFunction, maxSimilarity)); @@ -107,7 +107,7 @@ private int[] Cluster(double[] averageSimilarityFunction) //bool pillarsNotEqual = true; //while (pillarsNotEqual) //{ - var tempPillarIndexes = new List(currentPillarIndexes); + List tempPillarIndexes = new(currentPillarIndexes); for (int j = 0; j < currentPillarIndexes.Count; j++) { (currentPillarIndexes[j], currentCompactness) = ReselectPillar( @@ -184,7 +184,7 @@ private int[] AddPillar(List currentPillarIndexes) private (int clusterPointsIndex, double compactness) ReselectPillar(int pillarIndex, List pillarIndexes, int[] clustersBelonging) { int[] clusterPointsIndexes = data.Select((d, i) => i).Where(i => clustersBelonging[i] == pillarIndexes.IndexOf(pillarIndex)).ToArray(); - var clusterCompactness = new double[clusterPointsIndexes.Length]; + double[] clusterCompactness = new double[clusterPointsIndexes.Length]; for (int i = 0; i < clusterPointsIndexes.Length; i++) { @@ -223,13 +223,13 @@ private int[] AddPillar(List currentPillarIndexes) /// private int CalculateCompactnessForPotentialPillars(List pillarIndexes) { - var compactness = new double[data.Length]; + double[] compactness = new double[data.Length]; for (int i = 0; i < data.Length; i++) { if (!pillarIndexes.Contains(i)) { - var tempPillarIndexes = new List(pillarIndexes) { i }; + List tempPillarIndexes = new(pillarIndexes) { i }; int[] clustersBelonging = DetermineClusters(tempPillarIndexes); compactness[i] = CalculateCompactness(clustersBelonging, i, tempPillarIndexes); for (int j = 0; j < pillarIndexes.Count; j++) @@ -291,11 +291,11 @@ private void CalculateDistances() /// private int[] DetermineClusters(List pillarIndexes) { - var clustersBelonging = new int[distances.GetLength(0)]; + int[] clustersBelonging = new int[distances.GetLength(0)]; for (int i = 0; i < clustersBelonging.Length; i++) { - var clusterNumber = 0; + int clusterNumber = 0; for (int j = 1; j < pillarIndexes.Count; j++) { @@ -355,7 +355,7 @@ private double CalculateCompactness(int[] clustersBelonging, int pillarIndex, Li /// private double DistanceToNearestCompetitivePillar(List pillarIndexes, int pointIndex, int pillarIndex) { - var nearestPillarDistance = new List(); + List nearestPillarDistance = []; for (int k = 0; k < pillarIndexes.Count; k++) { diff --git a/Libiada.Clusterizator/Krab/Calculators/CommonCalculator.cs b/Libiada.Clusterizator/Krab/Calculators/CommonCalculator.cs index 37c246f2..b976a304 100644 --- a/Libiada.Clusterizator/Krab/Calculators/CommonCalculator.cs +++ b/Libiada.Clusterizator/Krab/Calculators/CommonCalculator.cs @@ -28,7 +28,7 @@ public static void CalculateCharacteristic(GraphManager graph, double normalized calculator.Calculate(graph); calculator = new TauCalculator(); calculator.Calculate(graph); - var lambdaCalculator = new LambdaCalculator(); + LambdaCalculator lambdaCalculator = new(); lambdaCalculator.Calculate(graph, normalizedDistanceWeight, distanceWeight); } } diff --git a/Libiada.Clusterizator/Krab/Calculators/EquipotencyCalculator.cs b/Libiada.Clusterizator/Krab/Calculators/EquipotencyCalculator.cs index bc7a11a7..8591eca7 100644 --- a/Libiada.Clusterizator/Krab/Calculators/EquipotencyCalculator.cs +++ b/Libiada.Clusterizator/Krab/Calculators/EquipotencyCalculator.cs @@ -18,7 +18,7 @@ public static class EquipotencyCalculator public static double Calculate(GraphManager manager) { // calculating nodes count in each group - var taxonPower = new List(); + List taxonPower = []; for (int i = 0; i < manager.GetNextTaxonNumber(); i++) { taxonPower.Add(0); diff --git a/Libiada.Clusterizator/Krab/Connection.cs b/Libiada.Clusterizator/Krab/Connection.cs index 83297214..255d1846 100644 --- a/Libiada.Clusterizator/Krab/Connection.cs +++ b/Libiada.Clusterizator/Krab/Connection.cs @@ -77,7 +77,7 @@ public Connection(int firstIndex, int secondIndex) /// public Connection Clone() { - var clone = new Connection(FirstElementIndex, SecondElementIndex) + Connection clone = new(FirstElementIndex, SecondElementIndex) { Connected = Connected, Distance = Distance, diff --git a/Libiada.Clusterizator/Krab/GraphElement.cs b/Libiada.Clusterizator/Krab/GraphElement.cs index 75d0e2e9..7b0ef44c 100644 --- a/Libiada.Clusterizator/Krab/GraphElement.cs +++ b/Libiada.Clusterizator/Krab/GraphElement.cs @@ -63,7 +63,7 @@ public int TaxonNumber /// public GraphElement Clone() { - var clone = new GraphElement(Content, Id) { TaxonNumber = taxonNumber }; + GraphElement clone = new(Content, Id) { TaxonNumber = taxonNumber }; return clone; } } diff --git a/Libiada.Clusterizator/Krab/GraphManager.cs b/Libiada.Clusterizator/Krab/GraphManager.cs index 0bbb6a3c..f9ee510a 100644 --- a/Libiada.Clusterizator/Krab/GraphManager.cs +++ b/Libiada.Clusterizator/Krab/GraphManager.cs @@ -164,8 +164,8 @@ public void Cut(Connection connection) /// public GraphManager Clone() { - var tempConnections = new List(); - var tempGraphElements = new List(); + List tempConnections = []; + List tempGraphElements = []; for (int i = 0; i < Connections.Count; i++) { tempConnections.Add(Connections[i].Clone()); @@ -186,7 +186,7 @@ public void ConnectGraph() { for (int i = 0; i < Elements.Count - 1; i++) { - var minDistance = double.MaxValue; + double minDistance = double.MaxValue; int pointNumber = -1; // searching for shortest available connection diff --git a/Libiada.Clusterizator/Krab/KrabClusterization.cs b/Libiada.Clusterizator/Krab/KrabClusterization.cs index 78a4004f..6dd6de2d 100644 --- a/Libiada.Clusterizator/Krab/KrabClusterization.cs +++ b/Libiada.Clusterizator/Krab/KrabClusterization.cs @@ -73,10 +73,10 @@ public KrabClusterization(double powerWeight, double normalizedDistanceWeight, d public int[] Cluster(int clustersCount, double[][] data) { // all connections (pairs of elements) - var connections = new List(); + List connections = []; // all elements - var elements = new List(); + List elements = []; for (int i = 0; i < data.Length; i++) { @@ -98,7 +98,7 @@ public int[] Cluster(int clustersCount, double[][] data) manager.ConnectGraph(); GraphManager tempManager = manager.Clone(); ChooseDivision(clustersCount, 0, manager); - var result = new int[data.Length]; + int[] result = new int[data.Length]; // extracting clusters from the graph for (int j = 0; j < optimalDivide.Elements.Count; j++) diff --git a/Libiada.Clusterizator/MeanShift/MeanShiftClusterization.cs b/Libiada.Clusterizator/MeanShift/MeanShiftClusterization.cs index 59e32cb9..f13a1c41 100644 --- a/Libiada.Clusterizator/MeanShift/MeanShiftClusterization.cs +++ b/Libiada.Clusterizator/MeanShift/MeanShiftClusterization.cs @@ -14,8 +14,8 @@ public MeanShiftClusterization(double bandwidth) public int[] Cluster(int clustersCount, double[][] data) { - var clusters = meanShift.Learn(data); - var result = new int[data.Length]; + MeanShiftClusterCollection clusters = meanShift.Learn(data); + int[] result = new int[data.Length]; for (int i = 0; i < result.Length; i++) { diff --git a/Libiada.Clusterizator/kMeans/KMeansClusterization.cs b/Libiada.Clusterizator/kMeans/KMeansClusterization.cs index 4e01ebcf..4f809fc3 100644 --- a/Libiada.Clusterizator/kMeans/KMeansClusterization.cs +++ b/Libiada.Clusterizator/kMeans/KMeansClusterization.cs @@ -21,10 +21,10 @@ public class KMeansClusterization : IClusterizator /// public int[] Cluster(int clustersCount, double[][] data) { - KMeans kMeans = new KMeans(clustersCount); + KMeans kMeans = new(clustersCount); - var clusters = kMeans.Learn(data); - var result = new int[data.Length]; + KMeansClusterCollection clusters = kMeans.Learn(data); + int[] result = new int[data.Length]; for (int i = 0; i < result.Length; i++) { diff --git a/Libiada.Core.Tests/Core/AbstractChainTests.cs b/Libiada.Core.Tests/Core/AbstractChainTests.cs index 7e2f4555..9ec6ee29 100644 --- a/Libiada.Core.Tests/Core/AbstractChainTests.cs +++ b/Libiada.Core.Tests/Core/AbstractChainTests.cs @@ -15,9 +15,9 @@ public class AbstractChainTests public void ToStringTest() { const string expected = "abcabccc"; - var chain = new Chain(expected); + Chain chain = new(expected); Assert.That(chain.ToString(), Is.EqualTo(expected)); - var baseChain = new BaseChain(expected); + BaseChain baseChain = new(expected); Assert.That(baseChain.ToString(), Is.EqualTo(expected)); } @@ -28,10 +28,10 @@ public void ToStringTest() public void ToStringDelimiterTest() { const string source = "abcabccc"; - var chain = new Chain(source); - var baseChain = new BaseChain(source); + Chain chain = new(source); + BaseChain baseChain = new(source); - var expected = "a b c a b c c c"; + string expected = "a b c a b c c c"; Assert.Multiple(() => { Assert.That(chain.ToString(" "), Is.EqualTo(expected)); @@ -53,10 +53,10 @@ public void ToStringDelimiterTest() public void ToStringLongDelimiterTest() { const string source = "abcabccc"; - var chain = new Chain(source); - var baseChain = new BaseChain(source); + Chain chain = new(source); + BaseChain baseChain = new(source); - var expected = "a - b - c - a - b - c - c - c"; + string expected = "a - b - c - a - b - c - c - c"; Assert.Multiple(() => { Assert.That(chain.ToString(" - "), Is.EqualTo(expected)); diff --git a/Libiada.Core.Tests/Core/AlphabetTests.cs b/Libiada.Core.Tests/Core/AlphabetTests.cs index 2a2455e4..cb543021 100644 --- a/Libiada.Core.Tests/Core/AlphabetTests.cs +++ b/Libiada.Core.Tests/Core/AlphabetTests.cs @@ -160,7 +160,7 @@ public void RemoveTest() [Test] public void CloneTest() { - var clone = firstAlphabet.Clone(); + IBaseObject clone = firstAlphabet.Clone(); Assert.That(firstAlphabet, Is.Not.SameAs(clone)); @@ -300,9 +300,9 @@ public void IndexOfTest() [Test] public void ToArrayTest() { - var a = new ValueString('a'); - var c = new ValueString('c'); - var e = new ValueString('e'); + ValueString a = new('a'); + ValueString c = new('c'); + ValueString e = new('e'); firstAlphabet.Add(a); firstAlphabet.Add(new ValueString('b')); @@ -329,7 +329,7 @@ public void ToStringTest() firstAlphabet.Add((ValueString)"a"); firstAlphabet.Add((ValueInt)2); - var result = firstAlphabet.ToString(); + string result = firstAlphabet.ToString(); 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 9d3a4d5e..08fb44c9 100644 --- a/Libiada.Core.Tests/Core/ArrangementManagers/BinaryIntervalsManagerTests.cs +++ b/Libiada.Core.Tests/Core/ArrangementManagers/BinaryIntervalsManagerTests.cs @@ -1,6 +1,7 @@ namespace Libiada.Core.Tests.Core.ArrangementManagers; using Libiada.Core.Core; +using Libiada.Core.Core.ArrangementManagers; /// /// The binary intervals manager tests. @@ -19,8 +20,8 @@ public class BinaryIntervalsManagerTests [Test] public void GetBinaryIntervalTest() { - var chain = ChainsStorage.Chains[2]; - var intervalManager = chain.GetRelationIntervalsManager(elements["A"], elements["C"]); + Chain chain = ChainsStorage.Chains[2]; + BinaryIntervalsManager intervalManager = chain.GetRelationIntervalsManager(elements["A"], elements["C"]); Assert.Multiple(() => { Assert.That(intervalManager.GetBinaryInterval(1), Is.EqualTo(1)); @@ -55,8 +56,8 @@ public void GetBinaryIntervalTest() [Test] public void GetBinaryIntervalIncompleteChainTest() { - var chain = ChainsStorage.BinaryChains[20]; - var intervalManager = chain.GetRelationIntervalsManager(elements["A"], elements["C"]); + Chain chain = ChainsStorage.BinaryChains[20]; + BinaryIntervalsManager intervalManager = chain.GetRelationIntervalsManager(elements["A"], elements["C"]); Assert.Multiple(() => { Assert.That(intervalManager.GetBinaryInterval(1), Is.EqualTo(1)); diff --git a/Libiada.Core.Tests/Core/ArrangementManagers/IntervalsManagerTests.cs b/Libiada.Core.Tests/Core/ArrangementManagers/IntervalsManagerTests.cs index 96a01c13..d382232a 100644 --- a/Libiada.Core.Tests/Core/ArrangementManagers/IntervalsManagerTests.cs +++ b/Libiada.Core.Tests/Core/ArrangementManagers/IntervalsManagerTests.cs @@ -65,8 +65,8 @@ public class IntervalsManagerTests [TestCase(5, Link.None)] public void IntervalsManagerCreationNoneLinkTest(int index, Link link) { - var intervalsManager = new IntervalsManager(congenericChains[index]); - var intervals = allIntervals[index][link]; + IntervalsManager intervalsManager = new(congenericChains[index]); + List intervals = allIntervals[index][link]; Assert.That(intervals, Has.Count.EqualTo(intervalsManager.GetArrangement(link).Length)); diff --git a/Libiada.Core.Tests/Core/BaseChainTests.cs b/Libiada.Core.Tests/Core/BaseChainTests.cs index e28fe125..b17edca8 100644 --- a/Libiada.Core.Tests/Core/BaseChainTests.cs +++ b/Libiada.Core.Tests/Core/BaseChainTests.cs @@ -15,11 +15,11 @@ public class BaseChainTests [Test] public void ConstructorWithLengthTest() { - var chain = new BaseChain(100); + BaseChain chain = new(100); Assert.That(chain.Length, Is.EqualTo(100)); - var expectedOrder = new int[100]; + int[] expectedOrder = new int[100]; Assert.That(chain.Order, Is.EqualTo(expectedOrder)); - var expectedAlphabet = new Alphabet(); + Alphabet expectedAlphabet = []; Assert.That(chain.Alphabet, Is.EqualTo(expectedAlphabet)); } @@ -38,11 +38,11 @@ public void ConstructorLessZeroLengthTest() [Test] public void ConstructorWithStringTest() { - var chain = new BaseChain("A"); + BaseChain chain = new("A"); Assert.That(chain.Length, Is.EqualTo(1)); - var expectedOrder = new[] { 1 }; + int[] expectedOrder = [1]; Assert.That(chain.Order, Is.EqualTo(expectedOrder)); - var expectedAlphabet = new Alphabet() { (ValueString)"A"}; + Alphabet expectedAlphabet = [(ValueString)"A"]; Assert.That(chain.Alphabet, Is.EqualTo(expectedAlphabet)); chain = new BaseChain("ABC"); @@ -87,7 +87,7 @@ public void ConstructorWithStringTest() [Test] public void GetByThisTest() { - var chain = new BaseChain(10); + BaseChain chain = new(10); chain.Set(new ValueString('1'), 0); Assert.That(((ValueString)chain[0]).Equals("1"), Is.True); } @@ -98,7 +98,7 @@ public void GetByThisTest() [Test] public void SetByThisTest() { - var chain = new BaseChain(10); + BaseChain chain = new(10); chain[0] = new ValueString('1'); Assert.That(((ValueString)chain.Get(0)).Equals("1"), Is.True); } @@ -109,7 +109,7 @@ public void SetByThisTest() [Test] public void GetTest() { - var chain = new BaseChain(10); + BaseChain chain = new(10); chain.Set(new ValueString('1'), 0); Assert.That(((ValueString)chain.Get(0)).Equals("1"), Is.True); } @@ -120,7 +120,7 @@ public void GetTest() [Test] public void SetTest() { - var chain = new BaseChain(10); + BaseChain chain = new(10); chain.Set(new ValueString('1'), 0); Assert.That(((ValueString)chain.Get(0)).Equals("1"), Is.True); } @@ -131,7 +131,7 @@ public void SetTest() [Test] public void RemoveTest() { - var chain = new BaseChain(10); + BaseChain chain = new(10); chain.Set(new ValueString('1'), 0); Assert.That(((ValueString)chain[0]).Equals("1"), Is.True); @@ -145,7 +145,7 @@ public void RemoveTest() [Test] public void DeleteTest() { - var chain = new BaseChain(10); + BaseChain chain = new(10); chain.Set(new ValueString('1'), 0); Assert.That(((ValueString)chain[0]).Equals("1"), Is.True); @@ -159,7 +159,7 @@ public void DeleteTest() [Test] public void GetLengthTest() { - var chain = new BaseChain(10); + BaseChain chain = new(10); Assert.That(chain.Length, Is.EqualTo(10)); } @@ -169,9 +169,9 @@ public void GetLengthTest() [Test] public void CloneTest() { - var chain = new BaseChain("123456789A"); + BaseChain chain = new("123456789A"); - var clone = (BaseChain)chain.Clone(); + BaseChain clone = (BaseChain)chain.Clone(); Assert.That(clone, Is.EqualTo(chain)); Assert.That(clone, Is.Not.SameAs(chain)); } diff --git a/Libiada.Core.Tests/Core/ChainTests.cs b/Libiada.Core.Tests/Core/ChainTests.cs index e141147a..aba7614a 100644 --- a/Libiada.Core.Tests/Core/ChainTests.cs +++ b/Libiada.Core.Tests/Core/ChainTests.cs @@ -25,9 +25,9 @@ public class ChainTests [Test] public void SimilarChainsGetTest() { - var congenericChainA = new CongenericChain([2, 8], elements["A"], 10); + CongenericChain congenericChainA = new([2, 8], elements["A"], 10); - var chainCreatedCongenericChain = chains[2].CongenericChain(elements["A"]); + CongenericChain chainCreatedCongenericChain = chains[2].CongenericChain(elements["A"]); Assert.That(chainCreatedCongenericChain, Is.EqualTo(congenericChainA)); } @@ -39,11 +39,11 @@ public void SimilarChainsGetTest() public void ChainTest() { 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) }; + Chain actual = new(source); + Alphabet alphabet = [new ValueInt(1), new ValueInt(2) , new ValueInt(3) , new ValueInt(4), new ValueInt(5)]; Assert.That(actual.Alphabet, Is.EqualTo(alphabet)); - var order = new int[] { 1, 2, 3, 2, 2, 4, 5, 1 }; + int[] order = [1, 2, 3, 2, 2, 4, 5, 1]; Assert.That(actual.Order, Is.EqualTo(order)); } @@ -62,7 +62,7 @@ public void IntervalsTest() ]; for (int i = 0; i < chains[0].Alphabet.Cardinality; i++) { - var actualIntervals = chains[0].CongenericChain(i).GetArrangement(Link.Both); + int[] actualIntervals = chains[0].CongenericChain(i).GetArrangement(Link.Both); for (int j = 0; j < actualIntervals.Length; j++) { Assert.That(actualIntervals[j], Is.EqualTo(intervals[i][j]), $"{j} and {i} intervals of sequence are not equal"); @@ -102,7 +102,7 @@ public void IntervalsTest() [TestCase(-1, 2, "T", 3)] public void GetElementPositionTest(int expected, int chainIndex, string element, int occurrence) { - var actual = chains[chainIndex].GetOccurrence(elements[element], occurrence); + int actual = chains[chainIndex].GetOccurrence(elements[element], occurrence); Assert.That(actual, Is.EqualTo(expected)); } } diff --git a/Libiada.Core.Tests/Core/Characteristics/Calculators/AccordanceCalculators/AccordanceCalculatorsTests.cs b/Libiada.Core.Tests/Core/Characteristics/Calculators/AccordanceCalculators/AccordanceCalculatorsTests.cs index ea869c64..ccb6bdad 100644 --- a/Libiada.Core.Tests/Core/Characteristics/Calculators/AccordanceCalculators/AccordanceCalculatorsTests.cs +++ b/Libiada.Core.Tests/Core/Characteristics/Calculators/AccordanceCalculators/AccordanceCalculatorsTests.cs @@ -45,8 +45,8 @@ /// protected void CalculationTest(int index, double firstValue, double secondValue) { - var firstChain = binaryChains[index].CongenericChain(elements["A"]); - var secondChain = binaryChains[index].CongenericChain(elements["B"]); + CongenericChain firstChain = binaryChains[index].CongenericChain(elements["A"]); + CongenericChain secondChain = binaryChains[index].CongenericChain(elements["B"]); double result1 = calculator.Calculate(firstChain, secondChain, Link.End); double result2 = calculator.Calculate(secondChain, firstChain, Link.End); Assert.That(result1, Is.EqualTo(firstValue).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 fa2e6a37..f14a72d7 100644 --- a/Libiada.Core.Tests/Core/Characteristics/Calculators/FullCalculators/AverageWordLengthTests.cs +++ b/Libiada.Core.Tests/Core/Characteristics/Calculators/FullCalculators/AverageWordLengthTests.cs @@ -36,7 +36,7 @@ public void ChainCalculationTest(int index, double value) [Test] public void CalculationTest() { - var sequence = new Chain(5) + Chain sequence = new(5) { [0] = new ValueString("bla"), [1] = new ValueString("blablab"), diff --git a/Libiada.Core.Tests/Core/Characteristics/Calculators/FullCalculators/LinkedFullCalculatorTests.cs b/Libiada.Core.Tests/Core/Characteristics/Calculators/FullCalculators/LinkedFullCalculatorTests.cs index 369f161f..aacc50ba 100644 --- a/Libiada.Core.Tests/Core/Characteristics/Calculators/FullCalculators/LinkedFullCalculatorTests.cs +++ b/Libiada.Core.Tests/Core/Characteristics/Calculators/FullCalculators/LinkedFullCalculatorTests.cs @@ -39,7 +39,7 @@ public class LinkedFullCalculatorTests public void CalculationTest(int sequenceIndex, FullCharacteristic type, Link link, double expected) { - var calculator = new LinkedFullCalculator(type, link); + LinkedFullCalculator calculator = new(type, link); double actual = calculator.Calculate(sequences[sequenceIndex]); Assert.That(actual, Is.EqualTo(expected).Within(0.0001d)); } diff --git a/Libiada.Core.Tests/Core/CongenericChainTests.cs b/Libiada.Core.Tests/Core/CongenericChainTests.cs index dcb803c4..0fd40d69 100644 --- a/Libiada.Core.Tests/Core/CongenericChainTests.cs +++ b/Libiada.Core.Tests/Core/CongenericChainTests.cs @@ -53,7 +53,7 @@ public void IndependenceMessageTest() { congenericChain = new CongenericChain(message, 10); - var newMessage = (ValueString)congenericChain.Element; + ValueString newMessage = (ValueString)congenericChain.Element; Assert.That(newMessage, Is.Not.SameAs(congenericChain.Element)); } @@ -121,8 +121,8 @@ public void ClearAndSetNewLengthTest() [Test] public void CongenericChainTest() { - var element = new ValueString("A"); - var result = new CongenericChain(element); + ValueString element = new("A"); + CongenericChain result = new(element); Assert.That(result.Element, Is.EqualTo(element)); Assert.That(result.Length, Is.Zero); Assert.That(result.Positions, Is.Empty); diff --git a/Libiada.Core.Tests/Core/CongenericScoreTrackTests.cs b/Libiada.Core.Tests/Core/CongenericScoreTrackTests.cs index 3f635a16..75afa2c3 100644 --- a/Libiada.Core.Tests/Core/CongenericScoreTrackTests.cs +++ b/Libiada.Core.Tests/Core/CongenericScoreTrackTests.cs @@ -16,8 +16,8 @@ public class CongenericScoreTrackTests public void ValueNoteOrderFirstTest() { // создание и заполнения списка(ов) нот для такта(ов) монотрека - var notes = new List - { + List notes = + [ 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), @@ -27,10 +27,10 @@ public void ValueNoteOrderFirstTest() 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 - { + List notes2 = + [ 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), @@ -44,16 +44,16 @@ public void ValueNoteOrderFirstTest() 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)); + MeasureAttributes attr = new(new Size(4, 4), new Key(5)); - var m1 = new Measure(notes, attr); - var m2 = new Measure(notes2, attr); + Measure m1 = new(notes, attr); + Measure m2 = new(notes2, attr); - var measuresList = new List { m1, m2 }; + List measuresList = [m1, m2]; - var uni = new CongenericScoreTrack(measuresList); + CongenericScoreTrack uni = new(measuresList); Assert.That(uni.NoteOrder()[0].Id, Is.Not.EqualTo(1)); @@ -94,8 +94,8 @@ public void ValueNoteOrderFirstTest() public void ValueNoteOrderSecondTest() { // создание и заполнения списка(ов) нот для такта(ов) монотрека - var notes = new List - { + List notes = + [ 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), @@ -105,10 +105,10 @@ public void ValueNoteOrderSecondTest() 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 - { + List notes2 = + [ 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), @@ -122,16 +122,16 @@ public void ValueNoteOrderSecondTest() 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)); + MeasureAttributes attr = new(new Size(4, 4), new Key(5)); - var m1 = new Measure(notes, attr); - var m2 = new Measure(notes2, attr); + Measure m1 = new(notes, attr); + Measure m2 = new(notes2, attr); - var measuresList = new List { m1, m2 }; + List measuresList = [m1, m2]; - var uni = new CongenericScoreTrack(measuresList); + CongenericScoreTrack uni = new(measuresList); Assert.That(uni.NoteIdOrder()[0], Is.Not.EqualTo(1)); @@ -172,63 +172,63 @@ public void ValueNoteOrderSecondTest() public void MeasureOrderTest() { // создание и заполнения списка(ов) нот для такта(ов) монотрека - var notes = new List - { + List notes = + [ 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 - { + List notes3 = + [ 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 - { + List notes2 = + [ 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 - { + List notes4 = + [ 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 - { + List notes5 = + [ new(new Duration(1, 4, false), false, Tie.None, 1), new(new Duration(1, 4, false), false, Tie.None, 1) - }; + ]; - var notes6 = new List - { + List notes6 = + [ 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)); + MeasureAttributes attr = new(new Size(4, 4), new Key(5)); - var m1 = new Measure(notes, attr); - var m2 = new Measure(notes2, attr); - var m3 = new Measure(notes3, attr); - var m4 = new Measure(notes4, attr); - var m5 = new Measure(notes5, attr); - var m6 = new Measure(notes6, attr); + Measure m1 = new(notes, attr); + Measure m2 = new(notes2, attr); + Measure m3 = new(notes3, attr); + Measure m4 = new(notes4, attr); + Measure m5 = new(notes5, attr); + Measure m6 = new(notes6, attr); - var measuresList = new List { m1, m2, m3, m4, m5, m5, m2, m3, m6 }; + List measuresList = [m1, m2, m3, m4, m5, m5, m2, m3, m6]; - var uni = new CongenericScoreTrack(measuresList); + CongenericScoreTrack uni = new(measuresList); Assert.That(uni.MeasureOrder()[0].Id, Is.EqualTo(0)); Assert.That(uni.MeasureOrder()[1].Id, Is.EqualTo(1)); diff --git a/Libiada.Core.Tests/Core/FmotifChainTests.cs b/Libiada.Core.Tests/Core/FmotifChainTests.cs index ec6e7a4f..beaf816d 100644 --- a/Libiada.Core.Tests/Core/FmotifChainTests.cs +++ b/Libiada.Core.Tests/Core/FmotifChainTests.cs @@ -16,7 +16,7 @@ public class FmotifChainTests [Test] public void FmotifChainTest() { - var chain = new FmotifChain(); + FmotifChain chain = new(); 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)); @@ -31,8 +31,8 @@ public void FmotifChainTest() [Test] public void FmotifChainEqualsTest() { - 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)); @@ -40,11 +40,11 @@ public void FmotifChainEqualsTest() fmotif2.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 4, false), false, Tie.None)); fmotif2.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 4, false), false, Tie.None)); - var firstChain = new FmotifChain(); + FmotifChain firstChain = new(); firstChain.FmotifsList.Add(fmotif1); firstChain.FmotifsList.Add(fmotif2); - var secondChain = new FmotifChain(); + FmotifChain secondChain = new(); secondChain.FmotifsList.Add(fmotif1); secondChain.FmotifsList.Add(fmotif2); Assert.That(firstChain, Is.EqualTo(secondChain)); diff --git a/Libiada.Core.Tests/Core/LinkTests.cs b/Libiada.Core.Tests/Core/LinkTests.cs index 3ee1cc34..32286abd 100644 --- a/Libiada.Core.Tests/Core/LinkTests.cs +++ b/Libiada.Core.Tests/Core/LinkTests.cs @@ -20,7 +20,7 @@ public class LinkTests [Test] public void LinkCountTest() { - var actualCount = EnumExtensions.ToArray().Length; + int actualCount = EnumExtensions.ToArray().Length; Assert.That(EnumExtensions.ToArray(), Has.Length.EqualTo(LinksCount)); } @@ -30,7 +30,7 @@ public void LinkCountTest() [Test] public void LinkValuesTest() { - var links = EnumExtensions.ToArray(); + Link[] links = EnumExtensions.ToArray(); for (int i = 0; i < LinksCount; i++) { Assert.That(links, Does.Contain((Link)i)); @@ -89,8 +89,8 @@ public void LinkHasDescriptionTest([Values]Link link) [Test] public void LinkValuesUniqueTest() { - var links = EnumExtensions.ToArray(); - var linkValues = links.Cast(); + Link[] links = EnumExtensions.ToArray(); + IEnumerable linkValues = links.Cast(); Assert.That(linkValues, Is.Unique); } } diff --git a/Libiada.Core.Tests/Core/SimpleTypes/AccidentalTests.cs b/Libiada.Core.Tests/Core/SimpleTypes/AccidentalTests.cs index e9666af9..0d302ba6 100644 --- a/Libiada.Core.Tests/Core/SimpleTypes/AccidentalTests.cs +++ b/Libiada.Core.Tests/Core/SimpleTypes/AccidentalTests.cs @@ -29,7 +29,7 @@ public void AccidentalCountTest() [Test] public void AccidentalValuesTest() { - var accidentals = EnumExtensions.ToArray(); + Accidental[] accidentals = EnumExtensions.ToArray(); for (int i = -2; i < AccidentalsCount - 2; i++) { Assert.That(accidentals, Does.Contain((Accidental)i)); @@ -85,8 +85,8 @@ public void AccidentalHasDescriptionTest([Values]Accidental accidental) [Test] public void AccidentalValuesUniqueTest() { - var accidentals = EnumExtensions.ToArray(); - var accidentalValues = accidentals.Cast(); + Accidental[] accidentals = EnumExtensions.ToArray(); + IEnumerable accidentalValues = accidentals.Cast(); Assert.That(accidentalValues, Is.Unique); } } diff --git a/Libiada.Core.Tests/Core/SimpleTypes/DurationTests.cs b/Libiada.Core.Tests/Core/SimpleTypes/DurationTests.cs index 044ab91b..a84453a8 100644 --- a/Libiada.Core.Tests/Core/SimpleTypes/DurationTests.cs +++ b/Libiada.Core.Tests/Core/SimpleTypes/DurationTests.cs @@ -14,9 +14,9 @@ public class DurationTests [Test] public void AddDurationTest() { - var duration1 = new Duration(1, 2, false); - var duration2 = new Duration(1, 4, false); - var duration3 = duration1.AddDuration(duration2); + Duration duration1 = new(1, 2, false); + Duration duration2 = new(1, 4, false); + Duration duration3 = duration1.AddDuration(duration2); Assert.Multiple(() => { diff --git a/Libiada.Core.Tests/Core/SimpleTypes/FmotifTypeTests.cs b/Libiada.Core.Tests/Core/SimpleTypes/FmotifTypeTests.cs index 091b23a4..f9204fd7 100644 --- a/Libiada.Core.Tests/Core/SimpleTypes/FmotifTypeTests.cs +++ b/Libiada.Core.Tests/Core/SimpleTypes/FmotifTypeTests.cs @@ -20,7 +20,7 @@ public class FmotifTypeTests [Test] public void FmotifTypeCountTest() { - var actualCount = EnumExtensions.ToArray().Length; + int actualCount = EnumExtensions.ToArray().Length; Assert.That(actualCount, Is.EqualTo(FmotifTypesCount)); } @@ -30,7 +30,7 @@ public void FmotifTypeCountTest() [Test] public void FmotifTypeValuesTest() { - var fmotifTypes = EnumExtensions.ToArray(); + FmotifType[] fmotifTypes = EnumExtensions.ToArray(); for (int i = 0; i < FmotifTypesCount; i++) { Assert.That(fmotifTypes, Does.Contain((FmotifType)i)); @@ -87,8 +87,8 @@ public void FmotifTypeHasDescriptionTest([Values]FmotifType fmotifType) [Test] public void FmotifTypeValuesUniqueTest() { - var fmotifTypes = EnumExtensions.ToArray(); - var fmotifTypeValues = fmotifTypes.Cast(); + FmotifType[] fmotifTypes = EnumExtensions.ToArray(); + IEnumerable fmotifTypeValues = fmotifTypes.Cast(); Assert.That(fmotifTypeValues, Is.Unique); } } diff --git a/Libiada.Core.Tests/Core/SimpleTypes/InstrumentTests.cs b/Libiada.Core.Tests/Core/SimpleTypes/InstrumentTests.cs index d6a5f6cf..316f23f4 100644 --- a/Libiada.Core.Tests/Core/SimpleTypes/InstrumentTests.cs +++ b/Libiada.Core.Tests/Core/SimpleTypes/InstrumentTests.cs @@ -20,7 +20,7 @@ public class InstrumentTests [Test] public void InstrumentCountTest() { - var actualCount = EnumExtensions.ToArray().Length; + int actualCount = EnumExtensions.ToArray().Length; Assert.That(actualCount, Is.EqualTo(InstrumentsCount)); } @@ -30,7 +30,7 @@ public void InstrumentCountTest() [Test] public void InstrumentValuesTest() { - var instruments = EnumExtensions.ToArray(); + Instrument[] instruments = EnumExtensions.ToArray(); for (int i = 0; i < InstrumentsCount; i++) { Assert.That(instruments, Does.Contain((Instrument)i)); @@ -82,8 +82,8 @@ public void InstrumentHasDescriptionTest([Values]Instrument instrument) [Test] public void InstrumentValuesUniqueTest() { - var instruments = EnumExtensions.ToArray(); - var instrumentValues = instruments.Cast(); + Instrument[] instruments = EnumExtensions.ToArray(); + IEnumerable instrumentValues = instruments.Cast(); Assert.That(instrumentValues, Is.Unique); } } diff --git a/Libiada.Core.Tests/Core/SimpleTypes/MeasureTests.cs b/Libiada.Core.Tests/Core/SimpleTypes/MeasureTests.cs index 216bbaeb..9bc94371 100644 --- a/Libiada.Core.Tests/Core/SimpleTypes/MeasureTests.cs +++ b/Libiada.Core.Tests/Core/SimpleTypes/MeasureTests.cs @@ -14,9 +14,9 @@ public class MeasureTests [Test] public void MeasureFirstTest() { - var notes = new List(); - var notes2 = new List(); - var attributes = new MeasureAttributes(new Size(4, 4), new Key(5)); + List notes = []; + List notes2 = []; + MeasureAttributes attributes = new(new Size(4, 4), new Key(5)); notes.Add(new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 4, false), false, Tie.None)); notes.Add(new ValueNote(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 4, false), false, Tie.None)); @@ -26,8 +26,8 @@ public void MeasureFirstTest() notes2.Add(new ValueNote(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 4, false), false, Tie.None)); notes2.Add(new ValueNote(new Pitch(3, NoteSymbol.C, 0), new Duration(1, 16, false), false, Tie.None)); - var m1 = new Measure(notes, attributes); - var m2 = new Measure(notes2, attributes); + Measure m1 = new(notes, attributes); + Measure m2 = new(notes2, attributes); Assert.That(m1, Is.EqualTo(m2)); } @@ -38,10 +38,10 @@ public void MeasureFirstTest() [Test] public void MeasureSecondTest() { - var notes = new List(); - var notes2 = new List(); - var attributes = new MeasureAttributes(new Size(4, 4), new Key(5)); - var attributes2 = new MeasureAttributes(new Size(3, 4), new Key(5)); + List notes = []; + List notes2 = []; + MeasureAttributes attributes = new(new Size(4, 4), new Key(5)); + MeasureAttributes attributes2 = new(new Size(3, 4), new Key(5)); notes.Add(new ValueNote(new Pitch(3, NoteSymbol.A, 0), new Duration(1, 4, false), false, Tie.None)); notes.Add(new ValueNote(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 4, false), false, Tie.None)); @@ -51,9 +51,9 @@ public void MeasureSecondTest() notes2.Add(new ValueNote(new Pitch(3, NoteSymbol.B, 0), new Duration(1, 4, false), false, Tie.None)); notes2.Add(new ValueNote(new Pitch(3, NoteSymbol.D, 0), new Duration(1, 16, false), false, Tie.None)); - var m1 = new Measure(notes, attributes); - var m2 = new Measure(notes2, attributes); - var m3 = new Measure(notes2, attributes2); + Measure m1 = new(notes, attributes); + Measure m2 = new(notes2, attributes); + Measure m3 = new(notes2, attributes2); 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 057e8df3..21d2f164 100644 --- a/Libiada.Core.Tests/Core/SimpleTypes/NoteSymbolTests.cs +++ b/Libiada.Core.Tests/Core/SimpleTypes/NoteSymbolTests.cs @@ -29,7 +29,7 @@ public void NoteSymbolCountTest() [Test] public void NoteSymbolValuesTest() { - var noteSymbols = EnumExtensions.ToArray(); + NoteSymbol[] noteSymbols = EnumExtensions.ToArray(); Assert.That(noteSymbols, Does.Contain((NoteSymbol)0)); Assert.That(noteSymbols, Does.Contain((NoteSymbol)2)); Assert.That(noteSymbols, Does.Contain((NoteSymbol)4)); @@ -90,8 +90,8 @@ public void NoteSymbolHasDescriptionTest([Values]NoteSymbol noteSymbol) [Test] public void NoteSymbolValuesUniqueTest() { - var noteSymbols = EnumExtensions.ToArray(); - var noteSymbolValues = noteSymbols.Cast(); + NoteSymbol[] noteSymbols = EnumExtensions.ToArray(); + IEnumerable noteSymbolValues = noteSymbols.Cast(); Assert.That(noteSymbolValues, Is.Unique); } } diff --git a/Libiada.Core.Tests/Core/SimpleTypes/TieTests.cs b/Libiada.Core.Tests/Core/SimpleTypes/TieTests.cs index a9b31d42..99ae4428 100644 --- a/Libiada.Core.Tests/Core/SimpleTypes/TieTests.cs +++ b/Libiada.Core.Tests/Core/SimpleTypes/TieTests.cs @@ -20,7 +20,7 @@ public class TieTests [Test] public void TieCountTest() { - var actualCount = EnumExtensions.ToArray().Length; + int actualCount = EnumExtensions.ToArray().Length; Assert.That(actualCount, Is.EqualTo(TiesCount)); } @@ -30,7 +30,7 @@ public void TieCountTest() [Test] public void TieValuesTest() { - var ties = EnumExtensions.ToArray(); + Tie[] ties = EnumExtensions.ToArray(); for (int i = 0; i < TiesCount; i++) { Assert.That(ties, Does.Contain((Tie)i)); @@ -85,8 +85,8 @@ public void TieHasDescriptionTest([Values]Tie tie) [Test] public void TieValuesUniqueTest() { - var ties = EnumExtensions.ToArray(); - var tieValues = ties.Cast(); + Tie[] ties = EnumExtensions.ToArray(); + IEnumerable tieValues = ties.Cast(); Assert.That(tieValues, Is.Unique); } } diff --git a/Libiada.Core.Tests/Core/SimpleTypes/ValuePhantomTests.cs b/Libiada.Core.Tests/Core/SimpleTypes/ValuePhantomTests.cs index 13bed77d..0335c3ee 100644 --- a/Libiada.Core.Tests/Core/SimpleTypes/ValuePhantomTests.cs +++ b/Libiada.Core.Tests/Core/SimpleTypes/ValuePhantomTests.cs @@ -42,7 +42,7 @@ public void AddMessagePhantomTest() public void CloneTest() { ValuePhantom m1 = [new ValueString('1'), new ValueString('2'), new ValueString('3')]; - var clone = (ValuePhantom)m1.Clone(); + ValuePhantom clone = (ValuePhantom)m1.Clone(); Assert.That(clone, Is.EqualTo(m1)); } diff --git a/Libiada.Core.Tests/DataTransformers/DissimilarChainFactoryTests.cs b/Libiada.Core.Tests/DataTransformers/DissimilarChainFactoryTests.cs index d53d2b2d..e3b2b7d4 100644 --- a/Libiada.Core.Tests/DataTransformers/DissimilarChainFactoryTests.cs +++ b/Libiada.Core.Tests/DataTransformers/DissimilarChainFactoryTests.cs @@ -1,5 +1,6 @@ namespace Libiada.Core.Tests.DataTransformers; +using Libiada.Core.Core; using Libiada.Core.DataTransformers; using Libiada.Core.Tests.Core; @@ -23,8 +24,8 @@ public class DissimilarChainFactoryTests [TestCase(2, 2)] public void DissimilarOrderTest(int chainIndex, int resultIndex) { - var result = DissimilarChainFactory.Create(ChainsStorage.Chains[chainIndex]); - var expected = ChainsStorage.DissimilarChains[resultIndex]; + Chain result = DissimilarChainFactory.Create(ChainsStorage.Chains[chainIndex]); + Chain expected = ChainsStorage.DissimilarChains[resultIndex]; Assert.That(result, Is.EqualTo(expected)); } @@ -42,9 +43,9 @@ public void DissimilarOrderTest(int chainIndex, int resultIndex) [TestCase(2, 5)] public void DissimilarSecondOrderTest(int chainIndex, int resultIndex) { - var result = DissimilarChainFactory.Create(ChainsStorage.Chains[chainIndex]); + Chain result = DissimilarChainFactory.Create(ChainsStorage.Chains[chainIndex]); result = DissimilarChainFactory.Create(result); - var expected = ChainsStorage.DissimilarChains[resultIndex]; + Chain expected = ChainsStorage.DissimilarChains[resultIndex]; Assert.That(result, Is.EqualTo(expected)); } } diff --git a/Libiada.Core.Tests/DataTransformers/HighOrderFactoryTests.cs b/Libiada.Core.Tests/DataTransformers/HighOrderFactoryTests.cs index fdd0a50a..2d19202c 100644 --- a/Libiada.Core.Tests/DataTransformers/HighOrderFactoryTests.cs +++ b/Libiada.Core.Tests/DataTransformers/HighOrderFactoryTests.cs @@ -30,8 +30,8 @@ public class HighOrderFactoryTests [TestCase(0, 5, Link.CycleEnd)] public void SecondOrderTest(int chainIndex, int resultIndex, Link link) { - var result = HighOrderFactory.Create(ChainsStorage.Chains[chainIndex], link); - var expected = ChainsStorage.HighOrderChains[resultIndex]; + Chain result = HighOrderFactory.Create(ChainsStorage.Chains[chainIndex], link); + Chain expected = ChainsStorage.HighOrderChains[resultIndex]; Assert.That(result, Is.EqualTo(expected)); } @@ -41,9 +41,9 @@ public void SecondOrderTest(int chainIndex, int resultIndex, Link link) [Test] public void ThirdOrderTest() { - var result = HighOrderFactory.Create(ChainsStorage.Chains[0], Link.End); + Chain result = HighOrderFactory.Create(ChainsStorage.Chains[0], Link.End); result = HighOrderFactory.Create(result, Link.End); - var expected = ChainsStorage.HighOrderChains[6]; + Chain expected = ChainsStorage.HighOrderChains[6]; Assert.That(result, Is.EqualTo(expected)); } } diff --git a/Libiada.Core.Tests/DataTransformers/PermutationGeneratorTests.cs b/Libiada.Core.Tests/DataTransformers/PermutationGeneratorTests.cs index 4bea5e6f..24d23497 100644 --- a/Libiada.Core.Tests/DataTransformers/PermutationGeneratorTests.cs +++ b/Libiada.Core.Tests/DataTransformers/PermutationGeneratorTests.cs @@ -24,13 +24,13 @@ public class PermutationGeneratorTests [Test] public void GetOrdersForTwoElementsTest() { - var result = PermutationGenerator.GetOrders(2); + int[][] result = PermutationGenerator.GetOrders(2); - Assert.That(result.Length, Is.EqualTo(Expected1.Length)); + Assert.That(result, Has.Length.EqualTo(Expected1.Length)); for (int i = 0; i < Expected1.Length; i++) { - var expected = Expected1[i]; - Assert.That(result[i].Length, Is.EqualTo(expected.Length)); + int[] expected = Expected1[i]; + Assert.That(result[i], Has.Length.EqualTo(expected.Length)); for (int j = 0; j < expected.Length; j++) { Assert.That(result[i].SequenceEqual(expected)); @@ -41,12 +41,12 @@ public void GetOrdersForTwoElementsTest() [Test] public void GetOrdersForThreeElementsTest() { - var result = PermutationGenerator.GetOrders(3); - Assert.That(result.Length, Is.EqualTo(Expected2.Length)); + int[][] result = PermutationGenerator.GetOrders(3); + Assert.That(result, Has.Length.EqualTo(Expected2.Length)); for (int i = 0; i < Expected2.Length; i++) { - var expected = Expected2[i]; - Assert.That(result[i].Length, Is.EqualTo(expected.Length)); + int[] expected = Expected2[i]; + Assert.That(result[i], Has.Length.EqualTo(expected.Length)); for (int j = 0; j < expected.Length; j++) { Assert.That(result[i].SequenceEqual(expected)); diff --git a/Libiada.Core.Tests/DataTransformers/SequenceConcatenatorTests.cs b/Libiada.Core.Tests/DataTransformers/SequenceConcatenatorTests.cs index 593107da..dd1b3133 100644 --- a/Libiada.Core.Tests/DataTransformers/SequenceConcatenatorTests.cs +++ b/Libiada.Core.Tests/DataTransformers/SequenceConcatenatorTests.cs @@ -11,23 +11,23 @@ public class SequenceConcatenatorTests public void ConcatenateTest() { int[] sequencesIndexes = [0, 2, 1]; - var sourceChains = ChainsStorage.ConcatinationChains; - var result = SequenceConcatenator.Concatenate([sourceChains[0], sourceChains[1], sourceChains[2]], sequencesIndexes); + List sourceChains = ChainsStorage.ConcatinationChains; + Chain 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([sourceChains[0], sourceChains[1], sourceChains[2]]); + List sourceChains = ChainsStorage.ConcatinationChains; + Chain result = SequenceConcatenator.ConcatenateAsOrdered([sourceChains[0], sourceChains[1], sourceChains[2]]); Assert.That(result, Is.EqualTo(sourceChains[3])); } [Test] public void GenerateConcatenationsTest() { - var sourceChains = ChainsStorage.ConcatinationChains; + List sourceChains = ChainsStorage.ConcatinationChains; Chain[] expectedChains = [ sourceChains[3], @@ -38,7 +38,7 @@ public void GenerateConcatenationsTest() sourceChains[8] ]; - var result = SequenceConcatenator.GenerateConcatenations([sourceChains[0], sourceChains[1], sourceChains[2]]); + IEnumerable result = SequenceConcatenator.GenerateConcatenations([sourceChains[0], sourceChains[1], sourceChains[2]]); Assert.That(result, Is.EqualTo(expectedChains)); } } diff --git a/Libiada.Core.Tests/Extensions/EnumExtensionsTests.cs b/Libiada.Core.Tests/Extensions/EnumExtensionsTests.cs index 95b145ea..35df8f73 100644 --- a/Libiada.Core.Tests/Extensions/EnumExtensionsTests.cs +++ b/Libiada.Core.Tests/Extensions/EnumExtensionsTests.cs @@ -36,7 +36,7 @@ private enum TestEnum : byte public void ToArrayTest() { TestEnum[] actual = EnumExtensions.ToArray(); - var expected = new[] { TestEnum.First, TestEnum.Second, TestEnum.Third }; + TestEnum[] expected = [TestEnum.First, TestEnum.Second, TestEnum.Third]; Assert.That(actual, Is.EqualTo(expected)); } diff --git a/Libiada.Core.Tests/Extensions/StringExtensionsTests.cs b/Libiada.Core.Tests/Extensions/StringExtensionsTests.cs index 6170de73..52ffc809 100644 --- a/Libiada.Core.Tests/Extensions/StringExtensionsTests.cs +++ b/Libiada.Core.Tests/Extensions/StringExtensionsTests.cs @@ -39,8 +39,8 @@ public void TrimEndTest() [Test] public void TrimEndWithTrashTest() { - var source = "Bagaza virus isolate BAGV/Spain/RLP-Hcc2/2010, complete genome."; - var expected = "Bagaza virus isolate BAGV/Spain/RLP-Hcc2/2010, complete genome."; + string source = "Bagaza virus isolate BAGV/Spain/RLP-Hcc2/2010, complete genome."; + string expected = "Bagaza virus isolate BAGV/Spain/RLP-Hcc2/2010, complete genome."; string actual = source.TrimEnd(", complete cds"); Assert.That(actual, Is.EqualTo(expected)); diff --git a/Libiada.Core.Tests/Iterators/CutRuleWithFixedStartTests.cs b/Libiada.Core.Tests/Iterators/CutRuleWithFixedStartTests.cs index 57995196..8c7b8ddd 100644 --- a/Libiada.Core.Tests/Iterators/CutRuleWithFixedStartTests.cs +++ b/Libiada.Core.Tests/Iterators/CutRuleWithFixedStartTests.cs @@ -16,7 +16,7 @@ public void CutRuleTest() { const int length = 12; const int step = 3; - var rule = new CutRuleWithFixedStart(length, step); + CutRuleWithFixedStart rule = new(length, step); CutRuleIterator iterator = rule.GetIterator(); for (int i = step; i <= length; i += step) diff --git a/Libiada.Core.Tests/Iterators/CutRuleWithShiftedAndFixedStartTests.cs b/Libiada.Core.Tests/Iterators/CutRuleWithShiftedAndFixedStartTests.cs index 16f10e78..28475614 100644 --- a/Libiada.Core.Tests/Iterators/CutRuleWithShiftedAndFixedStartTests.cs +++ b/Libiada.Core.Tests/Iterators/CutRuleWithShiftedAndFixedStartTests.cs @@ -14,7 +14,7 @@ public class CutRuleWithShiftedAndFixedStartTests [Test] public void CutRuleTest() { - var rule = new CutRuleWithShiftedAndFixedStart(18, 3, 5); + CutRuleWithShiftedAndFixedStart rule = new(18, 3, 5); CutRuleIterator iterator = rule.GetIterator(); diff --git a/Libiada.Core.Tests/Iterators/DiffCutterTests.cs b/Libiada.Core.Tests/Iterators/DiffCutterTests.cs index 071ba750..305407c0 100644 --- a/Libiada.Core.Tests/Iterators/DiffCutterTests.cs +++ b/Libiada.Core.Tests/Iterators/DiffCutterTests.cs @@ -15,7 +15,7 @@ public class DiffCutterTests public void DiffTest() { const string source = "reegwvwvw"; - var rule = new CutRuleWithFixedStart(source.Length, 3); + CutRuleWithFixedStart rule = new(source.Length, 3); List cuts = DiffCutter.Cut(source, rule); Assert.That(cuts[0], Is.EqualTo("ree")); diff --git a/Libiada.Core.Tests/Iterators/IteratorEndTests.cs b/Libiada.Core.Tests/Iterators/IteratorEndTests.cs index 0037baf0..996ecefb 100644 --- a/Libiada.Core.Tests/Iterators/IteratorEndTests.cs +++ b/Libiada.Core.Tests/Iterators/IteratorEndTests.cs @@ -31,7 +31,7 @@ public void ReadWindowModeTest() { const int length = 3; const int step = 1; - var iterator = new IteratorEnd(chainToIterate, length, step); + IteratorEnd iterator = new(chainToIterate, length, step); // 12 - 3 + 1 List message2 = @@ -70,7 +70,7 @@ public void ReadWindowModeTest() int i = 0; while (iterator.Next()) { - var message1 = iterator.Current(); + AbstractChain message1 = iterator.Current(); Assert.That(message2[i++], Is.EqualTo(message1)); } @@ -85,7 +85,7 @@ public void ReadBlockModeTest() { const int length = 3; const int step = 3; - var iterator = new IteratorEnd(chainToIterate, length, step); + IteratorEnd iterator = new(chainToIterate, length, step); List message2 = [ @@ -105,7 +105,7 @@ public void ReadBlockModeTest() int i = 0; while (iterator.Next()) { - var message1 = iterator.Current(); + AbstractChain message1 = iterator.Current(); Assert.That(message2[i++], Is.EqualTo(message1)); } diff --git a/Libiada.Core.Tests/Iterators/IteratorWritableEndTests.cs b/Libiada.Core.Tests/Iterators/IteratorWritableEndTests.cs index 0989913c..1e659ec7 100644 --- a/Libiada.Core.Tests/Iterators/IteratorWritableEndTests.cs +++ b/Libiada.Core.Tests/Iterators/IteratorWritableEndTests.cs @@ -32,8 +32,8 @@ public void WriteTest() { List messages = ['1', '3', '2', '2', '1', '2', '1', '3', '3', '1', '2', '1']; - var toWrite = new Chain(12); - var iteratorWrite = new IteratorWritableEnd(toWrite); + Chain toWrite = new(12); + IteratorWritableEnd iteratorWrite = new(toWrite); int i = 0; while (iteratorWrite.Next()) { diff --git a/Libiada.Core.Tests/Iterators/IteratorWritableStartTests.cs b/Libiada.Core.Tests/Iterators/IteratorWritableStartTests.cs index 0c413515..33821df1 100644 --- a/Libiada.Core.Tests/Iterators/IteratorWritableStartTests.cs +++ b/Libiada.Core.Tests/Iterators/IteratorWritableStartTests.cs @@ -33,8 +33,8 @@ public void WriteTest() List messages = ['1', '2', '1', '3', '3', '1', '2', '1', '2', '2', '3', '1']; - var toWrite = new Chain(12); - var iteratorWrite = new IteratorWritableStart(toWrite); + Chain toWrite = new(12); + IteratorWritableStart iteratorWrite = new(toWrite); int i = 0; while (iteratorWrite.Next()) { diff --git a/Libiada.Core.Tests/Music/FmotifIdentifierTests.cs b/Libiada.Core.Tests/Music/FmotifIdentifierTests.cs index 66e76eab..2574eed8 100644 --- a/Libiada.Core.Tests/Music/FmotifIdentifierTests.cs +++ b/Libiada.Core.Tests/Music/FmotifIdentifierTests.cs @@ -17,12 +17,12 @@ public class FmotifIdentifierTests public void FmotifIdentificationFirstTest() { // создание ф-мотивов - var fmotif1 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); - var fmotif2 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 1); - var fmotif3 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 2); - var fmotif4 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 3); - var fmotif5 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 4); - var fmotif6 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 5); + Fmotif fmotif1 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); + Fmotif fmotif2 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 1); + Fmotif fmotif3 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 2); + Fmotif fmotif4 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 3); + Fmotif fmotif5 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 4); + Fmotif fmotif6 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 5); 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)); @@ -43,7 +43,7 @@ public void FmotifIdentificationFirstTest() fmotif6.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); fmchain1.FmotifsList.Add(fmotif2); fmchain1.FmotifsList.Add(fmotif3); @@ -51,7 +51,7 @@ public void FmotifIdentificationFirstTest() fmchain1.FmotifsList.Add(fmotif5); fmchain1.FmotifsList.Add(fmotif6); - var fmid = new FmotifIdentifier(); + FmotifIdentifier fmid = new(); 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)); @@ -67,12 +67,12 @@ public void FmotifIdentificationFirstTest() public void FmotifIdentificationSecondTest() { // создание ф-мотивов - var fmotif1 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); - var fmotif2 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 1); - var fmotif3 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 2); - var fmotif4 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 3); - var fmotif5 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 4); - var fmotif6 = new Fmotif(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 5); + Fmotif fmotif1 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 0); + Fmotif fmotif2 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 1); + Fmotif fmotif3 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 2); + Fmotif fmotif4 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 3); + Fmotif fmotif5 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 4); + Fmotif fmotif6 = new(FmotifType.CompleteMinimalMeasure, PauseTreatment.Ignore, 5); 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)); @@ -93,7 +93,7 @@ public void FmotifIdentificationSecondTest() fmotif6.NoteList.Add(new ValueNote(new Pitch(3, NoteSymbol.D, 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); @@ -101,7 +101,7 @@ public void FmotifIdentificationSecondTest() fmchain1.FmotifsList.Add(fmotif5); fmchain1.FmotifsList.Add(fmotif6); - var fmid = new FmotifIdentifier(); + FmotifIdentifier fmid = new(); Assert.That(fmid.GetIdentification(fmchain1, true).FmotifsList[0].Id, Is.EqualTo(0)); Assert.That(fmid.GetIdentification(fmchain1, true).FmotifsList[1].Id, Is.EqualTo(0)); diff --git a/Libiada.Core.Tests/Music/MidiNumberManagerTests.cs b/Libiada.Core.Tests/Music/MidiNumberManagerTests.cs index 836f25cd..83985d5b 100644 --- a/Libiada.Core.Tests/Music/MidiNumberManagerTests.cs +++ b/Libiada.Core.Tests/Music/MidiNumberManagerTests.cs @@ -16,7 +16,7 @@ public class MidiNumberManagerTests public void GetOctaveFromMidiNumberTest() { Pitch initialPitch = new(1, NoteSymbol.A, 0); - var octave = MidiNumberManager.GetOctaveFromMidiNumber(initialPitch.MidiNumber); + short octave = MidiNumberManager.GetOctaveFromMidiNumber(initialPitch.MidiNumber); Assert.That(octave, Is.EqualTo(initialPitch.Octave)); initialPitch = new Pitch(5, NoteSymbol.C, Accidental.Sharp); @@ -31,7 +31,7 @@ public void GetOctaveFromMidiNumberTest() public void GetNoteSymbolFromMidiNumberTest() { Pitch initialPitch = new(1, NoteSymbol.A, Accidental.Bekar); - var step = MidiNumberManager.GetNoteSymbolFromMidiNumber(initialPitch.MidiNumber); + NoteSymbol step = MidiNumberManager.GetNoteSymbolFromMidiNumber(initialPitch.MidiNumber); Assert.That(step, Is.EqualTo(initialPitch.Step)); initialPitch = new Pitch(5, NoteSymbol.C, Accidental.Sharp); @@ -46,7 +46,7 @@ public void GetNoteSymbolFromMidiNumberTest() public void GetAlterFromMidiNumberTest() { Pitch initialPitch = new(1, NoteSymbol.A, Accidental.Bekar); - var alter = MidiNumberManager.GetAlterFromMidiNumber(initialPitch.MidiNumber); + Accidental alter = MidiNumberManager.GetAlterFromMidiNumber(initialPitch.MidiNumber); Assert.That(alter, Is.EqualTo(initialPitch.Alter)); initialPitch = new Pitch(5, NoteSymbol.C, Accidental.Sharp); diff --git a/Libiada.Core.Tests/Music/MusicXml/XmlReaderTests.cs b/Libiada.Core.Tests/Music/MusicXml/XmlReaderTests.cs index b11d9205..4af764ed 100644 --- a/Libiada.Core.Tests/Music/MusicXml/XmlReaderTests.cs +++ b/Libiada.Core.Tests/Music/MusicXml/XmlReaderTests.cs @@ -14,7 +14,7 @@ public class XmlReaderTests [Test] public void XmlReaderFirstTest() { - var xr = new MusicXmlReader($"{SystemData.ProjectFolderPath}LibiadaMusicExample7Liga.xml"); + MusicXmlReader xr = new($"{SystemData.ProjectFolderPath}LibiadaMusicExample7Liga.xml"); Assert.That(xr.MusicXmlDocument, Is.Not.Null); } } diff --git a/Libiada.Core.Tests/SpaceReorganizers/NullCycleSpaceReorganizerTests.cs b/Libiada.Core.Tests/SpaceReorganizers/NullCycleSpaceReorganizerTests.cs index d5ca4d96..668842cf 100644 --- a/Libiada.Core.Tests/SpaceReorganizers/NullCycleSpaceReorganizerTests.cs +++ b/Libiada.Core.Tests/SpaceReorganizers/NullCycleSpaceReorganizerTests.cs @@ -29,10 +29,10 @@ public void Initialization() [Test] public void LevelOneTest() { - var cycleTestChainLevel1 = new Chain("adbaacbbaacaa"); + Chain cycleTestChainLevel1 = new("adbaacbbaacaa"); - var rebulder = new NullCycleSpaceReorganizer(1); - var result = rebulder.Reorganize(testChain); + NullCycleSpaceReorganizer rebulder = new(1); + AbstractChain result = rebulder.Reorganize(testChain); Assert.That(result, Is.EqualTo(cycleTestChainLevel1)); } @@ -42,10 +42,10 @@ public void LevelOneTest() [Test] public void LevelFiveTest() { - var cycleTestChainLevel5 = new Chain("adbaacbbaacaadbaa"); + Chain cycleTestChainLevel5 = new("adbaacbbaacaadbaa"); - var reorganizer = new NullCycleSpaceReorganizer(5); - var result = reorganizer.Reorganize(testChain); + NullCycleSpaceReorganizer reorganizer = new(5); + AbstractChain result = reorganizer.Reorganize(testChain); Assert.That(result, Is.EqualTo(cycleTestChainLevel5)); } } diff --git a/Libiada.Core.Tests/SpaceReorganizers/NullReorganizerTests.cs b/Libiada.Core.Tests/SpaceReorganizers/NullReorganizerTests.cs index 03e99841..2f2a5f96 100644 --- a/Libiada.Core.Tests/SpaceReorganizers/NullReorganizerTests.cs +++ b/Libiada.Core.Tests/SpaceReorganizers/NullReorganizerTests.cs @@ -36,8 +36,8 @@ public void Initialization() [Test] public void FromParentToChildTest() { - var reorganizer = new NullReorganizer(); - var result = reorganizer.Reorganize(chain); + NullReorganizer reorganizer = new(); + AbstractChain result = reorganizer.Reorganize(chain); Assert.That(result, Is.EqualTo(baseChain)); } @@ -48,8 +48,8 @@ public void FromParentToChildTest() [Test] public void FromChildToParentTest() { - var reorganizer = new NullReorganizer(); - var result = reorganizer.Reorganize(baseChain); + NullReorganizer reorganizer = new(); + AbstractChain result = reorganizer.Reorganize(baseChain); 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 2f7dac53..c36fed6e 100644 --- a/Libiada.Core.Tests/TimeSeries/Aggregators/AverageTests.cs +++ b/Libiada.Core.Tests/TimeSeries/Aggregators/AverageTests.cs @@ -24,7 +24,7 @@ public class AverageTests [Test] public void AverageTest() { - var aggregator = new Average(); + Average aggregator = new(); double result = aggregator.Aggregate(distances); Assert.That(result, Is.EqualTo(average)); } diff --git a/Libiada.Core.Tests/TimeSeries/Aggregators/DifferenceModuleTests.cs b/Libiada.Core.Tests/TimeSeries/Aggregators/DifferenceModuleTests.cs index 14367044..0330dc27 100644 --- a/Libiada.Core.Tests/TimeSeries/Aggregators/DifferenceModuleTests.cs +++ b/Libiada.Core.Tests/TimeSeries/Aggregators/DifferenceModuleTests.cs @@ -24,7 +24,7 @@ public class DifferenceModuleTests [Test] public void DifferenceModuleTest() { - var aggregator = new DifferenceModule(); + DifferenceModule aggregator = new(); double result = aggregator.Aggregate(distances); Assert.That(result, Is.EqualTo(diffMod)); } diff --git a/Libiada.Core.Tests/TimeSeries/Aggregators/DifferenceSquareRootTests.cs b/Libiada.Core.Tests/TimeSeries/Aggregators/DifferenceSquareRootTests.cs index 8b8d221f..4bf077f2 100644 --- a/Libiada.Core.Tests/TimeSeries/Aggregators/DifferenceSquareRootTests.cs +++ b/Libiada.Core.Tests/TimeSeries/Aggregators/DifferenceSquareRootTests.cs @@ -24,7 +24,7 @@ public class DifferenceSquareRootTests [Test] public void DifferenceSquareRootTest() { - var aggregator = new DifferenceSquareRoot(); + DifferenceSquareRoot aggregator = new(); double result = aggregator.Aggregate(distances); Assert.That(result, Is.EqualTo(diffSqrt)); } diff --git a/Libiada.Core.Tests/TimeSeries/Aggregators/MaxTests.cs b/Libiada.Core.Tests/TimeSeries/Aggregators/MaxTests.cs index bab748aa..8d46589f 100644 --- a/Libiada.Core.Tests/TimeSeries/Aggregators/MaxTests.cs +++ b/Libiada.Core.Tests/TimeSeries/Aggregators/MaxTests.cs @@ -24,7 +24,7 @@ public class MaxTests [Test] public void MaxTest() { - var aggregator = new Max(); + Max aggregator = new(); double result = aggregator.Aggregate(distances); Assert.That(result, Is.EqualTo(max)); } diff --git a/Libiada.Core.Tests/TimeSeries/Aggregators/MinTests.cs b/Libiada.Core.Tests/TimeSeries/Aggregators/MinTests.cs index 5b86a93d..5f2f9bb3 100644 --- a/Libiada.Core.Tests/TimeSeries/Aggregators/MinTests.cs +++ b/Libiada.Core.Tests/TimeSeries/Aggregators/MinTests.cs @@ -24,7 +24,7 @@ public class MinTests [Test] public void MinTest() { - var aggregator = new Min(); + Min aggregator = new(); double result = aggregator.Aggregate(distances); Assert.That(result, Is.EqualTo(min)); } diff --git a/Libiada.Core.Tests/TimeSeries/Aggregators/SumModuleTests.cs b/Libiada.Core.Tests/TimeSeries/Aggregators/SumModuleTests.cs index 68ba55ea..0e94981b 100644 --- a/Libiada.Core.Tests/TimeSeries/Aggregators/SumModuleTests.cs +++ b/Libiada.Core.Tests/TimeSeries/Aggregators/SumModuleTests.cs @@ -24,7 +24,7 @@ public class SumModuleTests [Test] public void SumModuleTest() { - var aggregator = new SumModule(); + SumModule aggregator = new(); double result = aggregator.Aggregate(distances); Assert.That(result, Is.EqualTo(sumMod)); } diff --git a/Libiada.Core.Tests/TimeSeries/Aggregators/SumSquareRootTests.cs b/Libiada.Core.Tests/TimeSeries/Aggregators/SumSquareRootTests.cs index 1a19e07f..5fffd620 100644 --- a/Libiada.Core.Tests/TimeSeries/Aggregators/SumSquareRootTests.cs +++ b/Libiada.Core.Tests/TimeSeries/Aggregators/SumSquareRootTests.cs @@ -24,7 +24,7 @@ public class SumSquareRootTests [Test] public void SumSquareRootTest() { - var aggregator = new SumSquareRoot(); + SumSquareRoot aggregator = new(); double result = aggregator.Aggregate(distances); Assert.That(result, Is.EqualTo(sumSqrt)); } diff --git a/Libiada.Core.Tests/TimeSeries/Aligners/AllOffsetsAlignerTests.cs b/Libiada.Core.Tests/TimeSeries/Aligners/AllOffsetsAlignerTests.cs index edba6e77..ae606cc0 100644 --- a/Libiada.Core.Tests/TimeSeries/Aligners/AllOffsetsAlignerTests.cs +++ b/Libiada.Core.Tests/TimeSeries/Aligners/AllOffsetsAlignerTests.cs @@ -43,8 +43,8 @@ public class AllOffsetsAlignerTests public void AllOffsetsAlignTest(double[] firstSeries, double[] secondSeries, double[][] firstExpected, double[][] secondExpected) { - var aligner = new AllOffsetsAligner(); - var (first, second) = aligner.AlignSeries(firstSeries, secondSeries); + AllOffsetsAligner aligner = new(); + (double[][] first, double[][] second) = aligner.AlignSeries(firstSeries, secondSeries); Assert.Multiple(() => { Assert.That(first, Is.EqualTo(firstExpected)); diff --git a/Libiada.Core.Tests/TimeSeries/Aligners/ByShortestAlignerTests.cs b/Libiada.Core.Tests/TimeSeries/Aligners/ByShortestAlignerTests.cs index 4590234b..2df76ea4 100644 --- a/Libiada.Core.Tests/TimeSeries/Aligners/ByShortestAlignerTests.cs +++ b/Libiada.Core.Tests/TimeSeries/Aligners/ByShortestAlignerTests.cs @@ -29,8 +29,8 @@ public class ByShortestAlignerTests [Test] public void ShortestAlignTest() { - var aligner = new ByShortestAligner(); - var result = aligner.AlignSeries(shortTimeSeries, longTimeSeries); + ByShortestAligner aligner = new(); + (double[][] first, double[][] second) result = aligner.AlignSeries(shortTimeSeries, longTimeSeries); 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)); diff --git a/Libiada.Core.Tests/TimeSeries/Aligners/ByShortestFromRightAlignerTests.cs b/Libiada.Core.Tests/TimeSeries/Aligners/ByShortestFromRightAlignerTests.cs index 27c3ce4f..a04add79 100644 --- a/Libiada.Core.Tests/TimeSeries/Aligners/ByShortestFromRightAlignerTests.cs +++ b/Libiada.Core.Tests/TimeSeries/Aligners/ByShortestFromRightAlignerTests.cs @@ -34,8 +34,8 @@ public class ByShortestFromRightAlignerTests [Test] public void ShortestFromRightAlignTest() { - var aligner = new ByShortestFromRightAligner(); - var result = aligner.AlignSeries(shortTimeSeries, longTimeSeries); + ByShortestFromRightAligner aligner = new(); + (double[][] first, double[][] second) result = aligner.AlignSeries(shortTimeSeries, longTimeSeries); Assert.That(result.first[0], Is.EqualTo(shortTimeSeries)); Assert.That(result.second[0], Is.EqualTo(second)); diff --git a/Libiada.Core.Tests/TimeSeries/Aligners/FirstElementDuplicatorTests.cs b/Libiada.Core.Tests/TimeSeries/Aligners/FirstElementDuplicatorTests.cs index 2029883e..39a79daa 100644 --- a/Libiada.Core.Tests/TimeSeries/Aligners/FirstElementDuplicatorTests.cs +++ b/Libiada.Core.Tests/TimeSeries/Aligners/FirstElementDuplicatorTests.cs @@ -34,9 +34,9 @@ public class FirstElementDuplicatorTests public void FirstElementDuplicationAlignerTest(double[] firstTimeSeries, double[] secondTimeSeries, double[] expected) { - var aligner = new FirstElementDuplicator(); - var (first, second) = aligner.AlignSeries(firstTimeSeries, secondTimeSeries); - var actual = firstTimeSeries.Length < secondTimeSeries.Length ? first[0] : second[0]; + FirstElementDuplicator aligner = new(); + (double[][] first, double[][] second) = aligner.AlignSeries(firstTimeSeries, secondTimeSeries); + double[] actual = firstTimeSeries.Length < secondTimeSeries.Length ? first[0] : second[0]; Assert.That(actual, Is.EqualTo(expected)); } } diff --git a/Libiada.Core.Tests/TimeSeries/Aligners/LastElementDuplicatorTests.cs b/Libiada.Core.Tests/TimeSeries/Aligners/LastElementDuplicatorTests.cs index 48259f33..ee657acb 100644 --- a/Libiada.Core.Tests/TimeSeries/Aligners/LastElementDuplicatorTests.cs +++ b/Libiada.Core.Tests/TimeSeries/Aligners/LastElementDuplicatorTests.cs @@ -32,9 +32,9 @@ public class LastElementDuplicatorTests public void LastElementDuplicationAlignerTest(double[] firstTimeSeries, double[] secondTimeSeries, double[] expected) { - var aligner = new LastElementDuplicator(); - var (first, second) = aligner.AlignSeries(firstTimeSeries, secondTimeSeries); - var actual = firstTimeSeries.Length < secondTimeSeries.Length ? first[0] : second[0]; + LastElementDuplicator aligner = new(); + (double[][] first, double[][] second) = aligner.AlignSeries(firstTimeSeries, secondTimeSeries); + double[] actual = firstTimeSeries.Length < secondTimeSeries.Length ? first[0] : second[0]; Assert.That(actual, Is.EqualTo(expected)); } } diff --git a/Libiada.Core.Tests/TimeSeries/OneDimensional/ComparersTests/OneDimensionalTimeSeriesComparerTests.cs b/Libiada.Core.Tests/TimeSeries/OneDimensional/ComparersTests/OneDimensionalTimeSeriesComparerTests.cs index 98179747..728248da 100644 --- a/Libiada.Core.Tests/TimeSeries/OneDimensional/ComparersTests/OneDimensionalTimeSeriesComparerTests.cs +++ b/Libiada.Core.Tests/TimeSeries/OneDimensional/ComparersTests/OneDimensionalTimeSeriesComparerTests.cs @@ -313,7 +313,7 @@ public void CompareTest( IOneDimensionalPointsDistance calculator, IDistancesAggregator aggregator) { - var comparer = new OneDimensionalTimeSeriesComparer(aligner, calculator, aggregator); + OneDimensionalTimeSeriesComparer comparer = new(aligner, calculator, aggregator); double result = comparer.GetDistance(firstSeries, secondSeries); Assert.That(result, Is.EqualTo(expected)); } diff --git a/Libiada.Core.Tests/TimeSeries/OneDimensional/DistanceCalculatorsTests/EuclideanDistanceBetweenOneDimensionalPointsTests.cs b/Libiada.Core.Tests/TimeSeries/OneDimensional/DistanceCalculatorsTests/EuclideanDistanceBetweenOneDimensionalPointsTests.cs index 41fd4654..599653bd 100644 --- a/Libiada.Core.Tests/TimeSeries/OneDimensional/DistanceCalculatorsTests/EuclideanDistanceBetweenOneDimensionalPointsTests.cs +++ b/Libiada.Core.Tests/TimeSeries/OneDimensional/DistanceCalculatorsTests/EuclideanDistanceBetweenOneDimensionalPointsTests.cs @@ -26,7 +26,7 @@ public class EuclideanDistanceBetweenOneDimensionalPointsTests public void EuclideanDistanceTest(double firstPoint, double secondPoint, double expectedDistance) { - var calculator = new EuclideanDistanceBetweenOneDimensionalPointsCalculator(); + EuclideanDistanceBetweenOneDimensionalPointsCalculator calculator = new(); double result = calculator.GetDistance(firstPoint, secondPoint); Assert.That(result, Is.EqualTo(expectedDistance)); } diff --git a/Libiada.Core.Tests/TimeSeries/OneDimensional/DistanceCalculatorsTests/HammingDistanceBetweenOneDimensionalPointsTests.cs b/Libiada.Core.Tests/TimeSeries/OneDimensional/DistanceCalculatorsTests/HammingDistanceBetweenOneDimensionalPointsTests.cs index 4314f3e2..d56cdca1 100644 --- a/Libiada.Core.Tests/TimeSeries/OneDimensional/DistanceCalculatorsTests/HammingDistanceBetweenOneDimensionalPointsTests.cs +++ b/Libiada.Core.Tests/TimeSeries/OneDimensional/DistanceCalculatorsTests/HammingDistanceBetweenOneDimensionalPointsTests.cs @@ -28,7 +28,7 @@ public class HammingDistanceBetweenOneDimensionalPointsTests public void HammingDistanceTest(double firstPoint, double secondPoint, int expectedDistance) { - var calculator = new HammingDistanceBetweenOneDimensionalPointsCalculator(); + HammingDistanceBetweenOneDimensionalPointsCalculator calculator = new(); double result = calculator.GetDistance(firstPoint, secondPoint); Assert.That(result, Is.EqualTo(expectedDistance)); } diff --git a/Libiada.Core/Attributes/LinkAttribute.cs b/Libiada.Core/Attributes/LinkAttribute.cs index c647adfb..8a802376 100644 --- a/Libiada.Core/Attributes/LinkAttribute.cs +++ b/Libiada.Core/Attributes/LinkAttribute.cs @@ -18,4 +18,4 @@ public LinkAttribute(Link value) Value = value; } -} \ No newline at end of file +} diff --git a/Libiada.Core/Core/AbstractChain.cs b/Libiada.Core/Core/AbstractChain.cs index e5e7941a..bdf1deaf 100644 --- a/Libiada.Core/Core/AbstractChain.cs +++ b/Libiada.Core/Core/AbstractChain.cs @@ -108,9 +108,9 @@ public IBaseObject this[int index] /// public string ToString(string delimiter) { - var length = Length; + int length = Length; - var builder = new StringBuilder(length * 2); + StringBuilder builder = new(length * 2); for (int i = 0; i < length; i++) { @@ -129,8 +129,8 @@ public string ToString(string delimiter) /// public IBaseObject[] ToArray() { - var length = Length; - var result = new IBaseObject[length]; + int length = Length; + IBaseObject[] result = new IBaseObject[length]; for (int i = 0; i < length; i++) { @@ -148,8 +148,8 @@ public IBaseObject[] ToArray() /// public List ToList() { - var length = Length; - var result = new List(length); + int length = Length; + List result = new(length); for (int i = 0; i < length; i++) { diff --git a/Libiada.Core/Core/Alphabet.cs b/Libiada.Core/Core/Alphabet.cs index 71ebe267..3f72f066 100644 --- a/Libiada.Core/Core/Alphabet.cs +++ b/Libiada.Core/Core/Alphabet.cs @@ -12,12 +12,12 @@ public class Alphabet : IBaseObject, IEnumerable /// /// The elements within alphabet. /// - protected readonly List Elements = new List(); + protected readonly List Elements = []; /// /// The elements indexes. /// - protected readonly Dictionary ElementsIndexes = new Dictionary(); + protected readonly Dictionary ElementsIndexes = []; /// /// Gets count of elements in alphabet. @@ -107,11 +107,7 @@ public virtual void Remove(int index) /// public IBaseObject Clone() { - var clone = new Alphabet(); - foreach (IBaseObject element in Elements) - { - clone.Add(element); - } + Alphabet clone = [.. Elements]; return clone; } @@ -215,7 +211,7 @@ IEnumerator IEnumerable.GetEnumerator() /// public IBaseObject[] ToArray() { - var result = new List(); + List result = []; foreach (IBaseObject element in Elements) { @@ -233,7 +229,7 @@ public IBaseObject[] ToArray() /// public List ToList() { - var result = new List(); + List result = []; foreach (IBaseObject element in Elements) { @@ -271,10 +267,10 @@ public override int GetHashCode() /// public override string ToString() { - StringBuilder result = new StringBuilder(); + StringBuilder result = new(); result.Append("< "); - foreach(var element in Elements) result.Append($"{element}, "); + foreach(IBaseObject element in Elements) result.Append($"{element}, "); result.Remove(result.Length - 2, 2); result.Append(" >"); return result.ToString(); diff --git a/Libiada.Core/Core/ArrangementManagers/AccordanceIntervalsManager.cs b/Libiada.Core/Core/ArrangementManagers/AccordanceIntervalsManager.cs index c0b36b05..8f37202f 100644 --- a/Libiada.Core/Core/ArrangementManagers/AccordanceIntervalsManager.cs +++ b/Libiada.Core/Core/ArrangementManagers/AccordanceIntervalsManager.cs @@ -13,12 +13,12 @@ public class AccordanceIntervalsManager /// /// First accordance intervals. /// - public readonly List FilteredFirstIntervals = new List(); + public readonly List FilteredFirstIntervals = []; /// /// Second accordance intervals. /// - public readonly List FilteredSecondIntervals = new List(); + public readonly List FilteredSecondIntervals = []; /// /// First element occurrences count. diff --git a/Libiada.Core/Core/ArrangementManagers/ArrangementType.cs b/Libiada.Core/Core/ArrangementManagers/ArrangementType.cs index e6061f89..2886db71 100644 --- a/Libiada.Core/Core/ArrangementManagers/ArrangementType.cs +++ b/Libiada.Core/Core/ArrangementManagers/ArrangementType.cs @@ -19,4 +19,4 @@ public enum ArrangementType : byte /// The intervals and series. /// IntervalsAndSeries = 2 -} \ No newline at end of file +} diff --git a/Libiada.Core/Core/ArrangementManagers/BinaryIntervalsManager.cs b/Libiada.Core/Core/ArrangementManagers/BinaryIntervalsManager.cs index 799fe341..003c9caf 100644 --- a/Libiada.Core/Core/ArrangementManagers/BinaryIntervalsManager.cs +++ b/Libiada.Core/Core/ArrangementManagers/BinaryIntervalsManager.cs @@ -158,10 +158,10 @@ public int[] GetIntervals() /// private int FillPairsCount() { - var counter = 0; + int counter = 0; - var elementCounter = new ElementsCount(); - var firstElementCount = (int)elementCounter.Calculate(FirstChain); + ElementsCount elementCounter = new(); + int firstElementCount = (int)elementCounter.Calculate(FirstChain); for (int i = 1; i <= firstElementCount; i++) { diff --git a/Libiada.Core/Core/ArrangementManagers/IntervalsManager.cs b/Libiada.Core/Core/ArrangementManagers/IntervalsManager.cs index 1b177a0b..2f540b21 100644 --- a/Libiada.Core/Core/ArrangementManagers/IntervalsManager.cs +++ b/Libiada.Core/Core/ArrangementManagers/IntervalsManager.cs @@ -104,7 +104,7 @@ public int[] GetArrangement(Link link) result[i] = intervals[i]; } - result[result.Length - 1] = End; + result[^1] = End; return result; case Link.Both: result = new int[intervals.Length + 2]; @@ -114,7 +114,7 @@ public int[] GetArrangement(Link link) result[i + 1] = intervals[i]; } - result[result.Length - 1] = End; + result[^1] = End; return result; case Link.Cycle: result = new int[intervals.Length + 1]; @@ -123,7 +123,7 @@ public int[] GetArrangement(Link link) result[i] = intervals[i]; } - result[result.Length - 1] = Start + End - 1; + result[^1] = Start + End - 1; return result; case Link.CycleStart: result = new int[intervals.Length + 1]; @@ -132,7 +132,7 @@ public int[] GetArrangement(Link link) result[i] = intervals[i]; } - result[result.Length - 1] = Start + End - 1; + result[^1] = Start + End - 1; return result; case Link.CycleEnd: result = new int[intervals.Length + 1]; @@ -167,6 +167,6 @@ private void FillIntervals(int[] positions, int sequenceLength) intervals[i] = positions[i + 1] - positions[i]; } - End = sequenceLength - positions[positions.Length - 1]; + End = sequenceLength - positions[^1]; } } diff --git a/Libiada.Core/Core/ArrangementManagers/SeriesManager.cs b/Libiada.Core/Core/ArrangementManagers/SeriesManager.cs index 14f2b2cc..2cea87f2 100644 --- a/Libiada.Core/Core/ArrangementManagers/SeriesManager.cs +++ b/Libiada.Core/Core/ArrangementManagers/SeriesManager.cs @@ -20,7 +20,7 @@ public class SeriesManager : IArrangementManager /// public SeriesManager(CongenericChain chain) { - series = new List<(int start, int length)>(); + series = []; for (int i = 1; i <= chain.OccurrencesCount; i++) { series.Add(GetSeries(chain, i)); diff --git a/Libiada.Core/Core/BaseChain.cs b/Libiada.Core/Core/BaseChain.cs index 7817dbb4..e6bd42e5 100644 --- a/Libiada.Core/Core/BaseChain.cs +++ b/Libiada.Core/Core/BaseChain.cs @@ -22,7 +22,7 @@ public class BaseChain : AbstractChain /// /// The alphabet of chain. /// - protected Alphabet alphabet = new Alphabet(); + protected Alphabet alphabet = []; /// /// Initializes a new instance of the class. @@ -93,7 +93,7 @@ public BaseChain(int[] order, Alphabet alphabet) : this(order.Length) /// public BaseChain(int[] order) : this(order.Length) { - var alphabetCardinality = order.Max(); + int alphabetCardinality = order.Max(); for (int i = 1; i <= alphabetCardinality; i++) { alphabet.Add((ValueInt)i); @@ -135,7 +135,7 @@ public Alphabet Alphabet { get { - var result = (Alphabet)alphabet.Clone(); + Alphabet result = (Alphabet)alphabet.Clone(); // Removing NullValue. result.Remove(0); @@ -279,7 +279,7 @@ public override void ClearAndSetNewLength(int length) /// public override IBaseObject Clone() { - var clone = new BaseChain(order.Length); + BaseChain clone = new(order.Length); FillClone(clone); return clone; } diff --git a/Libiada.Core/Core/Chain.cs b/Libiada.Core/Core/Chain.cs index a361f0aa..76e84690 100644 --- a/Libiada.Core/Core/Chain.cs +++ b/Libiada.Core/Core/Chain.cs @@ -115,7 +115,7 @@ public Chain(IReadOnlyList source) : base(source) /// public Chain(short[] source) { - alphabet = new Alphabet() { NullValue.Instance() }; + alphabet = [NullValue.Instance()]; order = new int[source.Length]; for (int i = 0; i < source.Length; i++) { @@ -151,7 +151,7 @@ public override void ClearAndSetNewLength(int length) /// public new IBaseObject Clone() { - var clone = new Chain(order.Length); + Chain clone = new(order.Length); FillClone(clone); return clone; } @@ -256,7 +256,7 @@ public BinaryIntervalsManager GetRelationIntervalsManager(int first, int second) relationIntervalsManagers = new BinaryIntervalsManager[alphabet.Cardinality - 1, alphabet.Cardinality - 1]; } - var intervalsManager = relationIntervalsManagers[first - 1, second - 1]; + BinaryIntervalsManager? intervalsManager = relationIntervalsManagers[first - 1, second - 1]; if (intervalsManager == null) { @@ -356,7 +356,7 @@ public int GetOccurrence(IBaseObject element, int entry) /// public void SetArrangementManagers(ArrangementType arrangementType = ArrangementType.Intervals) { - foreach (var chain in congenericChains) + foreach (CongenericChain chain in congenericChains) { chain.CurrentArrangementType = arrangementType; chain.CreateArrangementManager(arrangementType); @@ -372,7 +372,7 @@ public void SetArrangementManagers(ArrangementType arrangementType = Arrangement /// protected void FillClone(IBaseObject clone) { - var tempChain = clone as Chain; + Chain? tempChain = clone as Chain; base.FillClone(tempChain); if (tempChain != null) { @@ -389,11 +389,11 @@ protected void FillClone(IBaseObject clone) /// private void FillCongenericChains() { - var occurrences = new List[alphabet.Cardinality - 1]; + List[] occurrences = new List[alphabet.Cardinality - 1]; for (int i = 0; i < alphabet.Cardinality - 1; i++) { - occurrences[i] = new List(); + occurrences[i] = []; } for (int j = 0; j < order.Length; j++) diff --git a/Libiada.Core/Core/Characteristics/Calculators/AccordanceCalculators/AccordanceCalculatorsFactory.cs b/Libiada.Core/Core/Characteristics/Calculators/AccordanceCalculators/AccordanceCalculatorsFactory.cs index 545bcf48..20a108cb 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/AccordanceCalculators/AccordanceCalculatorsFactory.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/AccordanceCalculators/AccordanceCalculatorsFactory.cs @@ -21,14 +21,11 @@ public static class AccordanceCalculatorsFactory /// public static IAccordanceCalculator CreateCalculator(AccordanceCharacteristic type) { - switch (type) + return type switch { - case AccordanceCharacteristic.MutualComplianceDegree: - return new MutualComplianceDegree(); - case AccordanceCharacteristic.PartialComplianceDegree: - return new PartialComplianceDegree(); - default: - throw new InvalidEnumArgumentException(nameof(type), (int)type, typeof(AccordanceCharacteristic)); - } + AccordanceCharacteristic.MutualComplianceDegree => new MutualComplianceDegree(), + AccordanceCharacteristic.PartialComplianceDegree => new PartialComplianceDegree(), + _ => throw new InvalidEnumArgumentException(nameof(type), (int)type, typeof(AccordanceCharacteristic)), + }; } } diff --git a/Libiada.Core/Core/Characteristics/Calculators/AccordanceCalculators/MutualComplianceDegree.cs b/Libiada.Core/Core/Characteristics/Calculators/AccordanceCalculators/MutualComplianceDegree.cs index 0d0954bd..b45a6e72 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/AccordanceCalculators/MutualComplianceDegree.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/AccordanceCalculators/MutualComplianceDegree.cs @@ -22,7 +22,7 @@ public class MutualComplianceDegree : IAccordanceCalculator /// public double Calculate(CongenericChain firstChain, CongenericChain secondChain, Link link) { - var partialAccordanceCalculator = new PartialComplianceDegree(); + PartialComplianceDegree partialAccordanceCalculator = new(); double firstResult = partialAccordanceCalculator.Calculate(firstChain, secondChain, link); double secondResult = partialAccordanceCalculator.Calculate(secondChain, firstChain, link); return Math.Sqrt(firstResult * secondResult); diff --git a/Libiada.Core/Core/Characteristics/Calculators/AccordanceCalculators/PartialComplianceDegree.cs b/Libiada.Core/Core/Characteristics/Calculators/AccordanceCalculators/PartialComplianceDegree.cs index 8555a4f8..5d39dce0 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/AccordanceCalculators/PartialComplianceDegree.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/AccordanceCalculators/PartialComplianceDegree.cs @@ -24,7 +24,7 @@ public class PartialComplianceDegree : IAccordanceCalculator /// public double Calculate(CongenericChain firstChain, CongenericChain secondChain, Link link) { - var manager = new AccordanceIntervalsManager(firstChain, secondChain, link); + AccordanceIntervalsManager manager = new(firstChain, secondChain, link); if (manager.FilteredFirstIntervals.Count == 0) { return 0; diff --git a/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/BinaryCalculator.cs b/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/BinaryCalculator.cs index c3aa652b..9dbf8623 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/BinaryCalculator.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/BinaryCalculator.cs @@ -35,11 +35,11 @@ public abstract class BinaryCalculator : IBinaryCalculator /// public List> CalculateAll(Chain chain, Link link) { - var result = new List>(); - var alphabetCardinality = chain.Alphabet.Cardinality; + List> result = []; + int alphabetCardinality = chain.Alphabet.Cardinality; for (int i = 0; i < alphabetCardinality; i++) { - result.Add(new List()); + result.Add([]); for (int j = 0; j < alphabetCardinality; j++) { result[i].Add(Calculate(chain.GetRelationIntervalsManager(i + 1, j + 1), link)); diff --git a/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/BinaryCalculatorsFactory.cs b/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/BinaryCalculatorsFactory.cs index 9bcda164..9fac69ee 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/BinaryCalculatorsFactory.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/BinaryCalculatorsFactory.cs @@ -21,22 +21,15 @@ public static class BinaryCalculatorsFactory /// public static IBinaryCalculator CreateCalculator(BinaryCharacteristic type) { - switch (type) + return type switch { - case BinaryCharacteristic.GeometricMean: - return new GeometricMean(); - case BinaryCharacteristic.InvolvedPartialDependenceCoefficient: - return new InvolvedPartialDependenceCoefficient(); - case BinaryCharacteristic.MutualDependenceCoefficient: - return new MutualDependenceCoefficient(); - case BinaryCharacteristic.NormalizedPartialDependenceCoefficient: - return new NormalizedPartialDependenceCoefficient(); - case BinaryCharacteristic.PartialDependenceCoefficient: - return new PartialDependenceCoefficient(); - case BinaryCharacteristic.Redundancy: - return new Redundancy(); - default: - throw new InvalidEnumArgumentException(nameof(type), (int)type, typeof(BinaryCharacteristic)); - } + BinaryCharacteristic.GeometricMean => new GeometricMean(), + BinaryCharacteristic.InvolvedPartialDependenceCoefficient => new InvolvedPartialDependenceCoefficient(), + BinaryCharacteristic.MutualDependenceCoefficient => new MutualDependenceCoefficient(), + BinaryCharacteristic.NormalizedPartialDependenceCoefficient => new NormalizedPartialDependenceCoefficient(), + BinaryCharacteristic.PartialDependenceCoefficient => new PartialDependenceCoefficient(), + BinaryCharacteristic.Redundancy => new Redundancy(), + _ => throw new InvalidEnumArgumentException(nameof(type), (int)type, typeof(BinaryCharacteristic)), + }; } } diff --git a/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/InvolvedPartialDependenceCoefficient.cs b/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/InvolvedPartialDependenceCoefficient.cs index 956b91d8..5983e874 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/InvolvedPartialDependenceCoefficient.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/InvolvedPartialDependenceCoefficient.cs @@ -27,7 +27,7 @@ public override double Calculate(BinaryIntervalsManager manager, Link link) return 0; } - var redundancyCalculator = new Redundancy(); + Redundancy redundancyCalculator = new(); double redundancy = redundancyCalculator.Calculate(manager, link); return redundancy * (2 * manager.PairsCount) / (manager.FirstChain.OccurrencesCount + manager.SecondChain.OccurrencesCount); diff --git a/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/MutualDependenceCoefficient.cs b/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/MutualDependenceCoefficient.cs index ae47e4db..0e297f39 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/MutualDependenceCoefficient.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/MutualDependenceCoefficient.cs @@ -27,7 +27,7 @@ public override double Calculate(BinaryIntervalsManager manager, Link link) return 0; } - var involvedCoefficientCalculator = new InvolvedPartialDependenceCoefficient(); + InvolvedPartialDependenceCoefficient involvedCoefficientCalculator = new(); double firstInvolvedCoefficient = involvedCoefficientCalculator.Calculate(manager, link); double secondInvolvedCoefficient = involvedCoefficientCalculator.Calculate(new BinaryIntervalsManager(manager.SecondChain, manager.FirstChain), link); diff --git a/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/NormalizedPartialDependenceCoefficient.cs b/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/NormalizedPartialDependenceCoefficient.cs index a036ca46..0671d075 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/NormalizedPartialDependenceCoefficient.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/NormalizedPartialDependenceCoefficient.cs @@ -27,7 +27,7 @@ public override double Calculate(BinaryIntervalsManager manager, Link link) return 0; } - var partialDependenceCoefficient = new PartialDependenceCoefficient(); + PartialDependenceCoefficient partialDependenceCoefficient = new(); double k1 = partialDependenceCoefficient.Calculate(manager, link); return k1 * 2 * manager.PairsCount / manager.FirstChain.Length; diff --git a/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/PartialDependenceCoefficient.cs b/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/PartialDependenceCoefficient.cs index 0d22cd56..3b30b38a 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/PartialDependenceCoefficient.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/PartialDependenceCoefficient.cs @@ -27,7 +27,7 @@ public override double Calculate(BinaryIntervalsManager manager, Link link) return 0; } - var redundancyCalculator = new Redundancy(); + Redundancy redundancyCalculator = new(); double redundancy = redundancyCalculator.Calculate(manager, link); return redundancy * manager.PairsCount / manager.SecondChain.OccurrencesCount; diff --git a/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/Redundancy.cs b/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/Redundancy.cs index 985fbe0d..538b8fd0 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/Redundancy.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/BinaryCalculators/Redundancy.cs @@ -60,7 +60,7 @@ public override double Calculate(BinaryIntervalsManager manager, Link link) avG = manager.PairsCount == 0 ? 0 : avG / manager.PairsCount; - var geometricMeanCalculator = new GeometricMean(); + GeometricMean geometricMeanCalculator = new(); double binaryGeometricMean = geometricMeanCalculator.Calculate(manager, link); return 1 - (binaryGeometricMean / Math.Pow(2, avG)); diff --git a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/ArithmeticMean.cs b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/ArithmeticMean.cs index 67efc09a..39eb03cc 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/ArithmeticMean.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/ArithmeticMean.cs @@ -21,11 +21,11 @@ public class ArithmeticMean : ICongenericCalculator /// public double Calculate(CongenericChain chain, Link link) { - var adder = new IntervalsSum(); - var counter = new IntervalsCount(); + IntervalsSum adder = new(); + IntervalsCount counter = new(); double intervalsSum = adder.Calculate(chain, link); - var intervalsCount = (int)counter.Calculate(chain, link); + int intervalsCount = (int)counter.Calculate(chain, link); return intervalsCount == 0 ? 0 : intervalsSum / intervalsCount; } } diff --git a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/AverageRemoteness.cs b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/AverageRemoteness.cs index 7533e8f9..d16a26c3 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/AverageRemoteness.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/AverageRemoteness.cs @@ -20,11 +20,11 @@ public class AverageRemoteness : ICongenericCalculator /// public double Calculate(CongenericChain chain, Link link) { - var depthCalculator = new Depth(); - var intervalsCount = new IntervalsCount(); + Depth depthCalculator = new(); + IntervalsCount intervalsCount = new(); double depth = depthCalculator.Calculate(chain, link); - var nj = (int)intervalsCount.Calculate(chain, link); + int nj = (int)intervalsCount.Calculate(chain, link); return nj == 0 ? 0 : depth / nj; } } diff --git a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/CongenericCalculatorsFactory.cs b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/CongenericCalculatorsFactory.cs index e9b5c2a3..ffed1b2e 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/CongenericCalculatorsFactory.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/CongenericCalculatorsFactory.cs @@ -21,60 +21,34 @@ public static class CongenericCalculatorsFactory /// public static ICongenericCalculator CreateCalculator(CongenericCharacteristic type) { - switch (type) + return type switch { - case CongenericCharacteristic.ArithmeticMean: - return new ArithmeticMean(); - case CongenericCharacteristic.AverageRemoteness: - return new AverageRemoteness(); - case CongenericCharacteristic.CuttingLength: - return new CuttingLength(); - case CongenericCharacteristic.CuttingLengthVocabularyEntropy: - return new CuttingLengthVocabularyEntropy(); - case CongenericCharacteristic.Depth: - return new Depth(); - case CongenericCharacteristic.DescriptiveInformation: - return new DescriptiveInformation(); - case CongenericCharacteristic.ElementsCount: - return new ElementsCount(); - case CongenericCharacteristic.GeometricMean: - return new GeometricMean(); - case CongenericCharacteristic.IdentificationInformation: - return new IdentificationInformation(); - case CongenericCharacteristic.IntervalsCount: - return new IntervalsCount(); - case CongenericCharacteristic.IntervalsSum: - return new IntervalsSum(); - case CongenericCharacteristic.Length: - return new Length(); - case CongenericCharacteristic.Periodicity: - return new Periodicity(); - case CongenericCharacteristic.Probability: - return new Probability(); - case CongenericCharacteristic.Regularity: - return new Regularity(); - case CongenericCharacteristic.Uniformity: - return new Uniformity(); - case CongenericCharacteristic.VariationsCount: - return new VariationsCount(); - case CongenericCharacteristic.Volume: - return new Volume(); - case CongenericCharacteristic.RemotenessDispersion: - return new RemotenessDispersion(); - case CongenericCharacteristic.RemotenessKurtosis: - return new RemotenessKurtosis(); - case CongenericCharacteristic.RemotenessKurtosisCoefficient: - return new RemotenessKurtosisCoefficient(); - case CongenericCharacteristic.RemotenessSkewness: - return new RemotenessSkewness(); - case CongenericCharacteristic.RemotenessSkewnessCoefficient: - return new RemotenessSkewnessCoefficient(); - case CongenericCharacteristic.RemotenessStandardDeviation: - return new RemotenessStandardDeviation(); - case CongenericCharacteristic.InformationAmount: - return new InformationAmount(); - default: - throw new InvalidEnumArgumentException(nameof(type), (int)type, typeof(CongenericCharacteristic)); - } + CongenericCharacteristic.ArithmeticMean => new ArithmeticMean(), + CongenericCharacteristic.AverageRemoteness => new AverageRemoteness(), + CongenericCharacteristic.CuttingLength => new CuttingLength(), + CongenericCharacteristic.CuttingLengthVocabularyEntropy => new CuttingLengthVocabularyEntropy(), + CongenericCharacteristic.Depth => new Depth(), + CongenericCharacteristic.DescriptiveInformation => new DescriptiveInformation(), + CongenericCharacteristic.ElementsCount => new ElementsCount(), + CongenericCharacteristic.GeometricMean => new GeometricMean(), + CongenericCharacteristic.IdentificationInformation => new IdentificationInformation(), + CongenericCharacteristic.IntervalsCount => new IntervalsCount(), + CongenericCharacteristic.IntervalsSum => new IntervalsSum(), + CongenericCharacteristic.Length => new Length(), + CongenericCharacteristic.Periodicity => new Periodicity(), + CongenericCharacteristic.Probability => new Probability(), + CongenericCharacteristic.Regularity => new Regularity(), + CongenericCharacteristic.Uniformity => new Uniformity(), + CongenericCharacteristic.VariationsCount => new VariationsCount(), + CongenericCharacteristic.Volume => new Volume(), + CongenericCharacteristic.RemotenessDispersion => new RemotenessDispersion(), + CongenericCharacteristic.RemotenessKurtosis => new RemotenessKurtosis(), + CongenericCharacteristic.RemotenessKurtosisCoefficient => new RemotenessKurtosisCoefficient(), + CongenericCharacteristic.RemotenessSkewness => new RemotenessSkewness(), + CongenericCharacteristic.RemotenessSkewnessCoefficient => new RemotenessSkewnessCoefficient(), + CongenericCharacteristic.RemotenessStandardDeviation => new RemotenessStandardDeviation(), + CongenericCharacteristic.InformationAmount => new InformationAmount(), + _ => throw new InvalidEnumArgumentException(nameof(type), (int)type, typeof(CongenericCharacteristic)), + }; } } diff --git a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/CuttingLength.cs b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/CuttingLength.cs index 10ba9c76..4eb8d8c0 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/CuttingLength.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/CuttingLength.cs @@ -57,8 +57,8 @@ private double CutCommon(AbstractChain chain) /// private bool IsRecoveryPossible(AbstractChain chain, int length) { - var iterator = new IteratorStart(chain, length, 1); - var alphabet = new Alphabet(); + IteratorStart iterator = new(chain, length, 1); + Alphabet alphabet = []; while (iterator.Next()) { diff --git a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/CuttingLengthVocabularyEntropy.cs b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/CuttingLengthVocabularyEntropy.cs index b47185ae..6c59a470 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/CuttingLengthVocabularyEntropy.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/CuttingLengthVocabularyEntropy.cs @@ -19,7 +19,7 @@ public class CuttingLengthVocabularyEntropy : ICongenericCalculator /// public double Calculate(CongenericChain chain, Link link) { - var cutLength = new CuttingLength(); + CuttingLength cutLength = new(); return Math.Log(chain.Length - cutLength.Calculate(chain, link) + 1, 2); } } diff --git a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/DescriptiveInformation.cs b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/DescriptiveInformation.cs index cca81cfc..57c635b0 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/DescriptiveInformation.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/DescriptiveInformation.cs @@ -19,7 +19,7 @@ public class DescriptiveInformation : ICongenericCalculator /// public double Calculate(CongenericChain chain, Link link) { - var calculator = new ArithmeticMean(); + ArithmeticMean calculator = new(); double arithmeticMean = calculator.Calculate(chain, link); return arithmeticMean == 0 ? 1 : Math.Pow(arithmeticMean, 1 / arithmeticMean); diff --git a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/GeometricMean.cs b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/GeometricMean.cs index d59d0f4a..a3af2627 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/GeometricMean.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/GeometricMean.cs @@ -19,7 +19,7 @@ public class GeometricMean : ICongenericCalculator /// public double Calculate(CongenericChain chain, Link link) { - var averageRemoteness = new AverageRemoteness(); + AverageRemoteness averageRemoteness = new(); double remoteness = averageRemoteness.Calculate(chain, link); return Math.Pow(2, remoteness); diff --git a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/IdentificationInformation.cs b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/IdentificationInformation.cs index 5cf021b9..03192d07 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/IdentificationInformation.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/IdentificationInformation.cs @@ -23,7 +23,7 @@ public class IdentificationInformation : ICongenericCalculator /// public double Calculate(CongenericChain chain, Link link) { - var arithmeticMean = new ArithmeticMean(); + ArithmeticMean arithmeticMean = new(); double mean = arithmeticMean.Calculate(chain, link); return mean == 0 ? 0 : (-1 / mean) * Math.Log(1 / mean, 2); diff --git a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/InformationAmount.cs b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/InformationAmount.cs index cbaf6bd7..55228c9c 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/InformationAmount.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/InformationAmount.cs @@ -20,9 +20,9 @@ public class InformationAmount : ICongenericCalculator /// public double Calculate(CongenericChain chain, Link link) { - var arithmeticMean = new ArithmeticMean(); + ArithmeticMean arithmeticMean = new(); // TODO: try to calculate it using multiplied intervals double mean = arithmeticMean.Calculate(chain, link); return mean == 0 ? 0 : -Math.Log(1 / mean, 2); } -} \ No newline at end of file +} diff --git a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/Periodicity.cs b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/Periodicity.cs index a03adcda..ab7704b3 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/Periodicity.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/Periodicity.cs @@ -20,8 +20,8 @@ public class Periodicity : ICongenericCalculator /// public double Calculate(CongenericChain chain, Link link) { - var geometricMeanCalculator = new GeometricMean(); - var arithmeticMeanCalculator = new ArithmeticMean(); + GeometricMean geometricMeanCalculator = new(); + ArithmeticMean arithmeticMeanCalculator = new(); double geometricMean = geometricMeanCalculator.Calculate(chain, link); double arithmeticMean = arithmeticMeanCalculator.Calculate(chain, link); diff --git a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/Probability.cs b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/Probability.cs index 4f835b55..4242617c 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/Probability.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/Probability.cs @@ -16,8 +16,8 @@ public class Probability : NonLinkableCongenericCalculator /// public override double Calculate(CongenericChain chain) { - var count = new ElementsCount(); - var length = new Length(); + ElementsCount count = new(); + Length length = new(); return count.Calculate(chain) / length.Calculate(chain); } diff --git a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/Regularity.cs b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/Regularity.cs index 4124edc3..6f117172 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/Regularity.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/Regularity.cs @@ -21,8 +21,8 @@ public class Regularity : ICongenericCalculator /// public double Calculate(CongenericChain chain, Link link) { - var geometricMeanCalculator = new GeometricMean(); - var descriptiveInformationCalculator = new DescriptiveInformation(); + GeometricMean geometricMeanCalculator = new(); + DescriptiveInformation descriptiveInformationCalculator = new(); double geometricMean = geometricMeanCalculator.Calculate(chain, link); double descriptiveInformation = descriptiveInformationCalculator.Calculate(chain, link); diff --git a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/RemotenessDispersion.cs b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/RemotenessDispersion.cs index ed4ab9cc..37789fda 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/RemotenessDispersion.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/RemotenessDispersion.cs @@ -19,19 +19,20 @@ public class RemotenessDispersion : ICongenericCalculator /// public double Calculate(CongenericChain chain, Link link) { - var intervals = chain.GetArrangement(link).ToList(); + int[] intervals = chain.GetArrangement(link); - if (intervals.Count == 0) + if (intervals.Length == 0) { return 0; } - var intervalsDictionary = intervals - .GroupBy(i => i) - .ToDictionary(i => i.Key, i => i.Count()); + // calcualting number of intervals of certain length + Dictionary intervalsDictionary = intervals + .GroupBy(i => i) + .ToDictionary(i => i.Key, i => i.Count()); - var intervalsCount = new IntervalsCount(); - var averageRemoteness = new AverageRemoteness(); + IntervalsCount intervalsCount = new(); + AverageRemoteness averageRemoteness = new(); double result = 0; double nj = intervalsCount.Calculate(chain, link); diff --git a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/RemotenessKurtosis.cs b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/RemotenessKurtosis.cs index 0ab5c78c..a84700b3 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/RemotenessKurtosis.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/RemotenessKurtosis.cs @@ -19,25 +19,26 @@ public class RemotenessKurtosis : ICongenericCalculator /// public double Calculate(CongenericChain chain, Link link) { - var intervals = chain.GetArrangement(link).ToList(); + int[] intervals = chain.GetArrangement(link); - if (intervals.Count == 0) + if (intervals.Length == 0) { return 0; } - List uniqueIntervals = intervals.Distinct().ToList(); + // calcualting number of intervals of certain length + Dictionary intervalsDictionary = intervals + .GroupBy(i => i) + .ToDictionary(i => i.Key, i => i.Count()); - var intervalsCount = new IntervalsCount(); - var averageRemoteness = new AverageRemoteness(); + IntervalsCount intervalsCount = new(); + AverageRemoteness averageRemoteness = new(); double result = 0; double gDeltaLog = averageRemoteness.Calculate(chain, link); double nj = intervalsCount.Calculate(chain, link); - foreach (int interval in uniqueIntervals) + foreach ((int interval, int nk) in intervalsDictionary) { - // number of intervals of certain length - double nk = intervals.Count(i => i == interval); double centeredRemoteness = Math.Log(interval, 2) - gDeltaLog; result += centeredRemoteness * centeredRemoteness * centeredRemoteness * centeredRemoteness * nk / nj; } diff --git a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/RemotenessKurtosisCoefficient.cs b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/RemotenessKurtosisCoefficient.cs index 49f7d1df..5c3a3d47 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/RemotenessKurtosisCoefficient.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/RemotenessKurtosisCoefficient.cs @@ -19,8 +19,8 @@ public class RemotenessKurtosisCoefficient : ICongenericCalculator /// public double Calculate(CongenericChain chain, Link link) { - var remotenessKurtosis = new RemotenessKurtosis(); - var remotenessStandardDeviation = new RemotenessStandardDeviation(); + RemotenessKurtosis remotenessKurtosis = new(); + RemotenessStandardDeviation remotenessStandardDeviation = new(); double standardDeviation = remotenessStandardDeviation.Calculate(chain, link); return standardDeviation == 0 ? 0 : remotenessKurtosis.Calculate(chain, link) / (standardDeviation * standardDeviation * standardDeviation * standardDeviation); diff --git a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/RemotenessSkewness.cs b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/RemotenessSkewness.cs index bfd0d1a4..e8c0f51b 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/RemotenessSkewness.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/RemotenessSkewness.cs @@ -19,25 +19,26 @@ public class RemotenessSkewness : ICongenericCalculator /// public double Calculate(CongenericChain chain, Link link) { - var intervals = chain.GetArrangement(link).ToList(); + int[] intervals = chain.GetArrangement(link); - if (intervals.Count == 0) + if (intervals.Length == 0) { return 0; } - List uniqueIntervals = intervals.Distinct().ToList(); + // calcualting number of intervals of certain length + Dictionary intervalsDictionary = intervals + .GroupBy(i => i) + .ToDictionary(i => i.Key, i => i.Count()); - var intervalsCount = new IntervalsCount(); - var averageRemoteness = new AverageRemoteness(); + IntervalsCount intervalsCount = new(); + AverageRemoteness averageRemoteness = new(); double result = 0; double gDeltaLog = averageRemoteness.Calculate(chain, link); double nj = intervalsCount.Calculate(chain, link); - foreach (int interval in uniqueIntervals) + foreach ((int interval, int nk) in intervalsDictionary) { - // number of intervals of certain length - double nk = intervals.Count(i => i == interval); double centeredRemoteness = Math.Log(interval, 2) - gDeltaLog; result += centeredRemoteness * centeredRemoteness * centeredRemoteness * nk / nj; } diff --git a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/RemotenessSkewnessCoefficient.cs b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/RemotenessSkewnessCoefficient.cs index fdd4cae7..e2b7f62e 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/RemotenessSkewnessCoefficient.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/RemotenessSkewnessCoefficient.cs @@ -19,8 +19,8 @@ public class RemotenessSkewnessCoefficient : ICongenericCalculator /// public double Calculate(CongenericChain chain, Link link) { - var remotenessSkewness = new RemotenessSkewness(); - var remotenessStandardDeviation = new RemotenessStandardDeviation(); + RemotenessSkewness remotenessSkewness = new(); + RemotenessStandardDeviation remotenessStandardDeviation = new(); double standardDeviation = remotenessStandardDeviation.Calculate(chain, link); return standardDeviation == 0 ? 0 : remotenessSkewness.Calculate(chain, link) / (standardDeviation * standardDeviation * standardDeviation); diff --git a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/RemotenessStandardDeviation.cs b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/RemotenessStandardDeviation.cs index bd34ae0b..534d29a7 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/RemotenessStandardDeviation.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/RemotenessStandardDeviation.cs @@ -19,7 +19,7 @@ public class RemotenessStandardDeviation : ICongenericCalculator /// public double Calculate(CongenericChain chain, Link link) { - var remotenessDispersion = new RemotenessDispersion(); + RemotenessDispersion remotenessDispersion = new(); return Math.Sqrt(remotenessDispersion.Calculate(chain, link)); } } diff --git a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/Uniformity.cs b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/Uniformity.cs index f10cac13..a1040b7f 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/Uniformity.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/CongenericCalculators/Uniformity.cs @@ -20,8 +20,8 @@ public class Uniformity : ICongenericCalculator /// public double Calculate(CongenericChain chain, Link link) { - var remotenessCalculator = new AverageRemoteness(); - var entropyCalculator = new IdentificationInformation(); + AverageRemoteness remotenessCalculator = new(); + IdentificationInformation entropyCalculator = new(); return entropyCalculator.Calculate(chain, link) - remotenessCalculator.Calculate(chain, link); } diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/ATSkew.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/ATSkew.cs index 308fb505..536b00c5 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/ATSkew.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/ATSkew.cs @@ -21,10 +21,10 @@ public override double Calculate(Chain chain) { DnaProcessor.CheckDnaAlphabet(chain.Alphabet); - var counter = new CongenericCalculators.ElementsCount(); + CongenericCalculators.ElementsCount counter = new(); - var a = (int)counter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("A"))); - var t = (int)counter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("T"))); + int a = (int)counter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("A"))); + int t = (int)counter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("T"))); return a + t == 0 ? 0 : (a - t) / (double)(a + t); } diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AlphabeticAverageRemoteness.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AlphabeticAverageRemoteness.cs index 70656af4..a8de4e80 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AlphabeticAverageRemoteness.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AlphabeticAverageRemoteness.cs @@ -20,7 +20,7 @@ public class AlphabeticAverageRemoteness : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var geometricMean = new GeometricMean(); + GeometricMean geometricMean = new(); int alphabetCardinality = chain.Alphabet.Cardinality; return Math.Log(geometricMean.Calculate(chain, link), alphabetCardinality); } diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/ArithmeticMean.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/ArithmeticMean.cs index ecd3cf5a..b991ec96 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/ArithmeticMean.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/ArithmeticMean.cs @@ -21,11 +21,11 @@ public class ArithmeticMean : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var adder = new IntervalsSum(); - var counter = new IntervalsCount(); + IntervalsSum adder = new(); + IntervalsCount counter = new(); double intervalsSum = adder.Calculate(chain, link); - var intervalsCount = (int)counter.Calculate(chain, link); + int intervalsCount = (int)counter.Calculate(chain, link); return intervalsCount == 0 ? 0 : intervalsSum / intervalsCount; } } diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemoteness.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemoteness.cs index 57a8812b..d4e2fd29 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemoteness.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemoteness.cs @@ -20,11 +20,11 @@ public class AverageRemoteness : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var depthCalculator = new Depth(); - var intervalsCount = new IntervalsCount(); + Depth depthCalculator = new(); + IntervalsCount intervalsCount = new(); double depth = depthCalculator.Calculate(chain, link); - var nj = (int)intervalsCount.Calculate(chain, link); + int nj = (int)intervalsCount.Calculate(chain, link); return nj == 0 ? 0 : depth / nj; } } diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessATSkew.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessATSkew.cs index 5dddd93d..62c1f915 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessATSkew.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessATSkew.cs @@ -24,7 +24,7 @@ public double Calculate(Chain chain, Link link) { DnaProcessor.CheckDnaAlphabet(chain.Alphabet); - var congenericRemotenessCalculator = new CongenericCalculators.AverageRemoteness(); + CongenericCalculators.AverageRemoteness congenericRemotenessCalculator = new(); double a = congenericRemotenessCalculator.Calculate(chain.GetOrCreateCongenericChain(new ValueString("A")), link); double t = congenericRemotenessCalculator.Calculate(chain.GetOrCreateCongenericChain(new ValueString("T")), link); diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessDispersion.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessDispersion.cs index 28cb1f15..ad257db3 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessDispersion.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessDispersion.cs @@ -19,19 +19,19 @@ public class AverageRemotenessDispersion : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var averageRemoteness = new AverageRemoteness(); - var intervalsCount = new IntervalsCount(); + AverageRemoteness averageRemoteness = new(); + IntervalsCount intervalsCount = new(); double result = 0; double g = averageRemoteness.Calculate(chain, link); - var n = (int)intervalsCount.Calculate(chain, link); + int n = (int)intervalsCount.Calculate(chain, link); if (n == 0) { return 0; } - var congenericAverageRemoteness = new CongenericCalculators.AverageRemoteness(); - var congenericIntervalsCount = new CongenericCalculators.IntervalsCount(); + CongenericCalculators.AverageRemoteness congenericAverageRemoteness = new(); + CongenericCalculators.IntervalsCount congenericIntervalsCount = new(); Alphabet alphabet = chain.Alphabet; for (int i = 0; i < alphabet.Cardinality; i++) { diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessGCRatio.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessGCRatio.cs index f5721706..df9be8c1 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessGCRatio.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessGCRatio.cs @@ -24,8 +24,8 @@ public double Calculate(Chain chain, Link link) { DnaProcessor.CheckDnaAlphabet(chain.Alphabet); - var congenericRemotenessCalculator = new CongenericCalculators.AverageRemoteness(); - var remotenessCalculator = new AverageRemoteness(); + CongenericCalculators.AverageRemoteness congenericRemotenessCalculator = new(); + AverageRemoteness remotenessCalculator = new(); double g = congenericRemotenessCalculator.Calculate(chain.GetOrCreateCongenericChain(new ValueString("G")), link); double c = congenericRemotenessCalculator.Calculate(chain.GetOrCreateCongenericChain(new ValueString("C")), link); diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessGCSkew.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessGCSkew.cs index 5d0facc4..e83005d2 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessGCSkew.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessGCSkew.cs @@ -24,7 +24,7 @@ public double Calculate(Chain chain, Link link) { DnaProcessor.CheckDnaAlphabet(chain.Alphabet); - var congenericRemotenessCalculator = new CongenericCalculators.AverageRemoteness(); + CongenericCalculators.AverageRemoteness congenericRemotenessCalculator = new(); double g = congenericRemotenessCalculator.Calculate(chain.GetOrCreateCongenericChain(new ValueString("G")), link); double c = congenericRemotenessCalculator.Calculate(chain.GetOrCreateCongenericChain(new ValueString("C")), link); diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessGCToATRatio.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessGCToATRatio.cs index 415b1e02..f650a319 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessGCToATRatio.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessGCToATRatio.cs @@ -24,7 +24,7 @@ public double Calculate(Chain chain, Link link) { DnaProcessor.CheckDnaAlphabet(chain.Alphabet); - var congenericRemotenessCalculator = new CongenericCalculators.AverageRemoteness(); + CongenericCalculators.AverageRemoteness congenericRemotenessCalculator = new(); double g = congenericRemotenessCalculator.Calculate(chain.GetOrCreateCongenericChain(new ValueString("G")), link); double c = congenericRemotenessCalculator.Calculate(chain.GetOrCreateCongenericChain(new ValueString("C")), link); diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessKurtosis.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessKurtosis.cs index fb8f5f0d..4b0a4d57 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessKurtosis.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessKurtosis.cs @@ -19,19 +19,19 @@ public class AverageRemotenessKurtosis : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var averageRemoteness = new AverageRemoteness(); - var intervalsCount = new IntervalsCount(); + AverageRemoteness averageRemoteness = new(); + IntervalsCount intervalsCount = new(); double result = 0; double g = averageRemoteness.Calculate(chain, link); - var n = (int)intervalsCount.Calculate(chain, link); + int n = (int)intervalsCount.Calculate(chain, link); if (n == 0) { return 0; } - var congenericIntervalsCount = new CongenericCalculators.IntervalsCount(); - var congenericAverageRemoteness = new CongenericCalculators.AverageRemoteness(); + CongenericCalculators.IntervalsCount congenericIntervalsCount = new(); + CongenericCalculators.AverageRemoteness congenericAverageRemoteness = new(); Alphabet alphabet = chain.Alphabet; for (int i = 0; i < alphabet.Cardinality; i++) { diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessKurtosisCoefficient.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessKurtosisCoefficient.cs index f5b2a80f..0b116762 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessKurtosisCoefficient.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessKurtosisCoefficient.cs @@ -19,8 +19,8 @@ public class AverageRemotenessKurtosisCoefficient : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var averageRemotenessKurtosis = new AverageRemotenessKurtosis(); - var averageRemotenessStandardDeviation = new AverageRemotenessStandardDeviation(); + AverageRemotenessKurtosis averageRemotenessKurtosis = new(); + AverageRemotenessStandardDeviation averageRemotenessStandardDeviation = new(); double standardDeviation = averageRemotenessStandardDeviation.Calculate(chain, link); return standardDeviation == 0 ? 0 : averageRemotenessKurtosis.Calculate(chain, link) / (standardDeviation * standardDeviation * standardDeviation * standardDeviation); diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessMKSkew.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessMKSkew.cs index 05e8783b..abd410b6 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessMKSkew.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessMKSkew.cs @@ -24,8 +24,8 @@ public double Calculate(Chain chain, Link link) { DnaProcessor.CheckDnaAlphabet(chain.Alphabet); - var congenericRemotenessCalculator = new CongenericCalculators.AverageRemoteness(); - var remotenessCalculator = new AverageRemoteness(); + CongenericCalculators.AverageRemoteness congenericRemotenessCalculator = new(); + AverageRemoteness remotenessCalculator = new(); double g = congenericRemotenessCalculator.Calculate(chain.GetOrCreateCongenericChain(new ValueString("G")), link); double c = congenericRemotenessCalculator.Calculate(chain.GetOrCreateCongenericChain(new ValueString("C")), link); diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessRYSkew.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessRYSkew.cs index 88ae4e42..63e95f5f 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessRYSkew.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessRYSkew.cs @@ -24,8 +24,8 @@ public double Calculate(Chain chain, Link link) { DnaProcessor.CheckDnaAlphabet(chain.Alphabet); - var congenericRemotenessCalculator = new CongenericCalculators.AverageRemoteness(); - var remotenessCalculator = new AverageRemoteness(); + CongenericCalculators.AverageRemoteness congenericRemotenessCalculator = new(); + AverageRemoteness remotenessCalculator = new(); double g = congenericRemotenessCalculator.Calculate(chain.GetOrCreateCongenericChain(new ValueString("G")), link); double c = congenericRemotenessCalculator.Calculate(chain.GetOrCreateCongenericChain(new ValueString("C")), link); diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessSWSkew.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessSWSkew.cs index 73cc9d41..cea5f80d 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessSWSkew.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessSWSkew.cs @@ -24,8 +24,8 @@ public double Calculate(Chain chain, Link link) { DnaProcessor.CheckDnaAlphabet(chain.Alphabet); - var congenericRemotenessCalculator = new CongenericCalculators.AverageRemoteness(); - var remotenessCalculator = new AverageRemoteness(); + CongenericCalculators.AverageRemoteness congenericRemotenessCalculator = new(); + AverageRemoteness remotenessCalculator = new(); double g = congenericRemotenessCalculator.Calculate(chain.GetOrCreateCongenericChain(new ValueString("G")), link); double c = congenericRemotenessCalculator.Calculate(chain.GetOrCreateCongenericChain(new ValueString("C")), link); diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessSkewness.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessSkewness.cs index 459f9db5..48dad4e7 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessSkewness.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessSkewness.cs @@ -19,19 +19,19 @@ public class AverageRemotenessSkewness : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var averageRemoteness = new AverageRemoteness(); - var intervalsCount = new IntervalsCount(); + AverageRemoteness averageRemoteness = new(); + IntervalsCount intervalsCount = new(); double result = 0; double g = averageRemoteness.Calculate(chain, link); - var n = (int)intervalsCount.Calculate(chain, link); + int n = (int)intervalsCount.Calculate(chain, link); if (n == 0) { return 0; } - var congenericIntervalsCount = new CongenericCalculators.IntervalsCount(); - var congenericAverageRemoteness = new CongenericCalculators.AverageRemoteness(); + CongenericCalculators.IntervalsCount congenericIntervalsCount = new(); + CongenericCalculators.AverageRemoteness congenericAverageRemoteness = new(); Alphabet alphabet = chain.Alphabet; for (int i = 0; i < alphabet.Cardinality; i++) { diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessSkewnessCoefficient.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessSkewnessCoefficient.cs index 050ce9a0..119a1aea 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessSkewnessCoefficient.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessSkewnessCoefficient.cs @@ -20,8 +20,8 @@ public class AverageRemotenessSkewnessCoefficient : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var averageRemotenessSkewness = new AverageRemotenessSkewness(); - var averageRemotenessStandardDeviation = new AverageRemotenessStandardDeviation(); + AverageRemotenessSkewness averageRemotenessSkewness = new(); + AverageRemotenessStandardDeviation averageRemotenessStandardDeviation = new(); double standardDeviation = averageRemotenessStandardDeviation.Calculate(chain, link); return standardDeviation == 0 ? 0 : averageRemotenessSkewness.Calculate(chain, link) / (standardDeviation * standardDeviation * standardDeviation); diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessStandardDeviation.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessStandardDeviation.cs index 6e4e8c6c..532850ec 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessStandardDeviation.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/AverageRemotenessStandardDeviation.cs @@ -19,7 +19,7 @@ public class AverageRemotenessStandardDeviation : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var averageRemotenessDispersion = new AverageRemotenessDispersion(); + AverageRemotenessDispersion averageRemotenessDispersion = new(); return Math.Sqrt(averageRemotenessDispersion.Calculate(chain, link)); } } diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/CuttingLength.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/CuttingLength.cs index 12d98859..462eb577 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/CuttingLength.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/CuttingLength.cs @@ -43,8 +43,8 @@ public override double Calculate(Chain chain) /// private bool IsRecoveryPossible(AbstractChain chain, int length) { - var iterator = new IteratorStart(chain, length, 1); - var alphabet = new Alphabet(); + IteratorStart iterator = new(chain, length, 1); + Alphabet alphabet = []; while (iterator.Next()) { diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/CuttingLengthVocabularyEntropy.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/CuttingLengthVocabularyEntropy.cs index 49d45657..d680303f 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/CuttingLengthVocabularyEntropy.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/CuttingLengthVocabularyEntropy.cs @@ -16,7 +16,7 @@ public class CuttingLengthVocabularyEntropy : NonLinkableFullCalculator /// public override double Calculate(Chain chain) { - var cutLength = new CuttingLength(); + CuttingLength cutLength = new(); return Math.Log(chain.Length - cutLength.Calculate(chain) + 1, 2); } } diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/Depth.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/Depth.cs index 72059906..323a1c5f 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/Depth.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/Depth.cs @@ -22,7 +22,7 @@ public class Depth : IFullCalculator public double Calculate(Chain chain, Link link) { double result = 0; - var calculator = new CongenericCalculators.Depth(); + CongenericCalculators.Depth calculator = new(); Alphabet alphabet = chain.Alphabet; for (int i = 0; i < alphabet.Cardinality; i++) { diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/DescriptiveInformation.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/DescriptiveInformation.cs index 21442853..e008f4f9 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/DescriptiveInformation.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/DescriptiveInformation.cs @@ -19,7 +19,7 @@ public class DescriptiveInformation : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var calculator = new CongenericCalculators.DescriptiveInformation(); + CongenericCalculators.DescriptiveInformation calculator = new(); Alphabet alphabet = chain.Alphabet; double result = 1; diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/ElementsCount.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/ElementsCount.cs index 37fafd34..157440a0 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/ElementsCount.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/ElementsCount.cs @@ -17,7 +17,7 @@ public class ElementsCount : NonLinkableFullCalculator /// public override double Calculate(Chain chain) { - var calculator = new CongenericCalculators.ElementsCount(); + CongenericCalculators.ElementsCount calculator = new(); Alphabet alphabet = chain.Alphabet; int count = 0; diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/EntropyDispersion.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/EntropyDispersion.cs index 7c75fbdd..0c5428c0 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/EntropyDispersion.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/EntropyDispersion.cs @@ -19,15 +19,15 @@ public class EntropyDispersion : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var identificationInformation = new IdentificationInformation(); - var intervalsCount = new IntervalsCount(); + IdentificationInformation identificationInformation = new(); + IntervalsCount intervalsCount = new(); double result = 0; double h = identificationInformation.Calculate(chain, link); - var n = (int)intervalsCount.Calculate(chain, link); + int n = (int)intervalsCount.Calculate(chain, link); - var congenericIntervalsCount = new CongenericCalculators.IntervalsCount(); - var congenericIdentificationInformation = new CongenericCalculators.IdentificationInformation(); + CongenericCalculators.IntervalsCount congenericIntervalsCount = new(); + CongenericCalculators.IdentificationInformation congenericIdentificationInformation = new(); Alphabet alphabet = chain.Alphabet; for (int i = 0; i < alphabet.Cardinality; i++) { diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/EntropyKurtosis.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/EntropyKurtosis.cs index 6c2daf37..ed15ecf9 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/EntropyKurtosis.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/EntropyKurtosis.cs @@ -19,15 +19,15 @@ public class EntropyKurtosis : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var identificationInformation = new IdentificationInformation(); - var intervalsCount = new IntervalsCount(); + IdentificationInformation identificationInformation = new(); + IntervalsCount intervalsCount = new(); double result = 0; double h = identificationInformation.Calculate(chain, link); - var n = (int)intervalsCount.Calculate(chain, link); + int n = (int)intervalsCount.Calculate(chain, link); - var congenericIntervalsCount = new CongenericCalculators.IntervalsCount(); - var congenericIdentificationInformation = new CongenericCalculators.IdentificationInformation(); + CongenericCalculators.IntervalsCount congenericIntervalsCount = new(); + CongenericCalculators.IdentificationInformation congenericIdentificationInformation = new(); Alphabet alphabet = chain.Alphabet; for (int i = 0; i < alphabet.Cardinality; i++) { diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/EntropyKurtosisCoefficient.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/EntropyKurtosisCoefficient.cs index 3abcf5a7..383e9585 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/EntropyKurtosisCoefficient.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/EntropyKurtosisCoefficient.cs @@ -19,8 +19,8 @@ public class EntropyKurtosisCoefficient : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var entropyKurtosis = new EntropyKurtosis(); - var entropyStandardDeviation = new EntropyStandardDeviation(); + EntropyKurtosis entropyKurtosis = new(); + EntropyStandardDeviation entropyStandardDeviation = new(); double standardDeviation = entropyStandardDeviation.Calculate(chain, link); diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/EntropySkewness.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/EntropySkewness.cs index 9bb357c0..ac9898b4 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/EntropySkewness.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/EntropySkewness.cs @@ -31,10 +31,10 @@ public double Calculate(Chain chain, Link link) { double result = 0; double h = identificationInformation.Calculate(chain, link); - var n = (int)intervalsCount.Calculate(chain, link); + int n = (int)intervalsCount.Calculate(chain, link); - var congenericIntervalsCount = new CongenericCalculators.IntervalsCount(); - var congenericIdentificationInformation = new CongenericCalculators.IdentificationInformation(); + CongenericCalculators.IntervalsCount congenericIntervalsCount = new(); + CongenericCalculators.IdentificationInformation congenericIdentificationInformation = new(); Alphabet alphabet = chain.Alphabet; for (int i = 0; i < alphabet.Cardinality; i++) { diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/EntropySkewnessCoefficient.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/EntropySkewnessCoefficient.cs index 195a39cb..720712e5 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/EntropySkewnessCoefficient.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/EntropySkewnessCoefficient.cs @@ -20,8 +20,8 @@ public class EntropySkewnessCoefficient : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var entropySkewness = new EntropySkewness(); - var entropyStandardDeviation = new EntropyStandardDeviation(); + EntropySkewness entropySkewness = new(); + EntropyStandardDeviation entropyStandardDeviation = new(); double standardDeviation = entropyStandardDeviation.Calculate(chain, link); diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/EntropyStandardDeviation.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/EntropyStandardDeviation.cs index aaec3b56..3261f4b1 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/EntropyStandardDeviation.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/EntropyStandardDeviation.cs @@ -19,7 +19,7 @@ public class EntropyStandardDeviation : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var entropyDispersion = new EntropyDispersion(); + EntropyDispersion entropyDispersion = new(); return Math.Sqrt(entropyDispersion.Calculate(chain, link)); } } diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/FullCalculatorsFactory.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/FullCalculatorsFactory.cs index 711dfe0a..c45dd5e4 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/FullCalculatorsFactory.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/FullCalculatorsFactory.cs @@ -21,120 +21,64 @@ public static class FullCalculatorsFactory /// public static IFullCalculator CreateCalculator(FullCharacteristic type) { - switch (type) + return type switch { - case FullCharacteristic.AlphabetCardinality: - return new AlphabetCardinality(); - case FullCharacteristic.AlphabeticAverageRemoteness: - return new AlphabeticAverageRemoteness(); - case FullCharacteristic.AlphabeticDepth: - return new AlphabeticDepth(); - case FullCharacteristic.ArithmeticMean: - return new ArithmeticMean(); - case FullCharacteristic.ATSkew: - return new ATSkew(); - case FullCharacteristic.AverageRemoteness: - return new AverageRemoteness(); - case FullCharacteristic.AverageRemotenessATSkew: - return new AverageRemotenessATSkew(); - case FullCharacteristic.AverageRemotenessDispersion: - return new AverageRemotenessDispersion(); - case FullCharacteristic.AverageRemotenessGCRatio: - return new AverageRemotenessGCRatio(); - case FullCharacteristic.AverageRemotenessGCSkew: - return new AverageRemotenessGCSkew(); - case FullCharacteristic.AverageRemotenessGCToATRatio: - return new AverageRemotenessGCToATRatio(); - case FullCharacteristic.AverageRemotenessKurtosis: - return new AverageRemotenessKurtosis(); - case FullCharacteristic.AverageRemotenessKurtosisCoefficient: - return new AverageRemotenessKurtosisCoefficient(); - case FullCharacteristic.AverageRemotenessMKSkew: - return new AverageRemotenessMKSkew(); - case FullCharacteristic.AverageRemotenessRYSkew: - return new AverageRemotenessRYSkew(); - case FullCharacteristic.AverageRemotenessSkewness: - return new AverageRemotenessSkewness(); - case FullCharacteristic.AverageRemotenessSkewnessCoefficient: - return new AverageRemotenessSkewnessCoefficient(); - case FullCharacteristic.AverageRemotenessStandardDeviation: - return new AverageRemotenessStandardDeviation(); - case FullCharacteristic.AverageRemotenessSWSkew: - return new AverageRemotenessSWSkew(); - case FullCharacteristic.AverageWordLength: - return new AverageWordLength(); - case FullCharacteristic.CuttingLength: - return new CuttingLength(); - case FullCharacteristic.CuttingLengthVocabularyEntropy: - return new CuttingLengthVocabularyEntropy(); - case FullCharacteristic.Depth: - return new Depth(); - case FullCharacteristic.DescriptiveInformation: - return new DescriptiveInformation(); - case FullCharacteristic.ElementsCount: - return new ElementsCount(); - case FullCharacteristic.EntropyDispersion: - return new EntropyDispersion(); - case FullCharacteristic.EntropyKurtosis: - return new EntropyKurtosis(); - case FullCharacteristic.EntropyKurtosisCoefficient: - return new EntropyKurtosisCoefficient(); - case FullCharacteristic.EntropySkewness: - return new EntropySkewness(); - case FullCharacteristic.EntropySkewnessCoefficient: - return new EntropySkewnessCoefficient(); - case FullCharacteristic.EntropyStandardDeviation: - return new EntropyStandardDeviation(); - case FullCharacteristic.GCRatio: - return new GCRatio(); - case FullCharacteristic.GCSkew: - return new GCSkew(); - case FullCharacteristic.GCToATRatio: - return new GCToATRatio(); - case FullCharacteristic.GeometricMean: - return new GeometricMean(); - case FullCharacteristic.IdentificationInformation: - return new IdentificationInformation(); - case FullCharacteristic.InformationAmount: - return new InformationAmount(); - case FullCharacteristic.IntervalsCount: - return new IntervalsCount(); - case FullCharacteristic.IntervalsSum: - return new IntervalsSum(); - case FullCharacteristic.Length: - return new Length(); - case FullCharacteristic.MKSkew: - return new MKSkew(); - case FullCharacteristic.Periodicity: - return new Periodicity(); - case FullCharacteristic.Probability: - return new Probability(); - case FullCharacteristic.Regularity: - return new Regularity(); - case FullCharacteristic.RemotenessDispersion: - return new RemotenessDispersion(); - case FullCharacteristic.RemotenessKurtosis: - return new RemotenessKurtosis(); - case FullCharacteristic.RemotenessKurtosisCoefficient: - return new RemotenessKurtosisCoefficient(); - case FullCharacteristic.RemotenessSkewness: - return new RemotenessSkewness(); - case FullCharacteristic.RemotenessSkewnessCoefficient: - return new RemotenessSkewnessCoefficient(); - case FullCharacteristic.RemotenessStandardDeviation: - return new RemotenessStandardDeviation(); - case FullCharacteristic.RYSkew: - return new RYSkew(); - case FullCharacteristic.SWSkew: - return new SWSkew(); - case FullCharacteristic.Uniformity: - return new Uniformity(); - case FullCharacteristic.VariationsCount: - return new VariationsCount(); - case FullCharacteristic.Volume: - return new Volume(); - default: - throw new InvalidEnumArgumentException(nameof(type), (int)type, typeof(FullCharacteristic)); - } + FullCharacteristic.AlphabetCardinality => new AlphabetCardinality(), + FullCharacteristic.AlphabeticAverageRemoteness => new AlphabeticAverageRemoteness(), + FullCharacteristic.AlphabeticDepth => new AlphabeticDepth(), + FullCharacteristic.ArithmeticMean => new ArithmeticMean(), + FullCharacteristic.ATSkew => new ATSkew(), + FullCharacteristic.AverageRemoteness => new AverageRemoteness(), + FullCharacteristic.AverageRemotenessATSkew => new AverageRemotenessATSkew(), + FullCharacteristic.AverageRemotenessDispersion => new AverageRemotenessDispersion(), + FullCharacteristic.AverageRemotenessGCRatio => new AverageRemotenessGCRatio(), + FullCharacteristic.AverageRemotenessGCSkew => new AverageRemotenessGCSkew(), + FullCharacteristic.AverageRemotenessGCToATRatio => new AverageRemotenessGCToATRatio(), + FullCharacteristic.AverageRemotenessKurtosis => new AverageRemotenessKurtosis(), + FullCharacteristic.AverageRemotenessKurtosisCoefficient => new AverageRemotenessKurtosisCoefficient(), + FullCharacteristic.AverageRemotenessMKSkew => new AverageRemotenessMKSkew(), + FullCharacteristic.AverageRemotenessRYSkew => new AverageRemotenessRYSkew(), + FullCharacteristic.AverageRemotenessSkewness => new AverageRemotenessSkewness(), + FullCharacteristic.AverageRemotenessSkewnessCoefficient => new AverageRemotenessSkewnessCoefficient(), + FullCharacteristic.AverageRemotenessStandardDeviation => new AverageRemotenessStandardDeviation(), + FullCharacteristic.AverageRemotenessSWSkew => new AverageRemotenessSWSkew(), + FullCharacteristic.AverageWordLength => new AverageWordLength(), + FullCharacteristic.CuttingLength => new CuttingLength(), + FullCharacteristic.CuttingLengthVocabularyEntropy => new CuttingLengthVocabularyEntropy(), + FullCharacteristic.Depth => new Depth(), + FullCharacteristic.DescriptiveInformation => new DescriptiveInformation(), + FullCharacteristic.ElementsCount => new ElementsCount(), + FullCharacteristic.EntropyDispersion => new EntropyDispersion(), + FullCharacteristic.EntropyKurtosis => new EntropyKurtosis(), + FullCharacteristic.EntropyKurtosisCoefficient => new EntropyKurtosisCoefficient(), + FullCharacteristic.EntropySkewness => new EntropySkewness(), + FullCharacteristic.EntropySkewnessCoefficient => new EntropySkewnessCoefficient(), + FullCharacteristic.EntropyStandardDeviation => new EntropyStandardDeviation(), + FullCharacteristic.GCRatio => new GCRatio(), + FullCharacteristic.GCSkew => new GCSkew(), + FullCharacteristic.GCToATRatio => new GCToATRatio(), + FullCharacteristic.GeometricMean => new GeometricMean(), + FullCharacteristic.IdentificationInformation => new IdentificationInformation(), + FullCharacteristic.InformationAmount => new InformationAmount(), + FullCharacteristic.IntervalsCount => new IntervalsCount(), + FullCharacteristic.IntervalsSum => new IntervalsSum(), + FullCharacteristic.Length => new Length(), + FullCharacteristic.MKSkew => new MKSkew(), + FullCharacteristic.Periodicity => new Periodicity(), + FullCharacteristic.Probability => new Probability(), + FullCharacteristic.Regularity => new Regularity(), + FullCharacteristic.RemotenessDispersion => new RemotenessDispersion(), + FullCharacteristic.RemotenessKurtosis => new RemotenessKurtosis(), + FullCharacteristic.RemotenessKurtosisCoefficient => new RemotenessKurtosisCoefficient(), + FullCharacteristic.RemotenessSkewness => new RemotenessSkewness(), + FullCharacteristic.RemotenessSkewnessCoefficient => new RemotenessSkewnessCoefficient(), + FullCharacteristic.RemotenessStandardDeviation => new RemotenessStandardDeviation(), + FullCharacteristic.RYSkew => new RYSkew(), + FullCharacteristic.SWSkew => new SWSkew(), + FullCharacteristic.Uniformity => new Uniformity(), + FullCharacteristic.VariationsCount => new VariationsCount(), + FullCharacteristic.Volume => new Volume(), + _ => throw new InvalidEnumArgumentException(nameof(type), (int)type, typeof(FullCharacteristic)), + }; } } diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/GCRatio.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/GCRatio.cs index 6c28e49e..c752388c 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/GCRatio.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/GCRatio.cs @@ -21,12 +21,12 @@ public override double Calculate(Chain chain) { DnaProcessor.CheckDnaAlphabet(chain.Alphabet); - var congenericCounter = new CongenericCalculators.ElementsCount(); - var counter = new ElementsCount(); + CongenericCalculators.ElementsCount congenericCounter = new(); + ElementsCount counter = new(); - var g = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("G"))); - var c = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("C"))); - var l = (int)counter.Calculate(chain); + int g = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("G"))); + int c = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("C"))); + int l = (int)counter.Calculate(chain); return l == 0 ? 0 : 100 * (g + c) / (double)l; } diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/GCSkew.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/GCSkew.cs index 50902dfe..b4f2ae88 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/GCSkew.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/GCSkew.cs @@ -21,10 +21,10 @@ public override double Calculate(Chain chain) { DnaProcessor.CheckDnaAlphabet(chain.Alphabet); - var counter = new CongenericCalculators.ElementsCount(); + CongenericCalculators.ElementsCount counter = new(); - var g = (int)counter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("G"))); - var c = (int)counter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("C"))); + int g = (int)counter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("G"))); + int c = (int)counter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("C"))); return g + c == 0 ? 0 : (g - c) / (double)(g + c); } diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/GCToATRatio.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/GCToATRatio.cs index 87c5d773..ee66a14b 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/GCToATRatio.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/GCToATRatio.cs @@ -21,12 +21,12 @@ public override double Calculate(Chain chain) { DnaProcessor.CheckDnaAlphabet(chain.Alphabet); - var counter = new CongenericCalculators.ElementsCount(); + CongenericCalculators.ElementsCount counter = new(); - var g = (int)counter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("G"))); - var c = (int)counter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("C"))); - var a = (int)counter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("A"))); - var t = (int)counter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("T"))); + int g = (int)counter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("G"))); + int c = (int)counter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("C"))); + int a = (int)counter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("A"))); + int t = (int)counter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("T"))); return a + t == 0 ? 0 : (g + c) / (double)(a + t); } diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/GeometricMean.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/GeometricMean.cs index 72a97089..ffdcfa4d 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/GeometricMean.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/GeometricMean.cs @@ -19,7 +19,7 @@ public class GeometricMean : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var averageRemoteness = new AverageRemoteness(); + AverageRemoteness averageRemoteness = new(); double remoteness = averageRemoteness.Calculate(chain, link); return Math.Pow(2, remoteness); diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/IdentificationInformation.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/IdentificationInformation.cs index 55f3a74f..5fc4c8b2 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/IdentificationInformation.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/IdentificationInformation.cs @@ -23,7 +23,7 @@ public class IdentificationInformation : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var identificationInformation = new CongenericCalculators.IdentificationInformation(); + CongenericCalculators.IdentificationInformation identificationInformation = new(); Alphabet alphabet = chain.Alphabet; double result = 0; diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/InformationAmount.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/InformationAmount.cs index 76142e1c..ac9968ac 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/InformationAmount.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/InformationAmount.cs @@ -21,7 +21,7 @@ public class InformationAmount : IFullCalculator public double Calculate(Chain chain, Link link) { double result = 0; - var calculator = new CongenericCalculators.InformationAmount(); + CongenericCalculators.InformationAmount calculator = new(); int alphabetCardinality = chain.Alphabet.Cardinality; for (int i = 0; i < alphabetCardinality; i++) { diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/IntervalsCount.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/IntervalsCount.cs index 5d23461e..07e46084 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/IntervalsCount.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/IntervalsCount.cs @@ -19,7 +19,7 @@ public class IntervalsCount : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var calculator = new CongenericCalculators.IntervalsCount(); + CongenericCalculators.IntervalsCount calculator = new(); Alphabet alphabet = chain.Alphabet; int sum = 0; diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/IntervalsSum.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/IntervalsSum.cs index af470bfc..8f36eb29 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/IntervalsSum.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/IntervalsSum.cs @@ -19,7 +19,7 @@ public class IntervalsSum : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var calculator = new CongenericCalculators.IntervalsSum(); + CongenericCalculators.IntervalsSum calculator = new(); Alphabet alphabet = chain.Alphabet; int sum = 0; diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/MKSkew.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/MKSkew.cs index b64f4317..f4be0aa4 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/MKSkew.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/MKSkew.cs @@ -21,14 +21,14 @@ public override double Calculate(Chain chain) { DnaProcessor.CheckDnaAlphabet(chain.Alphabet); - var congenericCounter = new CongenericCalculators.ElementsCount(); - var counter = new ElementsCount(); + CongenericCalculators.ElementsCount congenericCounter = new(); + ElementsCount counter = new(); - var g = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("G"))); - var c = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("C"))); - var a = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("A"))); - var t = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("T"))); - var l = (int)counter.Calculate(chain); + int g = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("G"))); + int c = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("C"))); + int a = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("A"))); + int t = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("T"))); + int l = (int)counter.Calculate(chain); return l == 0 ? 0 : ((c + a) - (g + t)) / (double)l; } diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/Probability.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/Probability.cs index 8be26fb8..bc69e7d6 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/Probability.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/Probability.cs @@ -16,7 +16,7 @@ public class Probability : NonLinkableFullCalculator /// public override double Calculate(Chain chain) { - var calculator = new CongenericCalculators.Probability(); + CongenericCalculators.Probability calculator = new(); double result = 0; Alphabet alphabet = chain.Alphabet; diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RYSkew.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RYSkew.cs index fe109046..85566188 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RYSkew.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RYSkew.cs @@ -21,14 +21,14 @@ public override double Calculate(Chain chain) { DnaProcessor.CheckDnaAlphabet(chain.Alphabet); - var congenericCounter = new CongenericCalculators.ElementsCount(); - var counter = new ElementsCount(); + CongenericCalculators.ElementsCount congenericCounter = new(); + ElementsCount counter = new(); - var g = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("G"))); - var c = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("C"))); - var a = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("A"))); - var t = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("T"))); - var l = (int)counter.Calculate(chain); + int g = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("G"))); + int c = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("C"))); + int a = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("A"))); + int t = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("T"))); + int l = (int)counter.Calculate(chain); return l == 0 ? 0 : ((g + a) - (c + t)) / (double)l; } diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/Regularity.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/Regularity.cs index c61f7ec1..35f1641f 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/Regularity.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/Regularity.cs @@ -19,8 +19,8 @@ public class Regularity : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var geometricMeanCalculator = new GeometricMean(); - var descriptiveInformationCalculator = new DescriptiveInformation(); + GeometricMean geometricMeanCalculator = new(); + DescriptiveInformation descriptiveInformationCalculator = new(); double geometricMean = geometricMeanCalculator.Calculate(chain, link); double descriptiveInformation = descriptiveInformationCalculator.Calculate(chain, link); diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RemotenessDispersion.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RemotenessDispersion.cs index 42ec3fc7..e11b2221 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RemotenessDispersion.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RemotenessDispersion.cs @@ -19,7 +19,7 @@ public class RemotenessDispersion : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var intervals = new List(); + List intervals = []; Alphabet alphabet = chain.Alphabet; for (int i = 0; i < alphabet.Cardinality; i++) { @@ -31,12 +31,12 @@ public double Calculate(Chain chain, Link link) return 0; } - var intervalsDictionary = intervals + Dictionary intervalsDictionary = intervals .GroupBy(i => i) .ToDictionary(i => i.Key, i => i.Count()); - var intervalsCount = new IntervalsCount(); - var geometricMean = new GeometricMean(); + IntervalsCount intervalsCount = new(); + GeometricMean geometricMean = new(); double result = 0; double gDelta = geometricMean.Calculate(chain, link); diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RemotenessKurtosis.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RemotenessKurtosis.cs index 2f807019..d23e6f28 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RemotenessKurtosis.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RemotenessKurtosis.cs @@ -19,7 +19,7 @@ public class RemotenessKurtosis : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var intervals = new List(); + List intervals = []; Alphabet alphabet = chain.Alphabet; for (int i = 0; i < alphabet.Cardinality; i++) { @@ -33,8 +33,8 @@ public double Calculate(Chain chain, Link link) List uniqueIntervals = intervals.Distinct().ToList(); - var intervalsCount = new IntervalsCount(); - var geometricMean = new GeometricMean(); + IntervalsCount intervalsCount = new(); + GeometricMean geometricMean = new(); double result = 0; double gDelta = geometricMean.Calculate(chain, link); diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RemotenessKurtosisCoefficient.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RemotenessKurtosisCoefficient.cs index 7bc13f38..6d1fef62 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RemotenessKurtosisCoefficient.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RemotenessKurtosisCoefficient.cs @@ -19,8 +19,8 @@ public class RemotenessKurtosisCoefficient : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var remotenessKurtosis = new RemotenessKurtosis(); - var remotenessStandardDeviation = new RemotenessStandardDeviation(); + RemotenessKurtosis remotenessKurtosis = new(); + RemotenessStandardDeviation remotenessStandardDeviation = new(); double standardDeviation = remotenessStandardDeviation.Calculate(chain, link); return standardDeviation == 0 ? 0 : remotenessKurtosis.Calculate(chain, link) / (standardDeviation * standardDeviation * standardDeviation * standardDeviation); diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RemotenessSkewness.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RemotenessSkewness.cs index f1bb45c3..9d1ab12e 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RemotenessSkewness.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RemotenessSkewness.cs @@ -19,7 +19,7 @@ public class RemotenessSkewness : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var intervals = new List(); + List intervals = []; Alphabet alphabet = chain.Alphabet; for (int i = 0; i < alphabet.Cardinality; i++) { @@ -33,8 +33,8 @@ public double Calculate(Chain chain, Link link) List uniqueIntervals = intervals.Distinct().ToList(); - var intervalsCount = new IntervalsCount(); - var geometricMean = new GeometricMean(); + IntervalsCount intervalsCount = new(); + GeometricMean geometricMean = new(); double result = 0; double gDelta = geometricMean.Calculate(chain, link); diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RemotenessSkewnessCoefficient.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RemotenessSkewnessCoefficient.cs index 4eaa3789..981487f2 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RemotenessSkewnessCoefficient.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RemotenessSkewnessCoefficient.cs @@ -19,8 +19,8 @@ public class RemotenessSkewnessCoefficient : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var remotenessSkewness = new RemotenessSkewness(); - var remotenessStandardDeviation = new RemotenessStandardDeviation(); + RemotenessSkewness remotenessSkewness = new(); + RemotenessStandardDeviation remotenessStandardDeviation = new(); double standardDeviation = remotenessStandardDeviation.Calculate(chain, link); return standardDeviation == 0 ? 0 : remotenessSkewness.Calculate(chain, link) / (standardDeviation * standardDeviation * standardDeviation); diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RemotenessStandardDeviation.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RemotenessStandardDeviation.cs index 6b7de082..6ee1c871 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RemotenessStandardDeviation.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/RemotenessStandardDeviation.cs @@ -19,7 +19,7 @@ public class RemotenessStandardDeviation : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var remotenessDispersion = new RemotenessDispersion(); + RemotenessDispersion remotenessDispersion = new(); return Math.Sqrt(remotenessDispersion.Calculate(chain, link)); } } diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/SWSkew.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/SWSkew.cs index ba0dac05..36f8ed92 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/SWSkew.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/SWSkew.cs @@ -21,14 +21,14 @@ public override double Calculate(Chain chain) { DnaProcessor.CheckDnaAlphabet(chain.Alphabet); - var congenericCounter = new CongenericCalculators.ElementsCount(); - var counter = new ElementsCount(); + CongenericCalculators.ElementsCount congenericCounter = new(); + ElementsCount counter = new(); - var g = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("G"))); - var c = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("C"))); - var a = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("A"))); - var t = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("T"))); - var l = (int)counter.Calculate(chain); + int g = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("G"))); + int c = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("C"))); + int a = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("A"))); + int t = (int)congenericCounter.Calculate(chain.GetOrCreateCongenericChain(new ValueString("T"))); + int l = (int)counter.Calculate(chain); return l == 0 ? 0 : ((g + c) - (a + t)) / (double)l; } diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/Uniformity.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/Uniformity.cs index b449ab7a..ed5d88ba 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/Uniformity.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/Uniformity.cs @@ -20,8 +20,8 @@ public class Uniformity : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var remotenessCalculator = new AverageRemoteness(); - var entropyCalculator = new IdentificationInformation(); + AverageRemoteness remotenessCalculator = new(); + IdentificationInformation entropyCalculator = new(); return entropyCalculator.Calculate(chain, link) - remotenessCalculator.Calculate(chain, link); } } diff --git a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/Volume.cs b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/Volume.cs index 8ad60b47..30af1c37 100644 --- a/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/Volume.cs +++ b/Libiada.Core/Core/Characteristics/Calculators/FullCalculators/Volume.cs @@ -21,7 +21,7 @@ public class Volume : IFullCalculator /// public double Calculate(Chain chain, Link link) { - var calculator = new CongenericCalculators.Volume(); + CongenericCalculators.Volume calculator = new(); Alphabet alphabet = chain.Alphabet; BigInteger result = 1; diff --git a/Libiada.Core/Core/CongenericChain.cs b/Libiada.Core/Core/CongenericChain.cs index 44eae200..8ed114a1 100644 --- a/Libiada.Core/Core/CongenericChain.cs +++ b/Libiada.Core/Core/CongenericChain.cs @@ -130,7 +130,7 @@ public int[] Order { get { - var result = new int[length]; + int[] result = new int[length]; for (int i = 0; i < positions.Count; i++) { result[positions[i]] = 1; @@ -452,7 +452,7 @@ public override int GetHashCode() { unchecked { - var hashCode = 325361583; + int hashCode = 325361583; hashCode = (hashCode * -1521134295) + element.GetHashCode(); hashCode = (hashCode * -1521134295) + length.GetHashCode(); foreach (int position in Positions) diff --git a/Libiada.Core/Core/CongenericScoreTrack.cs b/Libiada.Core/Core/CongenericScoreTrack.cs index 9b6699e6..dabfda53 100644 --- a/Libiada.Core/Core/CongenericScoreTrack.cs +++ b/Libiada.Core/Core/CongenericScoreTrack.cs @@ -15,7 +15,7 @@ public class CongenericScoreTrack : IBaseObject /// public CongenericScoreTrack(List measureList) { - MeasureList = new List(); + MeasureList = []; foreach (Measure measure in measureList) { // creating list of measures by cloning each of given measures @@ -36,13 +36,13 @@ public CongenericScoreTrack(List measureList) /// public List GetNotes() { - var result = new List(); + List result = []; foreach (Measure measure in MeasureList) { foreach (ValueNote note in measure.NoteList) { - var newPitches = note.Pitches.Select(p => new Pitch(p.MidiNumber)).ToList(); + List newPitches = note.Pitches.Select(p => new Pitch(p.MidiNumber)).ToList(); result.Add(new ValueNote(newPitches, note.Duration, note.Triplet, note.Tie)); } @@ -60,7 +60,7 @@ public List GetNotes() /// public List NoteOrder() { - var temp = new List(); + List temp = []; // запись в одну цепочку foreach (Measure measure in MeasureList) @@ -120,7 +120,7 @@ public long[] NoteIdOrder() List temp = NoteOrder(); // строй из Id, а не из объектов типа Note - var idTemp = new long[temp.Count]; + long[] idTemp = new long[temp.Count]; for (int i = 0; i < temp.Count; i++) { idTemp[i] = temp[i].Id; @@ -138,7 +138,7 @@ public long[] NoteIdOrder() /// public List MeasureOrder() { - var temp = new List(); + List temp = []; // запись в одну цепочку foreach (Measure measure in MeasureList) @@ -195,7 +195,7 @@ public long[] MeasureIdOrder() List temp = MeasureOrder(); // строй из Id, а не из объектов типа Measure - var idTemp = new long[temp.Count]; + long[] idTemp = new long[temp.Count]; for (int i = 0; i < temp.Count; i++) { idTemp[i] = temp[i].Id; @@ -242,7 +242,7 @@ public override int GetHashCode() { unchecked { - var hashCode = 773805597; + int hashCode = 773805597; foreach (Measure measure in MeasureList) { hashCode = (hashCode * -1521134295) + measure.GetHashCode(); diff --git a/Libiada.Core/Core/FmotifChain.cs b/Libiada.Core/Core/FmotifChain.cs index 585044b9..43bd1c3b 100644 --- a/Libiada.Core/Core/FmotifChain.cs +++ b/Libiada.Core/Core/FmotifChain.cs @@ -12,7 +12,7 @@ public class FmotifChain : IBaseObject /// public FmotifChain() { - FmotifsList = new List(); + FmotifsList = []; } public FmotifChain(List fmotifsList) @@ -33,7 +33,7 @@ public FmotifChain(List fmotifsList) /// public IBaseObject Clone() { - var clone = new FmotifChain(); + FmotifChain clone = new(); foreach (Fmotif fmotif in FmotifsList) { clone.FmotifsList.Add((Fmotif)fmotif.Clone()); diff --git a/Libiada.Core/Core/ScoreTrack.cs b/Libiada.Core/Core/ScoreTrack.cs index 0fd1c983..b4b24ad6 100644 --- a/Libiada.Core/Core/ScoreTrack.cs +++ b/Libiada.Core/Core/ScoreTrack.cs @@ -13,7 +13,7 @@ public class ScoreTrack : IBaseObject /// /// Gets congeneric tracks list. /// - public readonly List CongenericScoreTracks = new List(); + public readonly List CongenericScoreTracks = []; /// /// Initializes a new instance of the class. @@ -30,7 +30,7 @@ public ScoreTrack(List congenericScoreTracks) } // ПОЛИФОНИЧЕСКАЯ ВСТАВКА - var temp = (CongenericScoreTrack)MergedTracks(CongenericScoreTracks).Clone(); + CongenericScoreTrack temp = (CongenericScoreTrack)MergedTracks(CongenericScoreTracks).Clone(); CongenericScoreTracks.Clear(); CongenericScoreTracks.Add(temp); } @@ -97,10 +97,10 @@ public override int GetHashCode() private CongenericScoreTrack MergedTracks(List tracks) { // список склеенных дорожек - var temp = (CongenericScoreTrack)tracks[0].Clone(); + CongenericScoreTrack temp = (CongenericScoreTrack)tracks[0].Clone(); // список склеенных тактов - var tempList = new List(temp.MeasureList); + List tempList = new(temp.MeasureList); for (int i = 1; i < tracks.Count; i++) { if (tempList.Count != tracks[i].MeasureList.Count) @@ -111,7 +111,7 @@ private CongenericScoreTrack MergedTracks(List tracks) for (int j = 0; j < temp.MeasureList.Count; j++) { // склеивание j-тых тактов - var tempMeasure = (Measure)tracks[i].MeasureList[j].Clone(); + Measure tempMeasure = (Measure)tracks[i].MeasureList[j].Clone(); tempMeasure.MergeMeasures(tempList[j]); tempList.RemoveAt(j); tempList.Insert(j, tempMeasure); diff --git a/Libiada.Core/Core/SimpleTypes/Duration.cs b/Libiada.Core/Core/SimpleTypes/Duration.cs index b0b1ce20..6a512f7f 100644 --- a/Libiada.Core/Core/SimpleTypes/Duration.cs +++ b/Libiada.Core/Core/SimpleTypes/Duration.cs @@ -185,7 +185,7 @@ public Duration AddDuration(Duration duration) /// public Duration SubtractDuration(Duration duration) { - var temp = (Duration)duration.Clone(); + Duration temp = (Duration)duration.Clone(); temp.Numerator = -temp.Numerator; return AddDuration(temp); } @@ -198,7 +198,7 @@ public Duration SubtractDuration(Duration duration) /// public IBaseObject Clone() { - var temp = new Duration(Numerator, Denominator, false) + Duration temp = new(Numerator, Denominator, false) { OriginalNumerator = OriginalNumerator, OriginalDenominator = OriginalDenominator @@ -263,8 +263,8 @@ private void PlaceDot() else { // otherwise multiply it by 3/2 - Numerator = Numerator * 3; - Denominator = Denominator * 2; + Numerator *= 3; + Denominator *= 2; } } diff --git a/Libiada.Core/Core/SimpleTypes/Fmotif.cs b/Libiada.Core/Core/SimpleTypes/Fmotif.cs index 41b80dd8..9303e1fd 100644 --- a/Libiada.Core/Core/SimpleTypes/Fmotif.cs +++ b/Libiada.Core/Core/SimpleTypes/Fmotif.cs @@ -27,7 +27,7 @@ public Fmotif(FmotifType type, PauseTreatment pauseTreatment, long id = -1) { Id = id; Type = type; - NoteList = new List(); + NoteList = []; PauseTreatment = pauseTreatment; } @@ -245,7 +245,7 @@ public Fmotif TieGathered() /// public IBaseObject Clone() { - var clone = new Fmotif(Type, PauseTreatment, Id); + Fmotif clone = new(Type, PauseTreatment, Id); foreach (ValueNote note in NoteList) { clone.NoteList.Add((ValueNote)note.Clone()); @@ -313,8 +313,8 @@ public override bool Equals(object? obj) for (int j = 0; j < selfNote.Pitches.Count; j++) { - var selfPitch = selfNote.Pitches[j]; - var otherPitch = otherNote.Pitches[j]; + Pitch selfPitch = selfNote.Pitches[j]; + Pitch otherPitch = otherNote.Pitches[j]; if (firstTime) { @@ -404,8 +404,8 @@ public bool FmEquals(Fmotif other, PauseTreatment paramPauseTreatment, bool sequ // учитывая секентный перенос (Sequent) for (int j = 0; j < selfNote.Pitches.Count; j++) { - var selfPitch = selfNote.Pitches[j]; - var otherPitch = otherNote.Pitches[j]; + Pitch selfPitch = selfNote.Pitches[j]; + Pitch otherPitch = otherNote.Pitches[j]; if (firstTime) { // при первом сравнении вычисляем на сколько полутонов отличаются первые ноты, diff --git a/Libiada.Core/Core/SimpleTypes/Measure.cs b/Libiada.Core/Core/SimpleTypes/Measure.cs index 1f11ae88..68c4afd7 100644 --- a/Libiada.Core/Core/SimpleTypes/Measure.cs +++ b/Libiada.Core/Core/SimpleTypes/Measure.cs @@ -64,7 +64,7 @@ public void MergeMeasures(Measure measure) } else { - var tempNoteList = new List(0); + List tempNoteList = []; if (NoteList[k].Duration.Value < measure.NoteList[k].Duration.Value) { // нота из склеенного массива короче, значит нужно вторую разделить на две и склеить diff --git a/Libiada.Core/Core/SimpleTypes/MeasureAttributes.cs b/Libiada.Core/Core/SimpleTypes/MeasureAttributes.cs index c811dcd4..f10d0154 100644 --- a/Libiada.Core/Core/SimpleTypes/MeasureAttributes.cs +++ b/Libiada.Core/Core/SimpleTypes/MeasureAttributes.cs @@ -68,7 +68,7 @@ public override int GetHashCode() { unchecked { - var hashCode = 1812711144; + int hashCode = 1812711144; hashCode = (hashCode * -1521134295) + Size.GetHashCode(); hashCode = (hashCode * -1521134295) + Key.GetHashCode(); return hashCode; diff --git a/Libiada.Core/Core/SimpleTypes/NullValue.cs b/Libiada.Core/Core/SimpleTypes/NullValue.cs index 071a7443..01160cba 100644 --- a/Libiada.Core/Core/SimpleTypes/NullValue.cs +++ b/Libiada.Core/Core/SimpleTypes/NullValue.cs @@ -10,7 +10,7 @@ public class NullValue : IBaseObject /// /// The singletone value. /// - private static readonly NullValue Value = new NullValue(); + private static readonly NullValue Value = new(); /// /// Prevents a default instance of the class from being created. diff --git a/Libiada.Core/Core/SimpleTypes/ValueInt.cs b/Libiada.Core/Core/SimpleTypes/ValueInt.cs index 2857c394..aa4c905f 100644 --- a/Libiada.Core/Core/SimpleTypes/ValueInt.cs +++ b/Libiada.Core/Core/SimpleTypes/ValueInt.cs @@ -40,7 +40,7 @@ public class ValueInt : IBaseObject /// /// New . /// - public static implicit operator ValueInt(int from) => new ValueInt(from); + public static implicit operator ValueInt(int from) => new(from); /// /// The clone. diff --git a/Libiada.Core/Core/SimpleTypes/ValueNote.cs b/Libiada.Core/Core/SimpleTypes/ValueNote.cs index 67eaf677..100f08d5 100644 --- a/Libiada.Core/Core/SimpleTypes/ValueNote.cs +++ b/Libiada.Core/Core/SimpleTypes/ValueNote.cs @@ -31,7 +31,7 @@ public class ValueNote : IBaseObject /// The priority. /// public ValueNote(Duration duration, bool triplet, Tie tie, int priority = -1) : - this(new List(), duration, triplet, tie, priority) + this([], duration, triplet, tie, priority) { } @@ -54,7 +54,7 @@ public ValueNote(Duration duration, bool triplet, Tie tie, int priority = -1) : /// The priority. /// public ValueNote(Pitch pitch, Duration duration, bool triplet, Tie tie, int priority = -1) : - this(new List() { pitch }, duration, triplet, tie, priority) + this([pitch], duration, triplet, tie, priority) { } @@ -78,7 +78,7 @@ public ValueNote(Pitch pitch, Duration duration, bool triplet, Tie tie, int prio /// public ValueNote(IReadOnlyList pitchList, Duration duration, bool triplet, Tie tie, int priority = -1) { - Pitches = pitchList == null ? new List() : new List(pitchList); + Pitches = pitchList == null ? [] : new List(pitchList); // если не пауза то записываем высоту и наличие лиги if (Pitches.Count > 0) @@ -128,7 +128,7 @@ public ValueNote(IReadOnlyList pitchList, Duration duration, bool triplet /// public List SplitNote(Duration duration) { - var clone = new List(0) { (ValueNote)Clone(), (ValueNote)Clone() }; + List clone = new(0) { (ValueNote)Clone(), (ValueNote)Clone() }; clone[0].Duration = duration; clone[1].Duration = Duration.SubtractDuration(duration); return clone; @@ -145,10 +145,7 @@ public List SplitNote(Duration duration) /// public void AddPitch(Pitch pitch) { - if (pitch == null) - { - throw new ArgumentNullException(nameof(pitch)); - } + ArgumentNullException.ThrowIfNull(pitch, nameof(pitch)); Pitches.Add(pitch); } @@ -161,10 +158,7 @@ public void AddPitch(Pitch pitch) /// public void AddPitch(List pitch) { - if (pitch == null) - { - throw new ArgumentNullException(nameof(pitch)); - } + ArgumentNullException.ThrowIfNull(pitch, nameof(pitch)); Pitches.AddRange(pitch); } @@ -223,16 +217,16 @@ public override bool Equals(object? obj) return true; } - if (!(obj is ValueNote otherNote)) + if (obj is not ValueNote otherNote) { return false; } // одна нота - пауза - if (Pitches == null || Pitches.Count == 0) + if (Pitches.Count == 0) { // другая нота - пауза - if (otherNote.Pitches == null || otherNote.Pitches.Count == 0) + if (otherNote.Pitches.Count == 0) { // у пауз сравниваем только их длительности return Duration.Equals(otherNote.Duration); @@ -242,7 +236,7 @@ public override bool Equals(object? obj) return false; } - if (otherNote.Pitches == null || otherNote.Pitches.Count == 0) + if (otherNote.Pitches.Count == 0) { // нота и пауза не одно и то же return false; @@ -275,7 +269,7 @@ public override bool Equals(object? obj) /// public override string ToString() { - var result = new List(4 + Pitches.Count) + List result = new(4 + Pitches.Count) { Duration.ToString(), "MidiNumbers:" diff --git a/Libiada.Core/Core/SimpleTypes/ValuePhantom.cs b/Libiada.Core/Core/SimpleTypes/ValuePhantom.cs index d7d02470..e818cbd0 100644 --- a/Libiada.Core/Core/SimpleTypes/ValuePhantom.cs +++ b/Libiada.Core/Core/SimpleTypes/ValuePhantom.cs @@ -72,11 +72,7 @@ public override int Add(IBaseObject baseObject) /// public new IBaseObject Clone() { - var clone = new ValuePhantom(); - foreach (IBaseObject element in Elements) - { - clone.Add(element); - } + ValuePhantom clone = [.. Elements]; return clone; } diff --git a/Libiada.Core/Core/SimpleTypes/ValueString.cs b/Libiada.Core/Core/SimpleTypes/ValueString.cs index 1f127285..b6881859 100644 --- a/Libiada.Core/Core/SimpleTypes/ValueString.cs +++ b/Libiada.Core/Core/SimpleTypes/ValueString.cs @@ -56,7 +56,7 @@ public ValueString(string value) /// /// New . /// - public static implicit operator ValueString(string from) => new ValueString(from); + public static implicit operator ValueString(string from) => new(from); /// /// Operator of implicit casting from char to ValueString. @@ -67,7 +67,7 @@ public ValueString(string value) /// /// New . /// - public static implicit operator ValueString(char from) => new ValueString(from); + public static implicit operator ValueString(char from) => new(from); /// /// The clone. diff --git a/Libiada.Core/DataTransformers/DissimilarChainFactory.cs b/Libiada.Core/DataTransformers/DissimilarChainFactory.cs index cbac838a..bbe25959 100644 --- a/Libiada.Core/DataTransformers/DissimilarChainFactory.cs +++ b/Libiada.Core/DataTransformers/DissimilarChainFactory.cs @@ -31,9 +31,9 @@ public static class DissimilarChainFactory /// public static Chain Create(BaseChain source) { - var result = new List(); + List result = []; Alphabet sourceAlphabet = source.Alphabet; - var entries = new int[sourceAlphabet.Cardinality]; + int[] entries = new int[sourceAlphabet.Cardinality]; for (int i = 0; i < source.Length; i++) { diff --git a/Libiada.Core/DataTransformers/DnaCodingTables.cs b/Libiada.Core/DataTransformers/DnaCodingTables.cs index d79fb2b0..df1feac3 100644 --- a/Libiada.Core/DataTransformers/DnaCodingTables.cs +++ b/Libiada.Core/DataTransformers/DnaCodingTables.cs @@ -14,7 +14,7 @@ public static class DnaCodingTables /// Coding tables as dictionary of dictionaries /// with table numbers and codons as keys. /// - public static ReadOnlyDictionary> codingTables = new ReadOnlyDictionary>( + public static ReadOnlyDictionary> codingTables = new( new Dictionary> { { diff --git a/Libiada.Core/DataTransformers/DnaProcessing.cs b/Libiada.Core/DataTransformers/DnaProcessing.cs index 54b403d8..752be65e 100644 --- a/Libiada.Core/DataTransformers/DnaProcessing.cs +++ b/Libiada.Core/DataTransformers/DnaProcessing.cs @@ -22,13 +22,13 @@ public static void CheckDnaAlphabet(Alphabet alphabet) throw new Exception("DNA alphabet cardinality must be 4 or less"); } - var completeAlphabet = new Alphabet - { + Alphabet completeAlphabet = + [ new ValueString("A"), new ValueString("C"), new ValueString("T"), new ValueString("G") - }; + ]; for (int i = 0; i < alphabet.Cardinality; i++) { diff --git a/Libiada.Core/DataTransformers/DnaTransformer.cs b/Libiada.Core/DataTransformers/DnaTransformer.cs index 85f0f8e9..8347fe30 100644 --- a/Libiada.Core/DataTransformers/DnaTransformer.cs +++ b/Libiada.Core/DataTransformers/DnaTransformer.cs @@ -4,6 +4,8 @@ using Libiada.Core.Core.SimpleTypes; using Libiada.Core.Iterators; +using System.Collections.ObjectModel; + using static DnaCodingTables; /// @@ -35,26 +37,26 @@ public static BaseChain EncodeAmino(BaseChain inputChain, byte translationTable DnaProcessor.CheckDnaAlphabet(inputChain.Alphabet); - var aminoMap = codingTables[translationTable]; + ReadOnlyDictionary aminoMap = codingTables[translationTable]; - var result = new List(inputChain.Length / 3); + List result = new(inputChain.Length / 3); List codons = DiffCutter.Cut(inputChain.ToString(), new SimpleCutRule(inputChain.Length, 3, 3)); for (int i = 0; i < codons.Count; i++) { - var aminoAcid = aminoMap[codons[i]]; + IBaseObject aminoAcid = aminoMap[codons[i]]; if (aminoAcid is ValuePhantom phantom && phantom.Count(p => !p.Equals((ValueString)"*")) != 1) { throw new Exception($"Ambiguous amino code:{aminoAcid}"); } - var value = aminoAcid as ValueString ?? (ValueString)(aminoAcid as ValuePhantom).Single(p => !p.Equals((ValueString)"*")); - if (i != codons.Count - 1) { if (((ValueString)"*").Equals(aminoAcid)) throw new Exception("Unexpected stop-codon inside coding sequence"); - else result.Add(value); + + ValueString value = aminoAcid as ValueString ?? (ValueString)(aminoAcid as ValuePhantom).Single(p => !p.Equals((ValueString)"*")); + result.Add(value); } else if (aminoAcid.Equals((ValueString)"*")) return new BaseChain(result); else throw new Exception("No stop-codon at the end of coding sequence"); @@ -76,11 +78,11 @@ public static BaseChain EncodeAmino(BaseChain inputChain, byte translationTable public static BaseChain Decode(BaseChain inputChain) { // TODO: add coding table param - var result = new List(); + List result = []; for (int i = 0; i < inputChain.Length; i++) { string aminoAcid = inputChain[i].ToString(); - var element = new ValuePhantom(); + ValuePhantom element = []; switch (aminoAcid) { case "F": @@ -212,7 +214,7 @@ public static BaseChain Decode(BaseChain inputChain) public static BaseChain EncodeTriplets(BaseChain inputChain) { DnaProcessor.CheckDnaAlphabet(inputChain.Alphabet); - var result = new List(); + List result = []; List codons = DiffCutter.Cut(inputChain.ToString(), new SimpleCutRule(inputChain.Length, 3, 3)); foreach (string codon in codons) diff --git a/Libiada.Core/DataTransformers/HighOrderFactory.cs b/Libiada.Core/DataTransformers/HighOrderFactory.cs index ee93a8b4..1b177291 100644 --- a/Libiada.Core/DataTransformers/HighOrderFactory.cs +++ b/Libiada.Core/DataTransformers/HighOrderFactory.cs @@ -32,14 +32,14 @@ public static Chain Create(Chain source, Link link) throw new ArgumentException("Unknown or inapplicable link", nameof(link)); } - var result = new List(); + List result = []; Alphabet sourceAlphabet = source.Alphabet; - var entries = new int[sourceAlphabet.Cardinality]; - var intervals = new int[sourceAlphabet.Cardinality][]; + int[] entries = new int[sourceAlphabet.Cardinality]; + int[][] intervals = new int[sourceAlphabet.Cardinality][]; for (int j = 0; j < sourceAlphabet.Cardinality; j++) { - var intervalsManager = new IntervalsManager(source.CongenericChain(j)); + IntervalsManager intervalsManager = new(source.CongenericChain(j)); intervals[j] = intervalsManager.GetArrangement(link); } diff --git a/Libiada.Core/DataTransformers/SequenceConcatenator.cs b/Libiada.Core/DataTransformers/SequenceConcatenator.cs index 4ed1279f..5883d193 100644 --- a/Libiada.Core/DataTransformers/SequenceConcatenator.cs +++ b/Libiada.Core/DataTransformers/SequenceConcatenator.cs @@ -49,7 +49,7 @@ public static Chain Concatenate(Chain[] sourceSequences, int[] order) resultLength += sourceSequences[i].Length; } - Chain result = new Chain(resultLength); + Chain result = new(resultLength); int resultIndex = 0; for (int i = 0; i < sourceSequences.Length; i++) { @@ -81,15 +81,15 @@ public static Chain ConcatenateAsOrdered(Chain[] sourceSequences) resultLength += sourceSequences[i].Length; } - var resultOrder = new int[resultLength]; - var resultAlphabet = new Alphabet() { NullValue.Instance() }; + int[] resultOrder = new int[resultLength]; + Alphabet resultAlphabet = [NullValue.Instance()]; int resultIndex = 0; for (int i = 0; i < sourceSequences.Length; i++) { - var coder = new Dictionary(); - var chain = sourceSequences[i]; - var order = chain.Order; - var alphabet = chain.Alphabet; + Dictionary coder = []; + Chain chain = sourceSequences[i]; + int[] order = chain.Order; + Alphabet alphabet = chain.Alphabet; for (int m = 0; m < alphabet.Cardinality; m++) { if (!resultAlphabet.Contains(alphabet[m])) diff --git a/Libiada.Core/Extensions/ArrayExtensions.cs b/Libiada.Core/Extensions/ArrayExtensions.cs index 178cf3eb..bfb71249 100644 --- a/Libiada.Core/Extensions/ArrayExtensions.cs +++ b/Libiada.Core/Extensions/ArrayExtensions.cs @@ -25,7 +25,7 @@ public static class ArrayExtensions /// public static T[] DeleteAt(this T[] source, int index) { - var result = new T[source.Length - 1]; + T[] result = new T[source.Length - 1]; if (index > 0) { Array.Copy(source, 0, result, 0, index); @@ -53,7 +53,7 @@ public static T[] DeleteAt(this T[] source, int index) /// public static int[] DeleteAt(this int[] source, int index) { - var result = new int[source.Length - 1]; + int[] result = new int[source.Length - 1]; if (index > 0) { Array.Copy(source, 0, result, 0, index); @@ -84,7 +84,7 @@ public static int[] DeleteAt(this int[] source, int index) /// public static int[] AllIndexesOf(this T[] source, T element) { - var result = new List(); + List result = []; for (int i = 0; i < source.Length; i++) { @@ -111,7 +111,7 @@ public static int[] AllIndexesOf(this T[] source, T element) /// public static int[] AllIndexesOf(this int[] source, int element) { - var result = new List(); + List result = []; for (int i = 0; i < source.Length; i++) { if (source[i] == element) @@ -134,7 +134,7 @@ public static int[] AllIndexesOf(this int[] source, int element) /// public static string ToStringWithoutDelimiter(this IList array) { - var builder = new StringBuilder(); + StringBuilder builder = new(); foreach (object element in array) { @@ -178,7 +178,7 @@ public static string ToStringWithDefaultDelimiter(this IList array) /// public static string ToString(this IList array, string delimiter) { - var builder = new StringBuilder(); + StringBuilder builder = new(); foreach (T element in array) { @@ -203,7 +203,7 @@ public static string ToString(this IList array, string delimiter) /// public static int[] Rotate(this int[] array, uint rotations) { - var result = new int[array.Length]; + int[] result = new int[array.Length]; Array.Copy(array, rotations, result, 0, array.Length - rotations); Array.Copy(array, 0, result, result.Length - rotations, rotations); @@ -274,7 +274,7 @@ public static bool IsSorted(this List array) /// public static T[] SubArray(this T[] data, int index, int length) { - var result = new T[length]; + T[] result = new T[length]; Array.Copy(data, index, result, 0, length); return result; } diff --git a/Libiada.Core/Images/ColumnOrderExtractor.cs b/Libiada.Core/Images/ColumnOrderExtractor.cs index 459bc3af..4fa2c8c2 100644 --- a/Libiada.Core/Images/ColumnOrderExtractor.cs +++ b/Libiada.Core/Images/ColumnOrderExtractor.cs @@ -18,14 +18,14 @@ public class ColumnOrderExtractor : IImageOrderExtractor /// public BaseChain ExtractOrder(Rgba32[,] image) { - var order = new int[image.GetLength(0) * image.GetLength(1)]; - var alphabet = new Alphabet { NullValue.Instance() }; + int[] order = new int[image.GetLength(0) * image.GetLength(1)]; + Alphabet alphabet = [NullValue.Instance()]; for (int i = 0; i < image.GetLength(1); i++) { for (int j = 0; j < image.GetLength(0); j++) { - var pixelIndex = alphabet.IndexOf(new ValuePixel(image[j, i])); + int pixelIndex = alphabet.IndexOf(new ValuePixel(image[j, i])); if (pixelIndex == -1) { alphabet.Add(new ValuePixel(image[j, i])); diff --git a/Libiada.Core/Images/ImageProcessor.cs b/Libiada.Core/Images/ImageProcessor.cs index 8a7c7821..db33a0e1 100644 --- a/Libiada.Core/Images/ImageProcessor.cs +++ b/Libiada.Core/Images/ImageProcessor.cs @@ -35,7 +35,7 @@ public static BaseChain ProcessImage(Image image, IImageTransformer[] im image = imageTransformers[i].Transform(image); } - var points = new Rgba32[image.Width, image.Height]; + Rgba32[,] points = new Rgba32[image.Width, image.Height]; for (int i = 0; i < image.Width; i++) { diff --git a/Libiada.Core/Images/ImageResizer.cs b/Libiada.Core/Images/ImageResizer.cs index 92e35be6..d5366703 100644 --- a/Libiada.Core/Images/ImageResizer.cs +++ b/Libiada.Core/Images/ImageResizer.cs @@ -45,7 +45,7 @@ public ImageResizer(int newWidth, int newHeight) /// public Image Transform(Image image) { - var result = image.Clone(); + Image result = image.Clone(); result.Mutate(i => i.Resize(new Size(destinationWidth, destinationHeight))); return result; } diff --git a/Libiada.Core/Images/LineOrderExtractor.cs b/Libiada.Core/Images/LineOrderExtractor.cs index ed4a0ff5..b6c6bc93 100644 --- a/Libiada.Core/Images/LineOrderExtractor.cs +++ b/Libiada.Core/Images/LineOrderExtractor.cs @@ -21,15 +21,15 @@ public class LineOrderExtractor : IImageOrderExtractor /// public BaseChain ExtractOrder(Rgba32[,] image) { - var order = new int[image.GetLength(0) * image.GetLength(1)]; - var alphabet = new Alphabet { NullValue.Instance() }; + int[] order = new int[image.GetLength(0) * image.GetLength(1)]; + Alphabet alphabet = [NullValue.Instance()]; for (int i = 0; i < image.GetLength(0); i++) { for (int j = 0; j < image.GetLength(1); j++) { // TODO: refactor this to user standard BaseChain constructor - var pixelIndex = alphabet.IndexOf(new ValuePixel(image[i, j])); + int pixelIndex = alphabet.IndexOf(new ValuePixel(image[i, j])); if (pixelIndex == -1) { alphabet.Add(new ValuePixel(image[i, j])); diff --git a/Libiada.Core/Images/ZigzagOrderExtractor.cs b/Libiada.Core/Images/ZigzagOrderExtractor.cs index c4073e0b..bbe2d4e6 100644 --- a/Libiada.Core/Images/ZigzagOrderExtractor.cs +++ b/Libiada.Core/Images/ZigzagOrderExtractor.cs @@ -22,7 +22,7 @@ public class ZigzagOrderExtractor : IImageOrderExtractor public BaseChain ExtractOrder(Rgba32[,] image) { int[] order = new int[image.GetLength(0) * image.GetLength(1)]; - Alphabet alphabet = new Alphabet { NullValue.Instance() }; + Alphabet alphabet = [NullValue.Instance()]; for (int i = 0; i < image.GetLength(0); i++) @@ -31,7 +31,7 @@ public BaseChain ExtractOrder(Rgba32[,] image) { for (int j = 0; j < image.GetLength(1); j++) { - var pixelIndex = alphabet.IndexOf(new ValuePixel(image[i, j])); + int pixelIndex = alphabet.IndexOf(new ValuePixel(image[i, j])); if (pixelIndex == -1) { alphabet.Add(new ValuePixel(image[i, j])); @@ -45,7 +45,7 @@ public BaseChain ExtractOrder(Rgba32[,] image) { for (int j = image.GetLength(1) - 1, k = 0; j >= 0; j--, k++) { - var pixelIndex = alphabet.IndexOf(new ValuePixel(image[i, j])); + int pixelIndex = alphabet.IndexOf(new ValuePixel(image[i, j])); if (pixelIndex == -1) { alphabet.Add(new ValuePixel(image[i, j])); diff --git a/Libiada.Core/Iterators/CustomIterator.cs b/Libiada.Core/Iterators/CustomIterator.cs index 02cbc849..8afa1823 100644 --- a/Libiada.Core/Iterators/CustomIterator.cs +++ b/Libiada.Core/Iterators/CustomIterator.cs @@ -87,7 +87,7 @@ public bool Next() /// public AbstractChain Current() { - var elements = new List(); + List elements = []; for (int i = 0; i < starts[counter].Count; i++) { diff --git a/Libiada.Core/Iterators/CutRule.cs b/Libiada.Core/Iterators/CutRule.cs index 45d503a9..418cffc1 100644 --- a/Libiada.Core/Iterators/CutRule.cs +++ b/Libiada.Core/Iterators/CutRule.cs @@ -9,12 +9,12 @@ public abstract class CutRule /// /// The starts. /// - protected readonly List Starts = new List(); + protected readonly List Starts = []; /// /// The stops. /// - protected readonly List Ends = new List(); + protected readonly List Ends = []; /// /// Method returning iterator for this cut rule. diff --git a/Libiada.Core/Iterators/DiffCutter.cs b/Libiada.Core/Iterators/DiffCutter.cs index b31bee75..af4e9d75 100644 --- a/Libiada.Core/Iterators/DiffCutter.cs +++ b/Libiada.Core/Iterators/DiffCutter.cs @@ -19,7 +19,7 @@ public static class DiffCutter /// public static List Cut(string chain, CutRule rule) { - var result = new List(); + List result = []; rule.GetIterator(); CutRuleIterator iterator = rule.GetIterator(); diff --git a/Libiada.Core/Iterators/IteratorBase.cs b/Libiada.Core/Iterators/IteratorBase.cs index 748d7884..f330da55 100644 --- a/Libiada.Core/Iterators/IteratorBase.cs +++ b/Libiada.Core/Iterators/IteratorBase.cs @@ -85,7 +85,7 @@ public virtual AbstractChain Current() throw new InvalidOperationException("Iterator position is out of range."); } - var result = new BaseChain(Length); + BaseChain result = new(Length); for (int i = 0; i < Length; i++) { diff --git a/Libiada.Core/Music/BorodaDivider.cs b/Libiada.Core/Music/BorodaDivider.cs index b3e0f5b8..4cbcaab9 100644 --- a/Libiada.Core/Music/BorodaDivider.cs +++ b/Libiada.Core/Music/BorodaDivider.cs @@ -24,11 +24,11 @@ public class BorodaDivider /// public List Divide(ScoreTrack scoreTrack, PauseTreatment pauseTreatment, bool sequentialTransfer) { - var chains = new List(); + List chains = []; foreach (CongenericScoreTrack congenericTrack in scoreTrack.CongenericScoreTracks) { - var fmotifChain = (FmotifChain)Divide(congenericTrack, pauseTreatment, sequentialTransfer).Clone(); + FmotifChain fmotifChain = (FmotifChain)Divide(congenericTrack, pauseTreatment, sequentialTransfer).Clone(); chains.Add(fmotifChain); } @@ -56,9 +56,9 @@ public List Divide(ScoreTrack scoreTrack, PauseTreatment pauseTreat public FmotifChain Divide(CongenericScoreTrack congenericTrack, PauseTreatment pauseTreatment, bool sequentialTransfer) { // сохраняем имя цепи фмотивов как имя монотрека - var priorityDiscover = new PriorityDiscover(); - var fmotifDivider = new FmotifDivider(); - var fmotifIdentifier = new FmotifIdentifier(); + PriorityDiscover priorityDiscover = new(); + FmotifDivider fmotifDivider = new(); + FmotifIdentifier fmotifIdentifier = new(); // подсчет приоритетов priorityDiscover.Calculate(congenericTrack); diff --git a/Libiada.Core/Music/FmotifDivider.cs b/Libiada.Core/Music/FmotifDivider.cs index 7ee9cb08..a2da2f78 100644 --- a/Libiada.Core/Music/FmotifDivider.cs +++ b/Libiada.Core/Music/FmotifDivider.cs @@ -32,13 +32,13 @@ public class FmotifDivider /// public FmotifChain GetDivision(CongenericScoreTrack congenericTrack, PauseTreatment pauseTreatment) { - var chain = new FmotifChain(); // выходная, результирующая цепочка разбитых ф-мотивов + FmotifChain chain = new(); // выходная, результирующая цепочка разбитых ф-мотивов this.pauseTreatment = pauseTreatment; - var fmotifBuffer = new Fmotif(FmotifType.None, pauseTreatment); + Fmotif fmotifBuffer = new(FmotifType.None, pauseTreatment); // буффер для накопления нот, для последующего анализа его содержимого - var noteChain = new List(); + List noteChain = []; // цепочка нот, куда поочередно складываются ноты из последовательности тактов // для дальнейшего их анализа и распределения по ф-мотивам. @@ -77,10 +77,10 @@ public FmotifChain GetDivision(CongenericScoreTrack congenericTrack, PauseTreatm noteChain.RemoveAt(0); // проверка на наличие лиги у очередной ноты, если есть то заносим в буффер все ноты, объединенные данной лигой - if (fmotifBuffer.NoteList[fmotifBuffer.NoteList.Count - 1].Tie != Tie.None) + if (fmotifBuffer.NoteList[^1].Tie != Tie.None) { // если есть флаг начала лиги, то записываем в буфер все остальные лигованные ноты, пока не будет флага конца лиги - if (fmotifBuffer.NoteList[fmotifBuffer.NoteList.Count - 1].Tie == Tie.Start) + if (fmotifBuffer.NoteList[^1].Tie == Tie.Start) { // TODO: желательно сделать проверку когда собирается очередная лига, // не будет ли пуста цепь нот, до того как лига закончится (будет флаг конца лиги) @@ -104,7 +104,7 @@ public FmotifChain GetDivision(CongenericScoreTrack congenericTrack, PauseTreatm case PauseTreatment.Ignore: // удаляем все паузы в возвращаемом объекте (0) (паузы игнорируются) // если у очередной ноты нет лиги, то проверяем: если нота - не пауза, то выставляем флаг о следущей рассматриваемой ноте - if (fmotifBuffer.NoteList[fmotifBuffer.NoteList.Count - 1].Pitches.Count > 0) + if (fmotifBuffer.NoteList[^1].Pitches.Count > 0) { next = true; } @@ -155,7 +155,7 @@ public FmotifChain GetDivision(CongenericScoreTrack congenericTrack, PauseTreatm case PauseTreatment.Ignore: // удаляем все паузы в возвращаемом объекте (0) (паузы игнорируются) // если у очередной ноты нет лиги, то проверяем: если нота - не пауза, то выставляем флаг о следущей рассматриваемой ноте - if (fmotifBuffer.NoteList[fmotifBuffer.NoteList.Count - 1].Pitches.Count > 0) + if (fmotifBuffer.NoteList[^1].Pitches.Count > 0) { next = true; } @@ -164,7 +164,7 @@ public FmotifChain GetDivision(CongenericScoreTrack congenericTrack, PauseTreatm case PauseTreatment.NoteTrace: // длительность паузы прибавляется к предыдущей ноте, а она сама удаляется из текста (1) (пауза - звуковой след ноты) // проверяем: если нота - не пауза, то выставляем флаг о следущей рассматриваемой ноте - if (fmotifBuffer.NoteList[fmotifBuffer.NoteList.Count - 1].Pitches.Count > 0) + if (fmotifBuffer.NoteList[^1].Pitches.Count > 0) { wasNote = true; } @@ -212,12 +212,12 @@ public FmotifChain GetDivision(CongenericScoreTrack congenericTrack, PauseTreatm if (ExtractNoteList(fmotifBuffer).Count == 2) { // если длительность первой собранной ноты больше длительности второй собранной ноты - var first = TempExtractor(fmotifBuffer, 0); - var second = TempExtractor(fmotifBuffer, 1); + ValueNote first = TempExtractor(fmotifBuffer, 0); + ValueNote second = TempExtractor(fmotifBuffer, 1); if (first.Duration.Value > second.Duration.Value) { // заносим ноты/паузы первой собранной ноты в очередной фмотив с типом ЧМТ, и удаляем из буфера - var fm = new Fmotif(FmotifType.PartialMinimalMeasure, pauseTreatment, chain.FmotifsList.Count); + Fmotif fm = new(FmotifType.PartialMinimalMeasure, pauseTreatment, chain.FmotifsList.Count); for (int i = 0; i < n; i++) { // заносим @@ -266,11 +266,11 @@ public FmotifChain GetDivision(CongenericScoreTrack congenericTrack, PauseTreatm if (sameDurationChain) { // если длительность предпоследнего меньше длительности последнего - var lastButOne = TempExtractor(fmotifBuffer, ExtractNoteList(fmotifBuffer).Count - 2); - var last = TempExtractor(fmotifBuffer, ExtractNoteList(fmotifBuffer).Count - 1); + ValueNote lastButOne = TempExtractor(fmotifBuffer, ExtractNoteList(fmotifBuffer).Count - 2); + ValueNote last = TempExtractor(fmotifBuffer, ExtractNoteList(fmotifBuffer).Count - 1); if (lastButOne.Duration.Value < last.Duration.Value) { - var fmotifBuffer2 = new Fmotif(FmotifType.None, pauseTreatment); + Fmotif fmotifBuffer2 = new(FmotifType.None, pauseTreatment); // помещаем в буффер2 последнюю собранную ноту - большей длительности чем все равнодлительные // так как меняется в процессе @@ -290,11 +290,11 @@ public FmotifChain GetDivision(CongenericScoreTrack congenericTrack, PauseTreatm chain.FmotifsList.Add((Fmotif)dividedSameDuration[i].Clone()); // присваиваем очередной id - chain.FmotifsList[chain.FmotifsList.Count - 1].Id = chain.FmotifsList.Count - 1; + chain.FmotifsList[^1].Id = chain.FmotifsList.Count - 1; } // в буфер заносим последний фмотив цепочки фмотивов нот с равнодлительностью - fmotifBuffer = (Fmotif)dividedSameDuration[dividedSameDuration.Count - 1].Clone(); + fmotifBuffer = (Fmotif)dividedSameDuration[^1].Clone(); // добавляем сохраненную ноту с большой длительностью for (int i = 0; i < fmotifBuffer2.NoteList.Count; i++) @@ -331,7 +331,7 @@ public FmotifChain GetDivision(CongenericScoreTrack congenericTrack, PauseTreatm lastButOne = TempExtractor(fmotifBuffer, ExtractNoteList(fmotifBuffer).Count - 2); if (lastButOne.Duration.Value > last.Duration.Value) { - var fmotifBuffer2 = new Fmotif(FmotifType.None, pauseTreatment); + Fmotif fmotifBuffer2 = new(FmotifType.None, pauseTreatment); // помещаем в буффер2 последнюю собранную ноту - меньшей длительности чем все равнодлительные int count = fmotifBuffer.NoteList.Count; // так как меняется в процессе @@ -348,7 +348,7 @@ public FmotifChain GetDivision(CongenericScoreTrack congenericTrack, PauseTreatm chain.FmotifsList.Add((Fmotif)fmotif.Clone()); // присваиваем очередной id - chain.FmotifsList[chain.FmotifsList.Count - 1].Id = chain.FmotifsList.Count - 1; + chain.FmotifsList[^1].Id = chain.FmotifsList.Count - 1; } // очищаем буффер @@ -372,8 +372,8 @@ public FmotifChain GetDivision(CongenericScoreTrack congenericTrack, PauseTreatm if (growingDurationChain) { // если длительность предпоследнего меньше длительности последнего - var last = TempExtractor(fmotifBuffer, ExtractNoteList(fmotifBuffer).Count - 1); - var lastButOne = TempExtractor(fmotifBuffer, ExtractNoteList(fmotifBuffer).Count - 2); + ValueNote last = TempExtractor(fmotifBuffer, ExtractNoteList(fmotifBuffer).Count - 1); + ValueNote lastButOne = TempExtractor(fmotifBuffer, ExtractNoteList(fmotifBuffer).Count - 2); if (lastButOne.Duration.Value < last.Duration.Value) { // записываем очередную ноты в фмотив с типом возрастающая последовательность @@ -386,7 +386,7 @@ public FmotifChain GetDivision(CongenericScoreTrack congenericTrack, PauseTreatm // также сохраняем не вошедшую последнюю ноту (не удаляем ее) if (combination) { - var fm = new Fmotif((byte)fmotifBuffer.Type + FmotifType.IncreasingSequence, pauseTreatment, chain.FmotifsList.Count); + Fmotif fm = new((byte)fmotifBuffer.Type + FmotifType.IncreasingSequence, pauseTreatment, chain.FmotifsList.Count); // ЧМТВП или ПМТВП for (int i = 0; i < n; i++) @@ -412,7 +412,7 @@ public FmotifChain GetDivision(CongenericScoreTrack congenericTrack, PauseTreatm } else { - var fm = new Fmotif(FmotifType.IncreasingSequence, pauseTreatment, chain.FmotifsList.Count); + Fmotif fm = new(FmotifType.IncreasingSequence, pauseTreatment, chain.FmotifsList.Count); for (int i = 0; i < n; i++) { // заносим @@ -442,7 +442,7 @@ public FmotifChain GetDivision(CongenericScoreTrack congenericTrack, PauseTreatm if (ExtractNoteList(fmotifBuffer).Count == 1) { // заносим ноты/паузы 1 собранной ноты в очередной фмотив с типом ЧМТ, и удаляем из буфера - var fm = new Fmotif(FmotifType.PartialMinimalMeasure, pauseTreatment, chain.FmotifsList.Count); + Fmotif fm = new(FmotifType.PartialMinimalMeasure, pauseTreatment, chain.FmotifsList.Count); // for (int i = 0; i < FmotifBuffer.NoteList.Count; i++) foreach (ValueNote note in fmotifBuffer.NoteList) @@ -470,7 +470,7 @@ public FmotifChain GetDivision(CongenericScoreTrack congenericTrack, PauseTreatm chain.FmotifsList.Add((Fmotif)fmotif.Clone()); // присваиваем очередной id - chain.FmotifsList[chain.FmotifsList.Count - 1].Id = chain.FmotifsList.Count - 1; + chain.FmotifsList[^1].Id = chain.FmotifsList.Count - 1; } // очищаем буффер @@ -483,7 +483,7 @@ public FmotifChain GetDivision(CongenericScoreTrack congenericTrack, PauseTreatm if (combination) { // заносим оставшиеся ноты в комбинированный фмотив ЧМТ/ПМТ + ВП и в выходную цепочку - var fm = new Fmotif((byte)fmotifBuffer.Type + FmotifType.IncreasingSequence, pauseTreatment, chain.FmotifsList.Count); // ЧМТВП или ПМТВП + Fmotif fm = new((byte)fmotifBuffer.Type + FmotifType.IncreasingSequence, pauseTreatment, chain.FmotifsList.Count); // ЧМТВП или ПМТВП foreach (ValueNote note in fmotifBuffer.NoteList) { // заносим @@ -499,7 +499,7 @@ public FmotifChain GetDivision(CongenericScoreTrack congenericTrack, PauseTreatm else { // заносим оставшиеся ноты в фмотив ВП и в выходную цепочку - var fm = new Fmotif(FmotifType.IncreasingSequence, pauseTreatment, chain.FmotifsList.Count); + Fmotif fm = new(FmotifType.IncreasingSequence, pauseTreatment, chain.FmotifsList.Count); foreach (ValueNote note in fmotifBuffer.NoteList) { // заносим @@ -533,10 +533,10 @@ public FmotifChain GetDivision(CongenericScoreTrack congenericTrack, PauseTreatm /// private static void MoveTiedNotesFromFmotifBufferToFmotif(Fmotif fmotif, Fmotif fmotifBuffer) { - if (fmotif.NoteList[fmotif.NoteList.Count - 1].Tie != Tie.None) + if (fmotif.NoteList[^1].Tie != Tie.None) { // если есть флаг начала лиги, то записываем в буфер все остальные лигованные ноты, пока не будет флага конца лиги - if (fmotif.NoteList[fmotif.NoteList.Count - 1].Tie == Tie.Start) + if (fmotif.NoteList[^1].Tie == Tie.Start) { // TODO: желательно сделать проверку когда собирается очередная лига, // не будет ли пуста цепь нот, до того как лига закончится (будет флаг конца лиги) @@ -582,10 +582,10 @@ private static void MoveTiedNotesFromFmotifBufferToFmotif(Fmotif fmotif, Fmotif private List DivideSameDurationNotes(Fmotif fmotifBuff) { // создаем копию входного объекта - var fmotifBuffer = (Fmotif)fmotifBuff.Clone(); + Fmotif fmotifBuffer = (Fmotif)fmotifBuff.Clone(); // выходной список фмотивов - var result = new List(); + List result = []; // проверка на случай когда в аругменте метода количество собранных нот (из пауз/лиг) меньше двух if (ExtractNoteList(fmotifBuffer).Count < 2) @@ -641,8 +641,8 @@ private List DivideSameDurationNotes(Fmotif fmotifBuff) if (FirstPriorityIsLessThanSecond(fmotifBuffer)) { // приоритет первой ноты выше приоритета второй ноты (собранные ноты) - var first = TempExtractor(fmotifBuffer, 0); - var third = TempExtractor(fmotifBuffer, 2); + ValueNote first = TempExtractor(fmotifBuffer, 0); + ValueNote third = TempExtractor(fmotifBuffer, 2); if (first.Priority < third.Priority) { // приоритет первой ноты выше приоритета третьей ноты (собранные ноты) @@ -659,7 +659,7 @@ private List DivideSameDurationNotes(Fmotif fmotifBuff) // (ЧМТ - если есть знак триоли хотя бы у одной ноты) FmotifType typeF = FmotifType.CompleteMinimalMeasure; // тип ПМТ если не триоль first = TempExtractor(fmotifBuffer, 0); - var second = TempExtractor(fmotifBuffer, 1); + ValueNote second = TempExtractor(fmotifBuffer, 1); if (first.Triplet || second.Triplet) { typeF = FmotifType.PartialMinimalMeasure; // если есть хотя б один знак триоли @@ -738,8 +738,8 @@ private List DivideSameDurationNotes(Fmotif fmotifBuff) if (FirstPriorityIsLessThanSecond(fmotifBuffer)) { // приоритет первой ноты выше приоритета второй ноты (собранные ноты) !!!!!!!!!!!!!!!!!!! сравнение на саомо деле происход первой и третьей, разве нет? 08.04.2012 - var first = TempExtractor(fmotifBuffer, 0); - var third = TempExtractor(fmotifBuffer, 2); + ValueNote first = TempExtractor(fmotifBuffer, 0); + ValueNote third = TempExtractor(fmotifBuffer, 2); if (first.Priority < third.Priority) { // приоритет первой ноты выше приоритета третьей ноты (собранные ноты) @@ -756,7 +756,7 @@ private List DivideSameDurationNotes(Fmotif fmotifBuff) // (ЧМТ - если есть знак триоли хотя бы у одной ноты) FmotifType typeF = FmotifType.CompleteMinimalMeasure; // тип ПМТ если не триоль first = TempExtractor(fmotifBuffer, 0); - var second = TempExtractor(fmotifBuffer, 1); + ValueNote second = TempExtractor(fmotifBuffer, 1); if (first.Triplet || second.Triplet) { typeF = FmotifType.PartialMinimalMeasure; // если есть хотя б один знак триоли @@ -834,8 +834,8 @@ private List ExtractNoteList(Fmotif fmotifBuffer) /// private bool FirstPriorityIsLessThanSecond(Fmotif fmotifBuffer) { - var first = TempExtractor(fmotifBuffer, 0); - var second = TempExtractor(fmotifBuffer, 1); + ValueNote first = TempExtractor(fmotifBuffer, 0); + ValueNote second = TempExtractor(fmotifBuffer, 1); return first.Priority < second.Priority; } @@ -856,7 +856,7 @@ private bool FirstPriorityIsLessThanSecond(Fmotif fmotifBuffer) /// private Fmotif ExtractGivenNotesCountFromFmotifBuffer(Fmotif fmotifBuffer, FmotifType fmotifType, int noteCount) { - var fmotif = new Fmotif(fmotifType, pauseTreatment); + Fmotif fmotif = new(fmotifType, pauseTreatment); while (fmotifBuffer.NoteList.Count > 0) { if (ExtractNoteList(fmotif).Count == noteCount) @@ -895,7 +895,7 @@ private void SecondTempMethod(Fmotif fmotifBuffer, List fmotifList) { if (ExtractNoteList(fmotifBuffer).Count == 1) { - var fm = new Fmotif(FmotifType.PartialMinimalMeasure, pauseTreatment); + Fmotif fm = new(FmotifType.PartialMinimalMeasure, pauseTreatment); for (int j = 0; j < fmotifBuffer.NoteList.Count; j++) { // заносим diff --git a/Libiada.Core/Music/FmotifIdentifier.cs b/Libiada.Core/Music/FmotifIdentifier.cs index 51dbe8ea..c72359f9 100644 --- a/Libiada.Core/Music/FmotifIdentifier.cs +++ b/Libiada.Core/Music/FmotifIdentifier.cs @@ -25,11 +25,11 @@ public class FmotifIdentifier /// public FmotifChain GetIdentification(FmotifChain fmotifChain, bool sequentialTransfer) { - var chain = (FmotifChain)fmotifChain.Clone(); + FmotifChain chain = (FmotifChain)fmotifChain.Clone(); if (sequentialTransfer) { - var fmotifs = new Fmotif[fmotifChain.FmotifsList.Count]; + Fmotif[] fmotifs = new Fmotif[fmotifChain.FmotifsList.Count]; for (int i = 0; i < chain.FmotifsList.Count; i++) { fmotifs[i] = FmotifSequentialTransfer(chain.FmotifsList[i]); diff --git a/Libiada.Core/Music/MidiNumberManager.cs b/Libiada.Core/Music/MidiNumberManager.cs index 63eb225e..19c62d05 100644 --- a/Libiada.Core/Music/MidiNumberManager.cs +++ b/Libiada.Core/Music/MidiNumberManager.cs @@ -40,7 +40,7 @@ public static short GetOctaveFromMidiNumber(int midiNumber) /// public static NoteSymbol GetNoteSymbolFromMidiNumber(int midiNumber) { - var notes = new HashSet { 0, 2, 4, 5, 7, 9, 11 }; + HashSet notes = [0, 2, 4, 5, 7, 9, 11]; int step = midiNumber % NotesInOctave; if (notes.Contains(step)) diff --git a/Libiada.Core/Music/MusicXml/MusicXmlParser.cs b/Libiada.Core/Music/MusicXml/MusicXmlParser.cs index 756e84b0..3e1e19ac 100644 --- a/Libiada.Core/Music/MusicXml/MusicXmlParser.cs +++ b/Libiada.Core/Music/MusicXml/MusicXmlParser.cs @@ -45,7 +45,7 @@ public void Execute(XmlDocument xmlDocument) /// private List ParseCongenericScoreTracks(XmlDocument scoreNode) { - var temp = new List(); + List temp = []; XmlNodeList congenericList = scoreNode.GetElementsByTagName("part"); @@ -73,18 +73,18 @@ private List ParseCongenericScoreTracks(XmlDocument scoreN private List ParseMeasures(XmlNode congenericScoreNode) { XmlNodeList measureList = congenericScoreNode.ChildNodes; - var measures = new List(); + List measures = []; bool isOnRepeat = false; - var repeatedMeasures = new List(); + List repeatedMeasures = []; for (int i = 0; i < measureList.Count; i++) { List notes = ParseNotes(measureList[i].Clone()); MeasureAttributes attributes = ParseAttributes(measureList[i].Clone()); XmlNodeList childNodes = measureList[i]?.ChildNodes; - XmlNode lastNode = childNodes?[childNodes.Count - 1]; + XmlNode lastNode = childNodes?[^1]; if ((lastNode?.Name == "barline") && (lastNode.ChildNodes[0].Attributes["direction"].Value == "forward")) { - repeatedMeasures = new List() { new Measure(notes, attributes) }; + repeatedMeasures = [new Measure(notes, attributes)]; isOnRepeat = true; } else if (isOnRepeat) @@ -236,29 +236,29 @@ private Key ParseKey(XmlNode attributeNode) /// private List ParseNotes(XmlNode measureNode) { - var notes = new List(); + List notes = []; bool hasNotes = false; foreach (XmlNode measureChild in measureNode.ChildNodes) { if (measureChild.Name == "note") { - var measureChildClone = measureChild.Clone(); + XmlNode measureChildClone = measureChild.Clone(); foreach (XmlNode chordChild in measureChildClone.ChildNodes) { if (chordChild.Name == "chord") { // если найден "аккорд", то добавим текущую ноту к предыдущей уже мультиноте - var chordPitch = ParsePitch(measureChildClone); - if(chordPitch != null) notes[notes.Count - 1].AddPitch(chordPitch); - if (notes[notes.Count - 1].Tie != ParseTie(measureChildClone)) + Pitch? chordPitch = ParsePitch(measureChildClone); + if(chordPitch != null) notes[^1].AddPitch(chordPitch); + if (notes[^1].Tie != ParseTie(measureChildClone)) { - notes[notes.Count - 1].Tie = Tie.None; + notes[^1].Tie = Tie.None; } break; } - var pitch = ParsePitch(measureChildClone); + Pitch? pitch = ParsePitch(measureChildClone); ValueNote note = pitch == null ? new ValueNote(ParseDuration(measureChildClone), ParseTriplet(measureChildClone), ParseTie(measureChildClone)) : new ValueNote(pitch, ParseDuration(measureChildClone), ParseTriplet(measureChildClone), ParseTie(measureChildClone)); @@ -300,8 +300,8 @@ private List ParseNotes(XmlNode measureNode) childName = noteChild.Name; if (noteChild.Name == "pitch") { - var step = NoteSymbol.C; - var alter = Accidental.Bekar; + NoteSymbol step = NoteSymbol.C; + Accidental alter = Accidental.Bekar; byte octave = 0; bool hasStep = false; bool hasOctave = false; diff --git a/Libiada.Core/Music/MusicXml/MusicXmlReader.cs b/Libiada.Core/Music/MusicXml/MusicXmlReader.cs index 3c25a9e7..17f00ebc 100644 --- a/Libiada.Core/Music/MusicXml/MusicXmlReader.cs +++ b/Libiada.Core/Music/MusicXml/MusicXmlReader.cs @@ -1,5 +1,6 @@ namespace Libiada.Core.Music.MusicXml; +using System.IO; using System.Xml; /// @@ -10,7 +11,7 @@ public class MusicXmlReader /// /// MusicXml file as XmlDocument. /// - private XmlDocument musicXmlDocument; + private readonly XmlDocument musicXmlDocument = new(); /// /// Initializes a new instance of the class. @@ -20,7 +21,8 @@ public class MusicXmlReader /// public MusicXmlReader(string xpath) { - LoadNotes(xpath); + using FileStream fs = new(xpath, FileMode.Open); + LoadNotes(fs); } /// @@ -40,32 +42,7 @@ public MusicXmlReader(Stream stream) /// /// Thrown if curDoc is null. /// - public XmlDocument MusicXmlDocument - { - get - { - if (musicXmlDocument != null) - { - return (XmlDocument)musicXmlDocument.Clone(); - } - - throw new Exception("LibiadaMusic.XMLReader:you are trying to get empty XmlDocument!"); - } - } - - /// - /// The load notes. - /// - /// - /// The path. - /// - private void LoadNotes(string path) - { - using (var fs = new FileStream(path, FileMode.Open)) - { - LoadNotes(fs); - } - } + public XmlDocument MusicXmlDocument => (XmlDocument)musicXmlDocument.Clone(); /// /// The load notes. @@ -75,8 +52,6 @@ private void LoadNotes(string path) /// private void LoadNotes(Stream stream) { - var xd = new XmlDocument(); - xd.Load(stream); - musicXmlDocument = (XmlDocument)xd.Clone(); + musicXmlDocument.Load(stream); } } diff --git a/Libiada.Core/Music/PriorityDiscover.cs b/Libiada.Core/Music/PriorityDiscover.cs index 8e6dee97..dbc71ce1 100644 --- a/Libiada.Core/Music/PriorityDiscover.cs +++ b/Libiada.Core/Music/PriorityDiscover.cs @@ -54,19 +54,19 @@ public void Calculate(CongenericScoreTrack congenericTrack) public void Calculate(Measure measure) { // создаем новый такт, куда будут складываться ноты, после определения их приоритета. - var temp = new Measure(new List(), (MeasureAttributes)measure.Attributes.Clone()); + Measure temp = new([], (MeasureAttributes)measure.Attributes.Clone()); // считаем маску приоритетов для такта - var priorityMask = CalculatePriorityMask(measure); + Measure priorityMask = CalculatePriorityMask(measure); // соотнесение маски приоритетов и реального такта double durationBuffer = 0; // буфер длительности - var noteBuffer = new List(); + List noteBuffer = []; // буфер нот для сбора триоли и передачи в CollectTriplet - var maskBuffer = new List(); + List maskBuffer = []; // буфер маски приоритетов для сбора приоритетов маски под триолью и передачи в CollectTriplet double tripletDuration = 0; @@ -223,7 +223,7 @@ private void AlignPriorityMaskForNextNote(double durationBuffer, List private List CountTripletPriority(List noteBuffer, List maskBuffer) { // TODO: расчет приоритетов для триоли с числом нот больше 3 выполняется по четко не определенному правилу, сделать как должно быть - var temp = new List(); + List temp = []; // записываем в отдельный счетчик т.к. значение noteBuf.Count меняется во время цикла while (noteBuffer.Count > 0) @@ -232,7 +232,7 @@ private List CountTripletPriority(List noteBuffer, List(), (MeasureAttributes)measure.Attributes.Clone()); + Measure priorityMask = new([], (MeasureAttributes)measure.Attributes.Clone()); //---------------------------Занесение начальных долей размера такта--------------------------- //--------------------------------------------------------------------------------------------- - var newDuration = new Duration(1, measure.Attributes.Size.BeatBase, false); + Duration newDuration = new(1, measure.Attributes.Size.BeatBase, false); priorityMask.NoteList.Add(new ValueNote(newDuration, false, Tie.None, priority)); @@ -353,7 +353,7 @@ public Measure CalculatePriorityMask(Measure measure) } } - var duration = new Duration(1, measure.Attributes.Size.BeatBase, false); + Duration duration = new(1, measure.Attributes.Size.BeatBase, false); priorityMask.NoteList.Add(new ValueNote(duration, false, Tie.None, priority)); } } @@ -380,7 +380,7 @@ public Measure CalculatePriorityMask(Measure measure) } } - var duration = new Duration(1, measure.Attributes.Size.BeatBase, false); + Duration duration = new(1, measure.Attributes.Size.BeatBase, false); priorityMask.NoteList.Add(new ValueNote(duration, false, Tie.None, priority)); } } @@ -408,7 +408,7 @@ public Measure CalculatePriorityMask(Measure measure) priority = 2; } - var duration = new Duration(1, measure.Attributes.Size.BeatBase, false); + Duration duration = new(1, measure.Attributes.Size.BeatBase, false); priorityMask.NoteList.Add(new ValueNote(duration, false, Tie.None, priority)); } } @@ -444,7 +444,7 @@ private Measure SplitPriorityMask(Measure priorityMask, double minDuration) // проверка: останов будет тогда, когда длительности ВСЕХ нот в маске будут меньше либо равны длительности минимальной ноты while (!NeedToStopSplitting(priorityMask, minDuration)) { - var temp = new Measure(new List(), (MeasureAttributes)priorityMask.Attributes.Clone()); + Measure temp = new([], (MeasureAttributes)priorityMask.Attributes.Clone()); // создание объекта буфера для перехода к следущей маске нижнего уровня @@ -461,7 +461,7 @@ private Measure SplitPriorityMask(Measure priorityMask, double minDuration) for (int i = 0; i < priorityMask.NoteList.Count; i++) { - var duration = new Duration(1, priorityMask.NoteList[i].Duration.Denominator * 2, false); + Duration duration = new(1, priorityMask.NoteList[i].Duration.Denominator * 2, false); temp.NoteList.Add(new ValueNote(duration, false, Tie.None, priorityMask.NoteList[i].Priority)); diff --git a/Libiada.Core/SpaceReorganizers/NullCycleSpaceReorganizator.cs b/Libiada.Core/SpaceReorganizers/NullCycleSpaceReorganizator.cs index d1547719..64a4a610 100644 --- a/Libiada.Core/SpaceReorganizers/NullCycleSpaceReorganizator.cs +++ b/Libiada.Core/SpaceReorganizers/NullCycleSpaceReorganizator.cs @@ -50,14 +50,14 @@ public override AbstractChain Reorganize(AbstractChain source) return source; } - var result = new BaseChain(); + BaseChain result = new(); result.ClearAndSetNewLength(source.Length + level); for (int i = 0; i < source.Length; i++) { result[i] = source[i]; } - var iterator = new IteratorStart(source, level, 1); + IteratorStart iterator = new(source, level, 1); iterator.Reset(); iterator.Next(); AbstractChain addition = iterator.Current(); diff --git a/Libiada.Core/SpaceReorganizers/NullReorganizer.cs b/Libiada.Core/SpaceReorganizers/NullReorganizer.cs index b87dd139..efa623e7 100644 --- a/Libiada.Core/SpaceReorganizers/NullReorganizer.cs +++ b/Libiada.Core/SpaceReorganizers/NullReorganizer.cs @@ -19,7 +19,7 @@ public class NullReorganizer : SpaceReorganizer /// public override AbstractChain Reorganize(AbstractChain source) { - var result = source.Clone() as AbstractChain; + AbstractChain? result = source.Clone() as AbstractChain; if (result != null) { return result; @@ -28,8 +28,8 @@ public override AbstractChain Reorganize(AbstractChain source) result = new BaseChain(); result.ClearAndSetNewLength(source.Length); - var iteratorRead = new IteratorSimpleStart(source, 1); - var iteratorWrite = new IteratorWritableStart(result); + IteratorSimpleStart iteratorRead = new(source, 1); + IteratorWritableStart iteratorWrite = new(result); iteratorRead.Reset(); iteratorWrite.Reset(); iteratorRead.Next(); diff --git a/Libiada.Core/SpaceReorganizers/SpaceNotPhantomReorganizer.cs b/Libiada.Core/SpaceReorganizers/SpaceNotPhantomReorganizer.cs index 787f008d..b89f3358 100644 --- a/Libiada.Core/SpaceReorganizers/SpaceNotPhantomReorganizer.cs +++ b/Libiada.Core/SpaceReorganizers/SpaceNotPhantomReorganizer.cs @@ -19,7 +19,7 @@ public class SpaceNotPhantomReorganizer : SpaceReorganizer /// public override AbstractChain Reorganize(AbstractChain source) { - var elements = new List(); + List elements = []; for (int i = 0; i < source.Length; i++) { diff --git a/Libiada.Core/SpaceReorganizers/SpacePhantomReorganizer.cs b/Libiada.Core/SpaceReorganizers/SpacePhantomReorganizer.cs index c8191b9e..4f0d3711 100644 --- a/Libiada.Core/SpaceReorganizers/SpacePhantomReorganizer.cs +++ b/Libiada.Core/SpaceReorganizers/SpacePhantomReorganizer.cs @@ -19,11 +19,11 @@ public class SpacePhantomReorganizer : SpaceReorganizer /// public override AbstractChain Reorganize(AbstractChain source) { - var elements = new List(); + List elements = []; for (int i = 0; i < source.Length; i++) { - elements.Add(source[i] as ValuePhantom ?? new ValuePhantom { source[i] }); + elements.Add(source[i] as ValuePhantom ?? [source[i]]); } return new BaseChain(elements); diff --git a/Libiada.Core/SpaceReorganizers/SpaceReorganizerFromChainToChainByBlock.cs b/Libiada.Core/SpaceReorganizers/SpaceReorganizerFromChainToChainByBlock.cs index 8db94146..4b6afbd6 100644 --- a/Libiada.Core/SpaceReorganizers/SpaceReorganizerFromChainToChainByBlock.cs +++ b/Libiada.Core/SpaceReorganizers/SpaceReorganizerFromChainToChainByBlock.cs @@ -44,7 +44,7 @@ public SpaceReorganizerFromChainToChainByBlock(Link link, int blockSize) /// public override AbstractChain Reorganize(AbstractChain source) { - var result = new BaseChain(); + BaseChain result = new(); result.ClearAndSetNewLength(source.Length / blockSize); IteratorBase iteratorFrom; IWritableIterator iteratorTo; diff --git a/Libiada.Core/TimeSeries/Aggregators/Aggregator.cs b/Libiada.Core/TimeSeries/Aggregators/Aggregator.cs index 230dcc9b..a2ab4484 100644 --- a/Libiada.Core/TimeSeries/Aggregators/Aggregator.cs +++ b/Libiada.Core/TimeSeries/Aggregators/Aggregator.cs @@ -56,4 +56,4 @@ public enum Aggregator : byte [Display(Name = "Sum square root")] [Description("Square root of sum aggregator")] SumSquareRoot = 7, -} \ No newline at end of file +} diff --git a/Libiada.Core/TimeSeries/Aggregators/AggregatorsFactory.cs b/Libiada.Core/TimeSeries/Aggregators/AggregatorsFactory.cs index d050fe6a..2b51a286 100644 --- a/Libiada.Core/TimeSeries/Aggregators/AggregatorsFactory.cs +++ b/Libiada.Core/TimeSeries/Aggregators/AggregatorsFactory.cs @@ -20,24 +20,16 @@ public class AggregatorsFactory /// public IDistancesAggregator GetAggregator(Aggregator aggregator) { - switch (aggregator) + return aggregator switch { - case Aggregator.Average: - return new Average(); - case Aggregator.DifferenceModule: - return new DifferenceModule(); - case Aggregator.DifferenceSquareRoot: - return new DifferenceSquareRoot(); - case Aggregator.Max: - return new Max(); - case Aggregator.Min: - return new Min(); - case Aggregator.SumModule: - return new SumModule(); - case Aggregator.SumSquareRoot: - return new SumSquareRoot(); - default: - throw new InvalidEnumArgumentException(nameof(aggregator), (int)aggregator, typeof(Aggregator)); - } + Aggregator.Average => new Average(), + Aggregator.DifferenceModule => new DifferenceModule(), + Aggregator.DifferenceSquareRoot => new DifferenceSquareRoot(), + Aggregator.Max => new Max(), + Aggregator.Min => new Min(), + Aggregator.SumModule => new SumModule(), + Aggregator.SumSquareRoot => new SumSquareRoot(), + _ => throw new InvalidEnumArgumentException(nameof(aggregator), (int)aggregator, typeof(Aggregator)), + }; } -} \ No newline at end of file +} diff --git a/Libiada.Core/TimeSeries/Aggregators/Average.cs b/Libiada.Core/TimeSeries/Aggregators/Average.cs index eab05054..b5b11923 100644 --- a/Libiada.Core/TimeSeries/Aggregators/Average.cs +++ b/Libiada.Core/TimeSeries/Aggregators/Average.cs @@ -18,4 +18,4 @@ public double Aggregate(List distances) { return distances.Average(); } -} \ No newline at end of file +} diff --git a/Libiada.Core/TimeSeries/Aggregators/DifferenceModule.cs b/Libiada.Core/TimeSeries/Aggregators/DifferenceModule.cs index 3719f04e..4bcee2ef 100644 --- a/Libiada.Core/TimeSeries/Aggregators/DifferenceModule.cs +++ b/Libiada.Core/TimeSeries/Aggregators/DifferenceModule.cs @@ -23,4 +23,4 @@ public double Aggregate(List distances) } return Math.Abs(distance); } -} \ No newline at end of file +} diff --git a/Libiada.Core/TimeSeries/Aggregators/DifferenceSquareRoot.cs b/Libiada.Core/TimeSeries/Aggregators/DifferenceSquareRoot.cs index 81dbbbb7..f946c76d 100644 --- a/Libiada.Core/TimeSeries/Aggregators/DifferenceSquareRoot.cs +++ b/Libiada.Core/TimeSeries/Aggregators/DifferenceSquareRoot.cs @@ -23,4 +23,4 @@ public double Aggregate(List distances) } return Math.Sqrt(Math.Abs(distance)); } -} \ No newline at end of file +} diff --git a/Libiada.Core/TimeSeries/Aggregators/IDistancesAggregator.cs b/Libiada.Core/TimeSeries/Aggregators/IDistancesAggregator.cs index 77762a21..ec8f9077 100644 --- a/Libiada.Core/TimeSeries/Aggregators/IDistancesAggregator.cs +++ b/Libiada.Core/TimeSeries/Aggregators/IDistancesAggregator.cs @@ -15,4 +15,4 @@ public interface IDistancesAggregator /// The . /// double Aggregate(List distances); -} \ No newline at end of file +} diff --git a/Libiada.Core/TimeSeries/Aggregators/Max.cs b/Libiada.Core/TimeSeries/Aggregators/Max.cs index c0d6275d..0d76a54a 100644 --- a/Libiada.Core/TimeSeries/Aggregators/Max.cs +++ b/Libiada.Core/TimeSeries/Aggregators/Max.cs @@ -18,4 +18,4 @@ public double Aggregate(List distances) { return distances.Max(); } -} \ No newline at end of file +} diff --git a/Libiada.Core/TimeSeries/Aggregators/Min.cs b/Libiada.Core/TimeSeries/Aggregators/Min.cs index e610e88a..58c0bb00 100644 --- a/Libiada.Core/TimeSeries/Aggregators/Min.cs +++ b/Libiada.Core/TimeSeries/Aggregators/Min.cs @@ -18,4 +18,4 @@ public double Aggregate(List distances) { return distances.Min(); } -} \ No newline at end of file +} diff --git a/Libiada.Core/TimeSeries/Aggregators/SumModule.cs b/Libiada.Core/TimeSeries/Aggregators/SumModule.cs index 6e78015e..0855ab22 100644 --- a/Libiada.Core/TimeSeries/Aggregators/SumModule.cs +++ b/Libiada.Core/TimeSeries/Aggregators/SumModule.cs @@ -18,4 +18,4 @@ public double Aggregate(List distances) { return Math.Abs(distances.Sum()); } -} \ No newline at end of file +} diff --git a/Libiada.Core/TimeSeries/Aggregators/SumSquareRoot.cs b/Libiada.Core/TimeSeries/Aggregators/SumSquareRoot.cs index 204e97cc..af64af66 100644 --- a/Libiada.Core/TimeSeries/Aggregators/SumSquareRoot.cs +++ b/Libiada.Core/TimeSeries/Aggregators/SumSquareRoot.cs @@ -18,4 +18,4 @@ public double Aggregate(List distances) { return Math.Sqrt(Math.Abs(distances.Sum())); } -} \ No newline at end of file +} diff --git a/Libiada.Core/TimeSeries/Aligners/Aligner.cs b/Libiada.Core/TimeSeries/Aligners/Aligner.cs index b3999cfa..fb7de307 100644 --- a/Libiada.Core/TimeSeries/Aligners/Aligner.cs +++ b/Libiada.Core/TimeSeries/Aligners/Aligner.cs @@ -42,4 +42,4 @@ public enum Aligner : Byte [Display(Name = "Last element duplicate")] [Description("Last element duplicator")] LastElementDuplicator = 5 -} \ No newline at end of file +} diff --git a/Libiada.Core/TimeSeries/Aligners/AlignersFactory.cs b/Libiada.Core/TimeSeries/Aligners/AlignersFactory.cs index 80522d39..ce2a1e33 100644 --- a/Libiada.Core/TimeSeries/Aligners/AlignersFactory.cs +++ b/Libiada.Core/TimeSeries/Aligners/AlignersFactory.cs @@ -20,20 +20,14 @@ public class AlignersFactory /// public ITimeSeriesAligner GetAligner(Aligner aligner) { - switch (aligner) + return aligner switch { - case Aligner.ByShortestAligner: - return new ByShortestAligner(); - case Aligner.ByShortestFromRightAligner: - return new ByShortestFromRightAligner(); - case Aligner.AllOffsetsAligner: - return new AllOffsetsAligner(); - case Aligner.FirstElementDuplicator: - return new FirstElementDuplicator(); - case Aligner.LastElementDuplicator: - return new LastElementDuplicator(); - default: - throw new InvalidEnumArgumentException(nameof(aligner), (int)aligner, typeof(Aligner)); - } + Aligner.ByShortestAligner => new ByShortestAligner(), + Aligner.ByShortestFromRightAligner => new ByShortestFromRightAligner(), + Aligner.AllOffsetsAligner => new AllOffsetsAligner(), + Aligner.FirstElementDuplicator => new FirstElementDuplicator(), + Aligner.LastElementDuplicator => new LastElementDuplicator(), + _ => throw new InvalidEnumArgumentException(nameof(aligner), (int)aligner, typeof(Aligner)), + }; } -} \ No newline at end of file +} diff --git a/Libiada.Core/TimeSeries/Aligners/AllOffsetsAligner.cs b/Libiada.Core/TimeSeries/Aligners/AllOffsetsAligner.cs index ea731a96..8c076312 100644 --- a/Libiada.Core/TimeSeries/Aligners/AllOffsetsAligner.cs +++ b/Libiada.Core/TimeSeries/Aligners/AllOffsetsAligner.cs @@ -53,4 +53,4 @@ public class AllOffsetsAligner : ITimeSeriesAligner return (first, second); } } -} \ No newline at end of file +} diff --git a/Libiada.Core/TimeSeries/Aligners/ByShortestAligner.cs b/Libiada.Core/TimeSeries/Aligners/ByShortestAligner.cs index a0fafc97..e68e076d 100644 --- a/Libiada.Core/TimeSeries/Aligners/ByShortestAligner.cs +++ b/Libiada.Core/TimeSeries/Aligners/ByShortestAligner.cs @@ -31,4 +31,4 @@ public class ByShortestAligner : ITimeSeriesAligner return (first, second); } -} \ No newline at end of file +} diff --git a/Libiada.Core/TimeSeries/Aligners/ByShortestFromRightAligner.cs b/Libiada.Core/TimeSeries/Aligners/ByShortestFromRightAligner.cs index 6f83ed4e..291b0607 100644 --- a/Libiada.Core/TimeSeries/Aligners/ByShortestFromRightAligner.cs +++ b/Libiada.Core/TimeSeries/Aligners/ByShortestFromRightAligner.cs @@ -40,4 +40,4 @@ public class ByShortestFromRightAligner : ITimeSeriesAligner return (first, second); } -} \ No newline at end of file +} diff --git a/Libiada.Core/TimeSeries/Aligners/FirstElementDuplicator.cs b/Libiada.Core/TimeSeries/Aligners/FirstElementDuplicator.cs index ae7ff958..464df14a 100644 --- a/Libiada.Core/TimeSeries/Aligners/FirstElementDuplicator.cs +++ b/Libiada.Core/TimeSeries/Aligners/FirstElementDuplicator.cs @@ -27,7 +27,7 @@ public class FirstElementDuplicator : ITimeSeriesAligner if (firstSeries.Length < secondSeries.Length) { - List result = new List(secondSeries.Length); + List result = new(secondSeries.Length); for (int i = 0; i < length; i++) { @@ -42,7 +42,7 @@ public class FirstElementDuplicator : ITimeSeriesAligner } else { - List result = new List(firstSeries.Length); + List result = new(firstSeries.Length); for (int i = 0; i < length; i++) { @@ -59,4 +59,4 @@ public class FirstElementDuplicator : ITimeSeriesAligner return (first, second); } -} \ No newline at end of file +} diff --git a/Libiada.Core/TimeSeries/Aligners/ITimeSeriesAligner.cs b/Libiada.Core/TimeSeries/Aligners/ITimeSeriesAligner.cs index 7e4974dd..855260dd 100644 --- a/Libiada.Core/TimeSeries/Aligners/ITimeSeriesAligner.cs +++ b/Libiada.Core/TimeSeries/Aligners/ITimeSeriesAligner.cs @@ -18,4 +18,4 @@ public interface ITimeSeriesAligner /// The . /// (double[][] first, double[][] second) AlignSeries(double[] firstSeries, double[] secondSeries); -} \ No newline at end of file +} diff --git a/Libiada.Core/TimeSeries/Aligners/LastElementDuplicator.cs b/Libiada.Core/TimeSeries/Aligners/LastElementDuplicator.cs index 425d1a47..de7d4824 100644 --- a/Libiada.Core/TimeSeries/Aligners/LastElementDuplicator.cs +++ b/Libiada.Core/TimeSeries/Aligners/LastElementDuplicator.cs @@ -22,7 +22,7 @@ public class LastElementDuplicator : ITimeSeriesAligner double[][] first = new double[1][]; double[][] second = new double[1][]; - List result = new List(); + List result = []; if (firstSeries.Length < secondSeries.Length) { @@ -57,4 +57,4 @@ public class LastElementDuplicator : ITimeSeriesAligner return (first, second); } -} \ No newline at end of file +} diff --git a/Libiada.Core/TimeSeries/OneDimensional/Comparers/IOneDimensionalTimeSeriesComparer.cs b/Libiada.Core/TimeSeries/OneDimensional/Comparers/IOneDimensionalTimeSeriesComparer.cs index 1f5c0681..5dc2e411 100644 --- a/Libiada.Core/TimeSeries/OneDimensional/Comparers/IOneDimensionalTimeSeriesComparer.cs +++ b/Libiada.Core/TimeSeries/OneDimensional/Comparers/IOneDimensionalTimeSeriesComparer.cs @@ -18,4 +18,4 @@ public interface IOneDimensionalTimeSeriesComparer /// The . /// double GetDistance(double[] firstTimeSeries, double[] secondTimeSeries); -} \ No newline at end of file +} diff --git a/Libiada.Core/TimeSeries/OneDimensional/Comparers/OneDimensionalTimeSeriesComparer.cs b/Libiada.Core/TimeSeries/OneDimensional/Comparers/OneDimensionalTimeSeriesComparer.cs index 67298835..a0b5008e 100644 --- a/Libiada.Core/TimeSeries/OneDimensional/Comparers/OneDimensionalTimeSeriesComparer.cs +++ b/Libiada.Core/TimeSeries/OneDimensional/Comparers/OneDimensionalTimeSeriesComparer.cs @@ -63,7 +63,7 @@ public double GetDistance(double[] firstTimeSeries, double[] secondTimeSeries) for (int i = 0; i < first.Length; i++) { - List distances = new List(); + List distances = []; for (int j = 0; j < first[0].Length; j++) { distances.Add(this.calculator.GetDistance(first[i][j], second[i][j])); @@ -74,4 +74,4 @@ public double GetDistance(double[] firstTimeSeries, double[] secondTimeSeries) return aggregated.Min(); } -} \ No newline at end of file +} diff --git a/Libiada.Core/TimeSeries/OneDimensional/DistanceCalculators/DistanceCalculator.cs b/Libiada.Core/TimeSeries/OneDimensional/DistanceCalculators/DistanceCalculator.cs index 8b76784d..7c356459 100644 --- a/Libiada.Core/TimeSeries/OneDimensional/DistanceCalculators/DistanceCalculator.cs +++ b/Libiada.Core/TimeSeries/OneDimensional/DistanceCalculators/DistanceCalculator.cs @@ -18,4 +18,4 @@ public enum DistanceCalculator : byte [Display(Name = "Hamming")] [Description("Hamming distance between one dimensional points calculator")] HammingDistanceBetweenOneDimensionalPointsCalculator = 2 -} \ No newline at end of file +} diff --git a/Libiada.Core/TimeSeries/OneDimensional/DistanceCalculators/DistanceCalculatorsFactory.cs b/Libiada.Core/TimeSeries/OneDimensional/DistanceCalculators/DistanceCalculatorsFactory.cs index 21b6f737..b891b149 100644 --- a/Libiada.Core/TimeSeries/OneDimensional/DistanceCalculators/DistanceCalculatorsFactory.cs +++ b/Libiada.Core/TimeSeries/OneDimensional/DistanceCalculators/DistanceCalculatorsFactory.cs @@ -6,14 +6,11 @@ public class DistanceCalculatorsFactory { public IOneDimensionalPointsDistance GetDistanceCalculator(DistanceCalculator calculator) { - switch (calculator) + return calculator switch { - case DistanceCalculator.EuclideanDistanceBetweenOneDimensionalPointsCalculator: - return new EuclideanDistanceBetweenOneDimensionalPointsCalculator(); - case DistanceCalculator.HammingDistanceBetweenOneDimensionalPointsCalculator: - return new HammingDistanceBetweenOneDimensionalPointsCalculator(); - default: - throw new InvalidEnumArgumentException(nameof(calculator), (int)calculator, typeof(DistanceCalculator)); - } + DistanceCalculator.EuclideanDistanceBetweenOneDimensionalPointsCalculator => new EuclideanDistanceBetweenOneDimensionalPointsCalculator(), + DistanceCalculator.HammingDistanceBetweenOneDimensionalPointsCalculator => new HammingDistanceBetweenOneDimensionalPointsCalculator(), + _ => throw new InvalidEnumArgumentException(nameof(calculator), (int)calculator, typeof(DistanceCalculator)), + }; } -} \ No newline at end of file +} diff --git a/Libiada.Core/TimeSeries/OneDimensional/DistanceCalculators/EuclideanDistanceBetweenOneDimensionalPointsCalculator.cs b/Libiada.Core/TimeSeries/OneDimensional/DistanceCalculators/EuclideanDistanceBetweenOneDimensionalPointsCalculator.cs index 88b51902..48cdddaa 100644 --- a/Libiada.Core/TimeSeries/OneDimensional/DistanceCalculators/EuclideanDistanceBetweenOneDimensionalPointsCalculator.cs +++ b/Libiada.Core/TimeSeries/OneDimensional/DistanceCalculators/EuclideanDistanceBetweenOneDimensionalPointsCalculator.cs @@ -21,4 +21,4 @@ public double GetDistance(double firstPoint, double secondPoint) { return Math.Abs(firstPoint - secondPoint); } -} \ No newline at end of file +} diff --git a/Libiada.Core/TimeSeries/OneDimensional/DistanceCalculators/HammingDistanceBetweenOneDimensionalPointsCalculator.cs b/Libiada.Core/TimeSeries/OneDimensional/DistanceCalculators/HammingDistanceBetweenOneDimensionalPointsCalculator.cs index 49c98a14..a18428eb 100644 --- a/Libiada.Core/TimeSeries/OneDimensional/DistanceCalculators/HammingDistanceBetweenOneDimensionalPointsCalculator.cs +++ b/Libiada.Core/TimeSeries/OneDimensional/DistanceCalculators/HammingDistanceBetweenOneDimensionalPointsCalculator.cs @@ -63,4 +63,4 @@ public double GetDistance(double firstPoint, double secondPoint) return distance; } -} \ No newline at end of file +} diff --git a/Libiada.Core/TimeSeries/OneDimensional/DistanceCalculators/IOneDimensionalPointsDistance.cs b/Libiada.Core/TimeSeries/OneDimensional/DistanceCalculators/IOneDimensionalPointsDistance.cs index 15cea56f..2fa0c7be 100644 --- a/Libiada.Core/TimeSeries/OneDimensional/DistanceCalculators/IOneDimensionalPointsDistance.cs +++ b/Libiada.Core/TimeSeries/OneDimensional/DistanceCalculators/IOneDimensionalPointsDistance.cs @@ -18,4 +18,4 @@ public interface IOneDimensionalPointsDistance /// The . /// double GetDistance(double firstPoint, double secondPoint); -} \ No newline at end of file +} diff --git a/Libiada.Core/TimeSeries/OneDimensional/Restrictions/IRestriction.cs b/Libiada.Core/TimeSeries/OneDimensional/Restrictions/IRestriction.cs index a47d1e0c..526e585c 100644 --- a/Libiada.Core/TimeSeries/OneDimensional/Restrictions/IRestriction.cs +++ b/Libiada.Core/TimeSeries/OneDimensional/Restrictions/IRestriction.cs @@ -6,4 +6,4 @@ public interface IRestriction { double Restrict(double distance); -} \ No newline at end of file +} diff --git a/Libiada.Core/TimeSeries/OneDimensional/Restrictions/SoftRestriction.cs b/Libiada.Core/TimeSeries/OneDimensional/Restrictions/SoftRestriction.cs index 0e42757c..32b5a003 100644 --- a/Libiada.Core/TimeSeries/OneDimensional/Restrictions/SoftRestriction.cs +++ b/Libiada.Core/TimeSeries/OneDimensional/Restrictions/SoftRestriction.cs @@ -18,4 +18,4 @@ public double Restrict(double differenceModulus) { return differenceModulus / (1 + differenceModulus); } -} \ No newline at end of file +} diff --git a/Libiada.MarkovChains.Tests/MarkovChain/MarkovChainNotCongenericStaticTests.cs b/Libiada.MarkovChains.Tests/MarkovChain/MarkovChainNotCongenericStaticTests.cs index 0e3255b3..fe1f217c 100644 --- a/Libiada.MarkovChains.Tests/MarkovChain/MarkovChainNotCongenericStaticTests.cs +++ b/Libiada.MarkovChains.Tests/MarkovChain/MarkovChainNotCongenericStaticTests.cs @@ -51,7 +51,7 @@ public void MarkovChainNotCongenericZeroRankTwoTest() const int NoCongenericRank = 0; // creating markov chain - var markovChain = new MarkovChainNotCongenericStatic(MarkovChainRank, NoCongenericRank, generator); + MarkovChainNotCongenericStatic markovChain = new(MarkovChainRank, NoCongenericRank, generator); // length of generated sequence const int Length = 30; @@ -79,7 +79,7 @@ public void MarkovChainNotCongenericZeroRankTwoTest() */ // expected result of generation - var resultTheory = new Chain("aabaabaaaaaabaabaaaaaabaabaaaa"); + Chain resultTheory = new("aabaabaaaaaabaabaaaaaabaabaaaa"); // "a" 0.77; // "a" 0.15; // "b" 0.96; @@ -130,7 +130,7 @@ public void MarkovChainNotCongenericOneRangTwoTest() const int NoCongenericRank = 1; // creating markov chain - var markovChain = new MarkovChainNotCongenericStatic(MarkovChainRank, NoCongenericRank, generator); + MarkovChainNotCongenericStatic markovChain = new(MarkovChainRank, NoCongenericRank, generator); // length of generated sequence const int Length = 12; @@ -199,7 +199,7 @@ public void MarkovChainNotCongenericOneRangTwoTest() */ // expected result of generation - var result = new Chain("bacbacacaacb"); + Chain result = new("bacbacacaacb"); // 1 chain. . 0,77 b // 2 chain. . 0.15 a // 1 chain. . 0.96 @@ -260,7 +260,7 @@ public void MarkovChainNotCongenericDynamicZeroRangTwoTest() */ // expected result of generation - var resultTheory = new Chain("aabaabaaaaaabaabaaaaaabaabaaaa"); + Chain resultTheory = new("aabaabaaaaaabaabaaaaaabaabaaaa"); // "a" 0.77; // "a" 0.15; // "b" 0.96; @@ -378,7 +378,7 @@ public void MarkovChainNotCongenericDynamicOneRangTwoTest() */ // expected result of generation - var result = new Chain("bacbacacaacb"); + Chain result = new("bacbacacaacb"); // 1 chain. . 0,77 b // 2 chain. . 0.15 a // 1 chain. . 0.96 diff --git a/Libiada.MarkovChains.Tests/MarkovChain/Matrices/Probability/ProbabilityMatrixTests.cs b/Libiada.MarkovChains.Tests/MarkovChain/Matrices/Probability/ProbabilityMatrixTests.cs index 64cbbe47..68bddb22 100644 --- a/Libiada.MarkovChains.Tests/MarkovChain/Matrices/Probability/ProbabilityMatrixTests.cs +++ b/Libiada.MarkovChains.Tests/MarkovChain/Matrices/Probability/ProbabilityMatrixTests.cs @@ -86,7 +86,7 @@ public void AddLengthMoreThanChainRankTest() baseChain = new BaseChain("abb"); matrix = new Matrix(alphabet.Cardinality, 2); - var arrayCh = new int[baseChain.Length]; + int[] arrayCh = new int[baseChain.Length]; arrayCh[0] = alphabet.IndexOf(baseChain[0]); arrayCh[1] = alphabet.IndexOf(baseChain[1]); arrayCh[2] = alphabet.IndexOf(baseChain[2]); @@ -105,19 +105,17 @@ public void GetWithIndexesTest() alphabet.Add(d); // 3 => d baseChain = new BaseChain("ab"); - var ch1 = new BaseChain("cb"); - var ch2 = new BaseChain("ba"); - var ch3 = new BaseChain("bc"); - var ch4 = new BaseChain("ac"); - var ch5 = new BaseChain("b"); - var ch6 = new BaseChain("a"); - var ch7 = new BaseChain("c"); + BaseChain ch1 = new("cb"); + BaseChain ch2 = new("ba"); + BaseChain ch3 = new("bc"); + BaseChain ch4 = new("ac"); + BaseChain ch5 = new("b"); + BaseChain ch6 = new("a"); + BaseChain ch7 = new("c"); matrix = new Matrix(alphabet.Cardinality, 2); - var arrayToTeach = new int[2]; - arrayToTeach[0] = alphabet.IndexOf(ch1[0]); - arrayToTeach[1] = alphabet.IndexOf(ch1[1]); + int[] arrayToTeach = [alphabet.IndexOf(ch1[0]), alphabet.IndexOf(ch1[1])]; matrix.Add(arrayToTeach); arrayToTeach = new int[2]; @@ -176,10 +174,10 @@ public void GetThirdLevelChainTest() { matrix = new Matrix(testChain.Alphabet.Cardinality, 3); - var reorganizer = new NullCycleSpaceReorganizer(2); + NullCycleSpaceReorganizer reorganizer = new(2); testChain = (BaseChain)reorganizer.Reorganize(testChain); - var it = new IteratorStart(testChain, 3, 1); + IteratorStart it = new(testChain, 3, 1); while (it.Next()) { var chain = it.Current(); @@ -192,9 +190,7 @@ public void GetThirdLevelChainTest() matrix.Add(arrayToTeach); } - var toGet = new int[1]; - - toGet[0] = testChain.Alphabet.IndexOf((ValueString)"a"); + int[] toGet = [testChain.Alphabet.IndexOf((ValueString)"a")]; Assert.That(matrix.FrequencyFromObject(toGet), Is.EqualTo(6)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"b"); @@ -403,10 +399,10 @@ public void GetProbabilityMatrixTest() { matrix = new Matrix(testChain.Alphabet.Cardinality, 3); - var reorganizer = new NullCycleSpaceReorganizer(2); + NullCycleSpaceReorganizer reorganizer = new(2); testChain = (BaseChain)reorganizer.Reorganize(testChain); - var it = new IteratorStart(testChain, 3, 1); + IteratorStart it = new(testChain, 3, 1); while (it.Next()) { var chain = it.Current(); @@ -421,9 +417,7 @@ public void GetProbabilityMatrixTest() var probabilityMatrix = (ProbabilityMatrix)matrix.ProbabilityMatrix(); - var toGet = new int[1]; - - toGet[0] = testChain.Alphabet.IndexOf((ValueString)"a"); + int[] toGet = [testChain.Alphabet.IndexOf((ValueString)"a")]; Assert.That(probabilityMatrix.FrequencyFromObject(toGet), Is.EqualTo(0.5)); toGet[0] = testChain.Alphabet.IndexOf((ValueString)"b"); @@ -638,7 +632,7 @@ public void LargerNTest() baseChain = new BaseChain("fc"); matrix = new Matrix(alphabet.Cardinality, 2); - var array = new int[baseChain.Length]; + int[] array = new int[baseChain.Length]; array[0] = alphabet.IndexOf(baseChain[0]); array[1] = alphabet.IndexOf(baseChain[1]); Assert.Throws(() => matrix.FrequencyFromObject(array)); diff --git a/Libiada.MarkovChains.Tests/MarkovCompare/MarkovMetricsTests.cs b/Libiada.MarkovChains.Tests/MarkovCompare/MarkovMetricsTests.cs index 90c27049..2e7dfa34 100644 --- a/Libiada.MarkovChains.Tests/MarkovCompare/MarkovMetricsTests.cs +++ b/Libiada.MarkovChains.Tests/MarkovCompare/MarkovMetricsTests.cs @@ -32,9 +32,9 @@ public void Initialize() [Test] public void CompareSameChainTest() { - var markov = new MarkovChainNotCongenericStatic(2, 0, new MockGenerator()); + MarkovChainNotCongenericStatic markov = new(2, 0, new MockGenerator()); markov.Teach(testChain, TeachingMethod.Cycle); - var ma = new MarkovMetrics(); + MarkovMetrics ma = new(); Assert.That(ma.GetArithmeticalMean(markov), Is.EqualTo(ma.GetArithmeticalMean(markov))); } } diff --git a/Libiada.MarkovChains/MarkovChain/Builders/MatrixBuilder.cs b/Libiada.MarkovChains/MarkovChain/Builders/MatrixBuilder.cs index b64e49c2..86865753 100644 --- a/Libiada.MarkovChains/MarkovChain/Builders/MatrixBuilder.cs +++ b/Libiada.MarkovChains/MarkovChain/Builders/MatrixBuilder.cs @@ -21,14 +21,11 @@ public class MatrixBuilder : IMatrixBuilder /// public object Create(int alphabetCardinality, int i) { - switch (i) + return i switch { - case 0: - return (double)0; - case 1: - return new MatrixRow(alphabetCardinality, i); - default: - return new Matrix(alphabetCardinality, i); - } + 0 => (double)0, + 1 => new MatrixRow(alphabetCardinality, i), + _ => new Matrix(alphabetCardinality, i), + }; } } diff --git a/Libiada.MarkovChains/MarkovChain/Builders/ProbabilityMatrixBuilder.cs b/Libiada.MarkovChains/MarkovChain/Builders/ProbabilityMatrixBuilder.cs index cc59bf48..04e65a80 100644 --- a/Libiada.MarkovChains/MarkovChain/Builders/ProbabilityMatrixBuilder.cs +++ b/Libiada.MarkovChains/MarkovChain/Builders/ProbabilityMatrixBuilder.cs @@ -21,14 +21,11 @@ public class ProbabilityMatrixBuilder : IMatrixBuilder /// public object Create(int alphabetCardinality, int i) { - switch (i) + return i switch { - case 0: - return (double)0; - case 1: - return new ProbabilityMatrixRow(alphabetCardinality, i); - default: - return new ProbabilityMatrix(alphabetCardinality, i); - } + 0 => (double)0, + 1 => new ProbabilityMatrixRow(alphabetCardinality, i), + _ => new ProbabilityMatrix(alphabetCardinality, i), + }; } } diff --git a/Libiada.MarkovChains/MarkovChain/Generators/GeneratorFactory.cs b/Libiada.MarkovChains/MarkovChain/Generators/GeneratorFactory.cs index b969d6c2..24aaa7c6 100644 --- a/Libiada.MarkovChains/MarkovChain/Generators/GeneratorFactory.cs +++ b/Libiada.MarkovChains/MarkovChain/Generators/GeneratorFactory.cs @@ -19,12 +19,10 @@ public static class GeneratorFactory /// public static IGenerator Create(GeneratorType generator) { - switch (generator) + return generator switch { - case GeneratorType.SimpleGenerator: - return new SimpleGenerator(); - default: - throw new ArgumentException("This type of generator does not registered in system", "generator"); - } + GeneratorType.SimpleGenerator => new SimpleGenerator(), + _ => throw new ArgumentException("This type of generator does not registered in system", "generator"), + }; } } diff --git a/Libiada.MarkovChains/MarkovChain/Generators/SimpleGenerator.cs b/Libiada.MarkovChains/MarkovChain/Generators/SimpleGenerator.cs index 40340d6c..ee48c701 100644 --- a/Libiada.MarkovChains/MarkovChain/Generators/SimpleGenerator.cs +++ b/Libiada.MarkovChains/MarkovChain/Generators/SimpleGenerator.cs @@ -8,7 +8,7 @@ public class SimpleGenerator : IGenerator /// /// The random. /// - private Random random = new Random(); + private Random random = new(); /// /// The reset. diff --git a/Libiada.MarkovChains/MarkovChain/MarkovChainBase.cs b/Libiada.MarkovChains/MarkovChain/MarkovChainBase.cs index bc8d8edc..d3d02742 100644 --- a/Libiada.MarkovChains/MarkovChain/MarkovChainBase.cs +++ b/Libiada.MarkovChains/MarkovChain/MarkovChainBase.cs @@ -118,8 +118,8 @@ public BaseChain Generate(int length) /// public virtual void Teach(BaseChain chain, TeachingMethod method) { - var builder = new MatrixBuilder(); - var absMatrix = new IAbsoluteMatrix[HeterogeneityRank + 1]; + MatrixBuilder builder = new(); + IAbsoluteMatrix[] absMatrix = new IAbsoluteMatrix[HeterogeneityRank + 1]; Alphabet = chain.Alphabet; for (int i = 0; i < HeterogeneityRank + 1; i++) { @@ -129,7 +129,7 @@ public virtual void Teach(BaseChain chain, TeachingMethod method) SpaceReorganizer reorganizer = GetRebuilder(method); chain = (BaseChain)reorganizer.Reorganize(chain); - var it = new IteratorStart(chain, Rank, 1); + IteratorStart it = new(chain, Rank, 1); it.Reset(); int k = 0; @@ -145,7 +145,7 @@ public virtual void Teach(BaseChain chain, TeachingMethod method) } BaseChain chainToTeach = (BaseChain)it.Current(); - var indexedChain = new int[Rank]; + int[] indexedChain = new int[Rank]; for (int i = 0; i < Rank; i++) { indexedChain[i] = chain.Alphabet.IndexOf(chainToTeach[i]); @@ -201,14 +201,11 @@ protected IBaseObject GetObject(Dictionary list) /// protected virtual SpaceReorganizer GetRebuilder(TeachingMethod method) { - switch (method) + return method switch { - case TeachingMethod.None: - return new NullReorganizer(); - case TeachingMethod.Cycle: - return new NullCycleSpaceReorganizer(Rank - 1); - default: - throw new ArgumentException(); - } + TeachingMethod.None => new NullReorganizer(), + TeachingMethod.Cycle => new NullCycleSpaceReorganizer(Rank - 1), + _ => throw new ArgumentException(), + }; } } diff --git a/Libiada.MarkovChains/MarkovChain/MarkovChainFactory.cs b/Libiada.MarkovChains/MarkovChain/MarkovChainFactory.cs index 15508a6a..7b2cac80 100644 --- a/Libiada.MarkovChains/MarkovChain/MarkovChainFactory.cs +++ b/Libiada.MarkovChains/MarkovChain/MarkovChainFactory.cs @@ -30,20 +30,14 @@ public class MarkovChainFactory /// public MarkovChainBase Create(GeneratingMethod method, int rank, int heterogeneityRank, IGenerator generator) { - switch (method) + return method switch { - case GeneratingMethod.DynamicNotCongeneric: - return null; - case GeneratingMethod.StaticNotCongeneric: - return new MarkovChainNotCongenericStatic(rank, heterogeneityRank, generator); - case GeneratingMethod.DynamicCongeneric: - return null; - case GeneratingMethod.StaticCongeneric: - return new MarkovChainCongenericStatic(rank, generator); - case GeneratingMethod.Random: - return new MarkovChainRandom(rank, generator); - default: - throw new ArgumentException("This type of markov chain does not registered in system", "method"); - } + GeneratingMethod.DynamicNotCongeneric => null, + GeneratingMethod.StaticNotCongeneric => new MarkovChainNotCongenericStatic(rank, heterogeneityRank, generator), + GeneratingMethod.DynamicCongeneric => null, + GeneratingMethod.StaticCongeneric => new MarkovChainCongenericStatic(rank, generator), + GeneratingMethod.Random => new MarkovChainRandom(rank, generator), + _ => throw new ArgumentException("This type of markov chain does not registered in system", "method"), + }; } } diff --git a/Libiada.MarkovChains/MarkovChain/MarkovChainNotCongenericStatic.cs b/Libiada.MarkovChains/MarkovChain/MarkovChainNotCongenericStatic.cs index 9947cb74..0400ea68 100644 --- a/Libiada.MarkovChains/MarkovChain/MarkovChainNotCongenericStatic.cs +++ b/Libiada.MarkovChains/MarkovChain/MarkovChainNotCongenericStatic.cs @@ -40,10 +40,10 @@ public MarkovChainNotCongenericStatic(int rank, int heterogeneityRank, IGenerato /// public override BaseChain Generate(int length, int chainRank) { - var temp = new BaseChain(); + BaseChain temp = new(); temp.ClearAndSetNewLength(length); - var read = Rank > 1 ? new IteratorStart(temp, Rank - 1, 1) : null; - var write = new IteratorWritableStart(temp); + IteratorStart? read = Rank > 1 ? new IteratorStart(temp, Rank - 1, 1) : null; + IteratorWritableStart write = new(temp); if (read != null) { read.Reset(); @@ -76,7 +76,7 @@ public override BaseChain Generate(int length, int chainRank) if (read != null) { BaseChain chain = (BaseChain)read.Current(); - var indexedChain = new int[chain.Length]; + int[] indexedChain = new int[chain.Length]; for (int k = 0; k < chain.Length; k++) { indexedChain[k] = Alphabet.IndexOf(chain[k]); diff --git a/Libiada.MarkovChains/MarkovChain/MarkovChainRandom.cs b/Libiada.MarkovChains/MarkovChain/MarkovChainRandom.cs index c1eb381d..9ae08034 100644 --- a/Libiada.MarkovChains/MarkovChain/MarkovChainRandom.cs +++ b/Libiada.MarkovChains/MarkovChain/MarkovChainRandom.cs @@ -36,13 +36,11 @@ public MarkovChainRandom(int i, IGenerator generator) /// public override void Teach(BaseChain chain, TeachingMethod method) { - var builder = new MatrixBuilder(); - var absoluteMatrix = (IAbsoluteMatrix)builder.Create(chain.Alphabet.Cardinality, Rank); + MatrixBuilder builder = new(); + IAbsoluteMatrix absoluteMatrix = (IAbsoluteMatrix)builder.Create(chain.Alphabet.Cardinality, Rank); for (int i = 0; i < chain.Alphabet.Cardinality; i++) { - int[] temp = new int[1]; - temp[0] = chain.Alphabet.IndexOf(chain.Alphabet[i]); - + int[] temp = [chain.Alphabet.IndexOf(chain.Alphabet[i])]; absoluteMatrix.Add(temp); } diff --git a/Libiada.MarkovChains/MarkovChain/Matrices/Absolute/IOpenMatrix.cs b/Libiada.MarkovChains/MarkovChain/Matrices/Absolute/IOpenMatrix.cs index cd6a4165..860cbac1 100644 --- a/Libiada.MarkovChains/MarkovChain/Matrices/Absolute/IOpenMatrix.cs +++ b/Libiada.MarkovChains/MarkovChain/Matrices/Absolute/IOpenMatrix.cs @@ -1,7 +1,5 @@ namespace Libiada.MarkovChains.MarkovChain.Matrices.Absolute; -using System.Collections; - /// /// Interface for accessing inner data of matrix. /// @@ -12,7 +10,7 @@ public interface IOpenMatrix /// /// Gets elements list of matrix. /// - ArrayList ValueList { get; } + List ValueList { get; } /// /// Gets rank of matrix. diff --git a/Libiada.MarkovChains/MarkovChain/Matrices/Absolute/Matrix.cs b/Libiada.MarkovChains/MarkovChain/Matrices/Absolute/Matrix.cs index a689406e..12894b1d 100644 --- a/Libiada.MarkovChains/MarkovChain/Matrices/Absolute/Matrix.cs +++ b/Libiada.MarkovChains/MarkovChain/Matrices/Absolute/Matrix.cs @@ -1,7 +1,5 @@ namespace Libiada.MarkovChains.MarkovChain.Matrices.Absolute; -using System.Collections; - using MarkovChains.MarkovChain.Builders; using MarkovChains.MarkovChain.Matrices.Base; using MarkovChains.MarkovChain.Matrices.Probability; @@ -38,11 +36,11 @@ public double Count /// /// Gets the value list. /// - ArrayList IOpenMatrix.ValueList + List IOpenMatrix.ValueList { get { - return (ArrayList)this.ValueList.Clone(); + return new List(ValueList); } } @@ -76,7 +74,7 @@ double IOpenMatrix.Value /// public IProbabilityMatrix ProbabilityMatrix() { - var temp = new ProbabilityMatrix(AlphabetCardinality, Rank); + ProbabilityMatrix temp = new(AlphabetCardinality, Rank); temp.Fill(this); return temp; } diff --git a/Libiada.MarkovChains/MarkovChain/Matrices/Absolute/MatrixRow.cs b/Libiada.MarkovChains/MarkovChain/Matrices/Absolute/MatrixRow.cs index f181d5fe..e8f6182c 100644 --- a/Libiada.MarkovChains/MarkovChain/Matrices/Absolute/MatrixRow.cs +++ b/Libiada.MarkovChains/MarkovChain/Matrices/Absolute/MatrixRow.cs @@ -1,7 +1,5 @@ namespace Libiada.MarkovChains.MarkovChain.Matrices.Absolute; -using System.Collections; - using Base; using Builders; @@ -42,11 +40,11 @@ public double Count /// /// Gets the value list. /// - ArrayList IOpenMatrix.ValueList + List IOpenMatrix.ValueList { get { - return (ArrayList)ValueList.Clone(); + return new List(ValueList); } } @@ -110,7 +108,7 @@ public double Sum(int[] arrayOfIndexes) /// public IProbabilityMatrix ProbabilityMatrix() { - var temp = new ProbabilityMatrixRow(AlphabetCardinality, 1); + ProbabilityMatrixRow temp = new(AlphabetCardinality, 1); temp.Fill(this); return temp; } diff --git a/Libiada.MarkovChains/MarkovChain/Matrices/Base/MatrixBase.cs b/Libiada.MarkovChains/MarkovChain/Matrices/Base/MatrixBase.cs index 6a7c0ac3..87608e61 100644 --- a/Libiada.MarkovChains/MarkovChain/Matrices/Base/MatrixBase.cs +++ b/Libiada.MarkovChains/MarkovChain/Matrices/Base/MatrixBase.cs @@ -1,7 +1,5 @@ namespace Libiada.MarkovChains.MarkovChain.Matrices.Base; -using System.Collections; - using Builders; /// @@ -17,7 +15,7 @@ public abstract class MatrixBase /// /// Array of matrix elements. /// - protected readonly ArrayList ValueList; + protected readonly List ValueList; /// /// Dimensionality of the matrix. @@ -39,7 +37,7 @@ public abstract class MatrixBase public MatrixBase(int alphabetCardinality, int dimensionality, IMatrixBuilder builder) { AlphabetCardinality = alphabetCardinality; - ValueList = new ArrayList(); + ValueList = []; Rank = dimensionality; for (int i = 0; i < AlphabetCardinality; i++) { diff --git a/Libiada.MarkovChains/MarkovChain/Matrices/Base/MatrixCommon.cs b/Libiada.MarkovChains/MarkovChain/Matrices/Base/MatrixCommon.cs index 0aa66c2a..5490ad72 100644 --- a/Libiada.MarkovChains/MarkovChain/Matrices/Base/MatrixCommon.cs +++ b/Libiada.MarkovChains/MarkovChain/Matrices/Base/MatrixCommon.cs @@ -55,7 +55,7 @@ public override double FrequencyFromObject(int[] indexes) /// protected int[] GetChainLess(int[] indexes) { - var newIndexes = new int[indexes.Length - 1]; + int[] newIndexes = new int[indexes.Length - 1]; for (int i = 0; i < indexes.Length - 1; i++) { newIndexes[i] = indexes[i + 1]; diff --git a/Libiada.MarkovChains/MarkovChain/Matrices/Probability/ProbabilityMatrix.cs b/Libiada.MarkovChains/MarkovChain/Matrices/Probability/ProbabilityMatrix.cs index e995d151..0fcdffcf 100644 --- a/Libiada.MarkovChains/MarkovChain/Matrices/Probability/ProbabilityMatrix.cs +++ b/Libiada.MarkovChains/MarkovChain/Matrices/Probability/ProbabilityMatrix.cs @@ -80,7 +80,7 @@ public void Fill(IOpenMatrix matrix) /// public Dictionary GetProbabilityVector(Alphabet alphabet, int[] pred) { - var result = new Dictionary(); + Dictionary result = []; if ((pred.Length > Rank - 1) || (pred.Length == 0)) { throw new ArgumentException(); diff --git a/Libiada.MarkovChains/MarkovChain/Matrices/Probability/ProbabilityMatrixRow.cs b/Libiada.MarkovChains/MarkovChain/Matrices/Probability/ProbabilityMatrixRow.cs index bf4916f6..8bb7529c 100644 --- a/Libiada.MarkovChains/MarkovChain/Matrices/Probability/ProbabilityMatrixRow.cs +++ b/Libiada.MarkovChains/MarkovChain/Matrices/Probability/ProbabilityMatrixRow.cs @@ -70,7 +70,7 @@ public void Fill(IOpenMatrix matrix) /// public Dictionary GetProbabilityVector(Alphabet alphabet) { - return GetProbabilityVector(alphabet, new int[] { }); + return GetProbabilityVector(alphabet, []); } /// @@ -100,7 +100,7 @@ public Dictionary GetProbabilityVector(Alphabet alphabet, i throw new Exception(); } - var result = new Dictionary(); + Dictionary result = []; for (int i = 0; i < AlphabetCardinality; i++) { result.Add(alphabet[i], (double)ValueList[i]); diff --git a/Libiada.MarkovChains/MarkovCompare/MarkovMetrics.cs b/Libiada.MarkovChains/MarkovCompare/MarkovMetrics.cs index 70f66e3b..c01dcff2 100644 --- a/Libiada.MarkovChains/MarkovCompare/MarkovMetrics.cs +++ b/Libiada.MarkovChains/MarkovCompare/MarkovMetrics.cs @@ -22,7 +22,7 @@ public double GetArithmeticalMean(MarkovChainNotCongenericStatic chain) IProbabilityMatrix matrix = chain.PropabilityMatrix; for (int i = 0; i < chain.Alphabet.Cardinality; i++) { - int[] array = { i }; + int[] array = [i]; matrix.GetProbabilityVector(chain.Alphabet, array); } diff --git a/Libiada.PhantomChains.Tests/PhantomChainGeneratorTests.cs b/Libiada.PhantomChains.Tests/PhantomChainGeneratorTests.cs index 09831f15..d71a6a29 100644 --- a/Libiada.PhantomChains.Tests/PhantomChainGeneratorTests.cs +++ b/Libiada.PhantomChains.Tests/PhantomChainGeneratorTests.cs @@ -34,9 +34,9 @@ public void Initialize() [Test] public void FirstTest() { - var resultChain = new BaseChain([1, 2, 2, 1, 2, 1, 2, 1, 2, 2], [NullValue.Instance(), mother.PhantomMessageBc[1], mother.PhantomMessageA[0]]); + BaseChain resultChain = new([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()); + PhantomChainGenerator gen = new(mother.SourceChain, new MockGenerator()); List result = gen.Generate(1); Assert.That(result, Has.Count.EqualTo(1)); Assert.That(result[0], Is.EqualTo(resultChain)); @@ -48,10 +48,10 @@ public void FirstTest() [Test] public void SecondTest() { - var resultChain = new BaseChain( + BaseChain resultChain = new( [1, 2, 1, 2, 3], [NullValue.Instance(), mother.PhantomMessageBc[1], mother.PhantomMessageA[0], mother.PhantomMessageBc[0]]); - var gen = new PhantomChainGenerator(mother.UnnormalizedChain, new MockGenerator()); + PhantomChainGenerator gen = new(mother.UnnormalizedChain, new MockGenerator()); List result = gen.Generate(1); Assert.That(result, Has.Count.EqualTo(1)); Assert.That(result[0], Is.EqualTo(resultChain)); @@ -63,15 +63,15 @@ public void SecondTest() [Test] public void ThirdTest() { - var resultChain = new BaseChain(63); - var iterator = new IteratorWritableStart(resultChain); + BaseChain resultChain = new(63); + IteratorWritableStart iterator = new(resultChain); iterator.Reset(); while (iterator.Next()) { iterator.WriteValue(mother.PhantomMessageBc); } - var gen = new PhantomChainGenerator(resultChain, new SimpleGenerator()); + PhantomChainGenerator gen = new(resultChain, new SimpleGenerator()); List result = gen.Generate(3000); Assert.That(result, Has.Count.EqualTo(3000)); } @@ -82,15 +82,15 @@ public void ThirdTest() [Test] public void FourthTest() { - var resultChain = new BaseChain(10); - var iterator = new IteratorWritableStart(resultChain); + BaseChain resultChain = new(10); + IteratorWritableStart iterator = new(resultChain); iterator.Reset(); while (iterator.Next()) { iterator.WriteValue(mother.PhantomMessageBc); } - var gen = new PhantomChainGenerator(resultChain, new SimpleGenerator()); + PhantomChainGenerator gen = new(resultChain, new SimpleGenerator()); List res = gen.Generate(1000); int counter = 0; for (int i = 0; i < 999; i++) @@ -113,9 +113,9 @@ public void FourthTest() [Test] public void SixthTest() { - var sourceChain = new BaseChain(new List() { (ValueString)"X", (ValueString)"S", (ValueString)"C" }); + BaseChain sourceChain = new(new List() { (ValueString)"X", (ValueString)"S", (ValueString)"C" }); BaseChain forBuild = DnaTransformer.Decode(sourceChain); - var gen = new PhantomChainGenerator(forBuild, new SimpleGenerator()); + PhantomChainGenerator gen = new(forBuild, new SimpleGenerator()); List result = gen.Generate(1); Assert.That(result[0].Length, Is.EqualTo(9)); } diff --git a/Libiada.PhantomChains.Tests/TreeTests.cs b/Libiada.PhantomChains.Tests/TreeTests.cs index 227aae3b..23608b6d 100644 --- a/Libiada.PhantomChains.Tests/TreeTests.cs +++ b/Libiada.PhantomChains.Tests/TreeTests.cs @@ -17,14 +17,14 @@ public class TreeTests [Test] public void TreeVolumeTest() { - var m1 = new ValuePhantom { new ValueString('1'), new ValueString('2'), new ValueString('3') }; - var m2 = new ValuePhantom { new ValueString('4'), new ValueString('3') }; - var m3 = new ValuePhantom { new ValueString('a') }; + ValuePhantom m1 = [new ValueString('1'), new ValueString('2'), new ValueString('3')]; + ValuePhantom m2 = [new ValueString('4'), new ValueString('3')]; + ValuePhantom m3 = [new ValueString('a')]; - var test = new BaseChain(new List(){ m1, m2, m2, m3 }); + BaseChain test = new(new List(){ m1, m2, m2, m3 }); IGenerator generator = new SimpleGenerator(); - var tree = new TreeTop(test, generator); + TreeTop tree = new(test, generator); Assert.That(tree.Volume, Is.EqualTo(12)); TreeNode ch1 = tree.GetChild(0); Assert.That(ch1.Volume, Is.EqualTo(4)); diff --git a/Libiada.PhantomChains/AbstractNode.cs b/Libiada.PhantomChains/AbstractNode.cs index 7d5222e9..f11cd215 100644 --- a/Libiada.PhantomChains/AbstractNode.cs +++ b/Libiada.PhantomChains/AbstractNode.cs @@ -12,7 +12,7 @@ public abstract class AbstractNode /// /// The children. /// - protected readonly List Children = new List(); + protected readonly List Children = []; /// /// Gets or sets count of children elements. diff --git a/Libiada.PhantomChains/PhantomChainGenerator.cs b/Libiada.PhantomChains/PhantomChainGenerator.cs index db86f90a..45a6857d 100644 --- a/Libiada.PhantomChains/PhantomChainGenerator.cs +++ b/Libiada.PhantomChains/PhantomChainGenerator.cs @@ -24,7 +24,7 @@ public class PhantomChainGenerator /// /// The temp chains. /// - private readonly List tempChains = new List(); + private readonly List tempChains = []; /// /// The gen. @@ -34,7 +34,7 @@ public class PhantomChainGenerator /// /// Variants trees for separate fragments of phantom sequence (length 30 elements). /// - private readonly List tree = new List(); + private readonly List tree = []; /// /// The total length. @@ -53,8 +53,8 @@ public class PhantomChainGenerator public PhantomChainGenerator(BaseChain chain, IGenerator generator) { this.generator = generator; - var reorganizer = new SpacePhantomReorganizer(); - var internalChain = (BaseChain)reorganizer.Reorganize(chain); + SpacePhantomReorganizer reorganizer = new(); + BaseChain internalChain = (BaseChain)reorganizer.Reorganize(chain); for (int w = 0; w < internalChain.Length; w++) { totalLength += ((ValuePhantom)internalChain[w])[0].ToString().Length; @@ -82,7 +82,7 @@ public PhantomChainGenerator(BaseChain chain, IGenerator generator) } else { - tempMessage = new ValuePhantom { new ValueString('a') }; + tempMessage = [new ValueString('a')]; tempChains[i][j] = tempMessage; } @@ -116,8 +116,8 @@ public List Generate(ulong count) throw new Exception(); } - var res = new List(); - var tempRes = new List(); + List res = []; + List tempRes = []; for (int m = 0; m < tree.Count; m++) { tempRes.Add(null); @@ -149,7 +149,7 @@ public List Generate(ulong count) chainCounter++; if (tree.Count != 1) { - tree[tree.Count - 1] = new TreeTop(tempChains[tempChains.Count - 1], generator); + tree[^1] = new TreeTop(tempChains[^1], generator); } } diff --git a/Libiada.PhantomChains/PhantomTable.cs b/Libiada.PhantomChains/PhantomTable.cs index 2e0f8847..c1ee7380 100644 --- a/Libiada.PhantomChains/PhantomTable.cs +++ b/Libiada.PhantomChains/PhantomTable.cs @@ -11,12 +11,12 @@ public class PhantomTable /// /// List of starts positions of trees in phantom chain. /// - public readonly List StartPositions = new List(); + public readonly List StartPositions = []; /// /// The table. /// - private readonly List table = new List(); + private readonly List table = []; /// /// Initializes a new instance of the class. @@ -53,7 +53,7 @@ public PhantomTable(BaseChain source) } // tree root is associated with phantom message - var t = new ValuePhantom { NullValue.Instance() }; + ValuePhantom t = [NullValue.Instance()]; table[0] = new Record(t, v); } diff --git a/Libiada.PhantomChains/TreeTop.cs b/Libiada.PhantomChains/TreeTop.cs index 3f4caae6..144f5d53 100644 --- a/Libiada.PhantomChains/TreeTop.cs +++ b/Libiada.PhantomChains/TreeTop.cs @@ -91,7 +91,7 @@ public BaseChain Generate() { int len = table.Length - 1; len *= isString ? 3 : 1; - var result = new BaseChain(len); + BaseChain result = new(len); Find(result, generator, table); return result; diff --git a/Libiada.Segmenter.Tests/Base/Collectors/FrequencyDictionaryTests.cs b/Libiada.Segmenter.Tests/Base/Collectors/FrequencyDictionaryTests.cs index c932ced2..3e8ad12a 100644 --- a/Libiada.Segmenter.Tests/Base/Collectors/FrequencyDictionaryTests.cs +++ b/Libiada.Segmenter.Tests/Base/Collectors/FrequencyDictionaryTests.cs @@ -21,7 +21,7 @@ public class FrequencyDictionaryTests [Test] public void PutTest() { - var alphabet = new FrequencyDictionary(chain); + FrequencyDictionary alphabet = new(chain); const string word = "string"; const string unknown = "WOW"; const int pos = 20; @@ -40,7 +40,7 @@ public void PutTest() [Test] public void ContainsTest() { - var alphabet = new FrequencyDictionary(chain); + FrequencyDictionary alphabet = new(chain); string[] words = ["A", "G", "C", "T", "WORD", "AG"]; Assert.Multiple(() => { @@ -60,7 +60,7 @@ public void ContainsTest() public void GetTest() { // AACAGGTGCCCCTTATTT - var alphabet = new FrequencyDictionary(chain); + FrequencyDictionary alphabet = new(chain); string[] words = ["A", "G", "C", "T", "WORD", "AG"]; int[] positionsA = [0, 1, 3, 14]; int[] positionsG = [4, 5, 7]; @@ -82,7 +82,7 @@ public void GetTest() [Test] public void RemoveTest() { - var alphabet = new FrequencyDictionary(chain); + FrequencyDictionary alphabet = new(chain); string[] words = ["A", "G", "C", "T", "WORD", "AG"]; alphabet.Remove(words[0]); Assert.That(!alphabet.Contains(words[0])); @@ -101,7 +101,7 @@ public void RemoveTest() [Test] public void GetWordsTest() { - var alphabet = new FrequencyDictionary(chain); + FrequencyDictionary alphabet = new(chain); string[] words = ["A", "G", "C", "T"]; List alphabetWords = alphabet.GetWords(); Assert.That(!words.Except(alphabetWords).Any()); @@ -114,8 +114,8 @@ public void GetWordsTest() public void FillOneTest() { string str = chain.ToString(); - var alphabet1 = new FrequencyDictionary(str); - var alphabet2 = new FrequencyDictionary(chain); + FrequencyDictionary alphabet1 = new(str); + FrequencyDictionary alphabet2 = new(chain); Assert.That(alphabet1, Is.EqualTo(alphabet2)); } @@ -134,7 +134,7 @@ public void FillTwoTest() [Test] public void PowerTest() { - var alphabetChain = new FrequencyDictionary(chain); + FrequencyDictionary alphabetChain = new(chain); const int power = 4; Assert.That(alphabetChain.Count, Is.EqualTo(power)); } @@ -145,7 +145,7 @@ public void PowerTest() [Test] public void ClearTest() { - var alphabet = new FrequencyDictionary(chain); + FrequencyDictionary alphabet = new(chain); alphabet.Clear(); Assert.That(alphabet.Count, Is.EqualTo(0)); } @@ -156,8 +156,8 @@ public void ClearTest() [Test] public void AddTest() { - var alphabet = new FrequencyDictionary(); - var alphabetTest = new FrequencyDictionary(chain); + FrequencyDictionary alphabet = new(); + FrequencyDictionary alphabetTest = new(chain); string[] words = ["A", "G", "C", "T"]; const int power = 1; alphabet.Add(words[0], alphabetTest[words[0]]); @@ -176,8 +176,8 @@ public void AddTest() public void CloneTest() { string str = chain.ToString(); - var alphabet1 = new FrequencyDictionary(str); - var alphabet2 = new FrequencyDictionary(chain); + FrequencyDictionary alphabet1 = new(str); + FrequencyDictionary alphabet2 = new(chain); FrequencyDictionary alphabet3 = alphabet2.Clone(); Assert.Multiple(() => { @@ -193,8 +193,8 @@ public void CloneTest() public void EqualsTest() { string str = chain.ToString(); - var alphabet1 = new FrequencyDictionary(str); - var alphabet2 = new FrequencyDictionary(chain); + FrequencyDictionary alphabet1 = new(str); + FrequencyDictionary alphabet2 = new(chain); Assert.That(alphabet1, Is.EqualTo(alphabet2)); alphabet1.Remove(alphabet1.GetWord(1)); Assert.That(alphabet1, Is.Not.EqualTo(alphabet2)); @@ -206,7 +206,7 @@ public void EqualsTest() [Test] public void GetWordTest() { - var alphabet = new FrequencyDictionary(chain); + FrequencyDictionary alphabet = new(chain); for (int index = 0; index < alphabet.Count; index++) { Assert.That(alphabet.Contains(alphabet.GetWord(index))); diff --git a/Libiada.Segmenter.Tests/Base/Iterators/StartIteratorTests.cs b/Libiada.Segmenter.Tests/Base/Iterators/StartIteratorTests.cs index deaf9234..0798a3d9 100644 --- a/Libiada.Segmenter.Tests/Base/Iterators/StartIteratorTests.cs +++ b/Libiada.Segmenter.Tests/Base/Iterators/StartIteratorTests.cs @@ -34,7 +34,7 @@ public void HasNextTest() const int step = 1; int countSteps = 0; - var iterator = new StartIterator(chain, lengthCut, step); + StartIterator iterator = new(chain, lengthCut, step); while (iterator.HasNext()) { iterator.Next(); @@ -70,7 +70,7 @@ public void NextTest() const int lengthCut = 3; const int step = 1; - var iterator = new StartIterator(chain, lengthCut, step); + StartIterator iterator = new(chain, lengthCut, step); for (int i = 0; i < iterator.MaxShifts; i++) { @@ -95,7 +95,7 @@ public void ResetTest() { const int length = 2; const int step = 1; - var iterator = new StartIterator(chain, length, step); + StartIterator iterator = new(chain, length, step); if (iterator.Move(3)) { iterator.Reset(); @@ -113,7 +113,7 @@ public void MoveTest() int length = 2; int step = 1; int position = 3; - var iterator = new StartIterator(chain, length, step); + StartIterator iterator = new(chain, length, step); iterator.Move(position); Assert.That(iterator.CursorPosition, Is.EqualTo(position)); @@ -148,7 +148,7 @@ public void GetMaxShiftsTest() const int lengthCut = 3; const int step = 1; const int maxShifts = 16; - var iterator = new StartIterator(chain, lengthCut, step); + StartIterator iterator = new(chain, lengthCut, step); Assert.That(iterator.MaxShifts, Is.EqualTo(maxShifts)); } @@ -160,7 +160,7 @@ public void GetPositionTest() { const int lengthCut = 2; const int step = 1; - var iterator = new StartIterator(chain, lengthCut, step); + StartIterator iterator = new(chain, lengthCut, step); iterator.Next(); Assert.That(iterator.CursorPosition, Is.EqualTo(0)); iterator.Next(); diff --git a/Libiada.Segmenter.Tests/Base/Seekers/Converters/FilterTests.cs b/Libiada.Segmenter.Tests/Base/Seekers/Converters/FilterTests.cs index 3da8ab39..05a3496c 100644 --- a/Libiada.Segmenter.Tests/Base/Seekers/Converters/FilterTests.cs +++ b/Libiada.Segmenter.Tests/Base/Seekers/Converters/FilterTests.cs @@ -43,12 +43,12 @@ public void SetUp() [Test] public void FilteroutTest() { - var chain = new ComplexChain(list); - var filter = new Filter(chain); + ComplexChain chain = new(list); + Filter filter = new(chain); int hits = filter.FilterOut(str1); // TODO: find out why this code is not used - var sb = new StringBuilder(list.Count); + StringBuilder sb = new(list.Count); foreach (string s in list) { sb.Append(s); @@ -72,11 +72,11 @@ public void FilteroutTest() [Test] public void ReplaceTest() { - var chain = new ComplexChain(list); - var filter = new Filter(chain); + ComplexChain chain = new(list); + Filter filter = new(chain); int hits = filter.Replace(str2, "-"); - var sb = new StringBuilder(list.Count); + StringBuilder sb = new(list.Count); foreach (string s in list) { sb.Append(s); diff --git a/Libiada.Segmenter.Tests/Model/Threshold/ThresholdLinearTests.cs b/Libiada.Segmenter.Tests/Model/Threshold/ThresholdLinearTests.cs index c5a1d17a..32c0104a 100644 --- a/Libiada.Segmenter.Tests/Model/Threshold/ThresholdLinearTests.cs +++ b/Libiada.Segmenter.Tests/Model/Threshold/ThresholdLinearTests.cs @@ -22,7 +22,7 @@ public void NextTest() 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; const Criterion? criterion = null; - var threshold = new ThresholdLinear(left, right, step); + ThresholdLinear threshold = new(left, right, step); while ((current = threshold.Next(criterion)) > 0) { diff --git a/Libiada.Segmenter/Base/Collectors/DataCollector.cs b/Libiada.Segmenter/Base/Collectors/DataCollector.cs index 7ef3ad67..d7b25494 100644 --- a/Libiada.Segmenter/Base/Collectors/DataCollector.cs +++ b/Libiada.Segmenter/Base/Collectors/DataCollector.cs @@ -10,7 +10,7 @@ public class DataCollector /// /// The dictionary. /// - private Dictionary, List> dictionary = new Dictionary, List>(); + private Dictionary, List> dictionary = []; /// /// The add. @@ -44,7 +44,7 @@ public void Add(List accord, int position, int step) { if (!dictionary.ContainsKey(accord)) { - dictionary.Add(accord, new List()); + dictionary.Add(accord, []); } dictionary[accord].Add(position + step); diff --git a/Libiada.Segmenter/Base/Collectors/FrequencyDictionary.cs b/Libiada.Segmenter/Base/Collectors/FrequencyDictionary.cs index 0f554cd7..385b4dbf 100644 --- a/Libiada.Segmenter/Base/Collectors/FrequencyDictionary.cs +++ b/Libiada.Segmenter/Base/Collectors/FrequencyDictionary.cs @@ -11,7 +11,7 @@ public class FrequencyDictionary /// /// The words. /// - private Dictionary> words = new Dictionary>(); + private Dictionary> words = []; /// /// Initializes a new instance of the class. @@ -108,7 +108,7 @@ public List> GetWordsPositions() /// public List>> SortByPower() { - var list = new List>>(words); + List>> list = new(words); list.Sort((firstPair, nextPair) => firstPair.Value.Count.CompareTo(nextPair.Value.Count)); list.Reverse(); @@ -124,7 +124,7 @@ public List GetWords() { if (words.Count == 0) { - return new List(); + return []; } return new List(words.Keys); @@ -165,7 +165,7 @@ public void Put(string str, int pos) if (!words.ContainsKey(str)) { - var wordPositions = new List { pos }; + List wordPositions = [pos]; words.Add(str, wordPositions); } else @@ -255,7 +255,7 @@ public void Add(string str, List pos) /// public FrequencyDictionary Clone() { - var alphabet = new FrequencyDictionary(); + FrequencyDictionary alphabet = new(); for (IEnumerator e = words.Keys.GetEnumerator(); e.MoveNext();) { string word = e.Current; diff --git a/Libiada.Segmenter/Base/Iterators/BaseIterator.cs b/Libiada.Segmenter/Base/Iterators/BaseIterator.cs index 20f33eff..d15bebbb 100644 --- a/Libiada.Segmenter/Base/Iterators/BaseIterator.cs +++ b/Libiada.Segmenter/Base/Iterators/BaseIterator.cs @@ -26,7 +26,7 @@ public abstract class BaseIterator : IIterator /// /// The currentCut composed sequence was extracted from a chain /// - protected List currentCut = new List(); + protected List currentCut = []; /// /// Initializes a new instance of the class. diff --git a/Libiada.Segmenter/Base/Iterators/EndIterator.cs b/Libiada.Segmenter/Base/Iterators/EndIterator.cs index 14f27030..3faa29af 100644 --- a/Libiada.Segmenter/Base/Iterators/EndIterator.cs +++ b/Libiada.Segmenter/Base/Iterators/EndIterator.cs @@ -44,7 +44,7 @@ public override bool HasNext() /// public override List Next() { - CursorPosition = CursorPosition - step; + CursorPosition -= step; try { currentCut = chain.Substring(CursorPosition, CursorPosition + windowLength); diff --git a/Libiada.Segmenter/Base/Iterators/StartIterator.cs b/Libiada.Segmenter/Base/Iterators/StartIterator.cs index bf71482c..3b7042c4 100644 --- a/Libiada.Segmenter/Base/Iterators/StartIterator.cs +++ b/Libiada.Segmenter/Base/Iterators/StartIterator.cs @@ -46,7 +46,7 @@ public override List Next() { try { - CursorPosition = CursorPosition + step; + CursorPosition += step; currentCut = chain.Substring(CursorPosition, CursorPosition + windowLength); } catch (Exception) diff --git a/Libiada.Segmenter/Base/Seekers/Converters/SequenceCleaner.cs b/Libiada.Segmenter/Base/Seekers/Converters/SequenceCleaner.cs index 2edb475a..5cb694dc 100644 --- a/Libiada.Segmenter/Base/Seekers/Converters/SequenceCleaner.cs +++ b/Libiada.Segmenter/Base/Seekers/Converters/SequenceCleaner.cs @@ -49,7 +49,7 @@ public int FilterOut(List sequence) if (chainsEquals) { Chain.Remove(iterator.Position(), sequence.Count); - hits = hits + 1; + hits++; } } diff --git a/Libiada.Segmenter/Base/Seekers/Seeker.cs b/Libiada.Segmenter/Base/Seekers/Seeker.cs index fbacb892..97056c6a 100644 --- a/Libiada.Segmenter/Base/Seekers/Seeker.cs +++ b/Libiada.Segmenter/Base/Seekers/Seeker.cs @@ -52,7 +52,7 @@ public List Arrangement /// public override int Seek(List required) { - result = new List(); + result = []; while (iterator.HasNext()) { List sequence = iterator.Next(); diff --git a/Libiada.Segmenter/Base/Seekers/SeekerSequence.cs b/Libiada.Segmenter/Base/Seekers/SeekerSequence.cs index 4cf4d147..682afdc1 100644 --- a/Libiada.Segmenter/Base/Seekers/SeekerSequence.cs +++ b/Libiada.Segmenter/Base/Seekers/SeekerSequence.cs @@ -29,7 +29,7 @@ public SeekerSequence(IIterator where) /// public override int Seek(List sequence) { - result = new List(); + result = []; while (iterator.HasNext()) { List chain = iterator.Next(); diff --git a/Libiada.Segmenter/Base/Sequences/ComplexChain.cs b/Libiada.Segmenter/Base/Sequences/ComplexChain.cs index 08e606e5..0428eb81 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(Length); + List result = new(Length); for (int i = 0; i < Length; i++) { result.Add(this[i].ToString()); @@ -123,7 +123,7 @@ public override void DeleteAt(int index) /// public new ComplexChain Clone() { - var chain = new ComplexChain(ToList()) { Anchor = Anchor }; + ComplexChain chain = new(ToList()) { Anchor = Anchor }; return chain; } @@ -251,7 +251,7 @@ public void Remove(int pos, int len) public void Join(int pos, int len) { int wordEnd = pos + len; - var temporarySplice = new StringBuilder(); + StringBuilder temporarySplice = new(); temporarySplice.Clear(); if (wordEnd > Length) { diff --git a/Libiada.Segmenter/Extended/Helper.cs b/Libiada.Segmenter/Extended/Helper.cs index 3e140c8c..48a757c0 100644 --- a/Libiada.Segmenter/Extended/Helper.cs +++ b/Libiada.Segmenter/Extended/Helper.cs @@ -18,7 +18,7 @@ public static class Helper /// public static string ToString(List list) { - var result = new StringBuilder(); + StringBuilder result = new(); foreach (string element in list) { result.Append(element); diff --git a/Libiada.Segmenter/Model/Algorithm.cs b/Libiada.Segmenter/Model/Algorithm.cs index 41f1873a..054e9e06 100644 --- a/Libiada.Segmenter/Model/Algorithm.cs +++ b/Libiada.Segmenter/Model/Algorithm.cs @@ -8,12 +8,12 @@ public class Algorithm /// /// The results. /// - protected List results = new List(); + protected List results = []; /// /// The inputs. /// - protected List inputs = new List(); + protected List inputs = []; /// /// Initializes a new instance of the class. diff --git a/Libiada.Segmenter/Model/AlgorithmBase.cs b/Libiada.Segmenter/Model/AlgorithmBase.cs index 7d9a4776..18000642 100644 --- a/Libiada.Segmenter/Model/AlgorithmBase.cs +++ b/Libiada.Segmenter/Model/AlgorithmBase.cs @@ -82,14 +82,16 @@ public AlgorithmBase(Input parameters) /// public new void Slot() { - var par = new Dictionary(); - par.Add("Sequence", chain = new ComplexChain(inputs[0].Chain)); - par.Add("Alphabet", alphabet = new FrequencyDictionary(chain)); + Dictionary par = new() + { + { "Sequence", chain = new ComplexChain(inputs[0].Chain) }, + { "Alphabet", alphabet = new FrequencyDictionary(chain) } + }; while (criterion.State(chain, alphabet)) { UpdateParams(par, threshold.Next(criterion)); - var chainSplitter = new SimpleChainSplitter(extractor); + SimpleChainSplitter chainSplitter = new(extractor); chain = chainSplitter.Cut(par); alphabet = chainSplitter.FrequencyDictionary; } @@ -103,7 +105,7 @@ public AlgorithmBase(Input parameters) /// public new List Upload() { - var resultUpdate = new MainOutputData(); + MainOutputData resultUpdate = new(); resultUpdate.AddInfo((IIdentifiable)criterion, criterion.Value); resultUpdate.AddInfo((IIdentifiable)threshold, threshold.Value); diff --git a/Libiada.Segmenter/Model/AlgorithmFactory.cs b/Libiada.Segmenter/Model/AlgorithmFactory.cs index 5a9821c9..39ae1568 100644 --- a/Libiada.Segmenter/Model/AlgorithmFactory.cs +++ b/Libiada.Segmenter/Model/AlgorithmFactory.cs @@ -19,14 +19,11 @@ public static class AlgorithmFactory /// public static Algorithm Make(int index, Input input) { - switch (index) + return index switch { - case 0: - return new AlgorithmBase(input); - case 1: - return null; - default: - throw new ArgumentException("Unknown index", "index"); - } + 0 => new AlgorithmBase(input), + 1 => null, + _ => throw new ArgumentException("Unknown index", "index"), + }; } } diff --git a/Libiada.Segmenter/Model/Criterion/CriterionAttitudeOfRemoteness.cs b/Libiada.Segmenter/Model/Criterion/CriterionAttitudeOfRemoteness.cs index 8382dd72..f8a09ca1 100644 --- a/Libiada.Segmenter/Model/Criterion/CriterionAttitudeOfRemoteness.cs +++ b/Libiada.Segmenter/Model/Criterion/CriterionAttitudeOfRemoteness.cs @@ -15,12 +15,12 @@ public class CriterionAttitudeOfRemoteness : Criterion /// /// The word average length. /// - private readonly AverageWordLength wordAverageLength = new AverageWordLength(); + private readonly AverageWordLength wordAverageLength = new(); /// /// The remoteness. /// - private readonly AverageRemoteness remoteness = new AverageRemoteness(); + private readonly AverageRemoteness remoteness = new(); /// /// Initializes a new instance of the class. diff --git a/Libiada.Segmenter/Model/Criterion/CriterionEqualityOfDepths.cs b/Libiada.Segmenter/Model/Criterion/CriterionEqualityOfDepths.cs index 1e0d0792..5057d297 100644 --- a/Libiada.Segmenter/Model/Criterion/CriterionEqualityOfDepths.cs +++ b/Libiada.Segmenter/Model/Criterion/CriterionEqualityOfDepths.cs @@ -14,7 +14,7 @@ public class CriterionEqualityOfDepths : Criterion /// /// The depth. /// - private readonly Depth depth = new Depth(); + private readonly Depth depth = new(); /// /// Initializes a new instance of the class. diff --git a/Libiada.Segmenter/Model/Criterion/CriterionFactory.cs b/Libiada.Segmenter/Model/Criterion/CriterionFactory.cs index bed82be6..f3a2c8c9 100644 --- a/Libiada.Segmenter/Model/Criterion/CriterionFactory.cs +++ b/Libiada.Segmenter/Model/Criterion/CriterionFactory.cs @@ -25,24 +25,16 @@ public static class CriterionFactory /// public static Criterion Make(SegmentationCriterion criterion, ThresholdVariator threshold, double precision) { - switch (criterion) + return criterion switch { - case SegmentationCriterion.CriterionPartialOrlov: - return new CriterionPartialOrlov(threshold, precision); - case SegmentationCriterion.CriterionMinSymmetryByShrader: - return new CriterionMinSymmetryByShrader(threshold, precision); - case SegmentationCriterion.CriterionMinSymmetryByIntervals: - return new CriterionMinSymmetryByIntervals(threshold, precision); - case SegmentationCriterion.CriterionEqualityOfDepths: - return new CriterionEqualityOfDepths(threshold, precision); - case SegmentationCriterion.CriterionAttitudeOfRemoteness: - return new CriterionAttitudeOfRemoteness(threshold, precision); - case SegmentationCriterion.CriterionMinimumRegularity: - return new CriterionMinimumRegularity(threshold, precision); - case SegmentationCriterion.CriterionGoldenRatio: - return new CriterionGoldenRatio(threshold, precision); - default: - throw new InvalidEnumArgumentException(nameof(criterion), (int)criterion, typeof(SegmentationCriterion)); - } + SegmentationCriterion.CriterionPartialOrlov => new CriterionPartialOrlov(threshold, precision), + SegmentationCriterion.CriterionMinSymmetryByShrader => new CriterionMinSymmetryByShrader(threshold, precision), + SegmentationCriterion.CriterionMinSymmetryByIntervals => new CriterionMinSymmetryByIntervals(threshold, precision), + SegmentationCriterion.CriterionEqualityOfDepths => new CriterionEqualityOfDepths(threshold, precision), + SegmentationCriterion.CriterionAttitudeOfRemoteness => new CriterionAttitudeOfRemoteness(threshold, precision), + SegmentationCriterion.CriterionMinimumRegularity => new CriterionMinimumRegularity(threshold, precision), + SegmentationCriterion.CriterionGoldenRatio => new CriterionGoldenRatio(threshold, precision), + _ => throw new InvalidEnumArgumentException(nameof(criterion), (int)criterion, typeof(SegmentationCriterion)), + }; } } diff --git a/Libiada.Segmenter/Model/Criterion/CriterionMethod.cs b/Libiada.Segmenter/Model/Criterion/CriterionMethod.cs index e0f34918..c2d8de4c 100644 --- a/Libiada.Segmenter/Model/Criterion/CriterionMethod.cs +++ b/Libiada.Segmenter/Model/Criterion/CriterionMethod.cs @@ -48,7 +48,7 @@ public double DesignExpected(List accord, int chainLength, int winLen, D List left = minusOne.Positions(accord.GetRange(0, accord.Count - 1)); List right = minusOne.Positions(accord.GetRange(1, accord.Count - 1)); - List middle = midlLength != 0 ? mid.Positions(accord.GetRange(1, accord.Count - 2)) : new List(); + List middle = midlLength != 0 ? mid.Positions(accord.GetRange(1, accord.Count - 2)) : []; double criteria = -1; if (winLen == shortWord) @@ -94,7 +94,7 @@ public double IntervalEstimate(List stdData, int chainLength, int winLen, L int minusLength = winLen - 1; int start = stdData[0] + 1; - int end = chainLength - stdData[stdData.Count - 1] - minusLength; + int end = chainLength - stdData[^1] - minusLength; int pred = stdData[0]; int j = 1; double multiplicate = 1; @@ -109,17 +109,13 @@ public double IntervalEstimate(List stdData, int chainLength, int winLen, L } } - switch (anchor) + return anchor switch { - case Link.Start: - return 1 / Math.Pow(multiplicate * start, 1 / (double)j); - case Link.End: - return 1 / Math.Pow(multiplicate * end, 1 / (double)j); - case Link.Both: - return 0; - default: - return 0; - } + Link.Start => 1 / Math.Pow(multiplicate * start, 1 / (double)j), + Link.End => 1 / Math.Pow(multiplicate * end, 1 / (double)j), + Link.Both => 0, + _ => 0, + }; } /// diff --git a/Libiada.Segmenter/Model/Criterion/CriterionMinSymmetryByShrader.cs b/Libiada.Segmenter/Model/Criterion/CriterionMinSymmetryByShrader.cs index fc811a05..acb166fb 100644 --- a/Libiada.Segmenter/Model/Criterion/CriterionMinSymmetryByShrader.cs +++ b/Libiada.Segmenter/Model/Criterion/CriterionMinSymmetryByShrader.cs @@ -101,7 +101,7 @@ private double Symmetry(FrequencyDictionary alphabet) { if (positions[index].Count >= meronIndex) { - countM = countM + 1; + countM++; } } diff --git a/Libiada.Segmenter/Model/Criterion/CriterionMinimumRegularity.cs b/Libiada.Segmenter/Model/Criterion/CriterionMinimumRegularity.cs index 2dd14c77..8027e076 100644 --- a/Libiada.Segmenter/Model/Criterion/CriterionMinimumRegularity.cs +++ b/Libiada.Segmenter/Model/Criterion/CriterionMinimumRegularity.cs @@ -15,7 +15,7 @@ public class CriterionMinimumRegularity : Criterion /// /// The regularity. /// - private readonly DescriptiveInformation regularity = new DescriptiveInformation(); + private readonly DescriptiveInformation regularity = new(); /// /// Initializes a new instance of the class. diff --git a/Libiada.Segmenter/Model/Criterion/CriterionPartialOrlov.cs b/Libiada.Segmenter/Model/Criterion/CriterionPartialOrlov.cs index 6698c656..9f69ae5a 100644 --- a/Libiada.Segmenter/Model/Criterion/CriterionPartialOrlov.cs +++ b/Libiada.Segmenter/Model/Criterion/CriterionPartialOrlov.cs @@ -162,7 +162,7 @@ public double CalculateK(int factFrequency, int length) /// public double Frequency(ComplexChain chain, string word) { - var temp = new List(chain.Substring(0, chain.Length)); + List temp = new(chain.Substring(0, chain.Length)); return Frequency(temp, word) / (double)chain.Length; } @@ -178,7 +178,7 @@ public double Frequency(ComplexChain chain, string word) /// /// The . /// - public int Frequency(IEnumerable c, object o) + public int Frequency(IEnumerable c, object o) { int result = 0; if (o == null) diff --git a/Libiada.Segmenter/Model/MainOutputData.cs b/Libiada.Segmenter/Model/MainOutputData.cs index be2763c3..a83af2b1 100644 --- a/Libiada.Segmenter/Model/MainOutputData.cs +++ b/Libiada.Segmenter/Model/MainOutputData.cs @@ -26,7 +26,7 @@ public class MainOutputData /// /// The parameters. /// - private Dictionary parameters = new Dictionary(); + private Dictionary parameters = []; /// /// The get chain. diff --git a/Libiada.Segmenter/Model/PositionFilter.cs b/Libiada.Segmenter/Model/PositionFilter.cs index 8c5d7e9e..74b5fe75 100644 --- a/Libiada.Segmenter/Model/PositionFilter.cs +++ b/Libiada.Segmenter/Model/PositionFilter.cs @@ -15,7 +15,7 @@ public static List Filtrate(List std, int winLen) { if (std.Count == 0) { - return new List(); + return []; } int pos = 1; diff --git a/Libiada.Segmenter/Model/Seekers/DifferenceAverageIntervalExtractor.cs b/Libiada.Segmenter/Model/Seekers/DifferenceAverageIntervalExtractor.cs index 8ff4babd..4cdb4145 100644 --- a/Libiada.Segmenter/Model/Seekers/DifferenceAverageIntervalExtractor.cs +++ b/Libiada.Segmenter/Model/Seekers/DifferenceAverageIntervalExtractor.cs @@ -17,7 +17,7 @@ public class DifferenceAverageIntervalExtractor : WordExtractor /// public DifferenceAverageIntervalExtractor() { - wordPriority = new Dictionary, List>>(); + wordPriority = []; } /// @@ -31,15 +31,15 @@ public DifferenceAverageIntervalExtractor() /// public override sealed KeyValuePair, List>? Find(Dictionary par) { - var convoluted = (ComplexChain)par["Sequence"]; - var windowLen = (int)par["Window"]; - var alphabet = (FrequencyDictionary)par["Alphabet"]; - var level = (double)par["CurrentThreshold"]; + ComplexChain convoluted = (ComplexChain)par["Sequence"]; + int windowLen = (int)par["Window"]; + FrequencyDictionary alphabet = (FrequencyDictionary)par["Alphabet"]; + double level = (double)par["CurrentThreshold"]; int scanStep = 1; int disp = 0; - var it = new StartIterator(convoluted, windowLen, scanStep); + StartIterator it = new(convoluted, windowLen, scanStep); while (it.HasNext()) { @@ -63,13 +63,13 @@ public DifferenceAverageIntervalExtractor() /// public void CalculateStd(ComplexChain convoluted, int windowLen) { - var geometricMean = new GeometricMean(); - var arithmeticMean = new ArithmeticMean(); + GeometricMean geometricMean = new(); + ArithmeticMean arithmeticMean = new(); foreach (KeyValuePair, List> accord in fullEntry.Entry()) { PositionFilter.Filtrate(accord.Value, windowLen); - var temp = new ComplexChain(accord.Value); + ComplexChain temp = new(accord.Value); double geometric = geometricMean.Calculate(temp, convoluted.Anchor); double arithmetic = arithmeticMean.Calculate(temp, convoluted.Anchor); double std = 1 - (1 / Math.Abs(arithmetic - geometric)); diff --git a/Libiada.Segmenter/Model/Seekers/ProbabilityExtractor.cs b/Libiada.Segmenter/Model/Seekers/ProbabilityExtractor.cs index c03ff2de..596faa6d 100644 --- a/Libiada.Segmenter/Model/Seekers/ProbabilityExtractor.cs +++ b/Libiada.Segmenter/Model/Seekers/ProbabilityExtractor.cs @@ -21,11 +21,11 @@ public class ProbabilityExtractor : SubwordExtractor /// public override sealed KeyValuePair, List>? Find(Dictionary par) { - var convoluted = (ComplexChain)par["Sequence"]; + ComplexChain convoluted = (ComplexChain)par["Sequence"]; double pbalance = (int)par["Balance"] / 100.0; int windowLen = (int)par["Window"]; - var alphabet = (FrequencyDictionary)par["Alphabet"]; - var level = (double)par["CurrentThreshold"]; + FrequencyDictionary alphabet = (FrequencyDictionary)par["Alphabet"]; + double level = (double)par["CurrentThreshold"]; int scanStep = 1; int disp = 0; int length = convoluted.Length; @@ -34,7 +34,7 @@ public class ProbabilityExtractor : SubwordExtractor minusOneEntry = new DataCollector(); minusTwoEntry = new DataCollector(); - var it = new StartIterator(convoluted, windowLen, scanStep); + StartIterator it = new(convoluted, windowLen, scanStep); CriterionMethod criteriaCalculator = new ConvolutedCriterionMethod(); while (it.HasNext()) diff --git a/Libiada.Segmenter/Model/Seekers/SubwordExtractor.cs b/Libiada.Segmenter/Model/Seekers/SubwordExtractor.cs index 55431c93..5a65e202 100644 --- a/Libiada.Segmenter/Model/Seekers/SubwordExtractor.cs +++ b/Libiada.Segmenter/Model/Seekers/SubwordExtractor.cs @@ -11,12 +11,12 @@ public abstract class SubwordExtractor : WordExtractor /// /// The minus one entry. /// - protected DataCollector minusOneEntry = new DataCollector(); + protected DataCollector minusOneEntry = new(); /// /// The minus two entry. /// - protected DataCollector minusTwoEntry = new DataCollector(); + protected DataCollector minusTwoEntry = new(); /// /// Do not ask any questions, because it really very fast and redundant is also to the point diff --git a/Libiada.Segmenter/Model/Seekers/WordExtractor.cs b/Libiada.Segmenter/Model/Seekers/WordExtractor.cs index 92bfb422..e3d65d29 100644 --- a/Libiada.Segmenter/Model/Seekers/WordExtractor.cs +++ b/Libiada.Segmenter/Model/Seekers/WordExtractor.cs @@ -13,13 +13,12 @@ public abstract class WordExtractor /// /// The word priority. /// - protected Dictionary, List>> wordPriority = - new Dictionary, List>>(); + protected Dictionary, List>> wordPriority = []; /// /// The full entry. /// - protected DataCollector fullEntry = new DataCollector(); + protected DataCollector fullEntry = new(); /// /// Finds a word based on current parameters. @@ -46,8 +45,8 @@ public abstract class WordExtractor /// protected KeyValuePair, List>? DiscardCompositeWords(FrequencyDictionary alphabet, double level) { - var stds = new List(wordPriority.Keys); - var entries = new List, List>>(wordPriority.Values); + List stds = new(wordPriority.Keys); + List, List>> entries = new(wordPriority.Values); for (int index = entries.Count; --index >= 0;) { List entry = entries[index].Key; diff --git a/Libiada.Segmenter/Model/Seekers/WordExtractorFactory.cs b/Libiada.Segmenter/Model/Seekers/WordExtractorFactory.cs index 520f572a..fb743239 100644 --- a/Libiada.Segmenter/Model/Seekers/WordExtractorFactory.cs +++ b/Libiada.Segmenter/Model/Seekers/WordExtractorFactory.cs @@ -16,19 +16,15 @@ public static class WordExtractorFactory /// /// The . /// - public static WordExtractor GetSeeker(DeviationCalculationMethod deviationCalculationMethod) + public static WordExtractor? GetSeeker(DeviationCalculationMethod deviationCalculationMethod) { - switch (deviationCalculationMethod) + return deviationCalculationMethod switch { - case DeviationCalculationMethod.ProbabilityMethod: - return new ProbabilityExtractor(); - case DeviationCalculationMethod.AverageIntervalDifference: - return new DifferenceAverageIntervalExtractor(); - case DeviationCalculationMethod.Null: - return null; - default: - throw new InvalidEnumArgumentException(nameof(deviationCalculationMethod), (int)deviationCalculationMethod, typeof(DeviationCalculationMethod)); - } + DeviationCalculationMethod.ProbabilityMethod => new ProbabilityExtractor(), + DeviationCalculationMethod.AverageIntervalDifference => new DifferenceAverageIntervalExtractor(), + DeviationCalculationMethod.Null => null, + _ => throw new InvalidEnumArgumentException(nameof(deviationCalculationMethod), (int)deviationCalculationMethod, typeof(DeviationCalculationMethod)), + }; } /// @@ -40,7 +36,7 @@ public static WordExtractor GetSeeker(DeviationCalculationMethod deviationCalcul /// /// The . /// - public static WordExtractor GetSeeker(WordExtractor other) + public static WordExtractor? GetSeeker(WordExtractor other) { if (other is ProbabilityExtractor) { diff --git a/Libiada.Segmenter/Model/SimpleChainSplitter.cs b/Libiada.Segmenter/Model/SimpleChainSplitter.cs index b6303fab..de0a1031 100644 --- a/Libiada.Segmenter/Model/SimpleChainSplitter.cs +++ b/Libiada.Segmenter/Model/SimpleChainSplitter.cs @@ -99,7 +99,7 @@ private void FindLastWords() { if (!alphabet.Contains(letter)) { - alphabet.Add(letter, new List()); + alphabet.Add(letter, []); } alphabet.Put(letter, index); diff --git a/Libiada.Segmenter/Model/Threshold/ThresholdFactory.cs b/Libiada.Segmenter/Model/Threshold/ThresholdFactory.cs index aa199be8..45ef1a39 100644 --- a/Libiada.Segmenter/Model/Threshold/ThresholdFactory.cs +++ b/Libiada.Segmenter/Model/Threshold/ThresholdFactory.cs @@ -24,18 +24,13 @@ public static class ThresholdFactory /// public static ThresholdVariator Make(Threshold threshold, Input input) { - switch (threshold) + return threshold switch { - case Threshold.Linear: - return new ThresholdLinear(input.LeftBound, input.RightBound, input.Step); - case Threshold.Dichotomous: - return new ThresholdDichotomous(input.LeftBound, input.RightBound); - case Threshold.Random: - return new ThresholdRandom(input.LeftBound, input.RightBound); - case Threshold.Log: - return null; // Experimental threshold based on any log function - default: - throw new InvalidEnumArgumentException(nameof(threshold), (int)threshold, typeof(Threshold)); - } + Threshold.Linear => new ThresholdLinear(input.LeftBound, input.RightBound, input.Step), + Threshold.Dichotomous => new ThresholdDichotomous(input.LeftBound, input.RightBound), + Threshold.Random => new ThresholdRandom(input.LeftBound, input.RightBound), + Threshold.Log => null,// Experimental threshold based on any log function + _ => throw new InvalidEnumArgumentException(nameof(threshold), (int)threshold, typeof(Threshold)), + }; } } diff --git a/Libiada.Segmenter/PoemsSegmenter/FrequencySegmenter.cs b/Libiada.Segmenter/PoemsSegmenter/FrequencySegmenter.cs index e4adec7e..ff360650 100644 --- a/Libiada.Segmenter/PoemsSegmenter/FrequencySegmenter.cs +++ b/Libiada.Segmenter/PoemsSegmenter/FrequencySegmenter.cs @@ -18,10 +18,10 @@ public FrequencySegmenter(string textData, int maxLength, double threshold) public Dictionary Segmentation() { - List consonanceList = new List(); - Dictionary consonancesDictionary = new Dictionary(); + List consonanceList = []; + Dictionary consonancesDictionary = []; - StringBuilder stringBuilder = new StringBuilder(); + StringBuilder stringBuilder = new(); for (int i = 0; i < textData.Length; i++) { diff --git a/Libiada.Segmenter/PoemsSegmenter/PoemSegmenter.cs b/Libiada.Segmenter/PoemsSegmenter/PoemSegmenter.cs index 5fca414d..b30333ae 100644 --- a/Libiada.Segmenter/PoemsSegmenter/PoemSegmenter.cs +++ b/Libiada.Segmenter/PoemsSegmenter/PoemSegmenter.cs @@ -11,7 +11,7 @@ public class PoemSegmenter public double balance; public string startText; public string segmentedText = ""; - public List consonanceOrderedList = new List(); + public List consonanceOrderedList = []; public PoemSegmenter(string textData, int maxLength, double threshold, double balance) { @@ -24,7 +24,7 @@ public PoemSegmenter(string textData, int maxLength, double threshold, double ba public (Dictionary, string, string) StartSegmentation() { - Dictionary consonancesDictionary = new Dictionary(); + Dictionary consonancesDictionary = []; textData = textData.Replace("/n", ""); while (true) { @@ -32,7 +32,7 @@ public PoemSegmenter(string textData, int maxLength, double threshold, double ba consonanceOrderedList.Clear(); consonancesDictionary = Segmentation(); - var checkedDictionary = CheckSegmentationByCriteria(consonancesDictionary); + bool checkedDictionary = CheckSegmentationByCriteria(consonancesDictionary); if (checkedDictionary) { @@ -48,14 +48,14 @@ public PoemSegmenter(string textData, int maxLength, double threshold, double ba break; } } - var poemChain = GetPoemChain(); + string poemChain = GetPoemChain(); return (consonancesDictionary, poemChain, segmentedText); } public Dictionary Segmentation() { - Dictionary consonancesDictionary = new Dictionary(); - StringBuilder stringBuilder = new StringBuilder(); + Dictionary consonancesDictionary = []; + StringBuilder stringBuilder = new(); int n = maxLength; for (int i = 0; i < textData.Length; i++) { @@ -151,7 +151,7 @@ public Dictionary Segmentation() public Boolean CheckSegmentationByCriteria(Dictionary consonancesDictionary) { - PartialOrlovCriterion criterionPartialOrlov = new PartialOrlovCriterion(consonancesDictionary, text); + PartialOrlovCriterion criterionPartialOrlov = new(consonancesDictionary, text); double theoreticVolumeDictionary = criterionPartialOrlov.TheoreticalDictionaryVolume(); double actualVolumeDictionary = consonancesDictionary.Keys.Count; double difference = Math.Abs(actualVolumeDictionary - theoreticVolumeDictionary); diff --git a/Libiada.SequenceGenerator.Tests/IntervalsDistributionExtractorTests.cs b/Libiada.SequenceGenerator.Tests/IntervalsDistributionExtractorTests.cs index fd04a721..25270c27 100644 --- a/Libiada.SequenceGenerator.Tests/IntervalsDistributionExtractorTests.cs +++ b/Libiada.SequenceGenerator.Tests/IntervalsDistributionExtractorTests.cs @@ -20,7 +20,7 @@ public class IntervalsDistributionExtractorTests public void GetIntervalsDistributionTest(Link link) { List actualInternalsDistribution = new(orders.Length); - foreach (var order in orders) + foreach (int[] order in orders) { actualInternalsDistribution.Add(IntervalsDistributionExtractor.GetIntervalsDistribution(order, link)); } diff --git a/Libiada.SequenceGenerator.Tests/IntervalsDistributionsStorage.cs b/Libiada.SequenceGenerator.Tests/IntervalsDistributionsStorage.cs index 8f399462..143788b8 100644 --- a/Libiada.SequenceGenerator.Tests/IntervalsDistributionsStorage.cs +++ b/Libiada.SequenceGenerator.Tests/IntervalsDistributionsStorage.cs @@ -28,49 +28,49 @@ public static class IntervalsDistributionsStorage { Link.None, new IntervalsDistribution[] { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,3 } + { 1,3 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 } + { 1,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {2,1 } + { 1,1 }, + { 2,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 } + { 1,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 } + { 1,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {2,1 } + { 1,1 }, + { 2,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {2,2 } + { 2,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {2,1 } + { 2,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {3,1 } + { 1,1 }, + { 3,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 } + { 1,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 } + { 1,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {3,1 } + { 3,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {2,1 } + { 2,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 } + { 1,1 } }), new IntervalsDistribution().SetDistribution([]), } @@ -78,433 +78,433 @@ public static class IntervalsDistributionsStorage { Link.Start, new IntervalsDistribution[] { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,4 } + { 1,4 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,3 }, - {4,1 } + { 1,3 }, + { 4,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {3,1 } + { 1,2 }, + { 2,1 }, + { 3,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,3 }, - {3,1 } + { 1,3 }, + { 3,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {3,1 }, - {4,1 } + { 1,2 }, + { 3,1 }, + { 4,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,2 } + { 1,2 }, + { 2,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {2,3 } + { 1,1 }, + { 2,3 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {2,2 }, - {4,1 } + { 1,1 }, + { 2,2 }, + { 4,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {3,1 } + { 1,2 }, + { 2,1 }, + { 3,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,3 }, - {2,1 } + { 1,3 }, + { 2,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {4,1 } + { 1,2 }, + { 2,1 }, + { 4,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {2,1 }, + { 1,1 }, + { 2,1 }, { 3,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, + { 1,1 }, { 2,2 }, - {3,1 } + { 3,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {3,1 } + { 1,2 }, + { 2,1 }, + { 3,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {2,1 }, - {3,1 }, - {4,1 } + { 1,1 }, + { 2,1 }, + { 3,1 }, + { 4,1 } }), } }, { Link.End, new IntervalsDistribution[] { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,4 } + { 1,4 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,3 }, - {2,1 } + { 1,3 }, + { 2,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,2 } + { 1,2 }, + { 2,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,3 }, - {3,1 } + { 1,3 }, + { 3,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {3,1 } + { 1,2 }, + { 2,1 }, + { 3,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {3,1 } + { 1,2 }, + { 2,1 }, + { 3,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, + { 1,1 }, { 2,3 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, + { 1,1 }, { 2,2 }, - {3,1 } + { 3,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {3,1 } + { 1,2 }, + { 2,1 }, + { 3,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,3 }, - {4,1 } + { 1,3 }, + { 4,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {4,1 } + { 1,2 }, + { 2,1 }, + { 4,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {2,1 }, + { 1,1 }, + { 2,1 }, { 3,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ { 1,1}, { 2,2 }, - {4,1 } + { 4,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {3,1 }, - {4,1 } + { 1,2 }, + { 3,1 }, + { 4,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {2,1 }, - {3,1 }, - {4,1 } + { 1,1 }, + { 2,1 }, + { 3,1 }, + { 4,1 } }), } }, { Link.Both, new IntervalsDistribution[] { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,5 } + { 1,5 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,4 }, - {2,1 }, - {4,1 } + { 1,4 }, + { 2,1 }, + { 4,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,3 }, - {2,2 }, - {3,1 } + { 1,3 }, + { 2,2 }, + { 3,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,4 }, - {3,2 } + { 1,4 }, + { 3,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,3 }, - {2,1 }, - {3,2 }, - {4,1 } + { 1,3 }, + { 2,1 }, + { 3,2 }, + { 4,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,3 }, - {2,2 }, - {3,1 } + { 1,3 }, + { 2,2 }, + { 3,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,4 } + { 1,2 }, + { 2,4 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, + { 1,2 }, { 2,3 }, - {3,1 }, - {4,1 } + { 3,1 }, + { 4,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,3 }, - {2,2 }, - {3,1 } + { 1,3 }, + { 2,2 }, + { 3,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,4 }, - {2,1 }, - {4,1 } + { 1,4 }, + { 2,1 }, + { 4,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,3 }, - {2,2 }, - {4,2 } + { 1,3 }, + { 2,2 }, + { 4,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,2 }, + { 1,2 }, + { 2,2 }, { 3,3 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ { 1,2}, { 2,3 }, - {3,1 }, - {4,1 } + { 3,1 }, + { 4,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,3 }, - {2,1 }, - {3,2 }, - {4,1 } + { 1,3 }, + { 2,1 }, + { 3,2 }, + { 4,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,2 }, - {3,2 }, - {4,2 } + { 1,2 }, + { 2,2 }, + { 3,2 }, + { 4,2 } }), } }, { Link.Cycle, new IntervalsDistribution[] { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,4 } + { 1,4 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {4,1 } + { 1,2 }, + { 2,1 }, + { 4,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {4,1 } + { 1,2 }, + { 2,1 }, + { 4,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {3,2 } + { 1,2 }, + { 3,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {3,1 }, - {4,2 } + { 1,1 }, + { 3,1 }, + { 4,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {4,1 } + { 1,2 }, + { 2,1 }, + { 4,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {2,4 } + { 2,4 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {2,2 }, - {4,2 } + { 2,2 }, + { 4,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {3,2 } + { 1,2 }, + { 3,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {4,1 } + { 1,2 }, + { 2,1 }, + { 4,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {3,1 }, - {4,2 } + { 1,1 }, + { 3,1 }, + { 4,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, + { 1,1 }, { 3,1 }, - {4,2 } + { 4,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {2,2 }, - {4,2 } + { 2,2 }, + { 4,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {3,1 }, - {4,2 } + { 1,1 }, + { 3,1 }, + { 4,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {4,4 } + { 4,4 } }), } }, { Link.CycleStart, new IntervalsDistribution[] { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,4 } + { 1,4 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {4,1 } + { 1,2 }, + { 2,1 }, + { 4,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {4,1 } + { 1,2 }, + { 2,1 }, + { 4,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {3,2 } + { 1,2 }, + { 3,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {3,1 }, - {4,2 } + { 1,1 }, + { 3,1 }, + { 4,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {4,1 } + { 1,2 }, + { 2,1 }, + { 4,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {2,4 } + { 2,4 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {2,2 }, - {4,2 } + { 2,2 }, + { 4,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {3,2 } + { 1,2 }, + { 3,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {4,1 } + { 1,2 }, + { 2,1 }, + { 4,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {3,1 }, - {4,2 } + { 1,1 }, + { 3,1 }, + { 4,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, + { 1,1 }, { 3,1 }, - {4,2 } + { 4,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {2,2 }, - {4,2 } + { 2,2 }, + { 4,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {3,1 }, - {4,2 } + { 1,1 }, + { 3,1 }, + { 4,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {4,4 } + { 4,4 } }), } }, { Link.CycleEnd, new IntervalsDistribution[] { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,4 } + { 1,4 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {4,1 } + { 1,2 }, + { 2,1 }, + { 4,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {4,1 } + { 1,2 }, + { 2,1 }, + { 4,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {3,2 } + { 1,2 }, + { 3,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {3,1 }, - {4,2 } + { 1,1 }, + { 3,1 }, + { 4,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {4,1 } + { 1,2 }, + { 2,1 }, + { 4,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {2,4 } + { 2,4 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {2,2 }, - {4,2 } + { 2,2 }, + { 4,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {3,2 } + { 1,2 }, + { 3,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {4,1 } + { 1,2 }, + { 2,1 }, + { 4,1 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {3,1 }, - {4,2 } + { 1,1 }, + { 3,1 }, + { 4,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, + { 1,1 }, { 3,1 }, - {4,2 } + { 4,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {2,2 }, - {4,2 } + { 2,2 }, + { 4,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {3,1 }, - {4,2 } + { 1,1 }, + { 3,1 }, + { 4,2 } }), new IntervalsDistribution().SetDistribution(new Dictionary(){ - {4,4 } + { 4,4 } }), } } @@ -517,7 +517,7 @@ public static class IntervalsDistributionsStorage { { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,3 } + { 1,3 } }), new List(){ Orders[0] @@ -525,7 +525,7 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 } + { 1,2 } }), new List(){ Orders[1], @@ -535,8 +535,8 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {2,1 } + { 1,1 }, + { 2,1 } }), new List(){ Orders[2], @@ -545,7 +545,7 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 } + { 1,1 } }), new List(){ Orders[4], @@ -555,7 +555,7 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {2,2 } + { 2,2 } }), new List(){ Orders[6] @@ -563,7 +563,7 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {2,1 } + { 2,1 } }), new List(){ Orders[7], @@ -572,8 +572,8 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {3,1 } + { 1,1 }, + { 3,1 } }), new List(){ Orders[8] @@ -581,7 +581,7 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {3,1 } + { 3,1 } }), new List(){ Orders[11] @@ -599,7 +599,7 @@ public static class IntervalsDistributionsStorage { { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,4 } + { 1,4 } }), new List(){ Orders[0] @@ -607,8 +607,8 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,3 }, - {4,1 } + { 1,3 }, + { 4,1 } }), new List(){ Orders[1] @@ -616,9 +616,9 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {3,1 } + { 1,2 }, + { 2,1 }, + { 3,1 } }), new List(){ Orders[2], @@ -628,8 +628,8 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,3 }, - {3,1 } + { 1,3 }, + { 3,1 } }), new List(){ Orders[3] @@ -637,9 +637,9 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {3,1 }, - {4,1 } + { 1,2 }, + { 3,1 }, + { 4,1 } }), new List(){ Orders[4] @@ -647,8 +647,8 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,2 } + { 1,2 }, + { 2,2 } }), new List(){ Orders[5] @@ -656,8 +656,8 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {2,3 } + { 1,1 }, + { 2,3 } }), new List(){ Orders[6] @@ -665,9 +665,9 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {2,2 }, - {4,1 } + { 1,1 }, + { 2,2 }, + { 4,1 } }), new List(){ Orders[7] @@ -675,8 +675,8 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,3 }, - {2,1 } + { 1,3 }, + { 2,1 } }), new List(){ Orders[9] @@ -684,9 +684,9 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {4,1 } + { 1,2 }, + { 2,1 }, + { 4,1 } }), new List(){ Orders[10] @@ -694,9 +694,9 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {2,1 }, - {3,2 } + { 1,1 }, + { 2,1 }, + { 3,2 } }), new List(){ Orders[11] @@ -704,9 +704,9 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {2,2 }, - {3,1 } + { 1,1 }, + { 2,2 }, + { 3,1 } }), new List(){ Orders[12] @@ -714,10 +714,10 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {2,1 }, - {3,1 }, - {4,1 } + { 1,1 }, + { 2,1 }, + { 3,1 }, + { 4,1 } }), new List(){ Orders[14] @@ -729,7 +729,7 @@ public static class IntervalsDistributionsStorage { { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,4 } + { 1,4 } }), new List(){ Orders[0] @@ -737,8 +737,8 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,3 }, - {2,1 } + { 1,3 }, + { 2,1 } }), new List(){ Orders[1] @@ -746,8 +746,8 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,2 } + { 1,2 }, + { 2,2 } }), new List(){ Orders[2] @@ -755,8 +755,8 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,3 }, - {3,1 } + { 1,3 }, + { 3,1 } }), new List(){ Orders[3] @@ -764,9 +764,9 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {3,1 } + { 1,2 }, + { 2,1 }, + { 3,1 } }), new List(){ Orders[4], @@ -776,8 +776,8 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {2,3 } + { 1,1 }, + { 2,3 } }), new List(){ Orders[6] @@ -785,9 +785,9 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {2,2 }, - {3,1 } + { 1,1 }, + { 2,2 }, + { 3,1 } }), new List(){ Orders[7] @@ -795,8 +795,8 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,3 }, - {4,1 } + { 1,3 }, + { 4,1 } }), new List(){ Orders[9] @@ -804,9 +804,9 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {4,1 } + { 1,2 }, + { 2,1 }, + { 4,1 } }), new List(){ Orders[10] @@ -814,9 +814,9 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {2,1 }, - {3,2 } + { 1,1 }, + { 2,1 }, + { 3,2 } }), new List(){ Orders[11] @@ -824,9 +824,9 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {2,2 }, - {4,1 } + { 1,1 }, + { 2,2 }, + { 4,1 } }), new List(){ Orders[12] @@ -834,9 +834,9 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {3,1 }, - {4,1 } + { 1,2 }, + { 3,1 }, + { 4,1 } }), new List(){ Orders[13] @@ -844,10 +844,10 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {2,1 }, - {3,1 }, - {4,1 } + { 1,1 }, + { 2,1 }, + { 3,1 }, + { 4,1 } }), new List(){ Orders[14] @@ -859,7 +859,7 @@ public static class IntervalsDistributionsStorage { { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,5 } + { 1,5 } }), new List(){ Orders[0] @@ -867,9 +867,9 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,4 }, - {2,1 }, - {4,1 } + { 1,4 }, + { 2,1 }, + { 4,1 } }), new List(){ Orders[1], @@ -878,9 +878,9 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,3 }, - {2,2 }, - {3,1 } + { 1,3 }, + { 2,2 }, + { 3,1 } }), new List(){ Orders[2], @@ -890,8 +890,8 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,4 }, - {3,2 } + { 1,4 }, + { 3,2 } }), new List(){ Orders[3] @@ -899,10 +899,10 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,3 }, - {2,1 }, - {3,2 }, - {4,1 } + { 1,3 }, + { 2,1 }, + { 3,2 }, + { 4,1 } }), new List(){ Orders[4], @@ -911,8 +911,8 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,4 } + { 1,2 }, + { 2,4 } }), new List(){ Orders[6] @@ -920,10 +920,10 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,3 }, - {3,1 }, - {4,1 } + { 1,2 }, + { 2,3 }, + { 3,1 }, + { 4,1 } }), new List(){ Orders[7], @@ -932,9 +932,9 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,3 }, - {2,2 }, - {4,2 } + { 1,3 }, + { 2,2 }, + { 4,2 } }), new List(){ Orders[10] @@ -942,9 +942,9 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,2 }, - {3,3 } + { 1,2 }, + { 2,2 }, + { 3,3 } }), new List(){ Orders[11] @@ -952,10 +952,10 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,2 }, - {3,2 }, - {4,2 } + { 1,2 }, + { 2,2 }, + { 3,2 }, + { 4,2 } }), new List(){ Orders[14] @@ -967,7 +967,7 @@ public static class IntervalsDistributionsStorage { { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,4 } + { 1,4 } }), new List(){ Orders[0] @@ -975,9 +975,9 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {4,1 } + { 1,2 }, + { 2,1 }, + { 4,1 } }), new List(){ Orders[1], @@ -988,8 +988,8 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {3,2 } + { 1,2 }, + { 3,2 } }), new List(){ Orders[3], @@ -998,9 +998,9 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {3,1 }, - {4,2 } + { 1,1 }, + { 3,1 }, + { 4,2 } }), new List(){ Orders[4], @@ -1011,7 +1011,7 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {2,4 } + { 2,4 } }), new List(){ Orders[6] @@ -1019,8 +1019,8 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {2,2 }, - {4,2 } + { 2,2 }, + { 4,2 } }), new List(){ Orders[7], @@ -1029,7 +1029,7 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {4,4 } + { 4,4 } }), new List(){ Orders[14] @@ -1049,9 +1049,9 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {4,1 } + { 1,2 }, + { 2,1 }, + { 4,1 } }), new List(){ Orders[1], @@ -1062,8 +1062,8 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {3,2 } + { 1,2 }, + { 3,2 } }), new List(){ Orders[3], @@ -1072,9 +1072,9 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {3,1 }, - {4,2 } + { 1,1 }, + { 3,1 }, + { 4,2 } }), new List(){ Orders[4], @@ -1085,7 +1085,7 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {2,4 } + { 2,4 } }), new List(){ Orders[6] @@ -1093,8 +1093,8 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {2,2 }, - {4,2 } + { 2,2 }, + { 4,2 } }), new List(){ Orders[7], @@ -1103,7 +1103,7 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {4,4 } + { 4,4 } }), new List(){ Orders[14] @@ -1115,7 +1115,7 @@ public static class IntervalsDistributionsStorage { { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,4 } + { 1,4 } }), new List(){ Orders[0] @@ -1123,9 +1123,9 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {2,1 }, - {4,1 } + { 1,2 }, + { 2,1 }, + { 4,1 } }), new List(){ Orders[1], @@ -1136,8 +1136,8 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,2 }, - {3,2 } + { 1,2 }, + { 3,2 } }), new List(){ Orders[3], @@ -1146,9 +1146,9 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {1,1 }, - {3,1 }, - {4,2 } + { 1,1 }, + { 3,1 }, + { 4,2 } }), new List(){ Orders[4], @@ -1159,7 +1159,7 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {2,4 } + { 2,4 } }), new List(){ Orders[6] @@ -1167,8 +1167,8 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {2,2 }, - {4,2 } + { 2,2 }, + { 4,2 } }), new List(){ Orders[7], @@ -1177,7 +1177,7 @@ public static class IntervalsDistributionsStorage }, { new IntervalsDistribution().SetDistribution(new Dictionary(){ - {4,4 } + { 4,4 } }), new List(){ Orders[14] diff --git a/Libiada.SequenceGenerator.Tests/OrderEqualityComparerTests.cs b/Libiada.SequenceGenerator.Tests/OrderEqualityComparerTests.cs index f7b3350c..bb41583e 100644 --- a/Libiada.SequenceGenerator.Tests/OrderEqualityComparerTests.cs +++ b/Libiada.SequenceGenerator.Tests/OrderEqualityComparerTests.cs @@ -28,8 +28,8 @@ public class OrderEqualityComparerTests [TestCase(new[] { 2, 2, 2 }, new[] { 1, 2, 2 }, false)] public void EqualsTest(int[] first, int[] second, bool expected) { - var comparer = new OrderEqualityComparer(); - var actual = comparer.Equals(first, second); + OrderEqualityComparer comparer = new(); + bool actual = comparer.Equals(first, second); Assert.That(actual, Is.EqualTo(expected)); } @@ -52,8 +52,8 @@ public void EqualsTest(int[] first, int[] second, bool expected) [TestCase(new[] { 2, 2, 2 }, 207945)] public void GetHashCodeTest(int[] obj, int expected) { - var comparer = new OrderEqualityComparer(); - var actual = comparer.GetHashCode(obj); + OrderEqualityComparer comparer = new(); + int actual = comparer.GetHashCode(obj); Assert.That(actual, Is.EqualTo(expected)); } } diff --git a/Libiada.SequenceGenerator.Tests/SequenceIteratorTests.cs b/Libiada.SequenceGenerator.Tests/SequenceIteratorTests.cs index f9bc7532..3ccd64ab 100644 --- a/Libiada.SequenceGenerator.Tests/SequenceIteratorTests.cs +++ b/Libiada.SequenceGenerator.Tests/SequenceIteratorTests.cs @@ -25,13 +25,13 @@ public class SequenceIteratorTests [TestCase(new[] { 2, 2, 2 }, 7)] public void IteratorTest(int[] expected, int iterations) { - var iterator = new SequenceIterator(3, 2); + SequenceIterator iterator = new(3, 2); for (int i = 0; i < iterations; i++) { iterator.IterateSequencesCounter(); } - var actual = iterator.Iterator; + int[] actual = iterator.Iterator; Assert.That(actual, Is.EqualTo(expected)); } @@ -41,7 +41,7 @@ public void IteratorTest(int[] expected, int iterations) [Test] public void EnumeratorTest() { - var iterator = new SequenceIterator(3, 2); + SequenceIterator iterator = new(3, 2); int[][] expected = [ [1, 1, 1], diff --git a/Libiada.SequenceGenerator/IntervalsDistribution.cs b/Libiada.SequenceGenerator/IntervalsDistribution.cs index aed47d26..b8f2133e 100644 --- a/Libiada.SequenceGenerator/IntervalsDistribution.cs +++ b/Libiada.SequenceGenerator/IntervalsDistribution.cs @@ -7,7 +7,7 @@ public class IntervalsDistribution public IntervalsDistribution() { - Distribution = new Dictionary(); + Distribution = []; } public void AddInterval(int interval) @@ -33,7 +33,7 @@ public override bool Equals(object? obj) { return false; } - var distr = obj as IntervalsDistribution; + IntervalsDistribution? distr = obj as IntervalsDistribution; bool equal = false; if (this.Distribution.Count == distr.Distribution.Count) { @@ -66,8 +66,8 @@ public override int GetHashCode() int hashCode = -1573927371; foreach (var element in Distribution) { - hashCode = hashCode ^ element.Key.GetHashCode(); - hashCode = hashCode ^ element.Value.GetHashCode(); + hashCode ^= element.Key.GetHashCode(); + hashCode ^= element.Value.GetHashCode(); } return hashCode; diff --git a/Libiada.SequenceGenerator/IntervalsDistributionExtractor.cs b/Libiada.SequenceGenerator/IntervalsDistributionExtractor.cs index 6e3d989d..a63b2f36 100644 --- a/Libiada.SequenceGenerator/IntervalsDistributionExtractor.cs +++ b/Libiada.SequenceGenerator/IntervalsDistributionExtractor.cs @@ -6,12 +6,12 @@ public static class IntervalsDistributionExtractor { public static IntervalsDistribution GetIntervalsDistribution(int[] order, Link link) { - var sequence = new Chain(order); - var intervalsDistribution = new IntervalsDistribution(); - foreach (var el in sequence.Alphabet.ToList()) + Chain sequence = new(order); + IntervalsDistribution intervalsDistribution = new(); + foreach (IBaseObject el in sequence.Alphabet.ToList()) { - var congIntervals = sequence.CongenericChain(el).GetArrangement(link); - foreach (var interval in congIntervals) + int[] congIntervals = sequence.CongenericChain(el).GetArrangement(link); + foreach (int interval in congIntervals) { intervalsDistribution.AddInterval(interval); } @@ -21,17 +21,17 @@ public static IntervalsDistribution GetIntervalsDistribution(int[] order, Link l public static Dictionary> GetOrdersIntervalsDistributionsAccordance(int[][] orders, Link link) { - var accordance = new Dictionary>(); - foreach (var order in orders) + Dictionary> accordance = []; + foreach (int[] order in orders) { - var orderIntervalsDistribution = IntervalsDistributionExtractor.GetIntervalsDistribution(order, link); + IntervalsDistribution orderIntervalsDistribution = IntervalsDistributionExtractor.GetIntervalsDistribution(order, link); if (accordance.ContainsKey(orderIntervalsDistribution)) { accordance[orderIntervalsDistribution].Add(order); } else { - accordance.Add(orderIntervalsDistribution, new List { order }); + accordance.Add(orderIntervalsDistribution, [order]); } } return accordance; diff --git a/Libiada.SequenceGenerator/NonredundantSequenceGenerator.cs b/Libiada.SequenceGenerator/NonredundantSequenceGenerator.cs index 91543dd7..a6d8d713 100644 --- a/Libiada.SequenceGenerator/NonredundantSequenceGenerator.cs +++ b/Libiada.SequenceGenerator/NonredundantSequenceGenerator.cs @@ -11,7 +11,7 @@ public class NonRedundantSequenceGenerator : ISequenceGenerator /// /// The redundant sequence generator. /// - private readonly SequenceGenerator redundantSequenceGenerator = new SequenceGenerator(); + private readonly SequenceGenerator redundantSequenceGenerator = new(); /// /// The generate sequences. @@ -27,11 +27,11 @@ public class NonRedundantSequenceGenerator : ISequenceGenerator /// public List GenerateSequences(int length, int alphabetCardinality) { - var redundantResult = redundantSequenceGenerator.GenerateSequences(length, alphabetCardinality); - var nonRedundantResult = new List(); - foreach (var chain in redundantResult) + List redundantResult = redundantSequenceGenerator.GenerateSequences(length, alphabetCardinality); + List nonRedundantResult = []; + foreach (BaseChain chain in redundantResult) { - var chainAlphabetCardinality = chain.Alphabet.Cardinality; + int chainAlphabetCardinality = chain.Alphabet.Cardinality; bool nonRedundant = chain.Alphabet.All(el => (ValueInt)el <= chainAlphabetCardinality); if (nonRedundant) { diff --git a/Libiada.SequenceGenerator/NonredundantStrictSequenceGenerator.cs b/Libiada.SequenceGenerator/NonredundantStrictSequenceGenerator.cs index d935f076..c646aa7c 100644 --- a/Libiada.SequenceGenerator/NonredundantStrictSequenceGenerator.cs +++ b/Libiada.SequenceGenerator/NonredundantStrictSequenceGenerator.cs @@ -11,7 +11,7 @@ public class NonRedundantStrictSequenceGenerator : ISequenceGenerator /// /// The redundant sequence generator. /// - private readonly StrictSequenceGenerator redundantSequenceGenerator = new StrictSequenceGenerator(); + private readonly StrictSequenceGenerator redundantSequenceGenerator = new(); /// /// The generate sequences. @@ -27,11 +27,11 @@ public class NonRedundantStrictSequenceGenerator : ISequenceGenerator /// public List GenerateSequences(int length, int alphabetCardinality) { - var redundantResult = redundantSequenceGenerator.GenerateSequences(length, alphabetCardinality); - var nonRedundantResult = new List(); - foreach (var chain in redundantResult) + List redundantResult = redundantSequenceGenerator.GenerateSequences(length, alphabetCardinality); + List nonRedundantResult = []; + foreach (BaseChain chain in redundantResult) { - var chainAlphabetCardinality = chain.Alphabet.Cardinality; + int chainAlphabetCardinality = chain.Alphabet.Cardinality; bool nonRedundant = chain.Alphabet.All(el => (ValueInt)el <= chainAlphabetCardinality); if (nonRedundant) { @@ -53,7 +53,7 @@ public List GenerateSequences(int length, int alphabetCardinality) /// public List GenerateSequences(int length) { - var result = new List(); + List result = []; for (int i = 1; i <= length; i++) { result.AddRange(GenerateSequences(length, i)); diff --git a/Libiada.SequenceGenerator/OrderGenerator.cs b/Libiada.SequenceGenerator/OrderGenerator.cs index 7b5746a3..a94f95bb 100644 --- a/Libiada.SequenceGenerator/OrderGenerator.cs +++ b/Libiada.SequenceGenerator/OrderGenerator.cs @@ -20,8 +20,8 @@ public class OrderGenerator /// public List GenerateOrders(int length, int alphabetCardinality) { - var result = new List(); - var iterator = new OrderIterator(length, alphabetCardinality); + List result = []; + OrderIterator iterator = new(length, alphabetCardinality); foreach (int[] order in iterator) { result.Add(order); @@ -44,8 +44,8 @@ public List GenerateOrders(int length, int alphabetCardinality) /// public List StrictGenerateOrders(int length, int alphabetCardinality) { - var result = new List(); - var iterator = new OrderIterator(length, alphabetCardinality); + List result = []; + OrderIterator iterator = new(length, alphabetCardinality); foreach (int[] order in iterator) { if (order.Distinct().Count() == alphabetCardinality) diff --git a/Libiada.SequenceGenerator/OrderIterator.cs b/Libiada.SequenceGenerator/OrderIterator.cs index 0d8c75c4..396d2590 100644 --- a/Libiada.SequenceGenerator/OrderIterator.cs +++ b/Libiada.SequenceGenerator/OrderIterator.cs @@ -59,7 +59,7 @@ public OrderIterator(int length, int alphabetCardinality) /// public void IterateOrderCounter() { - var maximums = new int[order.Length]; + int[] maximums = new int[order.Length]; int max = 1; for (int i = 0; i < maximums.Length; i++) { diff --git a/Libiada.SequenceGenerator/SequenceGenerator.cs b/Libiada.SequenceGenerator/SequenceGenerator.cs index ad03dc4a..fb4e82b6 100644 --- a/Libiada.SequenceGenerator/SequenceGenerator.cs +++ b/Libiada.SequenceGenerator/SequenceGenerator.cs @@ -23,11 +23,11 @@ public class SequenceGenerator : ISequenceGenerator /// public List GenerateSequences(int length, int alphabetCardinality) { - var result = new List(); - var iterator = new SequenceIterator(length, alphabetCardinality); + List result = []; + SequenceIterator iterator = new(length, alphabetCardinality); foreach (int[] sequence in iterator) { - var elements = new List(sequence.Length); + List elements = new(sequence.Length); for (int i = 0; i < sequence.Length; i++) { elements.Add(new ValueInt(sequence[i])); diff --git a/Libiada.SequenceGenerator/StrictSequenceGenerator.cs b/Libiada.SequenceGenerator/StrictSequenceGenerator.cs index ea8339f9..088e5943 100644 --- a/Libiada.SequenceGenerator/StrictSequenceGenerator.cs +++ b/Libiada.SequenceGenerator/StrictSequenceGenerator.cs @@ -8,7 +8,7 @@ /// public class StrictSequenceGenerator : ISequenceGenerator { - private SequenceGenerator sequenceGenerator = new SequenceGenerator(); + private SequenceGenerator sequenceGenerator = new(); /// /// Generates numeric sequences using given length and alphabet cardinality. @@ -24,13 +24,13 @@ public class StrictSequenceGenerator : ISequenceGenerator /// public List GenerateSequences(int length, int alphabetCardinality) { - var result = new List(); - var iterator = new SequenceIterator(length, alphabetCardinality); + List result = []; + SequenceIterator iterator = new(length, alphabetCardinality); foreach(int[] sequence in iterator) { if(sequence.Distinct().Count() == alphabetCardinality) { - var elements = new List(sequence.Length); + List elements = new(sequence.Length); for (int i = 0; i < sequence.Length; i++) { elements.Add(new ValueInt(sequence[i])); @@ -52,7 +52,7 @@ public List GenerateSequences(int length, int alphabetCardinality) /// public List GenerateSequences(int length) { - var result = new List(); + List result = []; for (int i = 1; i <= length; i++) { result.AddRange(GenerateSequences(length, i));