コード例 #1
0
        public void InputHasTwoZerosTest()
        {
            var expected = new int[] { 0, 0, 0, 0, 0 };
            var actual   = Greedy.GetProductsOfAllIntsExceptAtIndex(new int[] { 4, 0, 9, 1, 0 });

            Assert.Equal(expected, actual);
        }
コード例 #2
0
        public void ArrayHasOneNegativeTest()
        {
            var actual   = Greedy.HighestProductOf3(new int[] { -5, 4, 8, 2, 3 });
            var expected = 96;

            Assert.Equal(expected, actual);
        }
コード例 #3
0
        public void AllNegativesInputTest()
        {
            var expected = new int[] { -8, -56, -14, -28 };
            var actual   = Greedy.GetProductsOfAllIntsExceptAtIndex(new int[] { -7, -1, -4, -2 });

            Assert.Equal(expected, actual);
        }
コード例 #4
0
        public void MyArray1()
        {
            var expected = new int[] { 24, 30, 40, 60, 120 };
            var actual   = Greedy.GetProductsOfAllIntsExceptAtIndex(new int[] { 5, 4, 3, 2, 1 });

            Assert.Equal(expected, actual);
        }
コード例 #5
0
        public void ArrayHasTwoNegativesTest()
        {
            var actual   = Greedy.HighestProductOf3(new int[] { -10, 1, 3, 2, -10 });
            var expected = 300;

            Assert.Equal(expected, actual);
        }
コード例 #6
0
        public void ArrayHasAllNegativesTest()
        {
            var actual   = Greedy.HighestProductOf3(new int[] { -5, -1, -3, -2 });
            var expected = -6;

            Assert.Equal(expected, actual);
        }
コード例 #7
0
        public void LongArrayInputTest()
        {
            var expected = new int[] { 120, 480, 240, 320, 960, 192 };
            var actual   = Greedy.GetProductsOfAllIntsExceptAtIndex(new int[] { 8, 2, 4, 3, 1, 5 });

            Assert.Equal(expected, actual);
        }
コード例 #8
0
    void Start()
    {
        // A*
        greedy = new Greedy(width, height, depth, nodeSize, origin);

        // Create main camera
        Vector3 position = new Vector3(width * -6, height * 18, depth * -6);

        Instantiate(cam, position, cam.transform.rotation);

        grid = greedy.GetGrid();

        // Add walls manually
        greedy.GetNode(2, 2, 2).SetWalkable(!greedy.GetNode(2, 2, 2).isWalkable);

        // Draw walls
        DrawWalls();

        // Create visual nodes
        stepVisual.Setup(grid);

        // Show goal node
        Object.Instantiate(goalObject, grid.GetPosition(goalX, goalY, goalZ) + new Vector3(5, 5, 5), new Quaternion());
        Object.Instantiate(goalObject, grid.GetPosition(startX, startY, startZ) + new Vector3(5, 5, 5), new Quaternion());
    }
