public void CheckLinesTest() { Board b = new Board(7, 7, 3); Point p, pc; List<Point> result; List<Point> knownh, knownv, knowndl, knowndr, known; pc = new Point(2, 2); knownh = new List<Point>(); ushort row; ushort col; ushort count; /* o o o o o o o o * o o o o o o o o * + + + + o o o o * o o o o o o o o * o o o o o o o o */ for (row = pc.Row, col = 0, count = 0; count < 4; col++, count++) { p = new Point(row, col); knownh.Add(p); b.PlaceItem(p, 1); } result = b.CheckLines(knownh.ElementAt(0)); Assert.AreEqual(0, result.Count); /* o o o o o o o o * o o o o o o o o * + + + + + o o o * o o o o o o o o * o o o o o o o o */ p = new Point(row, col++); knownh.Add(p); b.PlaceItem(p, 1); // from right result = b.CheckLines(knownh.ElementAt(4)); CollectionAssert.AreEquivalent(knownh, result); // from middle result = b.CheckLines(knownh.ElementAt(2)); CollectionAssert.AreEquivalent(knownh, result); // from left result = b.CheckLines(knownh.ElementAt(0)); CollectionAssert.AreEquivalent(knownh, result); // switch out the color b.ClearItem(pc); b.PlaceItem(pc, 2); // from left result = b.CheckLines(knownh.ElementAt(0)); Assert.AreEqual(0, result.Count); // from middle result = b.CheckLines(knownh.ElementAt(2)); Assert.AreEqual(0, result.Count); // from right result = b.CheckLines(knownh.ElementAt(4)); Assert.AreEqual(0, result.Count); b.ClearItem(pc); b.PlaceItem(pc, 1); // more than 5 /* o o o o o o o o * o o o o o o o o * + + + + + + o o * o o o o o o o o * o o o o o o o o */ p = new Point(row, col++); knownh.Add(p); b.PlaceItem(p, 1); result = b.CheckLines(p); CollectionAssert.AreEquivalent(knownh, result); /* o o + o o o o o * o o + o o o o o * + + + + + + + o * o o + o o o o o * o o + o o o o o */ knownv = new List<Point>(); for (row = 0, col = pc.Col, count = 0; count < 5; row++, count++) { p = new Point(row, col); knownv.Add(p); if (!p.Equals(pc)) b.PlaceItem(p, 1); } // from bottom result = b.CheckLines(p); CollectionAssert.AreEquivalent(knownv, result); // from top result = b.CheckLines(knownv.ElementAt(0)); CollectionAssert.AreEquivalent(knownv, result); // two directions known = new List<Point>(); known.AddRange(knownh.AsEnumerable()); known.AddRange(knownv.AsEnumerable()); // there is an extra point at the intersection known.Remove(pc); result = b.CheckLines(pc); CollectionAssert.AreEquivalent(known, result); /* o o + o o o o o * o o + o o o o o * + + + + + + + o * o o + + o o o o * o o + o + o o o * o o o o o + o o * o o o o o o + o */ knowndl = new List<Point>(); for (row = pc.Row, col = pc.Col, count = 0; count < 5; row++, col++, count++) { p = new Point(row, col); knowndl.Add(p); if (!p.Equals(pc)) b.PlaceItem(p, 1); } // from top left (second) result = b.CheckLines(knowndl.ElementAt(1)); CollectionAssert.AreEquivalent(knowndl, result); // from bottom right result = b.CheckLines(knowndl.ElementAt(4)); CollectionAssert.AreEquivalent(knowndl, result); // three directions known.AddRange(knowndl.AsEnumerable()); known.Remove(pc); result = b.CheckLines(pc); CollectionAssert.AreEquivalent(known, result); /* o o + o + o o o * o o + + o o o o * + + + + + + + o * o + + + o o o o * + o + o + o o o * o o + o o + o o * o o + o o o + o */ knowndr = new List<Point>(); for (row = 4, col = 0, count = 0; count < 5; row--, col++, count++) { p = new Point(row, col); knowndr.Add(p); if (!p.Equals(pc)) b.PlaceItem(p, 1); } // from bottom left result = b.CheckLines(knowndr.ElementAt(0)); CollectionAssert.AreEquivalent(knowndr, result); // from top right result = b.CheckLines(knowndr.ElementAt(4)); CollectionAssert.AreEquivalent(knowndr, result); // four directions known.AddRange(knowndr.AsEnumerable()); known.Remove(pc); result = b.CheckLines(pc); CollectionAssert.AreEquivalent(known, result); }
public void ClearItemTest() { Board b = new Board(2, 2, 1); b.PlaceItem(new Point(1, 1), 1); b.ClearItem(new Point(1, 1)); Assert.AreEqual(b.NumEmpty, 4, "did not clear item"); bool threwException = false; try { b.ClearItem(new Point(1, 1)); } catch { threwException = true; } Assert.IsTrue(threwException, "did not throw exception on double clear"); }