Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ public class Item
}
""");

codes.TryGetValue("MasterMemory.DatabaseBuilder.g.cs", out _).Should().BeTrue();
codes.TryGetValue("MasterMemory.DatabaseBuilder.g.cs", out _).ShouldBeTrue();

var mainCode = codes["MasterMemory.ItemTable.g.cs"];
WriteLine(mainCode);

mainCode.Should().Contain("namespace MasterMemory.Tables");
mainCode.Should().Contain("return ThrowKeyNotFound(key);");
mainCode.Should().Contain("public sealed partial class ItemTable");
mainCode.ShouldContain("namespace MasterMemory.Tables");
mainCode.ShouldContain("return ThrowKeyNotFound(key);");
mainCode.ShouldContain("public sealed partial class ItemTable");
}


Expand All @@ -42,13 +42,13 @@ public class Item
}
""");

codes.TryGetValue("MasterMemory.FooBarBazDatabaseBuilder.g.cs", out _).Should().BeTrue();
codes.TryGetValue("MasterMemory.FooBarBazDatabaseBuilder.g.cs", out _).ShouldBeTrue();

var mainCode = codes["MasterMemory.ItemTable.g.cs"];
WriteLine(mainCode);

mainCode.Should().Contain("namespace MyNamespace.Tables");
mainCode.Should().NotContain("return ThrowKeyNotFound(key);");
mainCode.Should().Contain("public sealed partial class ItemTable");
mainCode.ShouldContain("namespace MyNamespace.Tables");
mainCode.ShouldNotContain("return ThrowKeyNotFound(key);");
mainCode.ShouldContain("public sealed partial class ItemTable");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ public class IncrementalGeneratorTest
void VerifySourceOutputReasonIsCached((string Key, string Reasons)[] reasons)
{
var reason = reasons.FirstOrDefault(x => x.Key == "SourceOutput").Reasons;
reason.Should().Be("Cached");
reason.ShouldBe("Cached");
}

void VerifySourceOutputReasonIsNotCached((string Key, string Reasons)[] reasons)
{
var reason = reasons.FirstOrDefault(x => x.Key == "SourceOutput").Reasons;
reason.Should().NotBe("Cached");
reason.ShouldNotBe("Cached");
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" />
<PackageReference Include="FluentAssertions" Version="7.0.0" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
</ItemGroup>
Expand All @@ -23,7 +23,7 @@
<ItemGroup>
<Using Include="Xunit" />
<Using Include="Xunit.Abstractions" />
<Using Include="FluentAssertions" />
<Using Include="Shouldly" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void Ok([StringSyntax("C#-test")] string code, [CallerArgumentExpression(
}
OutputGeneratedCode(compilation);

diagnostics.Length.Should().Be(0);
diagnostics.Length.ShouldBe(0);
}

public Dictionary<string, string> GenerateCode([StringSyntax("C#-test")] string code, [CallerArgumentExpression("code")] string? codeExpr = null)
Expand All @@ -27,7 +27,7 @@ public Dictionary<string, string> GenerateCode([StringSyntax("C#-test")] string
{
output.WriteLine(item.ToString());
}
diagnostics.Length.Should().Be(0);
diagnostics.Length.ShouldBe(0);

var dict = new Dictionary<string, string>();
foreach (var syntaxTree in compilation.SyntaxTrees)
Expand All @@ -53,11 +53,11 @@ public void Verify(int id, [StringSyntax("C#-test")] string code, string diagnos
}
OutputGeneratedCode(compilation);

diagnostics.Length.Should().Be(1);
diagnostics[0].Id.Should().Be(idPrefix + id.ToString("000"));
diagnostics.Length.ShouldBe(1);
diagnostics[0].Id.ShouldBe(idPrefix + id.ToString("000"));

var text = GetLocationText(diagnostics[0], compilation.SyntaxTrees);
text.Should().Be(diagnosticsCodeSpan);
text.ShouldBe(diagnosticsCodeSpan);
}

public (string, string)[] Verify([StringSyntax("C#-test")] string code, [CallerArgumentExpression("code")] string? codeExpr = null)
Expand All @@ -82,7 +82,7 @@ public void Execute([StringSyntax("C#-test")] string code, string args, string e
}
OutputGeneratedCode(compilation);

stdout.Should().Be(expected);
stdout.ShouldBe(expected);
}

public string Error([StringSyntax("C#-test")] string code, string args, [CallerArgumentExpression("code")] string? codeExpr = null)
Expand Down
55 changes: 27 additions & 28 deletions tests/MasterMemory.Tests/BinarySearchTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FluentAssertions;
using Xunit;
using MessagePack;

Expand Down Expand Up @@ -43,26 +42,26 @@ public void Find()
// not found
if (firstIndex == -1)
{
f.Should().Be(-1);
l.Should().Be(-1);
u.Should().Be(-1);
f.ShouldBe(-1);
l.ShouldBe(-1);
u.ShouldBe(-1);
continue;
}

array[f].Should().Be(i);
array[l].Should().Be(i);
array[u].Should().Be(i);
array[f].ShouldBe(i);
array[l].ShouldBe(i);
array[u].ShouldBe(i);

l.Should().Be(firstIndex);
u.Should().Be(lastIndex);
l.ShouldBe(firstIndex);
u.ShouldBe(lastIndex);
}
}