コード例 #9
0
ファイル: ResultTests.cs プロジェクト: mrkmg/PathFinder
        public void GreedyPath()
        {
            var solver = new Greedy <TestNode>(_start, _end);

            solver.Run();
            Assert.Multiple(() =>
            {
                CollectionAssert.AreEqual(
                    new List <TestNode> {
                    _testGraph.GetNode(1, 1), _testGraph.GetNode(2, 2), _testGraph.GetNode(3, 3), _testGraph.GetNode(4, 3), _testGraph.GetNode(5, 3), _testGraph.GetNode(6, 4), _testGraph.GetNode(6, 5), _testGraph.GetNode(7, 6), _testGraph.GetNode(8, 7), _testGraph.GetNode(9, 8), _testGraph.GetNode(9, 9)
                },
                    solver.Path
                    );
                CollectionAssert.AreEqual(
                    new List <TestNode> {
                    _testGraph.GetNode(8, 9), _testGraph.GetNode(0, 0), _testGraph.GetNode(8, 6), _testGraph.GetNode(1, 0), _testGraph.GetNode(8, 8), _testGraph.GetNode(2, 0), _testGraph.GetNode(7, 3), _testGraph.GetNode(0, 1), _testGraph.GetNode(6, 7), _testGraph.GetNode(1, 2), _testGraph.GetNode(7, 8), _testGraph.GetNode(0, 2), _testGraph.GetNode(9, 7), _testGraph.GetNode(2, 3), _testGraph.GetNode(1, 3), _testGraph.GetNode(2, 1), _testGraph.GetNode(6, 3), _testGraph.GetNode(6, 2), _testGraph.GetNode(7, 4), _testGraph.GetNode(3, 1), _testGraph.GetNode(6, 6), _testGraph.GetNode(5, 6), _testGraph.GetNode(5, 2), _testGraph.GetNode(3, 2), _testGraph.GetNode(7, 7), _testGraph.GetNode(9, 6), _testGraph.GetNode(4, 2)
                },
                    solver.Open
                    );
                CollectionAssert.AreEqual(
                    new List <TestNode> {
                    _testGraph.GetNode(1, 1), _testGraph.GetNode(2, 2), _testGraph.GetNode(3, 3), _testGraph.GetNode(4, 3), _testGraph.GetNode(5, 3), _testGraph.GetNode(6, 4), _testGraph.GetNode(6, 5), _testGraph.GetNode(7, 6), _testGraph.GetNode(8, 7), _testGraph.GetNode(9, 8), _testGraph.GetNode(9, 9)
                },
                    solver.Closed
                    );
                Assert.AreEqual(29.0d, Math.Round(solver.PathCost));
            });
        }
コード例 #10
0
        public void ShortArrayTest()
        {
            var actual   = Greedy.HighestProductOf3(new int[] { 1, 2, 3, 4 });
            var expected = 24;

            Assert.Equal(expected, actual);
        }
コード例 #11
0
        public void PriceGoesDownAllDayTest()
        {
            var actual   = Greedy.AppleStocks(new int[] { 9, 7, 4, 1 });
            var expected = -2;

            Assert.Equal(expected, actual);
        }
コード例 #12
0
        public void PriceStaysTheSameAllDayTest()
        {
            var actual   = Greedy.AppleStocks(new int[] { 1, 1, 1, 1 });
            var expected = 0;

            Assert.Equal(expected, actual);
        }
コード例 #13
0
        public void PriceGoesUpAllDayTest()
        {
            var actual   = Greedy.AppleStocks(new int[] { 1, 6, 7, 9 });
            var expected = 8;

            Assert.Equal(expected, actual);
        }
コード例 #14
0
        public void PriceGoesDownThenUpTest()
        {
            var actual   = Greedy.AppleStocks(new int[] { 7, 2, 8, 9 });
            var expected = 7;

            Assert.Equal(expected, actual);
        }
コード例 #15
0
        public void PriceGoesUpThenDownTest()
        {
            var actual   = Greedy.AppleStocks(new int[] { 1, 5, 3, 2 });
            var expected = 4;

            Assert.Equal(expected, actual);
        }
コード例 #16
0
        public void LongerArrayTest()
        {
            var actual   = Greedy.HighestProductOf3(new int[] { 6, 1, 3, 5, 7, 8, 2 });
            var expected = 336;

            Assert.Equal(expected, actual);
        }
コード例 #17
0
        public void SmallArrayInputTest()
        {
            var expected = new int[] { 6, 3, 2 };
            var actual   = Greedy.GetProductsOfAllIntsExceptAtIndex(new int[] { 1, 2, 3 });

            Assert.Equal(expected, actual);
        }
コード例 #18
0
    public void Greedy(int startX, int startY, int endX, int endY)
    {
        ClearPath();
        Greedy g = GameObject.Instantiate(greedy, Vector3.zero, Quaternion.identity).GetComponent <Greedy>();

        g.StartGreed(startX, startY, endX, endY);
    }
