Exemple #1
0
        public void TestIndexing()
        {
            var hgc = new HexGridCollectionAdapter(3, 3);

            var allHexes = hgc.ToList();

            // this assumes that hexagons are generated column by column
            var i = 0;

            Assert.AreEqual(allHexes[i++], hgc.GetHex(HexCoords.CreateFromOffset(0, 0)));
            Assert.AreEqual(allHexes[i++], hgc.GetHex(HexCoords.CreateFromOffset(1, 0)));
            Assert.AreEqual(allHexes[i++], hgc.GetHex(HexCoords.CreateFromOffset(2, 0)));

            Assert.AreEqual(allHexes[i++], hgc.GetHex(HexCoords.CreateFromOffset(0, 1)));
            Assert.AreEqual(allHexes[i++], hgc.GetHex(HexCoords.CreateFromOffset(1, 1)));
            Assert.AreEqual(allHexes[i++], hgc.GetHex(HexCoords.CreateFromOffset(2, 1)));

            Assert.AreEqual(allHexes[i++], hgc.GetHex(HexCoords.CreateFromOffset(0, 2)));
            Assert.AreEqual(allHexes[i++], hgc.GetHex(HexCoords.CreateFromOffset(1, 2)));
            Assert.AreEqual(allHexes[i], hgc.GetHex(HexCoords.CreateFromOffset(2, 2)));

            Assert.ThrowsException <IndexOutOfRangeException>(() => hgc.GetHex(HexCoords.CreateFromOffset(-1, 0)));
            Assert.ThrowsException <IndexOutOfRangeException>(() => hgc.GetHex(HexCoords.CreateFromOffset(0, -1)));
            Assert.ThrowsException <IndexOutOfRangeException>(() => hgc.GetHex(HexCoords.CreateFromOffset(3, 0)));
            Assert.ThrowsException <IndexOutOfRangeException>(() => hgc.GetHex(HexCoords.CreateFromOffset(3, 2)));
            Assert.ThrowsException <IndexOutOfRangeException>(() => hgc.GetHex(HexCoords.CreateFromOffset(0, 3)));
        }
Exemple #2
0
        public void TestSize()
        {
            var hgc = new HexGridCollectionAdapter(3, 3);

            var hexes = hgc.ToList();

            Assert.AreEqual(hexes.Count, 3 * 3);
        }