コード例 #1
0
ファイル: Program.cs プロジェクト: fsgeek/TreeLib
        // "You know it seemed a bit daft me having to guard him when he's a guard."
        private static void TestFramework()
        {
            TextWriter savedOutput = Console.Out;

            Console.SetOut(TextWriter.Null);

            TestBase    testBase    = new TestBase();
            UnitTestMap unitTestMap = new UnitTestMap();

            testBase.TestNoThrow(String.Empty, delegate() { testBase.TestTrue(String.Empty, delegate() { return(true); }); });
            testBase.TestThrow(String.Empty, typeof(UnitTestFailureException), delegate() { testBase.TestTrue(String.Empty, delegate() { return(false); }); });
            testBase.TestThrow(String.Empty, typeof(UnitTestFailureException), delegate() { testBase.TestTrue(String.Empty, delegate() { throw new NotImplementedException(); }); });
            testBase.TestThrow(String.Empty, typeof(UnitTestFailureException), delegate() { testBase.TestNoThrow(String.Empty, delegate() { throw new NotImplementedException(); }); });
            testBase.TestThrow(String.Empty, typeof(UnitTestFailureException), delegate() { testBase.TestThrow(String.Empty, typeof(NotImplementedException), delegate() { throw new NotImplementedException(); }); });
            testBase.TestThrow(String.Empty, typeof(UnitTestFailureException), delegate() { testBase.TestThrow(String.Empty, typeof(NotImplementedException), delegate() { throw new Exception(); }); });
            testBase.TestNoThrow(String.Empty, delegate() { unitTestMap.TestTree(String.Empty, new SplayTreeMap <int, bool>(), new UnitTestMap.Op <int, bool>[] { }, delegate() { }); });
            testBase.TestThrow(String.Empty, typeof(UnitTestFailureException), delegate() { unitTestMap.TestTree(String.Empty, new SplayTreeMap <int, bool>(), new UnitTestMap.Op <int, bool>[] { new FailOp(), }, delegate() { throw new NotImplementedException(); }); });
            testBase.TestThrow(String.Empty, typeof(UnitTestFailureException), delegate() { unitTestMap.TestTree(String.Empty, new SplayTreeMap <int, bool>(), new UnitTestMap.Op <int, bool>[] { }, delegate() { throw new NotImplementedException(); }); });

            Console.WriteLine(new Range2MapEntry(new Range(0, 0), new Range(0, 0), String.Empty).ToString());
            Console.WriteLine(new MultiRankMapEntry(0, new Range(0, 0), 0));

            SplayTreeMap <int, int> tree = new SplayTreeMap <int, int>();

            tree.Add(1, 1);
            tree.Add(2, 2);
            TestBase.Dump(tree);

            Console.SetOut(savedOutput);
        }
コード例 #2
0
ファイル: MapTest.cs プロジェクト: Corniel/AIGames.Warlight2
        public void PickableStartRegions_Select_AreEqual()
        {
            var map = UnitTestMap.InitSmall();

            var act = map.PickableStartRegions.Select(region => region.Id).ToArray();
            var exp = new int[] { 1, 2, 3, 4, 7, 8, 9, 11 };

            CollectionAssert.AreEqual(exp, act);
        }
コード例 #3
0
        public void CreateStack_FromRegion_areEqual()
        {
            var map = UnitTestMap.Init();

            var move = Move.CreateStack(PlayerType.player1, map[17], 5);
            var act  = move.DebuggerDisplay;
            var exp  = "Stack(1): 17 (5)";

            Assert.AreEqual(exp, act);
        }
コード例 #4
0
        public void CreateSelect_FromRegion_areEqual()
        {
            var map = UnitTestMap.Init();

            var move = Move.CreateSelect(PlayerType.player2, map[17]);
            var act  = move.DebuggerDisplay;
            var exp  = "Select(2): 17";

            Assert.AreEqual(exp, act);
        }
コード例 #5
0
        public void Contains_12_AreEqual()
        {
            var map         = UnitTestMap.Init();
            var superregion = map.SuperRegions.Single(superRegion => superRegion.Id == 6);

            var act = superregion.Contains(map[12]);
            var exp = false;

            Assert.AreEqual(exp, act);
        }
コード例 #6
0
        public void SelectByIndex_39Australia_AreEqual()
        {
            var map         = UnitTestMap.Init();
            var superregion = map.SuperRegions.Single(superRegion => superRegion.Id == 6);

            var act = superregion[39];
            var exp = map[39];

            Assert.AreEqual(exp, act);
        }
コード例 #7
0
        public void DebugToString_Australia_AreEqual()
        {
            var map         = UnitTestMap.Init();
            var superregion = map.SuperRegions.Single(superRegion => superRegion.Id == 6);

            var act = superregion.DebugToString();
            var exp = "SuperRegion[6,2]: Australia, Regions: 4";

            Assert.AreEqual(exp, act);
        }