コード例 #19
0
        public void InputHasOneZeroTest()
        {
            var expected = new int[] { 0, 0, 36, 0 };
            var actual   = Greedy.GetProductsOfAllIntsExceptAtIndex(new int[] { 6, 2, 0, 3 });

            Assert.Equal(expected, actual);
        }
コード例 #20
0
        public void InputHasOneNegativeNumberTest()
        {
            var expected = new int[] { 32, -12, -24 };
            var actual   = Greedy.GetProductsOfAllIntsExceptAtIndex(new int[] { -3, 8, 4 });

            Assert.Equal(expected, actual);
        }
コード例 #21
0
        public void TestRunTicks()
        {
            var graph  = new TestGraph();
            var solver = new Greedy <TestNode>(graph.GetNode(0, 0), graph.GetNode(9, 9));

            solver.Run(1);
            Assert.AreEqual(SolverState.Incomplete, solver.State);
        }
コード例 #22
0
        public void TestNoPath()
        {
            var graph  = new TestGraph();
            var solver = new Greedy <TestNode>(graph.GetNode(0, 0), graph.GetNode(9, 0));

            solver.Run();
            Assert.AreEqual(SolverState.Failure, solver.State);
        }
コード例 #23
0
ファイル: ThrowTests.cs プロジェクト: mrkmg/PathFinder
        public void ThrowsWhenTryingToRunCompletedSolver()
        {
            var testGraph = new TestGraph();
            var solver    = new Greedy <TestNode>(testGraph.GetNode(0, 0), testGraph.GetNode(9, 9));

            solver.Run();
            Assert.Throws <InvalidOperationException>(() => solver.Run());
        }
コード例 #24
0
        public static void test_greedy()
        {
            var context = new Context("aaaaa");
            var chara   = new Character('a');
            var grd     = new Greedy(chara, 2, 4);

            // (a{1,3})
            ExecTest(context, grd);
        }
コード例 #25
0
ファイル: GreedyTest.cs プロジェクト: hkuntal/ComputerScience
        public void testGetTotalTime()
        {
            var worstCost = Greedy.getTotalTime(new int[] { 4, 2, 1, 3 });

            Assert.AreEqual(26, worstCost);

            worstCost = Greedy.getTotalTime(new int[] { 2, 3, 9, 8, 4 });
            Assert.AreEqual(88, worstCost);
        }
コード例 #26
0
        public static void test_greedyalternate()
        {
            var context = new Context("aaaaa");
            var chara   = new Character('a');
            var list2a  = new List(new IMatch[] { chara, chara });
            var alt     = new Alternate(new IMatch[] { chara, list2a });
            var greedy  = new Greedy(alt, 1, 2);

            // (a|aa){1,2}
            ExecTest(context, greedy);
        }
コード例 #27
0
 public void MonsterKiller()
 {
     Assert.Equal(0, Greedy.MonsterKiller(new int[] { }, 10, 2));
     Assert.Equal(1, Greedy.MonsterKiller(new int[] { -1 }, 10, 2));
     Assert.Equal(0, Greedy.MonsterKiller(new int[] { 11 }, 10, 0));
     Assert.Equal(3, Greedy.MonsterKiller(new int[] { 1, 2, 3 }, 10, 0));
     Assert.Equal(2, Greedy.MonsterKiller(new int[] { 1, 2, 3 }, 5, 0));
     Assert.Equal(3, Greedy.MonsterKiller(new int[] { 1, 2, 3 }, 5, 1));
     Assert.Equal(8, Greedy.MonsterKiller(new int[] { -3, 2, 3, -2, 8, 8, 6, 4, 3, 3 }, 10, 2));
     Assert.Equal(2, Greedy.MonsterKiller(new int[] { 4, 6, 2 }, 5, 1));
 }