// and empty
var emptyArray = Enumerable.Empty<int>().ToArray();
BinarySearch.FindFirst(emptyArray, 0, x => x, Comparer<int>.Default).Should().Be(-1);
BinarySearch.LowerBound(emptyArray, 0, emptyArray.Length, 0, x => x, Comparer<int>.Default).Should().Be(-1);
BinarySearch.UpperBound(emptyArray, 0, emptyArray.Length, 0, x => x, Comparer<int>.Default).Should().Be(-1);
BinarySearch.FindFirst(emptyArray, 0, x => x, Comparer<int>.Default).ShouldBe(-1);
BinarySearch.LowerBound(emptyArray, 0, emptyArray.Length, 0, x => x, Comparer<int>.Default).ShouldBe(-1);
BinarySearch.UpperBound(emptyArray, 0, emptyArray.Length, 0, x => x, Comparer<int>.Default).ShouldBe(-1);
}

[Fact]
Expand All @@ -72,7 +71,7 @@ public void Closest()
var array = Enumerable.Empty<int>().ToArray();

var near = BinarySearch.FindClosest(array, 0, 0, array.Length, x => x, Comparer<int>.Default, false);
near.Should().Be(-1);
near.ShouldBe(-1);

// mid
var source = new[]{
Expand All @@ -84,24 +83,24 @@ public void Closest()
new { id = 5, bound = 1000 },
};

BinarySearch.FindClosest(source, 0, source.Length, -100, x => x.bound, Comparer<int>.Default, true).Should().Be(-1);
// BinarySearch.FindClosest(source, 0, source.Length, -100, x => x.bound, Comparer<int>.Default, true).Should().Be(0);
BinarySearch.FindClosest(source, 0, source.Length, 0, x => x.bound, Comparer<int>.Default, true).Should().Be(0);
BinarySearch.FindClosest(source, 0, source.Length, 10, x => x.bound, Comparer<int>.Default, true).Should().Be(0);
BinarySearch.FindClosest(source, 0, source.Length, 50, x => x.bound, Comparer<int>.Default, true).Should().Be(0);
BinarySearch.FindClosest(source, 0, source.Length, -100, x => x.bound, Comparer<int>.Default, true).ShouldBe(-1);
// BinarySearch.FindClosest(source, 0, source.Length, -100, x => x.bound, Comparer<int>.Default, true).ShouldBe(0);
BinarySearch.FindClosest(source, 0, source.Length, 0, x => x.bound, Comparer<int>.Default, true).ShouldBe(0);
BinarySearch.FindClosest(source, 0, source.Length, 10, x => x.bound, Comparer<int>.Default, true).ShouldBe(0);
BinarySearch.FindClosest(source, 0, source.Length, 50, x => x.bound, Comparer<int>.Default, true).ShouldBe(0);

source[BinarySearch.FindClosest(source, 0, source.Length, 100, x => x.bound, Comparer<int>.Default, true)].id.Should().Be(1);
source[BinarySearch.FindClosest(source, 0, source.Length, 100, x => x.bound, Comparer<int>.Default, false)].id.Should().Be(1);
source[BinarySearch.FindClosest(source, 0, source.Length, 100, x => x.bound, Comparer<int>.Default, true)].id.ShouldBe(1);
source[BinarySearch.FindClosest(source, 0, source.Length, 100, x => x.bound, Comparer<int>.Default, false)].id.ShouldBe(1);

