Skip to content

Commit

Permalink
Add more unit tests to LineCanvas.
Browse files Browse the repository at this point in the history
  • Loading branch information
BDisp committed Nov 18, 2023
1 parent 680ba26 commit 66bc6f5
Showing 1 changed file with 231 additions and 27 deletions.
258 changes: 231 additions & 27 deletions UnitTests/Drawing/LineCanvasTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,23 +247,55 @@ public void Length_Zero_Cross_Is_Cross (Orientation orientation, string expected
TestHelpers.AssertEqual (output, expected, $"{lc}");
}

[InlineData (Orientation.Horizontal, "╥")]
[InlineData (Orientation.Vertical, "╞")]
[InlineData (Orientation.Horizontal, "╥", false)]
[InlineData (Orientation.Vertical, "╞", false)]
[InlineData (Orientation.Horizontal, "╥", true)]
[InlineData (Orientation.Vertical, "╞", true)]
[Theory, SetupFakeDriver]
public void Length_Zero_NextTo_Opposite_Is_T (Orientation orientation, string expected)
public void Length_Zero_NextTo_Opposite_Is_T (Orientation orientation, string expected, bool zeroLengthFirst)
{
var lc = new LineCanvas ();

if (zeroLengthFirst) {
// Add a line at 0, 0 that's has length of 0
lc.AddLine (new Point (0, 0), 0, orientation, LineStyle.Single);
}
// Add line with length of 1 in opposite orientation starting at same location
if (orientation == Orientation.Horizontal) {
lc.AddLine (new Point (0, 0), 1, Orientation.Vertical, LineStyle.Double);
} else {
lc.AddLine (new Point (0, 0), 1, Orientation.Horizontal, LineStyle.Double);

}
if (!zeroLengthFirst) {
// Add a line at 0, 0 that's has length of 0
lc.AddLine (new Point (0, 0), 0, orientation, LineStyle.Single);
}
TestHelpers.AssertEqual (output, expected, $"{lc}");
}

// Add a line at 0, 0 that's has length of 0
lc.AddLine (new Point (0, 0), 0, orientation, LineStyle.Single);
[InlineData (Orientation.Horizontal, "╨", false)]
[InlineData (Orientation.Vertical, "╡", false)]
[InlineData (Orientation.Horizontal, "╨", true)]
[InlineData (Orientation.Vertical, "╡", true)]
[Theory, SetupFakeDriver]
public void Length_Zero_NextTo_Negative_Opposite_Is_Opposite_T (Orientation orientation, string expected, bool zeroLengthFirst)
{
var lc = new LineCanvas ();

if (zeroLengthFirst) {
// Add a line at 0, 0 that's has length of 0
lc.AddLine (new Point (0, 0), 0, orientation, LineStyle.Single);
}
// Add line with length of 1 in opposite orientation starting at same location
if (orientation == Orientation.Horizontal) {
lc.AddLine (new Point (0, 0), -1, Orientation.Vertical, LineStyle.Double);
} else {
lc.AddLine (new Point (0, 0), -1, Orientation.Horizontal, LineStyle.Double);
}
if (!zeroLengthFirst) {
// Add a line at 0, 0 that's has length of 0
lc.AddLine (new Point (0, 0), 0, orientation, LineStyle.Single);
}
TestHelpers.AssertEqual (output, expected, $"{lc}");
}

Expand Down Expand Up @@ -795,30 +827,33 @@ public void Top_Left_From_TopRight_LeftUp ()
TestHelpers.AssertEqual (output, looksLike, $"{Environment.NewLine}{canvas}");
}

// [Fact, SetupFakeDriver]
// public void LeaveMargin_Top1_Left1 ()
// {
// var canvas = new LineCanvas ();
[Fact, SetupFakeDriver]
public void LeaveMargin_Top1_Left1 ()
{
var canvas = new LineCanvas ();

// // Upper box
// canvas.AddLine (new Point (0, 0), 9, Orientation.Horizontal, LineStyle.Single);
// canvas.AddLine (new Point (8, 0), 3, Orientation.Vertical, LineStyle.Single);
// canvas.AddLine (new Point (8, 3), -9, Orientation.Horizontal, LineStyle.Single);
// canvas.AddLine (new Point (0, 2), -3, Orientation.Vertical, LineStyle.Single);
// Upper box
canvas.AddLine (new Point (0, 0), 9, Orientation.Horizontal, LineStyle.Single);
canvas.AddLine (new Point (8, 0), 3, Orientation.Vertical, LineStyle.Single);
canvas.AddLine (new Point (8, 2), -9, Orientation.Horizontal, LineStyle.Single);
canvas.AddLine (new Point (0, 2), -3, Orientation.Vertical, LineStyle.Single);

// // Lower Box
// canvas.AddLine (new Point (5, 0), 2, Orientation.Vertical, LineStyle.Single);
// canvas.AddLine (new Point (0, 2), 9, Orientation.Horizontal, LineStyle.Single);
// Lower Box
canvas.AddLine (new Point (0, 2), 9, Orientation.Horizontal, LineStyle.Single);
canvas.AddLine (new Point (8, 2), 2, Orientation.Vertical, LineStyle.Single);
canvas.AddLine (new Point (8, 3), -9, Orientation.Horizontal, LineStyle.Single);
canvas.AddLine (new Point (0, 3), -2, Orientation.Vertical, LineStyle.Single);

// string looksLike =
//@"
//┌────┬──┐
//│ │ │
//├────┼──┤
//└────┴──┘
//";
// Assert.Equal (looksLike, $"{Environment.NewLine}{canvas}");
// }
// Middle vertical line
canvas.AddLine (new Point (5, 0), 4, Orientation.Vertical, LineStyle.Single);

string looksLike = @"
┌────┬──┐
│ │ │
├────┼──┤
└────┴──┘";
TestHelpers.AssertEqual (output, looksLike, $"{Environment.NewLine}{canvas}");
}

