Ejemplo n.º 1
0
        public void SolveTest_BasicCases()
        {
            int[,] map =
            {
                { 1, 1, 0 },
                { 0, 1, 1 }
            };

            int[] weight =
            {
                1,
                1
            };

            int[] expected = { 0, 2 };

            SolverNonFancy target = new SolverNonFancy();

            CollectionAssert.AreEqual(expected, target.SolveNonFancy(map, weight));

            weight = new int[] { 2, 2 };

            var actual = target.SolveNonFancy(map, weight);

            Assert.AreEqual(2, actual.Length);
            CollectionAssert.AreNotEqual(expected, actual);
        }
Ejemplo n.º 2
0
        private void RandomTest(Random rand, Action <int[], int[]> assert)
        {
            int[,] map = GetRandomMap(rand);

            int[] weight = GetRandomWeight(rand, map.GetLength(0));

            int[] expected = new PowerSet().Solve(map, weight);

            DebugDump(map, weight, expected);

            SolverNonFancy target = new SolverNonFancy();
            var            actual = target.SolveNonFancy(map, weight);

            Debug.WriteLineIf(actual.Length < expected.Length, "Diff = " + (expected.Length - actual.Length).ToString());
            assert(expected, actual);
        }
Ejemplo n.º 3
0
        public void FailedTestDetectedByRandom2()
        {
            int[,] map =
            {
                { 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, },
                { 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, },
                { 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, },
                { 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, },
                { 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, },
                { 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, },
                { 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, },
            };
            int[] weight =
            {
                15,
                8,
                3,
                13,
                10,
                3,
                10,
            };
            int[] expected =
            {
                1, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14,
            };
//Diff = 2
//a
//{int[10]}
//    [0]: 0
//    [1]: 1
//    [2]: 2
//    [3]: 3
//    [4]: 4
//    [5]: 5
//    [6]: 9
//    [7]: 10
//    [8]: 11
//    [9]: 12

            SolverNonFancy target = new SolverNonFancy();
            var            actual = target.SolveNonFancy(map, weight);

            CollectionAssert.AreEqual(expected, actual);
        }
Ejemplo n.º 4
0
        public void FailedTestDetectedByRandom3()
        {
            int[,] map =
            {
                { 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, },
                { 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, },
                { 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, },
                { 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, },
                { 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, },
                { 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, },
                { 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, },
                { 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, },
            };
            int[] weight =
            {
                14,
                11,
                11,
                2,
                6,
                6,
                1,
                4,
            };
            int[] expected =
            {
                0, 2, 3, 4, 5, 6, 7, 8,
            };
//Diff = 2
//a
//{int[6]}
//    [0]: 0
//    [1]: 1
//    [2]: 2
//    [3]: 3
//    [4]: 4
//    [5]: 5

            SolverNonFancy target = new SolverNonFancy();
            var            actual = target.SolveNonFancy(map, weight);

            CollectionAssert.AreEqual(expected, actual);
        }
Ejemplo n.º 5
0
        public void FailedTestDetectedByRandom1()
        {
            int[,] map =
            {
                { 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, },
                { 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, },
                { 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, },
                { 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, },
                { 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, },
                { 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, },
                { 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, },
                { 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, },
                { 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, },
                { 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, },
                { 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, },
            };

            int[] weight =
            {
                14,
                2,
                10,
                1,
                9,
                2,
                6,
                3,
                15,
                12,
                9,
            };

            int[] expected = { 1, 4, 5, 6, 7, 10, };
            // { 0, 1, 6, 7, 10};

            SolverNonFancy target = new SolverNonFancy();
            var            actual = target.SolveNonFancy(map, weight);

            CollectionAssert.AreEqual(expected, actual);
        }
Ejemplo n.º 6
0
        public void SolveTest_5X3Case()
        {
            int[,] map =
            {
                { 1, 1, 0, 1, 1 },
                { 0, 1, 1, 1, 0 },
                { 0, 1, 1, 0, 0 },
            };

            int[] weight =
            {
                3,
                2,
                1
            };

            int[] expected    = { 0, 2, 3, 4 };
            int[] powerSolver = new PowerSet().Solve(map, weight);

            SolverNonFancy target = new SolverNonFancy();
            var            actual = target.SolveNonFancy(map, weight);

            CollectionAssert.AreEqual(expected, actual);
        }