source[BinarySearch.FindClosest(source, 0, source.Length, 150, x => x.bound, Comparer<int>.Default, true)].id.Should().Be(1);
source[BinarySearch.FindClosest(source, 0, source.Length, 300, x => x.bound, Comparer<int>.Default, true)].id.Should().Be(3);
source[BinarySearch.FindClosest(source, 0, source.Length, 999, x => x.bound, Comparer<int>.Default, true)].id.Should().Be(4);
source[BinarySearch.FindClosest(source, 0, source.Length, 1000, x => x.bound, Comparer<int>.Default, true)].id.Should().Be(5);
source[BinarySearch.FindClosest(source, 0, source.Length, 1001, x => x.bound, Comparer<int>.Default, true)].id.Should().Be(5);
source[BinarySearch.FindClosest(source, 0, source.Length, 10000, x => x.bound, Comparer<int>.Default, true)].id.Should().Be(5);
// source[BinarySearch.FindClosest(source, 0, source.Length, 10000, x => x.bound, Comparer<int>.Default, false)].id.Should().Be(5);
source[BinarySearch.FindClosest(source, 0, source.Length, 150, x => x.bound, Comparer<int>.Default, true)].id.ShouldBe(1);
source[BinarySearch.FindClosest(source, 0, source.Length, 300, x => x.bound, Comparer<int>.Default, true)].id.ShouldBe(3);
source[BinarySearch.FindClosest(source, 0, source.Length, 999, x => x.bound, Comparer<int>.Default, true)].id.ShouldBe(4);
source[BinarySearch.FindClosest(source, 0, source.Length, 1000, x => x.bound, Comparer<int>.Default, true)].id.ShouldBe(5);
source[BinarySearch.FindClosest(source, 0, source.Length, 1001, x => x.bound, Comparer<int>.Default, true)].id.ShouldBe(5);
source[BinarySearch.FindClosest(source, 0, source.Length, 10000, x => x.bound, Comparer<int>.Default, true)].id.ShouldBe(5);
// source[BinarySearch.FindClosest(source, 0, source.Length, 10000, x => x.bound, Comparer<int>.Default, false)].id.ShouldBe(5);

BinarySearch.FindClosest(source, 0, source.Length, 10000, x => x.bound, Comparer<int>.Default, false).Should().Be(6);
BinarySearch.FindClosest(source, 0, source.Length, 10000, x => x.bound, Comparer<int>.Default, false).ShouldBe(6);
}
}
}
28 changes: 14 additions & 14 deletions tests/MasterMemory.Tests/DatabaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public void SingleDb()

var bin = builder.Build();
var db = new MemoryDatabase(bin);
db.SampleTable.FindById(8).Age.Should().Be(49);
db.SampleTable.FindById(8).Age.ShouldBe(49);

var tableInfo = MemoryDatabase.GetTableInfo(bin);
tableInfo[0].TableName.Should().Be("s_a_m_p_l_e");
tableInfo[0].TableName.ShouldBe("s_a_m_p_l_e");
}

[Fact]
Expand All @@ -61,12 +61,12 @@ public void All()
var bin = builder.Build();
var db = new MemoryDatabase(bin);

db.SampleTable.All.Select(x => x.Id).ToArray().Should().BeEquivalentTo(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
db.SampleTable.AllReverse.Select(x => x.Id).ToArray().Should().BeEquivalentTo(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }.Reverse());
db.SampleTable.SortByAge.Select(x => x.Id).OrderBy(x => x).ToArray().Should().BeEquivalentTo(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
db.SampleTable.All.Select(x => x.Id).ToArray().ShouldBeEquivalentTo(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
db.SampleTable.AllReverse.Select(x => x.Id).ToArray().ShouldBeEquivalentTo(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }.Reverse().ToArray());
db.SampleTable.SortByAge.Select(x => x.Id).OrderBy(x => x).ToArray().ShouldBeEquivalentTo(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
}

[Fact]
[Fact]
public void Ranges()
{
var builder = new DatabaseBuilder();
Expand All @@ -75,9 +75,9 @@ public void Ranges()
var bin = builder.Build();
var db = new MemoryDatabase(bin);

db.SampleTable.FindRangeByAge(2,2).Select(x=>x.Id).ToArray().Should().BeEquivalentTo( new int[] {} );
db.SampleTable.FindRangeByAge(30,50).Select(x=>x.Id).ToArray().Should().BeEquivalentTo( new int[] { 7, 8 } );
db.SampleTable.FindRangeByAge(100,100).Select(x=>x.Id).ToArray().Should().BeEquivalentTo( new int[] {} );
db.SampleTable.FindRangeByAge(2, 2).Select(x => x.Id).ToArray().ShouldBeEquivalentTo(new int[] { });
db.SampleTable.FindRangeByAge(30, 50).Select(x => x.Id).ToArray().ShouldBeEquivalentTo(new int[] { 7, 8 });
db.SampleTable.FindRangeByAge(100, 100).Select(x => x.Id).ToArray().ShouldBeEquivalentTo(new int[] { });
}


Expand All @@ -91,7 +91,7 @@ public void EmptyAll()
var bin = builder.Build();
var db = new MemoryDatabase(bin);

db.SampleTable.All.Any().Should().BeFalse();
db.SampleTable.All.Any().ShouldBeFalse();
}
{
var builder = new DatabaseBuilder();
Expand All @@ -100,7 +100,7 @@ public void EmptyAll()
var bin = builder.Build();
var db = new MemoryDatabase(bin);

db.SampleTable.All.Any().Should().BeFalse();
db.SampleTable.All.Any().ShouldBeFalse();
}
}

