Skip to content

Commit

Permalink
Add another MakrPoint2D object initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
windperson committed May 26, 2020
1 parent 48bfc92 commit a7795bc
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 67 deletions.
16 changes: 13 additions & 3 deletions src/GranDen.GameLib.Bingo/MarkPoint2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class MarkPoint2D : IntPoint2D
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="marked"></param>
public MarkPoint2D(int x, int y, bool marked) : base((x, y))
public MarkPoint2D(int x, int y, bool marked = true) : base((x, y))
{
Marked = marked;
}
Expand All @@ -34,11 +34,21 @@ public MarkPoint2D((int x, int y, bool marked) markPointTuple) : base((markPoint
}

/// <summary>
/// Init a MarkPoint2D object using base class object and a boolean value to indicate marked or not
/// Init a MarkPoint2D object using base class object and an optional boolean value to indicate marked or not
/// </summary>
/// <param name="point2D"></param>
/// <param name="marked"></param>
public MarkPoint2D(IntPoint2D point2D, bool marked) : base(point2D.X, point2D.Y)
public MarkPoint2D(IntPoint2D point2D, bool marked = true) : base(point2D.X, point2D.Y)
{
Marked = marked;
}

/// <summary>
/// Init a MarkPoint2D object using base class object and an optional boolean value to indicate marked or not
/// </summary>
/// <param name="pointTuple"></param>
/// <param name="marked"></param>
public MarkPoint2D((int x, int y) pointTuple, bool marked = true) : base(pointTuple.x, pointTuple.y)
{
Marked = marked;
}
Expand Down
48 changes: 24 additions & 24 deletions test/netcore/NetCoreBingoTest/ObjectThreeDotThreePoint2dTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,58 +181,58 @@ public override int GetHashCode()

private readonly List<MarkPoint2D> _marked1StRowData = new List<MarkPoint2D>
{
new MarkPoint2D(0, 0, true),
new MarkPoint2D(1, 0, true),
new MarkPoint2D(2, 0, true)
new MarkPoint2D(0, 0 ),
new MarkPoint2D(1, 0 ),
new MarkPoint2D(2, 0 )
};

private readonly List<MarkPoint2D> _marked2NdRowData = new List<MarkPoint2D>
{
new MarkPoint2D(0, 1, true),
new MarkPoint2D(1, 1, true),
new MarkPoint2D(2, 1, true)
new MarkPoint2D(0, 1),
new MarkPoint2D(1, 1),
new MarkPoint2D(2, 1)
};

private readonly List<MarkPoint2D> _marked3RdRowData = new List<MarkPoint2D>
{
new MarkPoint2D(0, 2, true),
new MarkPoint2D(1, 2, true),
new MarkPoint2D(2, 2, true)
new MarkPoint2D(0, 2),
new MarkPoint2D(1, 2),
new MarkPoint2D(2, 2)
};

private readonly List<MarkPoint2D> _marked1StColData = new List<MarkPoint2D>
{
new MarkPoint2D(0, 0, true),
new MarkPoint2D(0, 1, true),
new MarkPoint2D(0, 2, true)
new MarkPoint2D(0, 0),
new MarkPoint2D(0, 1),
new MarkPoint2D(0, 2)
};

private readonly List<MarkPoint2D> _marked2NdColData = new List<MarkPoint2D>
{
new MarkPoint2D(1, 0, true),
new MarkPoint2D(1, 1, true),
new MarkPoint2D(1, 2, true)
new MarkPoint2D(1, 0),
new MarkPoint2D(1, 1),
new MarkPoint2D(1, 2)
};

private readonly List<MarkPoint2D> _marked3rdColData = new List<MarkPoint2D>
{
new MarkPoint2D(2, 0, true),
new MarkPoint2D(2, 1, true),
new MarkPoint2D(2, 2, true)
new MarkPoint2D(2, 0),
new MarkPoint2D(2, 1),
new MarkPoint2D(2, 2)
};

private readonly List<MarkPoint2D> _markedSlashDiagonalData = new List<MarkPoint2D>
{
new MarkPoint2D(0, 0, true),
new MarkPoint2D(1, 1, true),
new MarkPoint2D(2, 2, true)
new MarkPoint2D(0, 0),
new MarkPoint2D(1, 1),
new MarkPoint2D(2, 2)
};

private readonly List<MarkPoint2D> _markedBackSlashDiagonalData = new List<MarkPoint2D>
{
new MarkPoint2D(3, 0, true),
new MarkPoint2D(2, 1, true),
new MarkPoint2D(1, 2, true)
new MarkPoint2D(3, 0),
new MarkPoint2D(2, 1),
new MarkPoint2D(1, 2)
};

#endregion
Expand Down
80 changes: 40 additions & 40 deletions test/netcore/NetCoreBingoTest/SimpleFourDotFourPoint2dTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,82 +164,82 @@ public void TestShouldGetDiagonalPrize()

readonly List<MarkPoint2D> _marked1StRowData = new List<MarkPoint2D>
{
new MarkPoint2D(0, 0, true),
new MarkPoint2D(1, 0, true),
new MarkPoint2D(2, 0, true),
new MarkPoint2D(3, 0, true)
new MarkPoint2D(0, 0),
new MarkPoint2D(1, 0),
new MarkPoint2D(2, 0),
new MarkPoint2D(3, 0)
};

readonly List<MarkPoint2D> _marked2NdRowData = new List<MarkPoint2D>
{
new MarkPoint2D(0, 1, true),
new MarkPoint2D(1, 1, true),
new MarkPoint2D(2, 1, true),
new MarkPoint2D(3, 1, true)
new MarkPoint2D(0, 1),
new MarkPoint2D(1, 1),
new MarkPoint2D(2, 1),
new MarkPoint2D(3, 1)
};

readonly List<MarkPoint2D> _marked3RdRowData = new List<MarkPoint2D>
{
new MarkPoint2D(0, 2, true),
new MarkPoint2D(1, 2, true),
new MarkPoint2D(2, 2, true),
new MarkPoint2D(3, 2, true)
new MarkPoint2D(0, 2),
new MarkPoint2D(1, 2),
new MarkPoint2D(2, 2),
new MarkPoint2D(3, 2)
};

readonly List<MarkPoint2D> _marked4ThRowData = new List<MarkPoint2D>
{
new MarkPoint2D(0, 3, true),
new MarkPoint2D(1, 3, true),
new MarkPoint2D(2, 3, true),
new MarkPoint2D(3, 3, true)
new MarkPoint2D(0, 3),
new MarkPoint2D(1, 3),
new MarkPoint2D(2, 3),
new MarkPoint2D(3, 3)
};

readonly List<MarkPoint2D> _marked1StColData = new List<MarkPoint2D>
{
new MarkPoint2D(0, 0, true),
new MarkPoint2D(0, 1, true),
new MarkPoint2D(0, 2, true),
new MarkPoint2D(0, 3, true)
new MarkPoint2D(0, 0),
new MarkPoint2D(0, 1),
new MarkPoint2D(0, 2),
new MarkPoint2D(0, 3)
};

readonly List<MarkPoint2D> _marked2NdColData = new List<MarkPoint2D>
{
new MarkPoint2D(1, 0, true),
new MarkPoint2D(1, 1, true),
new MarkPoint2D(1, 2, true),
new MarkPoint2D(1, 3, true)
new MarkPoint2D(1, 0),
new MarkPoint2D(1, 1),
new MarkPoint2D(1, 2),
new MarkPoint2D(1, 3)
};

readonly List<MarkPoint2D> _marked3rdColData = new List<MarkPoint2D>
{
new MarkPoint2D(2, 0, true),
new MarkPoint2D(2, 1, true),
new MarkPoint2D(2, 2, true),
new MarkPoint2D(2, 3, true)
new MarkPoint2D(2, 0),
new MarkPoint2D(2, 1),
new MarkPoint2D(2, 2),
new MarkPoint2D(2, 3)
};

readonly List<MarkPoint2D> _marked4thColData = new List<MarkPoint2D>
{
new MarkPoint2D(3, 0, true),
new MarkPoint2D(3, 1, true),
new MarkPoint2D(3, 2, true),
new MarkPoint2D(3, 3, true)
new MarkPoint2D(3, 0),
new MarkPoint2D(3, 1),
new MarkPoint2D(3, 2),
new MarkPoint2D(3, 3)
};

readonly List<MarkPoint2D> _markedSlashDiagonalData = new List<MarkPoint2D>
{
new MarkPoint2D(0, 0, true),
new MarkPoint2D(1, 1, true),
new MarkPoint2D(2, 2, true),
new MarkPoint2D(3, 3, true)
new MarkPoint2D(0, 0),
new MarkPoint2D(1, 1),
new MarkPoint2D(2, 2),
new MarkPoint2D(3, 3)
};

readonly List<MarkPoint2D> _markedBackSlashDiagonalData = new List<MarkPoint2D>
{
new MarkPoint2D(3, 0, true),
new MarkPoint2D(2, 1, true),
new MarkPoint2D(1, 2, true),
new MarkPoint2D(0, 3, true)
new MarkPoint2D(3, 0),
new MarkPoint2D(2, 1),
new MarkPoint2D(1, 2),
new MarkPoint2D(0, 3)
};

#endregion
Expand Down
118 changes: 118 additions & 0 deletions test/netcore/NetCoreBingoTest/Struct5x5Point2dTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
using System.Collections.Generic;
using System.Linq;
using GranDen.GameLib.Bingo;
using Xunit;

namespace NetCoreBingoTest
{
public class Struct5x5Point2dTest
{
[Fact]
public void TestNoPrizeLine()
{
//Arrange
var bingo = new Bingo2dPrizeClincher<MyPrize>(new List<PrizeLine2D<MyPrize>>());
var markedPoints = new List<MarkPoint2D>
{
new MarkPoint2D((0, 0, true)),
new MarkPoint2D((0, 1, true)),
new MarkPoint2D((1, 1, false))
};

//Act
var matchedPrizes = bingo.Decide(markedPoints);

//Assert
Assert.Empty(matchedPrizes);
}

[Fact]
public void TestAllPrizeLine()
{
//Arrange
var allPrize = _horizontalPrize.Concat(_verticalPrize).Concat(_diagonalPrize).ToList();
var bingo = new Bingo2dPrizeClincher<MyPrize>(allPrize);
var markedPoints = new List<MarkPoint2D>
{
new MarkPoint2D((0, 0)), new MarkPoint2D((1, 0)), new MarkPoint2D((2, 0)), new MarkPoint2D((3, 0)), new MarkPoint2D((4, 0)),
new MarkPoint2D((0, 1)), new MarkPoint2D((1, 1)), new MarkPoint2D((2, 1)), new MarkPoint2D((3, 1)), new MarkPoint2D((4, 1)),
new MarkPoint2D((0, 2)), new MarkPoint2D((1, 2)), new MarkPoint2D((2, 2)), new MarkPoint2D((3, 2)), new MarkPoint2D((4, 2)),
new MarkPoint2D((0, 3)), new MarkPoint2D((1, 3)), new MarkPoint2D((2, 3)), new MarkPoint2D((3, 3)), new MarkPoint2D((4, 3)),
new MarkPoint2D((0, 4)), new MarkPoint2D((1, 4)), new MarkPoint2D((2, 4)), new MarkPoint2D((3, 4)), new MarkPoint2D((4, 4)),
};

//Act
var matchedPrizes = bingo.Decide(markedPoints);

//Assert
Assert.True(matchedPrizes.Count == allPrize.Count);
Assert.Collection(matchedPrizes,
m => Assert.Equal(allPrize[0].Prize, m),
m => Assert.Equal(allPrize[1].Prize, m),
m => Assert.Equal(allPrize[2].Prize, m),
m => Assert.Equal(allPrize[3].Prize, m),
m => Assert.Equal(allPrize[4].Prize, m),
m => Assert.Equal(allPrize[5].Prize, m),
m => Assert.Equal(allPrize[6].Prize, m),
m => Assert.Equal(allPrize[7].Prize, m),
m => Assert.Equal(allPrize[8].Prize, m),
m => Assert.Equal(allPrize[9].Prize, m),
m => Assert.Equal(allPrize[10].Prize, m),
m => Assert.Equal(allPrize[11].Prize, m));
}

#region Helper Class and Properties

private struct MyPrize
{
public string Name { get; set; }
}

private static List<PrizeLine2D<MyPrize>> _horizontalPrize => new List<PrizeLine2D<MyPrize>>
{
new PrizeLine2D<MyPrize>(new List<(int X, int Y)> {(0, 0), (1, 0), (2, 0), (3, 0), (4, 0)},
new MyPrize {Name = "Horizontal Line1"}),

new PrizeLine2D<MyPrize>(new List<(int X, int Y)> {(0, 1), (1, 1), (2, 1), (3, 1), (4, 1)},
new MyPrize {Name = "Horizontal Line2"}),

new PrizeLine2D<MyPrize>(new List<(int X, int Y)> {(0, 2), (1, 2), (2, 2), (3, 2), (4, 2)},
new MyPrize {Name = "Horizontal Line3"}),

new PrizeLine2D<MyPrize>(new List<(int X, int Y)> {(0, 3), (1, 3), (2, 3), (3, 3), (4, 3)},
new MyPrize {Name = "Horizontal Line4"}),

new PrizeLine2D<MyPrize>(new List<(int X, int Y)> {(0, 4), (1, 4), (2, 4), (3, 4), (4, 4)},
new MyPrize {Name = "Horizontal Line5"}),
};

private static List<PrizeLine2D<MyPrize>> _verticalPrize => new List<PrizeLine2D<MyPrize>>
{
new PrizeLine2D<MyPrize>(new List<(int X, int Y)> {(0, 0), (0, 1), (0, 2), (0, 3), (0, 4)},
new MyPrize {Name = "Vertical Line1"}),

new PrizeLine2D<MyPrize>(new List<(int X, int Y)> {(1, 0), (1, 1), (1, 2), (1, 3), (1, 4)},
new MyPrize {Name = "Vertical Line2"}),

new PrizeLine2D<MyPrize>(new List<(int X, int Y)> {(2, 0), (2, 1), (2, 2), (2, 3), (2, 4)},
new MyPrize {Name = "Vertical Line3"}),

new PrizeLine2D<MyPrize>(new List<(int X, int Y)> {(3, 0), (3, 1), (3, 2), (3, 3), (3, 4)},
new MyPrize {Name = "Vertical Line4"}),

new PrizeLine2D<MyPrize>(new List<(int X, int Y)> {(4, 0), (4, 1), (4, 2), (4, 3), (4, 4)},
new MyPrize {Name = "Vertical Line5"}),
};

private static List<PrizeLine2D<MyPrize>> _diagonalPrize => new List<PrizeLine2D<MyPrize>>
{
new PrizeLine2D<MyPrize>(new List<(int X, int Y)> {(0, 0), (1, 1), (2, 2), (3, 3), (4, 4)},
new MyPrize {Name = "Diagonal Line1"}),

new PrizeLine2D<MyPrize>(new List<(int X, int Y)> {(4, 0), (3, 1), (2, 2), (1, 3), (0, 4)},
new MyPrize {Name = "Diagonal Line2"}),
};

#endregion
}
}

0 comments on commit a7795bc

Please sign in to comment.