Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
giometrix committed Dec 12, 2018
1 parent 24484d9 commit d6989a7
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/BloomFilterCore/BloomFilterCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BloomFilterCoreTests", "BloomFilterCoreTests\BloomFilterCoreTests.csproj", "{C9FFE627-189A-4C71-B8AE-6462ACE5A659}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +23,10 @@ Global
{ED85F325-3689-404A-A133-8EAC98151528}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ED85F325-3689-404A-A133-8EAC98151528}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ED85F325-3689-404A-A133-8EAC98151528}.Release|Any CPU.Build.0 = Release|Any CPU
{C9FFE627-189A-4C71-B8AE-6462ACE5A659}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C9FFE627-189A-4C71-B8AE-6462ACE5A659}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C9FFE627-189A-4C71-B8AE-6462ACE5A659}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C9FFE627-189A-4C71-B8AE-6462ACE5A659}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BloomFilterCore\BloomFilterCore.csproj" />
</ItemGroup>

</Project>
88 changes: 88 additions & 0 deletions src/BloomFilterCore/BloomFilterCoreTests/UnitTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using BloomFilterCore;
using Xunit;

namespace BloomFilterCoreTests
{
public class UnitTests
{

[Theory]
[InlineData(1000)]
[InlineData(2000)]
[InlineData(3000)]
[InlineData(4000)]
[InlineData(5000)]
public void is_in_filter_int(int value)
{
var filter = new BloomFilter<int>(10, HashFunctions.HashInt);
filter.Add(1);
filter.Add(100);
filter.Add(2);
filter.Add(200);
filter.Add(3);
filter.Add(value);
Assert.True(filter.Contains(value));

}

[Theory]
[InlineData(1000)]
[InlineData(2000)]
[InlineData(3000)]
[InlineData(4000)]
[InlineData(5000)]
public void is_not_in_filter_int(int value)
{
var filter = new BloomFilter<int>(10, HashFunctions.HashInt);
filter.Add(1);
filter.Add(100);
filter.Add(2);
filter.Add(200);
filter.Add(3);

Assert.False(filter.Contains(value));

}


[Theory]
[InlineData("apples")]
[InlineData("oranges")]
[InlineData("pineapples")]
[InlineData("pears")]
[InlineData("strawberries")]
public void is_in_filter_string(string value)
{
var filter = new BloomFilter<string>(10, HashFunctions.HashString);
filter.Add("bananas");
filter.Add("watermelons");
filter.Add("cantaloupes");
filter.Add("grapes");
filter.Add("grapefruits");
filter.Add(value);
Assert.True(filter.Contains(value));

}

[Theory]
[InlineData("apples")]
[InlineData("oranges")]
[InlineData("pineapples")]
[InlineData("pears")]
[InlineData("strawberries")]
public void is_not_in_filter_string(string value)
{
var filter = new BloomFilter<string>(10, HashFunctions.HashString);
filter.Add("bananas");
filter.Add("watermelons");
filter.Add("cantaloupes");
filter.Add("grapes");
filter.Add("grapefruits");

Assert.False(filter.Contains(value));

}

}
}

0 comments on commit d6989a7

Please sign in to comment.