Skip to content

Commit

Permalink
v1.5.6 continuing test project restucturing
Browse files Browse the repository at this point in the history
  • Loading branch information
smabuk committed Dec 25, 2023
1 parent b2adddc commit ce7ff81
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 71 deletions.
4 changes: 3 additions & 1 deletion src/Smab.Helpers/GridHelpers/DoesNotContain.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace Smab.Helpers;

//
// Modified from https://source.dot.net/#System.Linq/System/Linq/Contains.cs
//
public static partial class ArrayHelpers {

public static bool DoesNotContain<TSource>(this IEnumerable<TSource> source, TSource value) =>
Expand Down
2 changes: 1 addition & 1 deletion src/Smab.Helpers/GridHelpers/Point.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,5 @@ public static Point Parse(string s, IFormatProvider? provider) {
public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, [MaybeNullWhen(false)] out Point result)
=> ISimpleParsable<Point>.TryParse(s, provider, out result);

private string DebugDisplay => $$"""{{nameof(Point)}} ({{X}}, {{Y}})""";
private readonly string DebugDisplay => $$"""{{nameof(Point)}} ({{X}}, {{Y}})""";
}
2 changes: 1 addition & 1 deletion src/Smab.Helpers/GridHelpers/Point3d.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,5 @@ public static Point3d Parse(string s, IFormatProvider? provider) {
public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, [MaybeNullWhen(false)] out Point3d result)
=> ISimpleParsable<Point3d>.TryParse(s, provider, out result);

private string DebugDisplay => $$"""{{nameof(Point3d)}} ({{X}}, {{Y}}, {{Z}})""";
private readonly string DebugDisplay => $$"""{{nameof(Point3d)}} ({{X}}, {{Y}}, {{Z}})""";
}
2 changes: 1 addition & 1 deletion src/Smab.Helpers/MathsHelpers/RangeHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static implicit operator (long start, long end)(LongRange range) {
return (start, end);
}

