public void StepsTest() { Random rnd = new Random(0); MapCoordinates offset = new MapCoordinates(50, 50); for (int iTest = 0; iTest < 200; iTest++) { MapCoordinates loc1 = new MapCoordinates(rnd.Next(), rnd.Next()); MapCoordinates diff = new MapCoordinates(rnd.Next(100), rnd.Next(100)) - offset; if (rnd.Next(100) < 10) { diff = new MapCoordinates(diff.Column, 0); } if (rnd.Next(100) < 10) { diff = new MapCoordinates(0, diff.Row); } if (diff.Row == 0 && diff.Column == 0) { continue; } MapCoordinates loc2 = loc1 + diff; BresenhamStepper stepper = new BresenhamStepper(loc1, loc2); var steps = stepper.Steps.GetEnumerator(); bool foundLast = false; steps.MoveNext(); var foundFirst = steps.Current == loc1; for (int iStep = 0; iStep < 51; iStep++) { foundLast = steps.Current == loc2; if (foundLast) { break; } steps.MoveNext(); } Assert.IsTrue(foundFirst); Assert.IsTrue(foundLast); } }
private bool TestBresenhamConstruction( int columnStart, int rowStart, int columnEnd, int rowEnd, int?startingColumn = null, int?startingRow = null, bool expectException = false) { bool threwException = false; try { MapCoordinates start = new MapCoordinates(columnStart, rowStart); MapCoordinates end = new MapCoordinates(columnEnd, rowEnd); BresenhamStepper stepper = new BresenhamStepper(start, end, startingColumn, startingRow); } catch (Exception) { threwException = true; } return(!(!expectException && threwException || expectException && !threwException)); }