diff --git a/.gitignore b/.gitignore index fd44de4b..95740a06 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ - #ignore thumbnails created by windows Thumbs.db #Ignore files build by Visual Studio @@ -50,3 +49,4 @@ src/sentencepiece4c/build/ src/sentencepiece4cbuild/ !samples/**/release **/*.feature.cs +tests/CoverageResults/* diff --git a/.vscode/extensions.json b/.vscode/extensions.json index fccb0130..e386fcc4 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -9,6 +9,7 @@ "tim-koehler.helm-intellisense", "ms-dotnettools.vscodeintellicode-csharp", "redhat.vscode-yaml", - "wycliffeassociates.usfmvscode" + "wycliffeassociates.usfmvscode", + "ryanluker.vscode-coverage-gutters" ] } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 403c5908..384cf5d7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,6 @@ { "cmake.sourceDirectory": "${workspaceFolder}/src/sentencepiece4c", "cmake.buildDirectory": "${workspaceFolder}/src/sentencepiece4c/build", - "dotnet-test-explorer.testProjectPath": "**/*Tests.csproj", "editor.formatOnSave": true, "[csharp]": { "editor.defaultFormatter": "csharpier.csharpier-vscode" @@ -175,5 +174,13 @@ "xmltag", "zwsp" ], - "dotnet.defaultSolution": "Machine.sln" + "dotnet.defaultSolution": "Machine.sln", + "coverage-gutters.coverageFileNames": [ + "coverage.info", + "lcov.info", + "cov.xml", + "coverage.xml", + "jacoco.xml", + "coverage.cobertura.xml" + ] } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index e690165f..9687eb89 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -20,6 +20,25 @@ "reveal": "silent" }, "problemMatcher": "$msCompile" + }, + { + "label": "test with coverage", + "dependsOn": [], + "command": "dotnet", + "type": "process", + "args": [ + "test", + "/p:CollectCoverage=true", + "/p:CoverletOutputFormat=lcov%2cjson", + "/p:CoverletOutput=../CoverageResults/", + "/p:MergeWith=../CoverageResults/coverage.json", + "-m:1" + ], + "problemMatcher": "$msCompile", + "group": { + "kind": "test", + "isDefault": true + } } ] } \ No newline at end of file diff --git a/src/SIL.Machine/Corpora/ScriptureRef.cs b/src/SIL.Machine/Corpora/ScriptureRef.cs index bb19f84e..a0d3445e 100644 --- a/src/SIL.Machine/Corpora/ScriptureRef.cs +++ b/src/SIL.Machine/Corpora/ScriptureRef.cs @@ -68,14 +68,6 @@ public ScriptureRef ChangeVersification(ScrVers versification) return new ScriptureRef(vr, Path); } - public bool Overlaps(ScriptureRef other) - { - if (!VerseRef.AreOverlappingVersesRanges(VerseRef, other.VerseRef)) - return false; - - return Path.SequenceEqual(other.Path); - } - int IComparable.CompareTo(ScriptureRef other) { return CompareTo(other, compareSegments: true); diff --git a/tests/SIL.Machine.AspNetCore.Tests/SIL.Machine.AspNetCore.Tests.csproj b/tests/SIL.Machine.AspNetCore.Tests/SIL.Machine.AspNetCore.Tests.csproj index 71c50810..5956eaa0 100644 --- a/tests/SIL.Machine.AspNetCore.Tests/SIL.Machine.AspNetCore.Tests.csproj +++ b/tests/SIL.Machine.AspNetCore.Tests/SIL.Machine.AspNetCore.Tests.csproj @@ -13,6 +13,10 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tests/SIL.Machine.Morphology.HermitCrab.Tests/SIL.Machine.Morphology.HermitCrab.Tests.csproj b/tests/SIL.Machine.Morphology.HermitCrab.Tests/SIL.Machine.Morphology.HermitCrab.Tests.csproj index f248dbba..3763ddfd 100644 --- a/tests/SIL.Machine.Morphology.HermitCrab.Tests/SIL.Machine.Morphology.HermitCrab.Tests.csproj +++ b/tests/SIL.Machine.Morphology.HermitCrab.Tests/SIL.Machine.Morphology.HermitCrab.Tests.csproj @@ -13,6 +13,10 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/SIL.Machine.Tests/Corpora/ScriptureRefTests.cs b/tests/SIL.Machine.Tests/Corpora/ScriptureRefTests.cs index 5102e3cb..b395fcb7 100644 --- a/tests/SIL.Machine.Tests/Corpora/ScriptureRefTests.cs +++ b/tests/SIL.Machine.Tests/Corpora/ScriptureRefTests.cs @@ -8,10 +8,15 @@ public class ScriptureRefTests [TestCase("MAT 1:1", "MAT 1:2", ExpectedResult = -1, Description = "VerseLessThan")] [TestCase("MAT 1:1", "MAT 1:1", ExpectedResult = 0, Description = "VerseEqualTo")] [TestCase("MAT 1:2", "MAT 1:1", ExpectedResult = 1, Description = "VerseGreaterThan")] + [TestCase("MAT 1:1-3", "MAT 1:1", ExpectedResult = 1, Description = "MultiVerseExtensionGreaterThan")] + [TestCase("MAT 1:1", "MAT 1:1-3", ExpectedResult = -1, Description = "MultiVerseExtensionLessThan")] + [TestCase("MAT 1:1-3", "MAT 1:2", ExpectedResult = -1, Description = "MultiVerseStartLessThan")] + [TestCase("MAT 1:2", "MAT 1:1-3", ExpectedResult = 1, Description = "MultiVerseStartGreaterThan")] [TestCase("MAT 1:0/1:p", "MAT 1:0/2:p", ExpectedResult = -1, Description = "NonVerseLessThan")] [TestCase("MAT 1:0/1:p", "MAT 1:0/1:p", ExpectedResult = 0, Description = "NonVerseEqualTo")] [TestCase("MAT 1:0/2:p", "MAT 1:0/1:p", ExpectedResult = 1, Description = "NonVerseGreaterThan")] [TestCase("MAT 1:0/1:esb", "MAT 1:0/1:esb/1:p", ExpectedResult = -1, Description = "NonVerseParentChild")] + [TestCase("MAT 1:0/2:esb", "MAT 1:0/1:esb/1:p", ExpectedResult = 1, Description = "NonVerseParentOtherChild")] public int CompareTo_Strict(string ref1Str, string ref2Str) { var ref1 = ScriptureRef.Parse(ref1Str); @@ -19,6 +24,10 @@ public int CompareTo_Strict(string ref1Str, string ref2Str) int result = ref1.CompareTo(ref2); + // this tests the IComparable.CompareTo method responds the same as the ScriptureRef.CompareTo method. + int result2 = ((IComparable)ref1).CompareTo(ref2); + Assert.That(result, Is.EqualTo(result2)); + if (result < 0) result = -1; else if (result > 0) @@ -30,7 +39,8 @@ public int CompareTo_Strict(string ref1Str, string ref2Str) [TestCase("MAT 1:1", "MAT 1:1", ExpectedResult = 0, Description = "VerseEqualTo")] [TestCase("MAT 1:2", "MAT 1:1", ExpectedResult = 1, Description = "VerseGreaterThan")] [TestCase("MAT 1:0/1:p", "MAT 1:0/2:p", ExpectedResult = 0, Description = "NonVerseSameMarkerDifferentPosition")] - [TestCase("MAT 1:0/2:esb", "MAT 1:0/1:esb/1:p", ExpectedResult = -1, Description = "NonVerseParentChild")] + [TestCase("MAT 1:0/1:esb", "MAT 1:0/1:esb/1:p", ExpectedResult = -1, Description = "NonVerseParentChild")] + [TestCase("MAT 1:0/2:esb", "MAT 1:0/1:esb/1:p", ExpectedResult = -1, Description = "NonVerseParentOtherChild")] public int CompareTo_Relaxed(string ref1Str, string ref2Str) { var ref1 = ScriptureRef.Parse(ref1Str); @@ -44,4 +54,27 @@ public int CompareTo_Relaxed(string ref1Str, string ref2Str) result = 1; return result; } + + [TestCase] + public void IsEqualTo() + { + var ref1 = ScriptureRef.Parse("MAT 1:1/1:p"); + var ref1dup = ScriptureRef.Parse("MAT 1:1/1:p"); + var ref2 = ScriptureRef.Parse("MAT 1:2/1:p"); + var obj1 = "A different type"; + Assert.Multiple(() => + { + Assert.That(ref1.Equals(ref1dup)); + Assert.That(!ref1.Equals(ref2)); + Assert.That(!ref1.Equals(obj1)); + }); + } + + [TestCase] + public void IsEqualToThrowsArgumentException() + { + var ref1 = ScriptureRef.Parse("MAT 1:1/1:p"); + var obj1 = "A different type"; + Assert.Throws(() => ref1.CompareTo(obj1)); + } } diff --git a/tests/SIL.Machine.Tests/SIL.Machine.Tests.csproj b/tests/SIL.Machine.Tests/SIL.Machine.Tests.csproj index be3188ea..e34759a4 100644 --- a/tests/SIL.Machine.Tests/SIL.Machine.Tests.csproj +++ b/tests/SIL.Machine.Tests/SIL.Machine.Tests.csproj @@ -13,6 +13,10 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/SIL.Machine.Tokenization.SentencePiece.Tests/SIL.Machine.Tokenization.SentencePiece.Tests.csproj b/tests/SIL.Machine.Tokenization.SentencePiece.Tests/SIL.Machine.Tokenization.SentencePiece.Tests.csproj index f1c9e585..4327dedc 100644 --- a/tests/SIL.Machine.Tokenization.SentencePiece.Tests/SIL.Machine.Tokenization.SentencePiece.Tests.csproj +++ b/tests/SIL.Machine.Tokenization.SentencePiece.Tests/SIL.Machine.Tokenization.SentencePiece.Tests.csproj @@ -13,6 +13,10 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/SIL.Machine.Translation.Thot.Tests/SIL.Machine.Translation.Thot.Tests.csproj b/tests/SIL.Machine.Translation.Thot.Tests/SIL.Machine.Translation.Thot.Tests.csproj index fd1e6290..77697275 100644 --- a/tests/SIL.Machine.Translation.Thot.Tests/SIL.Machine.Translation.Thot.Tests.csproj +++ b/tests/SIL.Machine.Translation.Thot.Tests/SIL.Machine.Translation.Thot.Tests.csproj @@ -13,6 +13,10 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + runtime; build; native; contentfiles; analyzers; buildtransitive all