Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test coverage #182

Merged
merged 4 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#ignore thumbnails created by windows
Thumbs.db
#Ignore files build by Visual Studio
Expand Down Expand Up @@ -50,3 +49,4 @@ src/sentencepiece4c/build/
src/sentencepiece4cbuild/
!samples/**/release
**/*.feature.cs
tests/CoverageResults/*
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"tim-koehler.helm-intellisense",
"ms-dotnettools.vscodeintellicode-csharp",
"redhat.vscode-yaml",
"wycliffeassociates.usfmvscode"
"wycliffeassociates.usfmvscode",
"ryanluker.vscode-coverage-gutters"
]
}
11 changes: 9 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"
]
}
19 changes: 19 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
]
}
8 changes: 0 additions & 8 deletions src/SIL.Machine/Corpora/ScriptureRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScriptureRef>.CompareTo(ScriptureRef other)
{
return CompareTo(other, compareSegments: true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Hangfire.InMemory" Version="0.8.1" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
35 changes: 34 additions & 1 deletion tests/SIL.Machine.Tests/Corpora/ScriptureRefTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,26 @@ 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);
var ref2 = ScriptureRef.Parse(ref2Str);

int result = ref1.CompareTo(ref2);

// this tests the IComparable<ScriptureRef>.CompareTo method responds the same as the ScriptureRef.CompareTo method.
int result2 = ((IComparable<ScriptureRef>)ref1).CompareTo(ref2);
Assert.That(result, Is.EqualTo(result2));

if (result < 0)
result = -1;
else if (result > 0)
Expand All @@ -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);
Expand All @@ -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<ArgumentException>(() => ref1.CompareTo(obj1));
}
}
4 changes: 4 additions & 0 deletions tests/SIL.Machine.Tests/SIL.Machine.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
Loading