[InlineData (0, 0, 0, Orientation.Horizontal, LineStyle.Double, "═")]
[InlineData (0, 0, 0, Orientation.Vertical, LineStyle.Double, "║")]
Expand Down Expand Up @@ -986,5 +1021,174 @@ private View GetCanvas (out LineCanvas canvas, int offsetX = 0, int offsetY = 0)

return v;
}

[Fact, SetupFakeDriver]
public void TabWindow ()
{
var canvas = new LineCanvas ();

// Outer frame
canvas.AddLine (new Point (0, 0), 10, Orientation.Horizontal, LineStyle.Single);
canvas.AddLine (new Point (9, 0), 6, Orientation.Vertical, LineStyle.Single);
canvas.AddLine (new Point (9, 5), -10, Orientation.Horizontal, LineStyle.Single);
canvas.AddLine (new Point (0, 5), -6, Orientation.Vertical, LineStyle.Single);

// Tab frame
canvas.AddLine (new Point (1, 2), -2, Orientation.Vertical, LineStyle.Single);
canvas.AddLine (new Point (1, 1), 4, Orientation.Horizontal, LineStyle.Single);
canvas.AddLine (new Point (4, 1), 2, Orientation.Vertical, LineStyle.Single);

// Inner frame
canvas.AddLine (new Point (4, 2), 5, Orientation.Horizontal, LineStyle.Single);
canvas.AddLine (new Point (8, 2), 3, Orientation.Vertical, LineStyle.Single);
canvas.AddLine (new Point (8, 4), -8, Orientation.Horizontal, LineStyle.Single);
canvas.AddLine (new Point (1, 4), -3, Orientation.Vertical, LineStyle.Single);

string looksLike = @"
┌────────┐
│┌──┐ │
││ └───┐│
││ ││
│└──────┘│
└────────┘";
TestHelpers.AssertEqual (output, looksLike, $"{Environment.NewLine}{canvas}");
}

[Fact, SetupFakeDriver]
public void TabWindow_With_Border ()
{
var canvas = new LineCanvas ();

// Outer frame
canvas.AddLine (new Point (0, 0), 10, Orientation.Horizontal, LineStyle.Single);
canvas.AddLine (new Point (9, 0), 6, Orientation.Vertical, LineStyle.Single);
canvas.AddLine (new Point (9, 5), -10, Orientation.Horizontal, LineStyle.Single);
canvas.AddLine (new Point (0, 5), -6, Orientation.Vertical, LineStyle.Single);

// Tab frame
canvas.AddLine (new Point (1, 2), -2, Orientation.Vertical, LineStyle.Single);
canvas.AddLine (new Point (1, 1), 4, Orientation.Horizontal, LineStyle.Single);
canvas.AddLine (new Point (4, 1), 2, Orientation.Vertical, LineStyle.Single);

// Inner frame
canvas.AddLine (new Point (1, 2), 8, Orientation.Horizontal, LineStyle.Single);
canvas.AddLine (new Point (8, 2), 3, Orientation.Vertical, LineStyle.Single);
canvas.AddLine (new Point (8, 4), -8, Orientation.Horizontal, LineStyle.Single);
canvas.AddLine (new Point (1, 4), -3, Orientation.Vertical, LineStyle.Single);

string looksLike = @"
┌────────┐
│┌──┐ │
│├──┴───┐│
││ ││
│└──────┘│
└────────┘";
TestHelpers.AssertEqual (output, looksLike, $"{Environment.NewLine}{canvas}");
}

