Skip to content

Commit 2423c09

Browse files
authored
Merge pull request #3 from jeanbern/UnitTests
Unit tests
2 parents 8172fb8 + 367258a commit 2423c09

26 files changed

+1002589
-205
lines changed

.codecov.yml

-2
This file was deleted.

.github/workflows/codeql-analysis.yml

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
# We must fetch at least the immediate parents so that if this is
3636
# a pull request then we can checkout the head.
3737
fetch-depth: 2
38+
submodules: true
3839

3940
# If this run was triggered by a pull request event, then checkout
4041
# the head of the pull request instead of the merge commit.
@@ -51,6 +52,11 @@ jobs:
5152
# Prefix the list here with "+" to use these queries and those in the config file.
5253
# queries: ./path/to/local/query, your-org/your-repo/queries@main
5354

55+
- name: Setup dotnet core cli environment
56+
uses: actions/setup-dotnet@v1
57+
with:
58+
dotnet-version: '5.0'
59+
5460
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
5561
# If this step fails, then you should remove it and run the build manually (see below)
5662
- name: Autobuild

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "ChacoSharp"]
2+
path = ChacoSharp
3+
url = https://github.com/jeanbern/ChacoSharp

AllProjects.sln

+30-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1515
.codecov.yml = .codecov.yml
1616
.editorconfig = .editorconfig
1717
appveyor.yml = appveyor.yml
18+
.github\workflows\codeql-analysis.yml = .github\workflows\codeql-analysis.yml
1819
LICENSE = LICENSE
1920
README.md = README.md
2021
EndProjectSection
@@ -28,30 +29,58 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Portent.Test", "Portent.Tes
2829
EndProject
2930
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Portent.Benchmark", "Portent.Benchmark\Portent.Benchmark.csproj", "{BD1A249D-0576-49EE-BC96-63B9545674BE}"
3031
EndProject
31-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MinLA", "MinLA\MinLA.csproj", "{382F1CE8-1B54-4CFC-801A-05883A89295C}"
32+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MinLA", "MinLA\MinLA.csproj", "{382F1CE8-1B54-4CFC-801A-05883A89295C}"
33+
EndProject
34+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChacoSharp", "ChacoSharp\ChacoSharp.csproj", "{379A0679-7276-45D3-89CE-02B753809E99}"
3235
EndProject
3336
Global
3437
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3538
Debug|Any CPU = Debug|Any CPU
39+
Debug|x64 = Debug|x64
3640
Release|Any CPU = Release|Any CPU
41+
Release|x64 = Release|x64
3742
EndGlobalSection
3843
GlobalSection(ProjectConfigurationPlatforms) = postSolution
3944
{B51F0229-53A3-4773-8F45-5CFC3636C65E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
4045
{B51F0229-53A3-4773-8F45-5CFC3636C65E}.Debug|Any CPU.Build.0 = Debug|Any CPU
46+
{B51F0229-53A3-4773-8F45-5CFC3636C65E}.Debug|x64.ActiveCfg = Debug|Any CPU
47+
{B51F0229-53A3-4773-8F45-5CFC3636C65E}.Debug|x64.Build.0 = Debug|Any CPU
4148
{B51F0229-53A3-4773-8F45-5CFC3636C65E}.Release|Any CPU.ActiveCfg = Release|Any CPU
4249
{B51F0229-53A3-4773-8F45-5CFC3636C65E}.Release|Any CPU.Build.0 = Release|Any CPU
50+
{B51F0229-53A3-4773-8F45-5CFC3636C65E}.Release|x64.ActiveCfg = Release|Any CPU
51+
{B51F0229-53A3-4773-8F45-5CFC3636C65E}.Release|x64.Build.0 = Release|Any CPU
4352
{2745B9B8-FCA5-4648-994F-69A47C6AFA86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
4453
{2745B9B8-FCA5-4648-994F-69A47C6AFA86}.Debug|Any CPU.Build.0 = Debug|Any CPU
54+
{2745B9B8-FCA5-4648-994F-69A47C6AFA86}.Debug|x64.ActiveCfg = Debug|Any CPU
55+
{2745B9B8-FCA5-4648-994F-69A47C6AFA86}.Debug|x64.Build.0 = Debug|Any CPU
4556
{2745B9B8-FCA5-4648-994F-69A47C6AFA86}.Release|Any CPU.ActiveCfg = Release|Any CPU
4657
{2745B9B8-FCA5-4648-994F-69A47C6AFA86}.Release|Any CPU.Build.0 = Release|Any CPU
58+
{2745B9B8-FCA5-4648-994F-69A47C6AFA86}.Release|x64.ActiveCfg = Release|Any CPU
59+
{2745B9B8-FCA5-4648-994F-69A47C6AFA86}.Release|x64.Build.0 = Release|Any CPU
4760
{BD1A249D-0576-49EE-BC96-63B9545674BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
4861
{BD1A249D-0576-49EE-BC96-63B9545674BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
62+
{BD1A249D-0576-49EE-BC96-63B9545674BE}.Debug|x64.ActiveCfg = Debug|Any CPU
63+
{BD1A249D-0576-49EE-BC96-63B9545674BE}.Debug|x64.Build.0 = Debug|Any CPU
4964
{BD1A249D-0576-49EE-BC96-63B9545674BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
5065
{BD1A249D-0576-49EE-BC96-63B9545674BE}.Release|Any CPU.Build.0 = Release|Any CPU
66+
{BD1A249D-0576-49EE-BC96-63B9545674BE}.Release|x64.ActiveCfg = Release|Any CPU
67+
{BD1A249D-0576-49EE-BC96-63B9545674BE}.Release|x64.Build.0 = Release|Any CPU
5168
{382F1CE8-1B54-4CFC-801A-05883A89295C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
5269
{382F1CE8-1B54-4CFC-801A-05883A89295C}.Debug|Any CPU.Build.0 = Debug|Any CPU
70+
{382F1CE8-1B54-4CFC-801A-05883A89295C}.Debug|x64.ActiveCfg = Debug|Any CPU
71+
{382F1CE8-1B54-4CFC-801A-05883A89295C}.Debug|x64.Build.0 = Debug|Any CPU
5372
{382F1CE8-1B54-4CFC-801A-05883A89295C}.Release|Any CPU.ActiveCfg = Release|Any CPU
5473
{382F1CE8-1B54-4CFC-801A-05883A89295C}.Release|Any CPU.Build.0 = Release|Any CPU
74+
{382F1CE8-1B54-4CFC-801A-05883A89295C}.Release|x64.ActiveCfg = Release|Any CPU
75+
{382F1CE8-1B54-4CFC-801A-05883A89295C}.Release|x64.Build.0 = Release|Any CPU
76+
{379A0679-7276-45D3-89CE-02B753809E99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
77+
{379A0679-7276-45D3-89CE-02B753809E99}.Debug|Any CPU.Build.0 = Debug|Any CPU
78+
{379A0679-7276-45D3-89CE-02B753809E99}.Debug|x64.ActiveCfg = Debug|Any CPU
79+
{379A0679-7276-45D3-89CE-02B753809E99}.Debug|x64.Build.0 = Debug|Any CPU
80+
{379A0679-7276-45D3-89CE-02B753809E99}.Release|Any CPU.ActiveCfg = Release|Any CPU
81+
{379A0679-7276-45D3-89CE-02B753809E99}.Release|Any CPU.Build.0 = Release|Any CPU
82+
{379A0679-7276-45D3-89CE-02B753809E99}.Release|x64.ActiveCfg = Release|Any CPU
83+
{379A0679-7276-45D3-89CE-02B753809E99}.Release|x64.Build.0 = Release|Any CPU
5584
EndGlobalSection
5685
GlobalSection(SolutionProperties) = preSolution
5786
HideSolutionNode = FALSE

AllProjects.sln.DotSettings

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Dawg/@EntryIndexedValue">True</s:Boolean>
23
<s:Boolean x:Key="/Default/UserDictionary/Words/=nint/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

ChacoSharp

Submodule ChacoSharp added at 4327b2a

MinLA/MinLA.csproj

+2-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<TargetFramework>net5.0</TargetFramework>
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>
@@ -15,13 +15,8 @@
1515
</PropertyGroup>
1616

1717
<ItemGroup>
18+
<ProjectReference Include="..\ChacoSharp\ChacoSharp.csproj" />
1819
<ProjectReference Include="..\Portent\Portent.csproj" />
1920
</ItemGroup>
2021

21-
<ItemGroup>
22-
<Reference Include="ChacoSharp">
23-
<HintPath>..\..\..\Users\JPelleri\source\repos\ChacoSharp\bin\Release\netcoreapp3.1\ChacoSharp.dll</HintPath>
24-
</Reference>
25-
</ItemGroup>
26-
2722
</Project>

Portent.Benchmark/Portent.Benchmark.csproj

+20-10
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,33 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<TargetFramework>net5.0</TargetFramework>
66
<LangVersion>8.0</LangVersion>
7+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
78
<PlatformTarget>x64</PlatformTarget>
9+
810
<NullableContextOptions>enable</NullableContextOptions>
911
<Nullable>enable</Nullable>
10-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1112
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
1213
</PropertyGroup>
1314

1415
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
15-
<DebugType>none</DebugType>
16-
<DebugSymbols>false</DebugSymbols>
16+
<DebugType>pdbonly</DebugType>
17+
<DebugSymbols>true</DebugSymbols>
18+
<Optimize>true</Optimize>
1719
<WarningLevel>2</WarningLevel>
20+
21+
<!-- Use together -->
22+
<PublishTrimmed>true</PublishTrimmed>
23+
<PublishReadyToRun>true</PublishReadyToRun>
24+
25+
<!-- Use together -->
26+
<TieredCompilation>true</TieredCompilation>
27+
<TieredCompilationQuickJit>true</TieredCompilationQuickJit>
28+
29+
<ServerGarbageCollection>true</ServerGarbageCollection>
30+
<GCLargePages>true</GCLargePages>
31+
1832
</PropertyGroup>
1933

2034
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -24,8 +38,8 @@
2438
</PropertyGroup>
2539

2640
<ItemGroup>
27-
<PackageReference Include="BenchmarkDotNet" Version="0.12.0" />
28-
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.12.0" />
41+
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
42+
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.12.1" />
2943
</ItemGroup>
3044

3145
<ItemGroup>
@@ -41,8 +55,4 @@
4155
</None>
4256
</ItemGroup>
4357

44-
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
45-
<Exec Command="&quot;C:\Program Files\PowerShell\6\pwsh.exe&quot; -ExecutionPolicy ByPass C:\doctemp\signingScript.ps1 -filepath $(TargetPath)" />
46-
</Target>
47-
4858
</Project>

Portent.Test/DawgTests/DawgHelper.cs

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#nullable enable
2+
using System;
3+
using System.IO;
4+
using System.Linq;
5+
6+
namespace Portent.Test.DawgTests
7+
{
8+
internal static class DawgHelper
9+
{
10+
private const string TempAugPath = "writefile.aug";
11+
12+
public static Dawg Create(params string[] words)
13+
{
14+
var builder = new PartitionedGraphBuilder();
15+
foreach (var word in words.OrderBy(x => x))
16+
{
17+
builder.Insert(word, 0);
18+
}
19+
20+
using var compressed = builder.AsCompressedSparseRows();
21+
compressed.Save(TempAugPath);
22+
23+
using var read = File.OpenRead(TempAugPath);
24+
return new Dawg(read);
25+
}
26+
27+
public static Dawg CreateFromCorpus(string corpusLocation)
28+
{
29+
var builder = new PartitionedGraphBuilder();
30+
using var stream = File.OpenRead(corpusLocation);
31+
using var reader = new StreamReader(stream);
32+
string? line;
33+
while ((line = reader.ReadLine()) != null)
34+
{
35+
var lineTokens = line.Split(' ');
36+
if (lineTokens.Length != 2)
37+
{
38+
continue;
39+
}
40+
41+
if (!ulong.TryParse(lineTokens[1], out var count))
42+
{
43+
continue;
44+
}
45+
46+
builder.Insert(lineTokens[0], count);
47+
}
48+
49+
using var compressedGraph = builder.AsCompressedSparseRows();
50+
compressedGraph.Save(TempAugPath);
51+
52+
using var dawgStream = File.OpenRead(TempAugPath);
53+
return new Dawg(dawgStream);
54+
}
55+
56+
public static string[] BuildQuery1K(string queryLocation)
57+
{
58+
using var stream = File.OpenRead(queryLocation);
59+
var testList = new string[1000];
60+
var i = 0;
61+
62+
using var reader = new StreamReader(stream);
63+
64+
string? line;
65+
while ((line = reader.ReadLine()) != null)
66+
{
67+
var lineParts = line.Split(default(char[]), StringSplitOptions.None);
68+
if (lineParts.Length == 3)
69+
{
70+
testList[i++] = lineParts[0];
71+
}
72+
}
73+
74+
if (i != 1000)
75+
{
76+
// ReSharper disable once RedundantToStringCallForValueType - would box value type?
77+
throw new InvalidOperationException("Unexpected number of query inputs: " + i.ToString());
78+
}
79+
80+
return testList;
81+
}
82+
}
83+
}
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using Xunit;
4+
5+
namespace Portent.Test.DawgTests
6+
{
7+
public class LargeCorpusTests
8+
{
9+
[Theory]
10+
[InlineData(
11+
"TestData/frequency_dictionary_en_500_000.txt",
12+
"TestData/noisy_query_en_1000.txt",
13+
497,
14+
34814,
15+
869864,
16+
8775261)]
17+
public void Lookup_CountMatchesExpected_EmptyDictionary(string corpusLocation, string queryLocation, int matchCount0Errors, int matchCount1Errors, int matchCount2Errors, int matchCount3Errors)
18+
{
19+
using var dawg = DawgHelper.CreateFromCorpus(corpusLocation);
20+
var terms = DawgHelper.BuildQuery1K(queryLocation);
21+
Assert.Equal(matchCount0Errors, ResultTotal(dawg, terms, 0u));
22+
Assert.Equal(matchCount1Errors, ResultTotal(dawg, terms, 1u));
23+
Assert.Equal(matchCount2Errors, ResultTotal(dawg, terms, 2u));
24+
Assert.Equal(matchCount3Errors, ResultTotal(dawg, terms, 3u));
25+
}
26+
27+
private static int ResultTotal(Dawg dawg, IEnumerable<string> searchTerms, uint maxEdits)
28+
{
29+
return searchTerms.Sum(searchTerm => dawg.Lookup(searchTerm, maxEdits).Count());
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)