public void Deconstruct(out long start, out long end) {
public readonly void Deconstruct(out long start, out long end) {
start = Start;
end = End;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Smab.Helpers/Smab.Helpers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<PropertyGroup>
<PackageReleaseNotes>.NET 8.0</PackageReleaseNotes>
<VersionPrefix>1.5.5</VersionPrefix>
<VersionPrefix>1.5.6</VersionPrefix>
<Preview></Preview>
<VersionSuffix Condition="'$(Preview)' != '' And '$(BUILD_BUILDNUMBER)' == ''">$(Preview).$([System.DateTime]::get_Now().get_Year())$([System.DateTime]::get_Now().get_Month().ToString("D2"))$([System.DateTime]::get_Now().get_Day().ToString("D2"))-$([System.DateTime]::get_Now().get_Hour().ToString("D2"))$([System.DateTime]::get_Now().get_Minute().ToString("D2"))</VersionSuffix>
<VersionSuffix Condition="'$(Preview)' != '' And '$(BUILD_BUILDNUMBER)' != ''">$(Preview).$(BUILD_BUILDNUMBER)</VersionSuffix>
Expand Down
33 changes: 33 additions & 0 deletions test/Smab.Helpers.Test/ArrayHelperTests/GetAdjacent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace Smab.Helpers.Test.ArrayHelperTests;
public partial class GetAdjacent {

[Theory]
[InlineData(0, 0, false, 2)]
[InlineData(0, 0, true, 3)]
[InlineData(1, 1, false, 4)]
[InlineData(1, 1, true, 8)]
public void GetAdjacentCells_Should_Have(int X, int Y, bool includeDiagonals, int expected) {
(char, int)[] input = new (char, int)[26];
for (int i = 0; i < input.GetUpperBound(0); i++) {
input[i] = new((char)(65 + i), i + 1);
}
(char, int)[,] array = input.To2dArray<(char, int)>(5);
var points = array.GetAdjacentCells((X, Y), includeDiagonals: includeDiagonals);
points.Count().ShouldBe(expected);
}

[Theory]
[InlineData(0, 0, false, 1)]
[InlineData(1, 1, false, 3)]
[InlineData(1, 1, true, 6)]
public void GetAdjacentCells_Should_Not_Have(int X, int Y, bool includeDiagonals, int expected) {
(char, int)[] input = new (char, int)[26];
for (int i = 0; i < input.GetUpperBound(0); i++) {
input[i] = new((char)(65 + i), i + 1);
}
(char, int)[,] array = input.To2dArray(5);
var points = array.GetAdjacentCells((X, Y), includeDiagonals: includeDiagonals, exclude: [ArrayHelpers.RIGHT, ArrayHelpers.NORTH_EAST]);
points.Count().ShouldBe(expected);
}

}
29 changes: 0 additions & 29 deletions test/Smab.Helpers.Test/HelperMethodTests/ArrayHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,35 +139,6 @@ public void Walk2dArray_Should_Walk_Across_Then_Down() {
Assert.Equal(8, value.Item2);
}

[Theory]
[InlineData(0, 0, false, 2)]
[InlineData(0, 0, true, 3)]
[InlineData(1, 1, false, 4)]
[InlineData(1, 1, true, 8)]
public void GetAdjacentCells_Should_Have(int X, int Y, bool includeDiagonals, int expected) {
(char, int)[] input = new (char, int)[26];
for (int i = 0; i < input.GetUpperBound(0); i++) {
input[i] = new((char)(65 + i), i + 1);
}
(char, int)[,] array = input.To2dArray<(char, int)>(5);
var points = array.GetAdjacentCells((X, Y), includeDiagonals: includeDiagonals);
points.Count().ShouldBe(expected);
}

[Theory]
[InlineData(0, 0, false, 1)]
[InlineData(1, 1, false, 3)]
[InlineData(1, 1, true, 6)]
public void GetAdjacentCells_Should_Not_Have(int X, int Y, bool includeDiagonals, int expected) {
(char, int)[] input = new (char, int)[26];
for (int i = 0; i < input.GetUpperBound(0); i++) {
input[i] = new((char)(65 + i), i + 1);
}
(char, int)[,] array = input.To2dArray(5);
var points = array.GetAdjacentCells((X, Y), includeDiagonals: includeDiagonals, exclude: [ArrayHelpers.RIGHT, ArrayHelpers.NORTH_EAST]);
points.Count().ShouldBe(expected);
}

[Theory]
[InlineData(new int[] { 1, 2, 3, 4, 5, 6 }
, 3, 2, 2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.RegularExpressions;

namespace Smab.Helpers.Test.HelperMethodTests;

public partial class ParsingHelperTests {
[Fact]
public void TrimmedSplit_ShouldBe() {

const string INPUT = """
123, 4, 5 L : 123 ,
aaa, 4, ; x : 123 ,
""";

INPUT.TrimmedSplit().Length.ShouldBe(1);
INPUT.TrimmedSplit(Environment.NewLine).Length.ShouldBe(2);
INPUT.TrimmedSplit(',').Length.ShouldBe(6);
INPUT.TrimmedSplit([";"]).Length.ShouldBe(2);
INPUT.TrimmedSplit([";"]).Last().ShouldBe("x : 123 ,");
INPUT.TrimmedSplit(",", 5)[^2].ShouldBe("aaa");
}

namespace Smab.Helpers.Test.ParsingHelperTests;
public partial class As {
[Theory]
[InlineData("1", 1)]
[InlineData("23", 23)]
Expand All @@ -31,22 +14,6 @@ public void AsInt_ShouldBe(string input, int expected) {
Assert.Equal(expected, actual);
}

[Theory]
[InlineData("#", 1)]
[InlineData("#..#", 9)]
public void AsIntFromBinary_ShouldBe(string input, int expected) {
int actual = input.FromBinaryAs<int>();
Assert.Equal(expected, actual);
}

[Theory]
[InlineData("", 1)]
[InlineData("█ █", 9)]
public void AsIntFromBinary_WithReplacements_ShouldBe(string input, int expected) {
int actual = input.FromBinaryAs<int>(' ', '█');
Assert.Equal(expected, actual);
}

[Theory]
[InlineData("1", -99, 1)]
[InlineData("23", -99, 23)]
Expand All @@ -64,6 +31,7 @@ public void AsInts_ShouldBe(string[] input, int[] expected) {
int[] actual = ParsingHelpers.As<int>(input).ToArray();
Assert.Equal(expected, actual);
}

[Theory]
[InlineData((string[])["1", "2", "3"], (int[])[1, 2, 3,])]
[InlineData((string[])["3", "2", "1"], (int[])[3, 2, 1,])]
Expand All @@ -81,6 +49,7 @@ public void AsInts_FromString_ShouldBe_AsExtensionMethod(string input, int[] exp
int[] actual = [.. input.As<int>((char[]?)null)];
Assert.Equal(expected, actual);
}

[Theory]
[InlineData("1, 2, 3", (int[])[1, 2, 3])]
[InlineData("3, 2, 1", (int[])[3, 2, 1])]
Expand Down Expand Up @@ -129,6 +98,7 @@ public void AsLongs_ShouldBe(string[] input, long[] expected) {
long[] actual = ParsingHelpers.As<long>(input).ToArray();
Assert.Equal(expected, actual);
}

[Theory]
[InlineData((string[])["1", "2", "3"], (long[])[1, 2, 3,])]
[InlineData((string[])["3", "2", "1"], (long[])[3, 2, 1,])]
Expand Down Expand Up @@ -226,4 +196,5 @@ public static SomeThing Parse(string s, IFormatProvider? provider) {

public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, [MaybeNullWhen(false)] out SomeThing result) => ISimpleParsable<SomeThing>.TryParse(s, provider, out result);
}

}
19 changes: 19 additions & 0 deletions test/Smab.Helpers.Test/ParsingHelperTests/FromBinaryAs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Smab.Helpers.Test.ParsingHelperTests;
public partial class FromBinaryAs {
[Theory]
[InlineData("#", 1)]
[InlineData("#..#", 9)]
public void FromBinaryAs_ShouldBe(string input, int expected) {
int actual = input.FromBinaryAs<int>();
Assert.Equal(expected, actual);
}

[Theory]
[InlineData("", 1)]
[InlineData("█ █", 9)]
public void FromBinaryAs_WithReplacements_ShouldBe(string input, int expected) {
int actual = input.FromBinaryAs<int>(' ', '█');
Assert.Equal(expected, actual);
}

}
18 changes: 18 additions & 0 deletions test/Smab.Helpers.Test/ParsingHelperTests/TrimmedSplit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Smab.Helpers.Test.ParsingHelperTests;
public partial class TrimmedSplit {
[Fact]
public void TrimmedSplit_ShouldBe() {

const string INPUT = """
123, 4, 5 L : 123 ,
aaa, 4, ; x : 123 ,
""";

INPUT.TrimmedSplit().Length.ShouldBe(1);
INPUT.TrimmedSplit(Environment.NewLine).Length.ShouldBe(2);
INPUT.TrimmedSplit(',').Length.ShouldBe(6);
INPUT.TrimmedSplit([";"]).Length.ShouldBe(2);
INPUT.TrimmedSplit([";"]).Last().ShouldBe("x : 123 ,");
INPUT.TrimmedSplit(",", 5)[^2].ShouldBe("aaa");
}
}
4 changes: 2 additions & 2 deletions test/Smab.Helpers.Test/Smab.Helpers.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.5">
<PackageReference Include="xunit" Version="2.6.4" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down

0 comments on commit ce7ff81

Please sign in to comment.