コード例 #8
0
        public void CreateTransfer_FromRegions_areEqual()
        {
            var map = UnitTestMap.Init();

            var move = Move.CreateTransfer(PlayerType.player1, map[17], map[42], 18);
            var act  = move.DebuggerDisplay;
            var exp  = "A/T(1): 17=>42 (18)";

            Assert.AreEqual(exp, act);
        }
コード例 #9
0
        public void DebugToString_EasternAustralia_AreEqual()
        {
            var map    = UnitTestMap.Init();
            var region = map[42];

            var act = region.DebugToString();
            var exp = "Region[42,6]: Eastern Australia, Neighbors(2):  New Guinea, Western Australia";

            Assert.AreEqual(exp, act);
        }
コード例 #10
0
ファイル: MapTest.cs プロジェクト: Corniel/AIGames.Warlight2
        public void Contains_Region12_AreEqual()
        {
            var map    = UnitTestMap.Init();
            var region = map[12];

            var act = map.Contains(region);
            var exp = true;

            Assert.AreEqual(exp, act);
        }
コード例 #11
0
        public void DebugToString_Alaska_AreEqual()
        {
            var map    = UnitTestMap.Init();
            var region = map[1];

            var act = region.DebugToString();
            var exp = "Region[1,1]: Alaska*, Neighbors(3):  Northwest Territory, Alberta, Kamchatka";

            Assert.AreEqual(exp, act);
        }
コード例 #12
0
        public void Map_EasternAustralia_IsNotNull()
        {
            var map    = UnitTestMap.Init();
            var region = map[42];

            var parent = region.Map;

            Assert.IsNotNull(parent);
            Assert.AreEqual(map, parent);
        }
コード例 #13
0
        public void GetNeighbors_Afrika_AreEqual()
        {
            var map = UnitTestMap.Init();

            var superregion = map.SuperRegions.Single(superRegion => superRegion.Id == 4);

            var act = superregion.GetNeighbors().ToArray();
            var exp = new Region[] { map[12], map[18], map[20], map[36] };

            CollectionAssert.AreEqual(exp, act);
        }
コード例 #14
0
        public void GetIncludingNeighbors_SouthAmerica_AreEqual()
        {
            var map = UnitTestMap.Init();

            var superregion = map.SuperRegions.Single(superRegion => superRegion.Id == 2);

            var act = superregion.GetIncludingNeighbors().ToArray();
            var exp = new Region[] { map[9], map[11], map[12], map[10], map[13], map[21] };

            CollectionAssert.AreEqual(exp, act);
        }
コード例 #15
0
        public void GetBorders_Australia_AreEqual()
        {
            var map = UnitTestMap.Init();

            var superregion = map.SuperRegions.Single(superRegion => superRegion.Id == 6);

            var act = superregion.GetBorders().ToArray();
            var exp = new Region[] { map[39] };

            CollectionAssert.AreEqual(exp, act);
        }
コード例 #16
0
        public void Owner_Region_AreEqual()
        {
            var map = UnitTestMap.InitSmall();

            var state = new MapState(map.Count);

            state.Set(1, 2, 13);

            var act = state.Owner(map[1]);
            var exp = PlayerType.player2;

            Assert.AreEqual(exp, act);
        }
コード例 #17
0
        public void Armies_Region_AreEqual()
        {
            var map = UnitTestMap.InitSmall();

            var state = new MapState(map.Count);

            state.Set(1, (ushort)PlayerType.player1, 13);

            var act = state.Armies(map[1]);
            var exp = 13;

            Assert.AreEqual(exp, act);
        }
コード例 #18
0
ファイル: MapTest.cs プロジェクト: Corniel/AIGames.Warlight2
        public void Select_3Items_AreEqual()
        {
            var map = UnitTestMap.InitSmall();

            var act = map.Select(1, 2, 4).ToList();
            var exp = new List <Region>()
            {
                map[1],
                map[2],
                map[4],
            };

            CollectionAssert.AreEqual(exp, act);
        }
コード例 #19
0
        public void GetRegionsForPlayer_MapInit_AreEqual()
        {
            var map   = UnitTestMap.Init();
            var state = map.ToInitialRegionState();

            state.Set(03, (int)PlayerType.player1, 2);
            state.Set(14, (int)PlayerType.player1, 2);
            state.Set(21, (int)PlayerType.player1, 2);
            state.Set(16, (int)PlayerType.player2, 2);

            var player1s = map.GetRegionsForPlayer(PlayerType.player1, state).ToList();
            var player2s = map.GetRegionsForPlayer(PlayerType.player2, state).ToList();
            var neutrals = map.GetRegionsForPlayer(PlayerType.neutral, state).ToList();

            Assert.AreEqual(3, player1s.Count, "player1s.Count");
            Assert.AreEqual(1, player2s.Count, "player2s.Count");
            Assert.AreEqual(38, neutrals.Count, "neutrals.Count");
        }