コード例 #28
0
ファイル: EnamyControl.cs プロジェクト: zparkpai/MyGames
 GameObject Jd3;                                              //回合结束按钮对象
 private void Start()
 {
     Jd3         = GameObject.Find("JobBtnDown"); //得到回合结束按钮
     AllCubeMark = new CubeMark[24];              //获取地板
     EnamyStart  = GameObject.Find("Cube (5)");   //敌方大本营
     for (int i = 0; i < AllCube.Length; i++)
     {
         AllCubeMark[i] = AllCube[i].GetComponent <CubeMark>();      //获取地板脚本数组
     }
     Greed = transform.GetComponent <Greedy>();                      //找到判断脚本
     Card  = GameObject.Find("Cards").GetComponent <Cardscontrol>(); //得到卡牌脚本
 }
コード例 #29
0
        public static void test_negative_lookahead()
        {
            var context = new Context("aaaab");
            var chara   = new Character('a');
            var greedy  = new Greedy(chara, 1);
            var list2a  = new List(new IMatch[] { chara, chara });
            var assert  = new Lookaround(new CaptureGroup(list2a, 1), false);
            var list    = new List(new IMatch[] { greedy, assert });

            // (a+(?!(aa))
            ExecTest(context, list);
        }
コード例 #30
0
        public static void test_atomic()
        {
            var context = new Context("aaaab");
            var chara   = new Character('a');
            var charb   = new Character('b');
            var greedya = new Greedy(chara, 2);
            var atomic  = new Atomic(greedya);
            var alt     = new Alternate(new IMatch[] { chara, charb });
            var list    = new List(new IMatch[] { new CaptureGroup(atomic, 1), alt });

            // (((?>a{2,}))(?:a|b))
            ExecTest(context, list);
        }
コード例 #31
0
ファイル: RegexTests.cs プロジェクト: TheFellow/RegexLib
        public static void test_atomic()
        {
            var context = new Context("aaaab");
            var chara = new Character('a');
            var charb = new Character('b');
            var greedya = new Greedy(chara, 2);
            var atomic = new Atomic(greedya);
            var alt = new Alternate(new IMatch[] { chara, charb });
            var list = new List(new IMatch[] { new CaptureGroup(atomic, 1), alt });

            // (((?>a{2,}))(?:a|b))
            ExecTest(context, list);
        }
コード例 #32
0
ファイル: RegexTests.cs プロジェクト: TheFellow/RegexLib
        public static void test_negative_lookahead()
        {
            var context = new Context("aaaab");
            var chara = new Character('a');
            var greedy = new Greedy(chara, 1);
            var list2a = new List(new IMatch[] { chara, chara });
            var assert = new Lookaround(new CaptureGroup(list2a, 1), false);
            var list = new List(new IMatch[] { greedy, assert });

            // (a+(?!(aa))
            ExecTest(context, list);
        }
コード例 #33
0
ファイル: RegexTests.cs プロジェクト: TheFellow/RegexLib
        public static void test_greedyaltcapture()
        {
            var context = new Context("aaaaa");
            var chara = new Character('a');
            var list2a = new List(new IMatch[] { chara, chara });

            var grp1 = new CaptureGroup(chara, 1);
            var grp2 = new CaptureGroup(list2a, 2);
            var alt = new Alternate(new IMatch[] { grp1, grp2 });
            var greedy = new Greedy(alt, 1, 2);

            // ((a)|(aa)){1,2}
            ExecTest(context, greedy);
        }
コード例 #34
0
ファイル: RegexTests.cs プロジェクト: TheFellow/RegexLib
        public static void test_greedyalternate()
        {
            var context = new Context("aaaaa");
            var chara = new Character('a');
            var list2a = new List(new IMatch[] { chara, chara });
            var alt = new Alternate(new IMatch[] { chara, list2a });
            var greedy = new Greedy(alt, 1, 2);

            // (a|aa){1,2}
            ExecTest(context, greedy);
        }
コード例 #35
0
ファイル: RegexTests.cs プロジェクト: TheFellow/RegexLib
        public static void test_greedy()
        {
            var context = new Context("aaaaa");
            var chara = new Character('a');
            var grd = new Greedy(chara, 2, 4);

            // (a{1,3})
            ExecTest(context, grd);
        }