[Fact, SetupFakeDriver]
public void Test_Incomplete_Frame_Start_Left ()
{
var canvas = new LineCanvas ();

canvas.AddLine (new Point (0, 0), 1, Orientation.Vertical, LineStyle.Single);
canvas.AddLine (new Point (0, 0), 1, Orientation.Horizontal, LineStyle.Single);
canvas.AddLine (new Point (1, 0), 9, Orientation.Horizontal, LineStyle.Single);
canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, LineStyle.Single);
canvas.AddLine (new Point (9, 4), -10, Orientation.Horizontal, LineStyle.Single);
canvas.AddLine (new Point (0, 4), -2, Orientation.Vertical, LineStyle.Single);

string looksLike = @"
┌────────┐
│ │
└────────┘";
TestHelpers.AssertEqual (output, looksLike, $"{Environment.NewLine}{canvas}");
}

[Fact, SetupFakeDriver]
public void Test_Incomplete_Frame_Start_Top ()
{
var canvas = new LineCanvas ();

canvas.AddLine (new Point (0, 0), 1, Orientation.Horizontal, LineStyle.Single);
canvas.AddLine (new Point (5, 0), 5, Orientation.Horizontal, LineStyle.Single);
canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, LineStyle.Single);
canvas.AddLine (new Point (9, 4), -10, Orientation.Horizontal, LineStyle.Single);
canvas.AddLine (new Point (0, 4), -5, Orientation.Vertical, LineStyle.Single);

string looksLike = @"
┌ ────┐
│ │
│ │
│ │
└────────┘";
TestHelpers.AssertEqual (output, looksLike, $"{Environment.NewLine}{canvas}");
}

[Fact, SetupFakeDriver]
public void Test_Incomplete_Frame_Start_Right ()
{
var canvas = new LineCanvas ();

canvas.AddLine (new Point (0, 0), 10, Orientation.Horizontal, LineStyle.Single);
canvas.AddLine (new Point (9, 0), 1, Orientation.Vertical, LineStyle.Single);
canvas.AddLine (new Point (9, 3), 2, Orientation.Vertical, LineStyle.Single);
canvas.AddLine (new Point (9, 4), -10, Orientation.Horizontal, LineStyle.Single);
canvas.AddLine (new Point (0, 4), -5, Orientation.Vertical, LineStyle.Single);

string looksLike = @"
┌────────┐
│ │
└────────┘";
TestHelpers.AssertEqual (output, looksLike, $"{Environment.NewLine}{canvas}");
}

[Fact, SetupFakeDriver]
public void Test_Incomplete_Frame_Start_Bottom ()
{
var canvas = new LineCanvas ();

canvas.AddLine (new Point (9, 4), -1, Orientation.Vertical, LineStyle.Single);
canvas.AddLine (new Point (9, 4), -1, Orientation.Horizontal, LineStyle.Single);
canvas.AddLine (new Point (4, 4), -5, Orientation.Horizontal, LineStyle.Single);
canvas.AddLine (new Point (0, 4), -5, Orientation.Vertical, LineStyle.Single);
canvas.AddLine (new Point (0, 0), 10, Orientation.Horizontal, LineStyle.Single);
canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, LineStyle.Single);

string looksLike = @"
┌────────┐
│ │
│ │
│ │
└──── ┘";
TestHelpers.AssertEqual (output, looksLike, $"{Environment.NewLine}{canvas}");
}

[Theory]
[InlineData (0, 0, 1, Orientation.Vertical, 0, 0, 1, "┌")]
[InlineData (0, 0, 1, Orientation.Vertical, 0, 0, -1, "┐")]
[InlineData (0, 0, -1, Orientation.Vertical, 0, 0, 1, "└")]
[InlineData (0, 0, -1, Orientation.Vertical, 0, 0, -1, "┘")]
[InlineData (0, 0, 1, Orientation.Horizontal, 0, 0, 1, "┌")]
[InlineData (0, 0, -1, Orientation.Horizontal, 0, 0, 1, "┐")]
[InlineData (0, 0, 1, Orientation.Horizontal, 0, 0, -1, "└")]
[InlineData (0, 0, -1, Orientation.Horizontal, 0, 0, -1, "┘")]
public void Corner_Tests (int x, int y, int length, Orientation orientation, int x1, int y1, int length1, string looksLike)
{
var canvas = new LineCanvas ();
if (orientation == Orientation.Vertical) {
canvas.AddLine (new Point (x, y), length, Orientation.Vertical, LineStyle.Single);
canvas.AddLine (new Point (x1, y1), length1, Orientation.Horizontal, LineStyle.Single);
} else {
canvas.AddLine (new Point (x, y), length, Orientation.Horizontal, LineStyle.Single);
canvas.AddLine (new Point (x1, y1), length1, Orientation.Vertical, LineStyle.Single);
}

TestHelpers.AssertEqual (output, looksLike, $"{canvas}");
}
}
}

0 comments on commit 66bc6f5

Please sign in to comment.