Expand All @@ -120,9 +120,9 @@ public void WithNull()
var db = new MemoryDatabase(bin);

var sample = db.SampleTable.FindById(999);
sample.Age.Should().Be(10);
sample.FirstName.Should().BeNull();
sample.LastName.Should().Be("abcde");
sample.Age.ShouldBe(10);
sample.FirstName.ShouldBeNull();
sample.LastName.ShouldBe("abcde");
}
}
}
9 changes: 4 additions & 5 deletions tests/MasterMemory.Tests/IssueTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using FluentAssertions;
using MasterMemory.Tests.TestStructures;
using MasterMemory.Tests.TestStructures;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -58,9 +57,9 @@ public void Issue57()
var bin = builder.Build();
var db = new MemoryDatabase(bin);

db.SampleTable.FindRangeByAge(2, 2).Select(x => x.Id).ToArray().Should().BeEquivalentTo(new int[] { });
db.SampleTable.FindRangeByAge(30, 50).Select(x => x.Id).ToArray().Should().BeEquivalentTo(new int[] { 7, 8 });
db.SampleTable.FindRangeByAge(100, 100).Select(x => x.Id).ToArray().Should().BeEquivalentTo(new int[] { });
db.SampleTable.FindRangeByAge(2, 2).Select(x => x.Id).ToArray().ShouldBeEquivalentTo(new int[] { });
db.SampleTable.FindRangeByAge(30, 50).Select(x => x.Id).ToArray().ShouldBeEquivalentTo(new int[] { 7, 8 });
db.SampleTable.FindRangeByAge(100, 100).Select(x => x.Id).ToArray().ShouldBeEquivalentTo(new int[] { });
}

}
Expand Down
4 changes: 2 additions & 2 deletions tests/MasterMemory.Tests/MasterMemory.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="FluentAssertions" Version="5.7.0" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
</ItemGroup>
Expand All @@ -22,7 +22,7 @@
<ItemGroup>
<Using Include="Xunit" />
<Using Include="Xunit.Abstractions" />
<Using Include="FluentAssertions" />
<Using Include="Shouldly" />
</ItemGroup>

</Project>
13 changes: 6 additions & 7 deletions tests/MasterMemory.Tests/MemoryKeyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Xunit;
using System.Linq;
using MasterMemory.Tests.Tables;
using FluentAssertions;
using MessagePack;
using System.Collections.Generic;

Expand Down Expand Up @@ -45,15 +44,15 @@ public void Unique()
{
var table = CreateTable();

table.FindById(8).Id.Should().Be(8);
table.FindById(8).Id.ShouldBe(8);
Assert.Throws<KeyNotFoundException>(() => table.FindById(100));

table.FindByIdAndAge((4, 89)).Id.Should().Be(4);
table.FindByIdAndAge((4, 89)).Id.ShouldBe(4);

Assert.Throws<KeyNotFoundException>(() => table.FindByIdAndAge((4, 899)));
Assert.Throws<KeyNotFoundException>(() => table.FindByIdAndAge((5, 89)));

table.FindByIdAndAgeAndFirstName((6, 29, "bbb")).Id.Should().Be(6);
table.FindByIdAndAgeAndFirstName((6, 29, "bbb")).Id.ShouldBe(6);
Assert.Throws<KeyNotFoundException>(() => table.FindByIdAndAgeAndFirstName((6, 29, "bbbz")));
}

Expand All @@ -64,10 +63,10 @@ public void Range()

var test = table.FindByFirstName("eee");

table.FindByFirstName("eee").Select(x => x.Id).OrderBy(x => x).Should().BeEquivalentTo(new[] { 1, 10 });
table.FindByFirstName("eeee").Count.Should().Be(0);
table.FindByFirstName("eee").Select(x => x.Id).OrderBy(x => x).ToArray().ShouldBeEquivalentTo(new[] { 1, 10 });
table.FindByFirstName("eeee").Count.ShouldBe(0);

table.FindClosestByFirstNameAndLastName(("aaa", "takz")).Id.Should().Be(4);
table.FindClosestByFirstNameAndLastName(("aaa", "takz")).Id.ShouldBe(4);
}
}
}
Loading
Loading