private void PrepareLabTests(Lab07 solver)
        {
            TestSets["ElementsInDistance"] = new TestSet(solver, "Part 1 - CanPlaceElementsInDistance");
            TestSets["ElementsInDistance"].TestCases.Add(new CanPlaceElementsInDistanceTestCase(1, null, "Równoodległe 1", new int[] { 1, 2, 3 }, 3, 1, true));
            TestSets["ElementsInDistance"].TestCases.Add(new CanPlaceElementsInDistanceTestCase(1, null, "Równoodległe 2", new int[] { 0, 2, 4, 6, 8, 10 }, 2, 4, true));
            TestSets["ElementsInDistance"].TestCases.Add(new CanPlaceElementsInDistanceTestCase(1, null, "Równoodległe z przerwą", new int[] { 4, 5, 6, 7, 8, 9, 15, 16, 17, 18, 19, 20 }, 5, 5, false));
            TestSets["ElementsInDistance"].TestCases.Add(new CanPlaceElementsInDistanceTestCase(1, null, "Powtórzenie", new int[] { 2, 2, 5, 6, 7, 8, 9, 10 }, 6, 4, false));
            TestSets["ElementsInDistance"].TestCases.Add(new CanPlaceElementsInDistanceTestCase(1, null, "Wiele powtórzeń jednej pozycji", new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, 3, 0, true));
            TestSets["ElementsInDistance"].TestCases.Add(new CanPlaceElementsInDistanceTestCase(1, null, "Mały test, niepowodzenie", new int[] { 1, 2, 4, 8, 9 }, 4, 10, false));
            TestSets["ElementsInDistance"].TestCases.Add(new CanPlaceElementsInDistanceTestCase(1, null, "Mały test, powodzenie", new int[] { 0, 5, 6, 7, 8, 10 }, 3, 5, true));

            TestSets["LargestMinDistance"] = new TestSet(solver, "Part 2 - LargestMinDistance");
            TestSets["LargestMinDistance"].TestCases.Add(new LargestMinDistanceTestCase(1, null, "Równoodległe 1", new int[] { 1, 2, 3 }, 3, 1));
            TestSets["LargestMinDistance"].TestCases.Add(new LargestMinDistanceTestCase(1, null, "Równoodległe 2", new int[] { 0, 2, 4, 6, 8, 10 }, 3, 4));
            TestSets["LargestMinDistance"].TestCases.Add(new LargestMinDistanceTestCase(1, null, "Równoodległe z przerwą", new int[] { 4, 5, 6, 7, 8, 9, 15, 16, 17, 18, 19, 20 }, 3, 5));
            TestSets["LargestMinDistance"].TestCases.Add(new LargestMinDistanceTestCase(1, null, "Powtórzenie", new int[] { 2, 2, 5, 6, 7, 8, 9, 10 }, 3, 4));
            TestSets["LargestMinDistance"].TestCases.Add(new LargestMinDistanceTestCase(1, null, "Wiele powtórzeń jednej pozycji", new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, 3, 0));
            TestSets["LargestMinDistance"].TestCases.Add(new LargestMinDistanceTestCase(1, null, "Mały test 1", new int[] { 1, 2, 4, 8, 9 }, 3, 3));
            TestSets["LargestMinDistance"].TestCases.Add(new LargestMinDistanceTestCase(1, null, "Mały test 2", new int[] { 0, 5, 6, 7, 8, 10 }, 3, 5));

            TestSets["LargestMinDistance"].TestCases.Add(new LargestMinDistanceTestCase(1, new ArgumentException(), "Zbyt mało pozycji 1", new int[] { 2 }, 2, 0));
            TestSets["LargestMinDistance"].TestCases.Add(new LargestMinDistanceTestCase(1, new ArgumentException(), "Zbyt mało pozycji 2", new int[] { 5, 21, 44, 45 }, 5, 0));
            TestSets["LargestMinDistance"].TestCases.Add(new LargestMinDistanceTestCase(1, new ArgumentException(), "Zbyt mało obiektów", new int[] { 5, 21, 44, 45 }, 1, 0));
            TestSets["LargestMinDistance"].TestCases.Add(new LargestMinDistanceTestCase(1, null, "Powtórzenie, wszystkie zajęte", new int[] { 2, 2 }, 2, 0));
            TestSets["LargestMinDistance"].TestCases.Add(new LargestMinDistanceTestCase(1, null, "Odległa pozycja", new int[] { 2, 4, 5, 7, 9, 11, 20, 200 }, 6, 2));
            TestSets["LargestMinDistance"].TestCases.Add(new LargestMinDistanceTestCase(1, null, "Równoodległe 3", new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }, 5, 6));
            TestSets["LargestMinDistance"].TestCases.Add(new LargestMinDistanceTestCase(1, null, "Wiele powtórzeń różnych pozycji", new int[] { 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6 }, 6, 1));
            TestSets["LargestMinDistance"].TestCases.Add(new LargestMinDistanceTestCase(1, null, "Średni test 1", new int[] { 4, 5, 6, 7, 8, 11, 20, 21, 22, 33, 44, 45, 46, 99 }, 2, 95));
            TestSets["LargestMinDistance"].TestCases.Add(new LargestMinDistanceTestCase(1, null, "Średni test 2", new int[] { 4, 5, 6, 7, 8, 11, 20, 21, 22, 33, 44, 45, 46, 99 }, 4, 18));
            TestSets["LargestMinDistance"].TestCases.Add(new LargestMinDistanceTestCase(1, null, "Średni test 3", new int[] { 4, 5, 6, 7, 8, 11, 20, 21, 22, 33, 44, 45, 46, 99 }, 5, 13));
            TestSets["LargestMinDistance"].TestCases.Add(new LargestMinDistanceTestCase(1, null, "Średni test 4", new int[] { 1, 2, 4, 5, 7, 8, 10, 43, 76, 99 }, 4, 23));
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            DataContractSerializer dcs = new DataContractSerializer(typeof(TestSet), new Type[] { typeof(ClosestPointsTestCase) });
            FileStream             fs;

            Console.WriteLine("Brute force algorithm tests:");
            fs = new FileStream("STB.dat", FileMode.Open);
            TestSet simpleTestsBrute = (TestSet)dcs.ReadObject(fs);

            fs.Close();
            simpleTestsBrute.PreformTests(true, false);

            Console.WriteLine("Sweep line algorithm tests:");
            fs = new FileStream("ST.dat", FileMode.Open);
            TestSet simpleTests = (TestSet)dcs.ReadObject(fs);

            fs.Close();
            simpleTests.PreformTests(true, false);

            Console.WriteLine("Sweep line algorithm performance tests:");
            fs = new FileStream("PT.dat", FileMode.Open);
            TestSet performanceTests = (TestSet)dcs.ReadObject(fs);

            fs.Close();
            performanceTests.PreformTests(true, true);

            return;
        }
Ejemplo n.º 3
0
 public override void PrepareTestSets()
 {
     TestSets["ClassCirculationTests"]     = new TestSet(new ConstrainedFlows(), "Testy zajęciowe: circulation (2 pkt)");
     TestSets["ClassConstrainedFlowTests"] = new TestSet(new ConstrainedFlows(), "Testy zajęciowe: constrained flow (2 pkt)");
     PrepareClassCirculationTests();
     PrepareClassConstrainedFlowTests();
 }
Ejemplo n.º 4
0
        static void Main()
        {
            bool isExtraTests = true;

            TestSet set = new TestSet();

            set.TestCases.Add(new BridgeCrossingTestCase(5, new int[] { 1, 2, 5, 10 }, 17));
            set.TestCases.Add(new BridgeCrossingTestCase(5, new int[] { 15, 10, 6, 7 }, 42));
            set.TestCases.Add(new BridgeCrossingTestCase(5, new int[] { 10, 25, 20, 5 }, 60));
            set.TestCases.Add(new BridgeCrossingTestCase(5, new int[] { 100 }, 100));
            set.TestCases.Add(new BridgeCrossingTestCase(5, new int[] { 1, 20 }, 20));
            set.TestCases.Add(new BridgeCrossingTestCase(5, new int[] { 1, 10, 100 }, 111));
            set.TestCases.Add(new BridgeCrossingTestCase(5, new int[] { 2, 2, 2, 2, 2 }, 14));
            set.TestCases.Add(new BridgeCrossingTestCase(5, new int[] { 1, 2, 3, 4, 5 }, 16));
            set.TestCases.Add(new BridgeCrossingTestCase(5, new int[] { 1, 1, 5, 5, 10, 10 }, 22));
            set.TestCases.Add(new BridgeCrossingTestCase(5, GenerateTestArray(5, 555), 284));
            set.TestCases.Add(new BridgeCrossingTestCase(5, GenerateTestArray(6, 666), 346));
            set.TestCases.Add(new BridgeCrossingTestCase(5, GenerateTestArray(7, 777), 216));
            Console.WriteLine("\nBasic tests");
            set.PreformTests(verbose: true, checkTimeLimit: false);

            if (isExtraTests)
            {
                TestSet set2 = new TestSet();
                set2.TestCases.Add(new BridgeCrossingTestCase(3, GenerateTestArray(8, 888), 313));
                set2.TestCases.Add(new BridgeCrossingTestCase(30, GenerateTestArray(9, 999), 453));
                Console.WriteLine("\nExtra tests");
                set2.PreformTests(verbose: true, checkTimeLimit: true);
            }
        }
Ejemplo n.º 5
0
        public override void PrepareTestSets()
        {
            TestSets["LabGameResultTests"] = new TestSet(new Game(), "Lab. Tests - game result only", null, false);
            TestSets["LabMovesListTests"]  = new TestSet(new Game(), "Lab. Tests - game result and moves list", null, true);
            GameTestCase tc;
            Random       rnd;

            int[] tab;

            tc = new GameTestCase(1, null, "Anti Greedy 1", new int[] { 90, 100, 10, 1 }, 101);
            TestSets["LabGameResultTests"].TestCases.Add(tc);
            TestSets["LabMovesListTests"].TestCases.Add(tc);

            tc = new GameTestCase(1, null, "Anti Greedy 2", new int[] { 5, 100, 20, 1, 10 }, 35);
            TestSets["LabGameResultTests"].TestCases.Add(tc);
            TestSets["LabMovesListTests"].TestCases.Add(tc);

            tc = new GameTestCase(1, null, "Negative moves values", new int[] { -51, -40, 50, 30 }, -1);
            TestSets["LabGameResultTests"].TestCases.Add(tc);
            TestSets["LabMovesListTests"].TestCases.Add(tc);

            tc = new GameTestCase(1, null, "One move", new int[] { -1 }, -1);
            TestSets["LabGameResultTests"].TestCases.Add(tc);
            TestSets["LabMovesListTests"].TestCases.Add(tc);

            tc = new GameTestCase(1, null, "Many equal moves", Enumerable.Repeat(1, 1111).ToArray(), 556);
            TestSets["LabGameResultTests"].TestCases.Add(tc);
            TestSets["LabMovesListTests"].TestCases.Add(tc);

            rnd = new Random(12345);
            tab = new int[800];
            for (int i = 0; i < tab.Length; ++i)
            {
                tab[i] = rnd.Next(-4000, 4000);
            }
            tc = new GameTestCase(1, null, "Random 1", tab, -17528);
            TestSets["LabGameResultTests"].TestCases.Add(tc);
            TestSets["LabMovesListTests"].TestCases.Add(tc);

            rnd = new Random(12347);
            tab = new int[1500];
            for (int i = 0; i < tab.Length; ++i)
            {
                tab[i] = rnd.Next(-500, 500);
            }
            tc = new GameTestCase(1, null, "Random 2", tab, 7014);
            TestSets["LabGameResultTests"].TestCases.Add(tc);
            TestSets["LabMovesListTests"].TestCases.Add(tc);

            rnd = new Random(12349);
            tab = new int[3000];
            for (int i = 0; i < tab.Length; ++i)
            {
                tab[i] = rnd.Next(-3000, 3000);
            }
            tc = new GameTestCase(3, null, "Random 3", tab, -28993);
            TestSets["LabGameResultTests"].TestCases.Add(tc);
            TestSets["LabMovesListTests"].TestCases.Add(tc);
        }
Ejemplo n.º 6
0
        static void Main()
        {
            TestSet changeMakingNoLimits = new TestSet();

            changeMakingNoLimits.TestCases.Add(new ChangeMakingNoLimitsTestCase(5, null, 10, new int[] { 5, 1, 2 }, new int[] { 2, 0, 0 }));
            changeMakingNoLimits.TestCases.Add(new ChangeMakingNoLimitsTestCase(5, null, 123, new int[] { 1, 2, 5, 10, 20, 50, 100, 200 }, new int[] { 1, 1, 0, 0, 1, 0, 1, 0 }));
            changeMakingNoLimits.TestCases.Add(new ChangeMakingNoLimitsTestCase(5, null, 123, new int[] { 2, 5, 10, 20, 50, 100, 200 }, new int[] { 4, 1, 0, 1, 0, 1, 0 }));
            changeMakingNoLimits.TestCases.Add(new ChangeMakingNoLimitsTestCase(5, null, 23, new int[] { 1 }, new int[] { 23 }));
            changeMakingNoLimits.TestCases.Add(new ChangeMakingNoLimitsTestCase(5, null, 23, new int[] { 2 }, null));
            changeMakingNoLimits.TestCases.Add(new ChangeMakingNoLimitsTestCase(5, null, 23, new int[] { 50 }, null));

            TestSet changeMakingLimits = new TestSet();

            changeMakingLimits.TestCases.Add(new ChangeMakingLimitsTestCase(5, null, 10, new int[] { 5, 1, 2 }, new int[] { 1, 20, 10 }, new int[] { 1, 1, 2 }));

            changeMakingLimits.TestCases.Add(new ChangeMakingLimitsTestCase(5, null, 123, new int[] { 1, 2, 5, 10, 20, 50, 100, 200 },
                                                                            new int[] { 99999, 99999, 99999, 99999, 99999, 99999, 99999, 99999 },
                                                                            new int[] { 1, 1, 0, 0, 1, 0, 1, 0 }));

            changeMakingLimits.TestCases.Add(new ChangeMakingLimitsTestCase(5, null, 123, new int[] { 2, 5, 10, 20, 50, 100, 200 },
                                                                            new int[] { 99999, 99999, 99999, 99999, 99999, 99999, 99999 },
                                                                            new int[] { 4, 1, 1, 0, 0, 1, 0 }));

            changeMakingLimits.TestCases.Add(new ChangeMakingLimitsTestCase(5, null, 123, new int[] { 1, 2, 5, 10, 20, 50, 100, 200 },
                                                                            new int[] { 0, 99999, 99999, 99999, 99999, 99999, 99999, 99999 },
                                                                            new int[] { 0, 4, 1, 1, 0, 0, 1, 0 }));

            changeMakingLimits.TestCases.Add(new ChangeMakingLimitsTestCase(5, null, 123, new int[] { 1, 2, 5, 10, 20, 50, 100, 200 },
                                                                            new int[] { 99999, 99999, 3, 4, 3, 0, 0, 99999 },
                                                                            new int[] { 0, 4, 3, 4, 3, 0, 0, 0 }));

            changeMakingLimits.TestCases.Add(new ChangeMakingLimitsTestCase(5, null, 23, new int[] { 1, 2, 5 },
                                                                            new int[] { 99999, 99999, 3 },
                                                                            new int[] { 0, 4, 3 }));

            changeMakingLimits.TestCases.Add(new ChangeMakingLimitsTestCase(5, null, 23, new int[] { 5, 1, 2 },
                                                                            new int[] { 2, 3, 5 },
                                                                            new int[] { 2, 3, 5 }));

            changeMakingLimits.TestCases.Add(new ChangeMakingLimitsTestCase(5, null, 23, new int[] { 5, 5, 1, 2 },
                                                                            new int[] { 3, 2, 3, 3 },
                                                                            new int[] { 3, 1, 1, 1 }));

            changeMakingLimits.TestCases.Add(new ChangeMakingLimitsTestCase(5, null, 23, new int[] { 2 }, new int[15], null));
            changeMakingLimits.TestCases.Add(new ChangeMakingLimitsTestCase(5, null, 23, new int[] { 50 }, new int[1], null));
            changeMakingLimits.TestCases.Add(new ChangeMakingLimitsTestCase(5, null, 23, new int[] { 1 }, new int[20], null));

            changeMakingLimits.TestCases.Add(new ChangeMakingLimitsTestCase(5, null, 141, new int[] { 2, 137, 65, 35, 30, 9, 123, 81, 71 },
                                                                            new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
                                                                            new int[] { 1, 0, 1, 1, 1, 1, 0, 0, 0 }));

            Console.WriteLine("\nChange Making without coins limits");
            changeMakingNoLimits.PreformTests(verbose: true, checkTimeLimit: false);

            Console.WriteLine("\nChange Making with coins limits");
            changeMakingLimits.PreformTests(verbose: true, checkTimeLimit: false);
        }
Ejemplo n.º 7
0
        static void Main()
        {
            if (Graphs.GraphLibraryVersion.ToString() != "7.0.3")
            {
                Console.WriteLine("\nPobierz nową wersję biblioteki\n");
                return;
            }

            var simpleTests = new TestSet();

            simpleTests.TestCases.Add(CreateBasicTest1());
            simpleTests.TestCases.Add(CreateBasicTest2());
            simpleTests.TestCases.Add(CreateBasicTest3());
            simpleTests.TestCases.Add(CreateBasicTest4());
            simpleTests.TestCases.Add(CreateBasicTest5());
            simpleTests.TestCases.Add(CreateBasicTest6());
            simpleTests.TestCases.Add(CreateBasicTest7());
            simpleTests.TestCases.Add(CreateBasicTest8());
            Console.WriteLine("Standard tests:");
            simpleTests.PreformTests(true, false);


            var fullTests = new TestSet();

            fullTests.TestCases.Add(CreateFullTestCase1());
            fullTests.TestCases.Add(CreateFullTestCase2());
            fullTests.TestCases.Add(CreateFullTestCase3());
            fullTests.TestCases.Add(CreateFullTestCase4());
            fullTests.TestCases.Add(CreateFullTestCase5());
            fullTests.TestCases.Add(CreateFullTestCase6());
            fullTests.TestCases.Add(CreateFullTestCase7());
            fullTests.TestCases.Add(CreateFullTestCase8());
            fullTests.TestCases.Add(CreateFullTestCase9());
            fullTests.TestCases.Add(CreateFullTestCase10());
            fullTests.TestCases.Add(CreateFullTestCase11());
            Console.WriteLine("Tests with limits:");
            fullTests.PreformTests(true, false);


            var cappedTests = new TestSet();

            cappedTests.TestCases.Add(CreateCappedTestCase1());
            cappedTests.TestCases.Add(CreateCappedTestCase2());
            cappedTests.TestCases.Add(CreateCappedTestCase3());
            cappedTests.TestCases.Add(CreateCappedTestCase4());
            cappedTests.TestCases.Add(CreateCappedTestCase5());
            cappedTests.TestCases.Add(CreateCappedTestCase6());
            cappedTests.TestCases.Add(CreateCappedTestCase7());
            cappedTests.TestCases.Add(CreateCappedTestCase8());
            cappedTests.TestCases.Add(CreateCappedTestCase9());
            cappedTests.TestCases.Add(CreateCappedTestCase10());
            Console.WriteLine("Test with capped production:");
            cappedTests.PreformTests(true, false);
        }
Ejemplo n.º 8
0
        public override void PrepareTestSets()
        {
            TestSets["SolutionExistenceTests"] = new TestSet(new Squares(), "Części 1 - testy sprawdzające istnienie rozwiązania", null, false);

            TestSets["SolutionExistenceTests"].TestCases.Add(new FindDisivionTestCase(1, null, "pole o boku 1", 1, new int[] { 1 }, 1));
            TestSets["SolutionExistenceTests"].TestCases.Add(new FindDisivionTestCase(1, null, "pole z jednostkowymi kwadratami", 10, new int[] { 1 }, 100));
            TestSets["SolutionExistenceTests"].TestCases.Add(new FindDisivionTestCase(1, null, "dostępny kwadrat większy niż pole", 2, new int[] { 5 }, 0));
            TestSets["SolutionExistenceTests"].TestCases.Add(new FindDisivionTestCase(1, null, "nieparzyste pole, dopuszczalne kwadraty parzyste", 9, new int[] { 2, 4, 6 }, 0));
            TestSets["SolutionExistenceTests"].TestCases.Add(new FindDisivionTestCase(1, null, "bok pola liczbą pierwszą (7)", 7, new int[] { 6, 5, 4, 1, 2, 3 }, 9));
            TestSets["SolutionExistenceTests"].TestCases.Add(new FindDisivionTestCase(1, null, "prosty test poprawnościowy", 6, new int[] { 3, 2 }, 4));
            TestSets["SolutionExistenceTests"].TestCases.Add(new FindDisivionTestCase(1, null, "prosty test poprawnościowy", 6, new int[] { 7, 9, 5, 13 }, 0));
            TestSets["SolutionExistenceTests"].TestCases.Add(new FindDisivionTestCase(1, null, "brak dopuszczalnych kwadratów", 5, new int[] { }, 0));
            TestSets["SolutionExistenceTests"].TestCases.Add(new FindDisivionTestCase(1, null, "pole bez dzielenia", 8, new int[] { 2, 4, 8 }, 1));
            TestSets["SolutionExistenceTests"].TestCases.Add(new FindDisivionTestCase(1, null, "pole o boku 5", 5, new int[] { 1, 2, 3 }, 8));
            TestSets["SolutionExistenceTests"].TestCases.Add(new FindDisivionTestCase(1, null, "pole o boku 6", 6, new int[] { 1, 5 }, 12));

            TestSets["SmallTests"] = new TestSet(new Squares(), "Części 2 - małe testy poprawnościowe", null, true);

            TestSets["SmallTests"].TestCases.Add(new FindDisivionTestCase(1, null, "pole o boku 1", 1, new int[] { 1 }, 1));
            TestSets["SmallTests"].TestCases.Add(new FindDisivionTestCase(1, null, "pole z jednostkowymi kwadratami", 10, new int[] { 1 }, 100));
            TestSets["SmallTests"].TestCases.Add(new FindDisivionTestCase(1, null, "dostępny kwadrat większy niż pole", 2, new int[] { 5 }, 0));
            TestSets["SmallTests"].TestCases.Add(new FindDisivionTestCase(1, null, "nieparzyste pole, dopuszczalne kwadraty parzyste", 9, new int[] { 2, 4, 6 }, 0));
            TestSets["SmallTests"].TestCases.Add(new FindDisivionTestCase(1, null, "bok pola liczbą pierwszą (7)", 7, new int[] { 6, 5, 4, 1, 2, 3 }, 9));
            TestSets["SmallTests"].TestCases.Add(new FindDisivionTestCase(1, null, "prosty test poprawnościowy", 6, new int[] { 3, 2 }, 4));
            TestSets["SmallTests"].TestCases.Add(new FindDisivionTestCase(1, null, "prosty test poprawnościowy", 6, new int[] { 7, 9, 5, 13 }, 0));
            TestSets["SmallTests"].TestCases.Add(new FindDisivionTestCase(1, null, "brak dopuszczalnych kwadratów", 5, new int[] { }, 0));
            TestSets["SmallTests"].TestCases.Add(new FindDisivionTestCase(1, null, "pole bez dzielenia", 8, new int[] { 2, 4, 8 }, 1));
            TestSets["SmallTests"].TestCases.Add(new FindDisivionTestCase(1, null, "pole o boku 5", 5, new int[] { 1, 2, 3 }, 8));
            TestSets["SmallTests"].TestCases.Add(new FindDisivionTestCase(1, null, "pole o boku 6", 6, new int[] { 1, 5 }, 12));


            TestSets["BigTests"] = new TestSet(new Squares(), "Część 3 - testy wydajnościowe", null, true);

            TestSets["BigTests"].TestCases.Add(new FindDisivionTestCase(2, null, "dużo kwadratów o boku 1", 50, new int[] { 1 }, 2500));
            TestSets["BigTests"].TestCases.Add(new FindDisivionTestCase(10, null, "mało kwadratów o długim boku", 2000, new int[] { 500 }, 16));
            TestSets["BigTests"].TestCases.Add(new FindDisivionTestCase(1, null, "mało kwadratów o długim boku", 101, new int[] { 5 }, 0));
            TestSets["BigTests"].TestCases.Add(new FindDisivionTestCase(1, null, "bok pola liczbą pierwszą (11)", 11, new int[] { 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 11));
            TestSets["BigTests"].TestCases.Add(new FindDisivionTestCase(1, null, "próba podziału pola o nieparzystym boku na tylko parzyste", 25, new int[] { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24 }, 0));
            TestSets["BigTests"].TestCases.Add(new FindDisivionTestCase(1, null, "dużo rozmiarów, wszystkie większe niż rozmiar pola", 10, Enumerable.Range(11, 10000).ToArray(), 0));
            TestSets["BigTests"].TestCases.Add(new FindDisivionTestCase(5, null, "duże pole, ale proste rozwiązanie: 4 kwadraty o boku 20", 40, Enumerable.Range(1, 20).ToArray(), 4));
            TestSets["BigTests"].TestCases.Add(new FindDisivionTestCase(20, null, "pole o boku 13", 13, Enumerable.Range(1, 12).ToArray(), 11));
            TestSets["BigTests"].TestCases.Add(new FindDisivionTestCase(20, null, "pole o boku 19", 19, Enumerable.Range(3, 14).ToArray(), 14));
            TestSets["BigTests"].TestCases.Add(new FindDisivionTestCase(25, null, "pole o boku 23", 23, new int[] { 3, 4, 7 }, 32));
            TestSets["BigTests"].TestCases.Add(new FindDisivionTestCase(30, null, "pole o boku 25", 25, new int[] { 4, 5, 6, 7 }, 25));
        }
Ejemplo n.º 9
0
        static void Main()
        {
            TestSet finalVelocitiesTests = new TestSet();

            finalVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.FinalVelocities, new int[] { 0 }, 0, 0));
            finalVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.FinalVelocities, new int[] { 10 }, 10, 10));
            finalVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.FinalVelocities, new int[] { 10, 3, 5, 4 }, 2, 22));
            finalVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.FinalVelocities, new int[] { 4, 11, 5, 5, 5 }, 0, 30));
            finalVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.FinalVelocities, new int[] { 10, 10, 5, 3, 1 }, 1, 29));
            finalVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.FinalVelocities, new int[] { 10, 10, 5, 3, 1, 9, 24, 3, 4, 19, 18, 7, 7, 8, 10, 5 }, 1, 143));
            finalVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.FinalVelocities, new int[] { 7, 10, 2, 18, 4, 6, 6 }, 1, 53));
            finalVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.FinalVelocities, GenerateTestArray(20, 1024), 1, 1101));
            finalVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.FinalVelocities, GenerateTestArray(100, 1024), 0, 4650));
            finalVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.FinalVelocities, GenerateTestArray(100, 123424), 1, 5337));
            finalVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.FinalVelocities, GenerateTestArray(1000, 123424), 1, 49209));

            Console.WriteLine("\nFinal velocities tests");
            finalVelocitiesTests.PreformTests(verbose: true, checkTimeLimit: false);


            TestSet journeyVelocitiesTests = new TestSet();

            journeyVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.JourneyVelocities, new int[] { 10 }, 10, 10, true));
            journeyVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.JourneyVelocities, new int[] { 10, 1, 1, 1 }, 7, 13, true));
            journeyVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.JourneyVelocities, new int[] { 10, 3, 5, 4 }, 2, 22, true));
            journeyVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.JourneyVelocities, new int[] { 4, 11, 5, 5, 5 }, 0, 30, true));
            journeyVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.JourneyVelocities, new int[] { 10, 10, 5, 3, 1 }, 0, 29, true));
            journeyVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.JourneyVelocities, new int[] { 5, 5, 10, 23, 45, 2, 1, 23, 9, 0, 8, 4, 1, 24, 86, 5, 6, 100, 353, 4, 5, 67, 32, 45, 23, 34, 56, 32, 23 }, 0, 1031, true));
            journeyVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.JourneyVelocities, GenerateTestArray(20, 1024), 0, 1101, true));
            journeyVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.JourneyVelocities, GenerateTestArray(100, 1024), 0, 4650, true));
            journeyVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.JourneyVelocities, GenerateTestArray(100, 123424), 0, 5337, true));
            journeyVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.JourneyVelocities, GenerateTestArray(1000, 123424), 0, 49209, true));
            int[] x = { 2, 2 }, y = GenerateTestArray(1000, 123424), z = new int[x.Length + y.Length];
            x.CopyTo(z, 0);
            y.CopyTo(z, x.Length);
            journeyVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.JourneyVelocities, z, 0, 49213, true));



            Console.WriteLine("\nJourney velocities tests");
            journeyVelocitiesTests.PreformTests(verbose: true, checkTimeLimit: false);
        }
Ejemplo n.º 10
0
        static void Main()
        {
            TestSet finalVelocitiesTests = new TestSet();

            finalVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.FinalVelocities, new int[] { 0 }, 0, 0));
            finalVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.FinalVelocities, new int[] { 10 }, 10, 10));
            finalVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.FinalVelocities, new int[] { 10, 3, 5, 4 }, 2, 22));
            finalVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.FinalVelocities, new int[] { 4, 11, 5, 5, 5 }, 0, 30));
            finalVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.FinalVelocities, new int[] { 10, 10, 5, 3, 1 }, 1, 29));
            finalVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.FinalVelocities, new int[] { 10, 10, 5, 3, 1, 9, 24, 3, 4, 19, 18, 7, 7, 8, 10, 5 }, 1, 143));
            finalVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.FinalVelocities, new int[] { 7, 10, 2, 18, 4, 6, 6 }, 1, 53));
            finalVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.FinalVelocities, GenerateTestArray(20, 1024), 1, 1101));
            finalVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.FinalVelocities, GenerateTestArray(100, 1024), 0, 4650));
            finalVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.FinalVelocities, GenerateTestArray(100, 123424), 1, 5337));
            finalVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.FinalVelocities, GenerateTestArray(1000, 123424), 1, 49209));

            Console.WriteLine("\nFinal velocities tests");
            finalVelocitiesTests.PreformTests(verbose: true, checkTimeLimit: false);


            TestSet journeyVelocitiesTests = new TestSet();

            journeyVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.JourneyVelocities, new int[] { 10 }, 10, 10, true));
            journeyVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.JourneyVelocities, new int[] { 10, 1, 1, 1 }, 7, 13, true));
            journeyVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.JourneyVelocities, new int[] { 10, 3, 5, 4 }, 2, 22, true));
            journeyVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.JourneyVelocities, new int[] { 4, 11, 5, 5, 5 }, 0, 30, true));
            journeyVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.JourneyVelocities, new int[] { 10, 10, 5, 3, 1 }, 0, 29, true));
            journeyVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.JourneyVelocities, new int[] { 5, 5, 10, 23, 45, 2, 1, 23, 9, 0, 8, 4, 1, 24, 86, 5, 6, 100, 353, 4, 5, 67, 32, 45, 23, 34, 56, 32, 23 }, 0, 1031, true));
            journeyVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.JourneyVelocities, GenerateTestArray(20, 1024), 0, 1101, true));
            journeyVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.JourneyVelocities, GenerateTestArray(100, 1024), 0, 4650, true));
            journeyVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.JourneyVelocities, GenerateTestArray(100, 123424), 0, 5337, true));
            journeyVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.JourneyVelocities, GenerateTestArray(1000, 123424), 0, 49209, true));
            int[] x = { 2, 2 }, y = GenerateTestArray(1000, 123424), z = new int[x.Length + y.Length];
            x.CopyTo(z, 0);
            y.CopyTo(z, x.Length);
            journeyVelocitiesTests.TestCases.Add(new VelocityMeasurementsTestCase(5, VelocityMeasurements.JourneyVelocities, z, 0, 49213, true));



            Console.WriteLine("\nJourney velocities tests");
            journeyVelocitiesTests.PreformTests(verbose: true, checkTimeLimit: false);

            //Custom Tests by G.Rozdzialik:
            Console.WriteLine("Custom tests");

            int[] testMeasurementsCounts = new int[] { 5, 100, 150, 200, 300, 400, 500, 1500, 4000 };
            int[] seeds = new int[] { 123456, 1000, 123456, 123456, 123456, 123456, 123456, 123456, 123456 };

            Stopwatch stopwatch = new Stopwatch();

            for (int i = 0; i < testMeasurementsCounts.Length; i++)
            {
                int[]  measurements = GenerateTestArray(testMeasurementsCounts[i], seeds[i]);
                bool[] isBrakingValue;

                stopwatch.Restart();
                Velocities velocities = VelocityMeasurements.FinalVelocities(measurements, out isBrakingValue);
                stopwatch.Stop();

                Console.WriteLine("Custom test {0,-1}:", i + 1, velocities.minVelocity, velocities.maxVelocity);
                Console.WriteLine("  min = {0}", velocities.minVelocity);
                Console.WriteLine("  max = {0}", velocities.maxVelocity);

                VelocityMeasurementsTestCase testCase = new VelocityMeasurementsTestCase(2, VelocityMeasurements.FinalVelocities,
                                                                                         measurements, velocities.minVelocity, velocities.maxVelocity);

                if (testCase.CustomIsBrakingArrayCorrect(isBrakingValue))
                {
                    Console.WriteLine("  isBrakingValue correct");
                }
                else
                {
                    Console.WriteLine("  isBrakingValue INVALID");
                }
                Console.WriteLine("  time elapsed = {0,5} ms", stopwatch.ElapsedMilliseconds);
                Console.WriteLine(String.Empty);
            }
            //------------------------------------------------------------------------
        }
Ejemplo n.º 11
0
        static void Main()
        {
            bool isExtraTests           = true;
            bool runCustomTests         = true;
            bool runLargeCustomTests    = true;
            bool runExtremelyLargeTests = true;

            Console.WriteLine("Running boilerplate task");
            long boilerplateTaskTimeElapsed = PerformBoilerplateTask();

            Console.WriteLine("Boilerplate task done\n");

            TestSet set = new TestSet();

            set.TestCases.Add(new BridgeCrossingTestCase(5, new int[] { 1, 2, 5, 10 }, 17));
            set.TestCases.Add(new BridgeCrossingTestCase(5, new int[] { 15, 10, 6, 7 }, 42));
            set.TestCases.Add(new BridgeCrossingTestCase(5, new int[] { 10, 25, 20, 5 }, 60));
            set.TestCases.Add(new BridgeCrossingTestCase(5, new int[] { 100 }, 100));
            set.TestCases.Add(new BridgeCrossingTestCase(5, new int[] { 1, 20 }, 20));
            set.TestCases.Add(new BridgeCrossingTestCase(5, new int[] { 1, 10, 100 }, 111));
            set.TestCases.Add(new BridgeCrossingTestCase(5, new int[] { 2, 2, 2, 2, 2 }, 14));
            set.TestCases.Add(new BridgeCrossingTestCase(5, new int[] { 1, 2, 3, 4, 5 }, 16));
            set.TestCases.Add(new BridgeCrossingTestCase(5, new int[] { 1, 1, 5, 5, 10, 10 }, 22));
            set.TestCases.Add(new BridgeCrossingTestCase(5, GenerateTestArray(5, 555), 284));
            set.TestCases.Add(new BridgeCrossingTestCase(5, GenerateTestArray(6, 666), 346));
            set.TestCases.Add(new BridgeCrossingTestCase(5, GenerateTestArray(7, 777), 216));
            Console.WriteLine("\nBasic tests");

            long[] elapsedTime = new long[5];
            var    stopwatch   = System.Diagnostics.Stopwatch.StartNew();

            set.PreformTests(verbose: true, checkTimeLimit: false);
            stopwatch.Stop();
            elapsedTime[0] = stopwatch.ElapsedMilliseconds;


            if (isExtraTests)
            {
                TestSet set2 = new TestSet();
                set2.TestCases.Add(new BridgeCrossingTestCase(3, GenerateTestArray(8, 888), 313));
                set2.TestCases.Add(new BridgeCrossingTestCase(30, GenerateTestArray(9, 999), 453));
                Console.WriteLine("\nExtra tests");

                stopwatch.Restart();
                set2.PreformTests(verbose: true, checkTimeLimit: true);
                stopwatch.Stop();
                elapsedTime[1] = stopwatch.ElapsedMilliseconds;
            }

            if (runCustomTests)
            {
                TestSet set3 = new TestSet();
                set3.TestCases.Add(new BridgeCrossingTestCase(3, GenerateTestArray(8, 123), 283));
                set3.TestCases.Add(new BridgeCrossingTestCase(30, GenerateTestArray(9, 1234), 641));
                set3.TestCases.Add(new BridgeCrossingTestCase(30, GenerateTestArray(9, 5678), 305));
                set3.TestCases.Add(new BridgeCrossingTestCase(30, GenerateTestArray(9, 9012), 335));
                set3.TestCases.Add(new BridgeCrossingTestCase(30, GenerateTestArray(9, 3456), 452));
                set3.TestCases.Add(new BridgeCrossingTestCase(30, GenerateTestArray(9, 7890), 364));
                Console.WriteLine("\nCustom tests");

                stopwatch.Restart();
                set3.PreformTests(verbose: true, checkTimeLimit: false);
                stopwatch.Stop();
                elapsedTime[2] = stopwatch.ElapsedMilliseconds;
            }

            if (runLargeCustomTests)
            {
                TestSet set4 = new TestSet();
                set4.TestCases.Add(new BridgeCrossingTestCase(300, GenerateTestArray(10, 2703), 249));
                set4.TestCases.Add(new BridgeCrossingTestCase(300, GenerateTestArray(10, 6969), 245));
                set4.TestCases.Add(new BridgeCrossingTestCase(300, GenerateTestArray(10, 1), 379));
                Console.WriteLine("\nCustom large tests");

                stopwatch.Restart();
                set4.PreformTests(verbose: true, checkTimeLimit: false);
                stopwatch.Stop();
                elapsedTime[3] = stopwatch.ElapsedMilliseconds;
            }

            if (runExtremelyLargeTests)
            {
                TestSet set5 = new TestSet();
                set5.TestCases.Add(new BridgeCrossingTestCase(300, GenerateTestArray(150, 1), 3678));
                set5.TestCases.Add(new BridgeCrossingTestCase(300, GenerateTestArray(250, 2), 6268));
                set5.TestCases.Add(new BridgeCrossingTestCase(300, GenerateTestArray(300, 3), 7537));
                set5.TestCases.Add(new BridgeCrossingTestCase(300, GenerateTestArray(400, 4), 10169));
                set5.TestCases.Add(new BridgeCrossingTestCase(300, GenerateTestArray(400, 5), 9862));
                set5.TestCases.Add(new BridgeCrossingTestCase(300, GenerateTestArray(500, 6), 12615));
                set5.TestCases.Add(new BridgeCrossingTestCase(300, GenerateTestArray(600, 7), 14124));
                set5.TestCases.Add(new BridgeCrossingTestCase(300, GenerateTestArray(1500, 8), 36810));
                set5.TestCases.Add(new BridgeCrossingTestCase(300, GenerateTestArray(3000, 9), 73827));
                set5.TestCases.Add(new BridgeCrossingTestCase(300, GenerateTestArray(100000, 10), 2478340));
                Console.WriteLine("\nCustom extremely large tests");

                stopwatch.Restart();
                set5.PreformTests(verbose: true, checkTimeLimit: false);
                stopwatch.Stop();
                elapsedTime[4] = stopwatch.ElapsedMilliseconds;
            }

            Console.WriteLine("Basic tests   : {0,5} ms          ({1:F3} times the boilerplate time)", elapsedTime[0], (double)elapsedTime[0] / boilerplateTaskTimeElapsed);
            Console.WriteLine("Extra tests   : {0,5} ms          ({1:F3} times the boilerplate time)", elapsedTime[1], (double)elapsedTime[1] / boilerplateTaskTimeElapsed);
            if (runCustomTests)
            {
                Console.WriteLine("Custom tests  : {0,5} ms          ({1:F3} times the boilerplate time)", elapsedTime[2], (double)elapsedTime[2] / boilerplateTaskTimeElapsed);
            }
            if (runLargeCustomTests)
            {
                Console.WriteLine("Large custom  : {0,5} ms          ({1:F3} times the boilerplate time)", elapsedTime[3], (double)elapsedTime[3] / boilerplateTaskTimeElapsed);
            }
            if (runExtremelyLargeTests)
            {
                Console.WriteLine("Extreme custom: {0,5} ms          ({1:F3} times the boilerplate time)", elapsedTime[4], (double)elapsedTime[4] / boilerplateTaskTimeElapsed);
            }
        }
Ejemplo n.º 12
0
        static void Main()
        {
            bool drawBitmaps = false;

            TestSet isSameSideTests = new TestSet();

            isSameSideTests.TestCases.Add(new IsSameSideTestCase(5, new Point(0, 1), new Point(2, 1), new Segment(new Point(1, 1), new Point(4, 4)), false));
            isSameSideTests.TestCases.Add(new IsSameSideTestCase(5, new Point(2, 1), new Point(0, 1), new Segment(new Point(1, 1), new Point(4, 4)), false));
            isSameSideTests.TestCases.Add(new IsSameSideTestCase(5, new Point(1, 3), new Point(2, 6), new Segment(new Point(1, 1), new Point(4, 4)), true));
            isSameSideTests.TestCases.Add(new IsSameSideTestCase(5, new Point(2, 6), new Point(1, 3), new Segment(new Point(1, 1), new Point(4, 4)), true));
            isSameSideTests.TestCases.Add(new IsSameSideTestCase(5, new Point(2, 2), new Point(3, 3), new Segment(new Point(1, 1), new Point(4, 4)), true));
            isSameSideTests.TestCases.Add(new IsSameSideTestCase(5, new Point(2, 2), new Point(-1, -1), new Segment(new Point(1, 1), new Point(4, 4)), true));
            isSameSideTests.TestCases.Add(new IsSameSideTestCase(5, new Point(2, 2), new Point(5, 3), new Segment(new Point(1, 1), new Point(4, 4)), true));
            isSameSideTests.TestCases.Add(new IsSameSideTestCase(5, new Point(2, 2), new Point(1, 3), new Segment(new Point(1, 1), new Point(4, 4)), true));
            isSameSideTests.TestCases.Add(new IsSameSideTestCase(5, new Point(2, 2), new Point(1, 3), new Segment(new Point(-5, -2), new Point(-1, -4)), true));
            isSameSideTests.TestCases.Add(new IsSameSideTestCase(5, new Point(0, 0), new Point(1, 1), new Segment(new Point(-5, -2), new Point(-1, -4)), true));
            isSameSideTests.TestCases.Add(new IsSameSideTestCase(5, new Point(0, 0), new Point(-3, -4), new Segment(new Point(-5, -2), new Point(-1, -4)), false));
            isSameSideTests.TestCases.Add(new IsSameSideTestCase(5, new Point(0, 0), new Point(-10, 0), new Segment(new Point(-5, -2), new Point(-1, -4)), false));
            isSameSideTests.TestCases.Add(new IsSameSideTestCase(5, new Point(2, 3), new Point(-3, 4), new Segment(new Point(-5, 5), new Point(0, 0)), true));
            isSameSideTests.TestCases.Add(new IsSameSideTestCase(5, new Point(-4, 1), new Point(-1, 4), new Segment(new Point(-5, 5), new Point(0, 0)), false));

            TestSet polygonAreaTests = new TestSet();

            polygonAreaTests.TestCases.Add(new PolygonAreaTestCase(5, new Point[] { new Point(0, 0) }, 0));
            polygonAreaTests.TestCases.Add(new PolygonAreaTestCase(5, new Point[] { new Point(1, 1), new Point(2, 2) }, 0));
            polygonAreaTests.TestCases.Add(new PolygonAreaTestCase(5, new Point[] { new Point(1, 1), new Point(2, 2), new Point(2, 0) }, 1));
            polygonAreaTests.TestCases.Add(new PolygonAreaTestCase(5, new Point[] { new Point(-1, -1), new Point(2, -1), new Point(2, 3),
                                                                                    new Point(-1, 3) }, 12));
            polygonAreaTests.TestCases.Add(new PolygonAreaTestCase(5, new Point[] { new Point(3, 4), new Point(5, 11), new Point(12, 8),
                                                                                    new Point(9, 5), new Point(5, 6) }, 30));
            polygonAreaTests.TestCases.Add(new PolygonAreaTestCase(5, new Point[] { new Point(-5, 0), new Point(-3, 0), new Point(-2, -1),
                                                                                    new Point(0, -1), new Point(0, 3), new Point(-2, 1), new Point(-3, 2) }, 10));
            polygonAreaTests.TestCases.Add(new PolygonAreaTestCase(5, new Point[] { new Point(-3, -2), new Point(-4, -4), new Point(-2, -3), new Point(0, -3),
                                                                                    new Point(0, -5), new Point(5, 0), new Point(0, 0), new Point(0, 2), new Point(-1, 2), new Point(-1, 1), new Point(-6, 1) }, 31));
            polygonAreaTests.TestCases.Add(new PolygonAreaTestCase(5, GenerateRandomPolygon(12, 111), 120.5));
            polygonAreaTests.TestCases.Add(new PolygonAreaTestCase(5, GenerateRandomPolygon(16, 222), 172));
            polygonAreaTests.TestCases.Add(new PolygonAreaTestCase(5, GenerateRandomPolygon(20, 111), 139));

            TestSet sutherlandHodgmanTests = new TestSet();

            Point[] sp1 = new Point[] { new Point(2, 1), new Point(4, 1), new Point(4, 3), new Point(2, 3) };
            Point[] cp1 = new Point[] { new Point(3, 2), new Point(5, 2), new Point(5, 4), new Point(3, 4) };
            Point[] sh1 = new Point[] { new Point(3, 2), new Point(4, 2), new Point(4, 3), new Point(3, 3) };
            sutherlandHodgmanTests.TestCases.Add(new SutherlandHodgmanTestCase(5, sp1, cp1, sh1));

            Point[] sp2 = new Point[] { new Point(2, 1), new Point(4, 1), new Point(4, 3), new Point(2, 3) };
            Point[] cp2 = new Point[] { new Point(5, 2), new Point(7, 2), new Point(7, 4), new Point(5, 4) };
            Point[] sh2 = new Point[] { };
            sutherlandHodgmanTests.TestCases.Add(new SutherlandHodgmanTestCase(5, sp2, cp2, sh2));

            Point[] sp3 = new Point[] { new Point(-1, 1), new Point(0, 1), new Point(0, 2), new Point(1, 2), new Point(1, 1),
                                        new Point(2, 1), new Point(2, 3), new Point(-1, 3) };
            Point[] cp3 = new Point[] { new Point(-1, 0), new Point(2, 0), new Point(2, 2), new Point(-1, 2) };
            Point[] sh3 = new Point[] { new Point(-1, 2), new Point(-1, 1), new Point(0, 1), new Point(0, 2), new Point(1, 2),
                                        new Point(1, 1), new Point(2, 1), new Point(2, 2) };
            sutherlandHodgmanTests.TestCases.Add(new SutherlandHodgmanTestCase(5, sp3, cp3, sh3));

            Point[] sp4  = new Point[] { new Point(2, 1), new Point(4, 1), new Point(4, 3), new Point(2, 3) };
            Point[] cp4  = new Point[] { new Point(1, 0), new Point(5, 0), new Point(5, 4), new Point(1, 4) };
            Point[] sh4a = new Point[] { new Point(2, 1), new Point(4, 1), new Point(4, 3), new Point(2, 3) };
            sutherlandHodgmanTests.TestCases.Add(new SutherlandHodgmanTestCase(5, sp4, cp4, sh4a));

            Point[] sh4b = new Point[] { new Point(2, 3), new Point(2, 1), new Point(4, 1), new Point(4, 3) };
            sutherlandHodgmanTests.TestCases.Add(new SutherlandHodgmanTestCase(5, cp4, sp4, sh4b));

            Point[] sp5 = new Point[] { new Point(2, 2), new Point(3, 2), new Point(3, 4), new Point(4, 4),
                                        new Point(4, 2), new Point(5, 2), new Point(5, 5), new Point(2, 5) };
            Point[] cp5a = new Point[] { new Point(1, 3), new Point(6, 3), new Point(6, 6), new Point(1, 6) };
            Point[] sh5a = new Point[] { new Point(2, 3), new Point(3, 3), new Point(3, 4), new Point(4, 4),
                                         new Point(4, 3), new Point(5, 3), new Point(5, 5), new Point(2, 5) };
            sutherlandHodgmanTests.TestCases.Add(new SutherlandHodgmanTestCase(5, sp5, cp5a, sh5a));

            Point[] cp5b = new Point[] { new Point(1, 1), new Point(6, 1), new Point(6, 3), new Point(1, 3) };
            Point[] sh5b = new Point[] { new Point(2, 3), new Point(2, 2), new Point(3, 2), new Point(3, 3),
                                         new Point(4, 3), new Point(4, 2), new Point(5, 2), new Point(5, 3) };
            sutherlandHodgmanTests.TestCases.Add(new SutherlandHodgmanTestCase(5, sp5, cp5b, sh5b));

            Point[] sp6 = GenerateRandomPolygon(16, 222);
            Point[] cp6 = new Point[] { new Point(-9, -3), new Point(8.5, -3), new Point(8.5, 4), new Point(-9, 4) };
            Point[] sh6 = new Point[] { new Point(6.8, -3), new Point(8, 0), new Point(8.5, 0.5), new Point(8.5, 2),
                                        new Point(7.5, 4), new Point(-6, 4), new Point(-6, 2), new Point(-5, 0), new Point(-8, -2), new Point(-7.25, -3) };
            sutherlandHodgmanTests.TestCases.Add(new SutherlandHodgmanTestCase(5, sp6, cp6, sh6));

            Point[] sp7  = GenerateRandomPolygon(20, 111);
            Point[] cp7a = new Point[] { new Point(-8, -5), new Point(-6, -5), new Point(-6, 5), new Point(-8, 5) };
            Point[] sh7a = new Point[] { new Point(-6, 4), new Point(-7, 4), new Point(-6, 3), new Point(-6, -0.75),
                                         new Point(-8, -2.25), new Point(-8, -3.2), new Point(-6, -3.6) };
            sutherlandHodgmanTests.TestCases.Add(new SutherlandHodgmanTestCase(5, sp7, cp7a, sh7a));

            Point[] cp7b = new Point[] { new Point(4, -3), new Point(-4, -7), new Point(0, -7) };
            Point[] sh7b = new Point[] { new Point(4, -3), new Point(-2.8, -6.4), new Point(-2.5, -7), new Point(-1, -7),
                                         new Point(0, -6), new Point(0.5, -6.5) };
            sutherlandHodgmanTests.TestCases.Add(new SutherlandHodgmanTestCase(5, sp7, cp7b, sh7b));


            TestSet sutherlandHodgmanTestsWithDuplicates = new TestSet();

            Point[] dsp1  = new Point[] { new Point(2, 1), new Point(4, 1), new Point(4, 3), new Point(2, 3) };
            Point[] dcp1a = new Point[] { new Point(4, 1), new Point(6, 1), new Point(6, 3), new Point(4, 3) };
            Point[] dsh1a = new Point[] { new Point(4, 1), new Point(4, 3) };
            sutherlandHodgmanTestsWithDuplicates.TestCases.Add(new SutherlandHodgmanTestCase(5, dsp1, dcp1a, dsh1a));

            Point[] dcp1b = new Point[] { new Point(5, 4), new Point(3, 2), new Point(5, 0), new Point(7, 2) };
            Point[] dsh1b = new Point[] { new Point(4, 3), new Point(3, 2), new Point(4, 1) };
            sutherlandHodgmanTestsWithDuplicates.TestCases.Add(new SutherlandHodgmanTestCase(5, dsp1, dcp1b, dsh1b));

            Point[] dsp2 = new Point[] { new Point(0, 0), new Point(1, 0), new Point(1, 1), new Point(2, 1),
                                         new Point(2, 0), new Point(3, 0), new Point(3, 4), new Point(0, 4) };
            Point[] dch2 = new Point[] { new Point(0, 0), new Point(1, 0), new Point(1, 5), new Point(0, 5) };
            Point[] dsh2 = new Point[] { new Point(0, 0), new Point(1, 0), new Point(1, 1), new Point(1, 4), new Point(0, 4) };
            sutherlandHodgmanTestsWithDuplicates.TestCases.Add(new SutherlandHodgmanTestCase(5, dsp2, dch2, dsh2));

            Point[] dsp3 = GenerateRandomPolygon(14, 12345);
            Point[] dch3 = new Point[] { new Point(5, 7), new Point(-7, 5), new Point(-7, 0), new Point(5, 0) };
            Point[] dsh3 = new Point[] { new Point(5, 0), new Point(5, 6), new Point(4, 6), new Point(2.75, 6.625),
                                         new Point(-5.8, 5.2), new Point(-5, 2), new Point(-7, 2), new Point(-7, 1), new Point(-6, 0) };
            sutherlandHodgmanTestsWithDuplicates.TestCases.Add(new SutherlandHodgmanTestCase(5, dsp3, dch3, dsh3));

            Point[] dsp4 = GenerateRandomPolygon(16, 222);
            Point[] dcp4 = new Point[] { new Point(-9, -2), new Point(8, -2), new Point(8, 4), new Point(-9, 4) };
            Point[] dsh4 = new Point[] { new Point(7.2, -2), new Point(8, 0), new Point(8, 3), new Point(7.5, 4),
                                         new Point(-6, 4), new Point(-6, 2), new Point(-5, 0), new Point(-8, -2) };
            sutherlandHodgmanTestsWithDuplicates.TestCases.Add(new SutherlandHodgmanTestCase(5, dsp4, dcp4, dsh4));

            Console.WriteLine("IsSameSide tests");
            isSameSideTests.PreformTests(verbose: true, checkTimeLimit: false);

            Console.WriteLine("\nPolygon area tests");
            polygonAreaTests.PreformTests(verbose: true, checkTimeLimit: false);

            Console.WriteLine("\nSutherland-Hodgman tests");
            sutherlandHodgmanTests.PreformTests(verbose: true, checkTimeLimit: false);

            Console.WriteLine("\nSutherland-Hodgman tests with duplicates");
            sutherlandHodgmanTestsWithDuplicates.PreformTests(verbose: true, checkTimeLimit: false);

            if (drawBitmaps)
            {
                System.IO.Directory.CreateDirectory("../../Testy");
                BitmapDrawer bitmapDrawer = new BitmapDrawer(sp1, cp1, SutherlandHodgman.GetIntersectedPolygon(sp1, cp1), 1);
                bitmapDrawer = new BitmapDrawer(sp2, cp2, SutherlandHodgman.GetIntersectedPolygon(sp2, cp2), 2);
                bitmapDrawer = new BitmapDrawer(sp3, cp3, SutherlandHodgman.GetIntersectedPolygon(sp3, cp3), 3);
                bitmapDrawer = new BitmapDrawer(sp4, cp4, SutherlandHodgman.GetIntersectedPolygon(sp4, cp4), 4);
                bitmapDrawer = new BitmapDrawer(cp4, sp4, SutherlandHodgman.GetIntersectedPolygon(cp4, sp4), 5);
                bitmapDrawer = new BitmapDrawer(sp5, cp5a, SutherlandHodgman.GetIntersectedPolygon(sp5, cp5a), 6);
                bitmapDrawer = new BitmapDrawer(sp5, cp5b, SutherlandHodgman.GetIntersectedPolygon(sp5, cp5b), 7);
                bitmapDrawer = new BitmapDrawer(sp6, cp6, SutherlandHodgman.GetIntersectedPolygon(sp6, cp6), 8);
                bitmapDrawer = new BitmapDrawer(sp7, cp7a, SutherlandHodgman.GetIntersectedPolygon(sp7, cp7a), 9);
                bitmapDrawer = new BitmapDrawer(sp7, cp7b, SutherlandHodgman.GetIntersectedPolygon(sp7, cp7b), 10);
                bitmapDrawer = new BitmapDrawer(dsp1, dcp1a, SutherlandHodgman.GetIntersectedPolygon(dsp1, dcp1a), 11);
                bitmapDrawer = new BitmapDrawer(dsp1, dcp1b, SutherlandHodgman.GetIntersectedPolygon(dsp1, dcp1b), 12);
                bitmapDrawer = new BitmapDrawer(dsp2, dch2, SutherlandHodgman.GetIntersectedPolygon(dsp2, dch2), 13);
                bitmapDrawer = new BitmapDrawer(dsp3, dch3, SutherlandHodgman.GetIntersectedPolygon(dsp3, dch3), 14);
                bitmapDrawer = new BitmapDrawer(dsp4, dcp4, SutherlandHodgman.GetIntersectedPolygon(dsp4, dcp4), 15);
            }
        }
        private void PrepareRouteTestSets()
        {
            List <(Graph, bool, int, string)> labTests = new List <(Graph, bool, int, string)>();

            Graph  g;
            bool   expectNull;
            int    optNum;
            string desc;

            //1
            desc = "skierowany cykl";
            g    = new AdjacencyMatrixGraph(true, 3);
            g.AddEdge(0, 1);
            g.AddEdge(1, 2);
            g.AddEdge(2, 0);
            expectNull = false;
            optNum     = 1;
            labTests.Add((g, expectNull, optNum, desc));


            //2
            desc = "dag";
            g    = new AdjacencyMatrixGraph(true, 4);
            g.AddEdge(0, 1);
            g.AddEdge(1, 2);
            g.AddEdge(2, 3);
            g.AddEdge(0, 2);
            g.AddEdge(0, 3);
            g.AddEdge(1, 3);
            expectNull = true;
            optNum     = 0;
            labTests.Add((g, expectNull, optNum, desc));

            //3
            desc = "cykl z krawędzią wiszącą";
            g    = new AdjacencyMatrixGraph(true, 4);
            g.AddEdge(0, 1);
            g.AddEdge(1, 2);
            g.AddEdge(2, 0);
            g.AddEdge(1, 3);
            expectNull = true;
            optNum     = 0;
            labTests.Add((g, expectNull, optNum, desc));

            //4
            desc = "ósemka";
            g    = new AdjacencyListsGraph <AVLAdjacencyList>(true, 5);
            g.AddEdge(0, 1);
            g.AddEdge(1, 2);
            g.AddEdge(2, 0);
            g.AddEdge(1, 3);
            g.AddEdge(3, 4);
            g.AddEdge(4, 1);
            expectNull = false;
            optNum     = 1;
            labTests.Add((g, expectNull, optNum, desc));

            //5
            desc = "ósemka + wierzchołki izolowane";
            g    = new AdjacencyListsGraph <AVLAdjacencyList>(true, 10);
            g.AddEdge(0, 1);
            g.AddEdge(1, 2);
            g.AddEdge(2, 0);
            g.AddEdge(1, 3);
            g.AddEdge(3, 4);
            g.AddEdge(4, 1);
            expectNull = false;
            optNum     = 1;
            labTests.Add((g, expectNull, optNum, desc));

            //6
            desc = "dwa rozłączne cykle";
            g    = new AdjacencyListsGraph <AVLAdjacencyList>(true, 10);
            for (int i = 0; i < 4; ++i)
            {
                g.AddEdge(i, i + 1);
                g.AddEdge(5 + i, 5 + i + 1);
            }
            g.AddEdge(4, 0);
            g.AddEdge(9, 5);
            expectNull = false;
            optNum     = 2;
            labTests.Add((g, expectNull, optNum, desc));

            //7
            desc = "bardziej skomplikowany graf z jedną trasą";
            g    = new AdjacencyListsGraph <HashTableAdjacencyList>(true, 7);
            g.AddEdge(0, 2);
            g.AddEdge(2, 3);
            g.AddEdge(3, 5);
            g.AddEdge(5, 6);
            g.AddEdge(6, 1);
            g.AddEdge(1, 2);
            g.AddEdge(1, 3);
            g.AddEdge(3, 4);
            g.AddEdge(4, 1);
            g.AddEdge(2, 6);
            g.AddEdge(6, 0);
            expectNull = false;
            optNum     = 1;
            labTests.Add((g, expectNull, optNum, desc));

            //8
            desc = "bardziej skomplikowany graf bez rozwiązania";
            g    = new AdjacencyListsGraph <HashTableAdjacencyList>(true, 7);
            g.AddEdge(0, 2);
            g.AddEdge(2, 3);
            g.AddEdge(3, 5);
            g.AddEdge(5, 6);
            g.AddEdge(6, 1);
            g.AddEdge(1, 2);
            g.AddEdge(1, 3);
            g.AddEdge(3, 4);
            g.AddEdge(4, 1);
            g.AddEdge(2, 6);
            g.AddEdge(6, 0);
            g.AddEdge(6, 2);
            expectNull = true;
            optNum     = 0;
            labTests.Add((g, expectNull, optNum, desc));

            //9
            desc = "graf pełny, krawędzie tam i z powrotem";
            g    = new AdjacencyListsGraph <SimpleAdjacencyList>(true, 7);
            for (int i = 0; i < 7; ++i)
            {
                for (int j = i + 1; j < 7; ++j)
                {
                    g.AddEdge(i, j);
                    g.AddEdge(j, i);
                }
            }
            expectNull = false;
            optNum     = 1;
            labTests.Add((g, expectNull, optNum, desc));


            //10
            desc = "graf z kilku nietrywialnych składowych";
            g    = new AdjacencyListsGraph <SimpleAdjacencyList>(true, 20);

            g.AddEdge(2, 3);
            g.AddEdge(3, 4);
            g.AddEdge(4, 1);
            g.AddEdge(1, 2);
            g.AddEdge(0, 4);
            g.AddEdge(4, 0);

            g.AddEdge(5, 6);
            g.AddEdge(6, 7);
            g.AddEdge(7, 5);
            g.AddEdge(5, 9);
            g.AddEdge(9, 8);
            g.AddEdge(8, 5);

            g.AddEdge(10, 11);
            g.AddEdge(11, 12);
            g.AddEdge(12, 13);
            g.AddEdge(13, 10);
            g.AddEdge(10, 12);
            g.AddEdge(12, 14);
            g.AddEdge(14, 10);

            g.AddEdge(15, 16);
            g.AddEdge(16, 17);
            g.AddEdge(17, 18);
            g.AddEdge(18, 15);
            g.AddEdge(19, 15);
            g.AddEdge(15, 18);
            g.AddEdge(18, 17);
            g.AddEdge(17, 16);
            g.AddEdge(16, 19);

            expectNull = false;
            optNum     = 4;
            labTests.Add((g, expectNull, optNum, desc));


            TestSets["LabShortRoutes"] = new TestSet(new RoutePlanner(), "Część 2 - dużo krótkich tras");
            TestSets["LabLongRoutes"]  = new TestSet(new RoutePlanner(), "Część 3 - mało długich tras");

            foreach (var(gr, en, on, des) in labTests)
            {
                TestSets["LabShortRoutes"].TestCases.Add(new ShortRoutesTestCase(1, null, des, gr, en));
                TestSets["LabLongRoutes"].TestCases.Add(new LongRoutesTestCase(1, null, des, gr, en, on));
            }
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            GraphExport          ge  = new GraphExport();
            RandomGraphGenerator rgg = new RandomGraphGenerator();

            Graph[] directedGraphs = new Graph[8];
            directedGraphs[0] = new AdjacencyListsGraph <AVLAdjacencyList>(true, 3)
            {
                new Edge(0, 1), new Edge(1, 2), new Edge(2, 0)
            };
            directedGraphs[1] = new AdjacencyListsGraph <SimpleAdjacencyList>(true, 3)
            {
                new Edge(0, 1), new Edge(1, 2), new Edge(2, 1)
            };
            directedGraphs[2] = new AdjacencyMatrixGraph(true, 4)
            {
                new Edge(0, 1), new Edge(0, 2), new Edge(1, 3), new Edge(2, 3)
            };
            directedGraphs[3] = new AdjacencyListsGraph <HashTableAdjacencyList>(true, 10);
            directedGraphs[4] = new AdjacencyMatrixGraph(true, 10)
            {
                new Edge(0, 1), new Edge(0, 2), new Edge(0, 3), new Edge(2, 4), new Edge(2, 5), new Edge(2, 6),
                new Edge(5, 7), new Edge(5, 8), new Edge(5, 9), new Edge(6, 5), new Edge(7, 8), new Edge(8, 2)
            };
            rgg.SetSeed(111);
            directedGraphs[5] = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.2);
            rgg.SetSeed(222);
            directedGraphs[6] = rgg.DirectedCycle(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), 1000);
            rgg.SetSeed(333);
            directedGraphs[7] = rgg.DAG(typeof(AdjacencyMatrixGraph), 200, 0.2, 1, 1);

            TestSet findCycleDirected = new TestSet();

            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[0], true));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[1], true));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[2], false));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[3], false));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[4], true));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[5], true));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[6], true));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[7], false));

            Graph[] undirectedGraphs = new Graph[6];
            undirectedGraphs[0] = new AdjacencyListsGraph <AVLAdjacencyList>(false, 3)
            {
                new Edge(0, 1), new Edge(1, 2), new Edge(2, 0)
            };
            undirectedGraphs[1] = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 4)
            {
                new Edge(0, 1), new Edge(1, 2), new Edge(2, 3), new Edge(3, 1)
            };
            undirectedGraphs[2] = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 10);
            undirectedGraphs[3] = new AdjacencyMatrixGraph(false, 10)
            {
                new Edge(0, 1), new Edge(0, 2), new Edge(0, 3), new Edge(2, 4), new Edge(2, 5), new Edge(2, 6),
                new Edge(5, 7), new Edge(5, 8), new Edge(5, 9), new Edge(8, 2)
            };
            rgg.SetSeed(444);
            undirectedGraphs[4] = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.2);
            rgg.SetSeed(555);
            undirectedGraphs[5] = rgg.TreeGraph(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), 1000, 1.0);

            TestSet findCycleUndirected = new TestSet();

            findCycleUndirected.TestCases.Add(new FindCycleTestCase(5, null, undirectedGraphs[0], true));
            findCycleUndirected.TestCases.Add(new FindCycleTestCase(5, null, undirectedGraphs[1], true));
            findCycleUndirected.TestCases.Add(new FindCycleTestCase(5, null, undirectedGraphs[2], false));
            findCycleUndirected.TestCases.Add(new FindCycleTestCase(5, null, undirectedGraphs[3], true));
            findCycleUndirected.TestCases.Add(new FindCycleTestCase(5, null, undirectedGraphs[4], true));
            findCycleUndirected.TestCases.Add(new FindCycleTestCase(5, null, undirectedGraphs[5], false));

            Graph[] trees = new Graph[10];
            trees[0] = new AdjacencyListsGraph <AVLAdjacencyList>(false, 3)
            {
                new Edge(0, 1), new Edge(1, 2)
            };
            trees[1] = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 4)
            {
                new Edge(0, 1), new Edge(1, 2), new Edge(2, 3)
            };
            trees[2] = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 1);
            trees[3] = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 2)
            {
                new Edge(0, 1)
            };
            trees[4] = new AdjacencyMatrixGraph(false, 5)
            {
                new Edge(1, 3), new Edge(2, 4)
            };
            trees[5] = new AdjacencyMatrixGraph(true, 3)
            {
                new Edge(0, 1), new Edge(0, 2)
            };
            rgg.SetSeed(777);
            trees[6] = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.2);
            rgg.SetSeed(888);
            trees[7] = rgg.TreeGraph(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), 1000, 1.0);
            rgg.SetSeed(999);
            trees[8] = rgg.TreeGraph(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), 1001, 1.0);
            trees[9] = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 10);
            for (int i = 1; i < 10; ++i)
            {
                trees[9].AddEdge(i - 1, i);
            }

            TestSet treeCenter = new TestSet();

            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[0], true, new int[] { 1 }));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[1], true, new int[] { 1, 2 }));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[2], true, new int[] { 0 }));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[3], true, new int[] { 0, 1 }));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[4], false, null));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, new ArgumentException(), trees[5], false, null));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[6], false, null));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[7], true, new int[] { 305, 786 }));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[8], true, new int[] { 60 }));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[9], true, new int[] { 4, 5 }));

            //
            // Odkomentuj odpowiednią linię aby zobaczyć wybrany graf
            // Pamiętaj, że przykłady numerowane są od 1
            //
            //ge.Export(directedGraphs[0]);
            //ge.Export(directedGraphs[1]);
            //ge.Export(directedGraphs[2]);
            //ge.Export(directedGraphs[3]);
            //ge.Export(directedGraphs[4]);
            //ge.Export(directedGraphs[5]);
            //ge.Export(directedGraphs[6]);
            //ge.Export(directedGraphs[7]);
            //ge.Export(undirectedGraphs[0]);
            //ge.Export(undirectedGraphs[1]);
            //ge.Export(undirectedGraphs[2]);
            ge.Export(undirectedGraphs[3]);
            //ge.Export(undirectedGraphs[4]);
            //ge.Export(undirectedGraphs[5]);
            //ge.Export(trees[0]);
            //ge.Export(trees[1]);
            //ge.Export(trees[2]);
            //ge.Export(trees[3]);
            //ge.Export(trees[4]);
            //ge.Export(trees[5]);
            //ge.Export(trees[6]);
            //ge.Export(trees[7]);
            //ge.Export(trees[8]);

            long[]    timeElapsed = new long[9];
            Stopwatch stopwatch   = new Stopwatch();


            Console.WriteLine("\nCycle Finding\n");

            FindCycleTestCase.ResultOnly = true;
            Console.WriteLine("\nDirected Graphs - result only");
            stopwatch.Start();
            findCycleDirected.PreformTests(verbose: true, checkTimeLimit: false);
            stopwatch.Stop();
            timeElapsed[0] = stopwatch.ElapsedMilliseconds;
            Console.WriteLine("\nUndirected Graphs - result only");
            stopwatch.Restart();
            findCycleUndirected.PreformTests(verbose: true, checkTimeLimit: false);
            stopwatch.Stop();
            timeElapsed[1] = stopwatch.ElapsedMilliseconds;

            FindCycleTestCase.ResultOnly = false;
            Console.WriteLine("\nDirected Graphs - full funcionality");
            stopwatch.Restart();
            findCycleDirected.PreformTests(verbose: true, checkTimeLimit: false, forceExecution: false);
            stopwatch.Stop();
            timeElapsed[2] = stopwatch.ElapsedMilliseconds;
            Console.WriteLine("\nUndirected Graphs - full funcionality");
            stopwatch.Restart();
            findCycleUndirected.PreformTests(verbose: true, checkTimeLimit: false, forceExecution: false);
            stopwatch.Stop();
            timeElapsed[3] = stopwatch.ElapsedMilliseconds;

            Console.WriteLine("\nTree Center\n");
            TreeCenterTestCase.ResultOnly = true;
            Console.WriteLine("\nResult only");
            stopwatch.Restart();
            treeCenter.PreformTests(verbose: true, checkTimeLimit: false);
            stopwatch.Stop();
            timeElapsed[4] = stopwatch.ElapsedMilliseconds;
            Console.WriteLine("\nFull funcionality");
            TreeCenterTestCase.ResultOnly = false;

            stopwatch.Restart();
            treeCenter.PreformTests(verbose: true, checkTimeLimit: false, forceExecution: false);
            stopwatch.Stop();
            timeElapsed[5] = stopwatch.ElapsedMilliseconds;

            Console.WriteLine("\n\nPerformance metrics for the initial task tests");
            for (int i = 0; i < 6; i++)
            {
                Console.WriteLine("Testset {0}: {1,5} ms", i + 1, timeElapsed[i]);
            }



            // Nie radzę tych grafów próbować eksportować za pomocą GraphViz (mają sporo wierzchołków)
            // Wyjątek stanowi customTrees[0]
            Console.WriteLine("\n\nCustom tests");
            Console.WriteLine("Generating graphs. This may take a while");

            // Cycle in directed graphs
            Graph[] customDirectedGraphs = new Graph[5];
            customDirectedGraphs[0] = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.7);
            customDirectedGraphs[1] = rgg.DAG(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 1000, 0.9, 1, 1);
            customDirectedGraphs[2] = rgg.DirectedCycle(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 1000);
            customDirectedGraphs[3] = rgg.DirectedGraph(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 1000, 0.5);
            customDirectedGraphs[4] = rgg.DirectedGraph(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 1000, 0.7);

            TestSet customDirectedGraphsTestSet = new TestSet();

            customDirectedGraphsTestSet.TestCases.Add(new FindCycleTestCase(5, null, customDirectedGraphs[0], true));
            customDirectedGraphsTestSet.TestCases.Add(new FindCycleTestCase(5, null, customDirectedGraphs[1], false));
            customDirectedGraphsTestSet.TestCases.Add(new FindCycleTestCase(5, null, customDirectedGraphs[2], true));
            customDirectedGraphsTestSet.TestCases.Add(new FindCycleTestCase(5, null, customDirectedGraphs[3], true));
            customDirectedGraphsTestSet.TestCases.Add(new FindCycleTestCase(5, null, customDirectedGraphs[4], true));


            // Cycle in undirected graphs
            Graph[] customUndirectedGraphs = new Graph[5];
            customUndirectedGraphs[0] = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.7);
            customUndirectedGraphs[1] = rgg.TreeGraph(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 1000, 1);
            customUndirectedGraphs[2] = rgg.UndirectedCycle(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 1000);
            customUndirectedGraphs[3] = rgg.UndirectedGraph(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 1000, 0.5);
            customUndirectedGraphs[4] = rgg.UndirectedGraph(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 1000, 0.7);

            TestSet customUndirectedGraphsTestSet = new TestSet();

            customUndirectedGraphsTestSet.TestCases.Add(new FindCycleTestCase(5, null, customUndirectedGraphs[0], true));
            customUndirectedGraphsTestSet.TestCases.Add(new FindCycleTestCase(5, null, customUndirectedGraphs[1], false));
            customUndirectedGraphsTestSet.TestCases.Add(new FindCycleTestCase(5, null, customUndirectedGraphs[2], true));
            customUndirectedGraphsTestSet.TestCases.Add(new FindCycleTestCase(5, null, customUndirectedGraphs[3], true));
            customUndirectedGraphsTestSet.TestCases.Add(new FindCycleTestCase(5, null, customUndirectedGraphs[4], true));

            // Tree center
            Graph[] customTrees = new Graph[5];
            customTrees[0] = new AdjacencyMatrixGraph(false, 1);
            customTrees[1] = rgg.TreeGraph(typeof(AdjacencyMatrixGraph), 100, 0.5);
            customTrees[2] = rgg.TreeGraph(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), 100, 1);
            customTrees[3] = rgg.TreeGraph(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 1000, 1);
            customTrees[4] = rgg.TreeGraph(typeof(AdjacencyListsGraph <AVLAdjacencyList>), 10000, 1);

            TestSet customTreeSet = new TestSet();

            customTreeSet.TestCases.Add(new TreeCenterTestCase(5, null, customTrees[0], true, new int[] { 0 }));
            customTreeSet.TestCases.Add(new TreeCenterTestCase(5, null, customTrees[1], false, null));
            customTreeSet.TestCases.Add(new TreeCenterTestCase(5, null, customTrees[2], true, new int[] { 77 }));
            customTreeSet.TestCases.Add(new TreeCenterTestCase(5, null, customTrees[3], true, new int[] { 146, 282 }));
            customTreeSet.TestCases.Add(new TreeCenterTestCase(5, null, customTrees[4], true, new int[] { 6780, 8396 }));



            Console.WriteLine("Custom cycle finding in directed graphs");
            stopwatch.Restart();
            customDirectedGraphsTestSet.PreformTests(verbose: true, checkTimeLimit: false, forceExecution: false);
            stopwatch.Stop();
            timeElapsed[6] = stopwatch.ElapsedMilliseconds;

            Console.WriteLine("Custom cycle finding in undirected graphs");
            stopwatch.Restart();
            customUndirectedGraphsTestSet.PreformTests(verbose: true, checkTimeLimit: false, forceExecution: false);
            stopwatch.Stop();
            timeElapsed[7] = stopwatch.ElapsedMilliseconds;

            Console.WriteLine("Custom tree center");
            stopwatch.Restart();
            customTreeSet.PreformTests(verbose: true, checkTimeLimit: false, forceExecution: false);
            stopwatch.Stop();
            timeElapsed[8] = stopwatch.ElapsedMilliseconds;


            Console.WriteLine("\n\nPerformance metrics for the custom tests");
            for (int i = 6; i < timeElapsed.Length; i++)
            {
                Console.WriteLine("Testset {0}: {1,5} ms", i + 1, timeElapsed[i]);
            }
        }
Ejemplo n.º 15
0
        public override void PrepareTestSets()
        {
            const int testCaseNumber = 9;
            Random    rnd;

            int[][] tabs       = new int[testCaseNumber][];
            int[][] sortedTabs = new int[testCaseNumber][];

            tabs[0] = new int[2] {
                3, -2
            };
            tabs[1] = new int[10] {
                5, 8, -3, 10, 2, 5, 7, -6, 5, 1
            };
            tabs[2] = new int[1] {
                -1
            };
            tabs[3] = new int[0];

            tabs[4] = new int[500];
            for (int i = 0; i < tabs[4].Length; ++i)
            {
                tabs[4][i] = i - 250;
            }

            rnd     = new Random(123);
            tabs[5] = new int[800];
            for (int i = 0; i < tabs[5].Length; ++i)
            {
                tabs[5][i] = rnd.Next(-500, 500);
            }

            rnd     = new Random(125);
            tabs[6] = new int[2000];
            for (int i = 0; i < tabs[6].Length; ++i)
            {
                tabs[6][i] = rnd.Next();
            }

            rnd     = new Random(127);
            tabs[7] = new int[1000];
            for (int i = 0; i < tabs[7].Length; ++i)
            {
                tabs[7][i] = rnd.Next(-10, 10);
            }

            rnd     = new Random(129);
            tabs[8] = new int[1600];
            for (int i = 0; i < tabs[8].Length; ++i)
            {
                tabs[8][i] = rnd.Next(-1000, 1000);
            }

            for (int k = 0; k < testCaseNumber; ++k)
            {
                sortedTabs[k] = (int[])tabs[k].Clone();
                Array.Sort(sortedTabs[k]);
            }

            double[] limits = new double[testCaseNumber] {
                1, 1, 1, 1, 1, 1, 1, 1, 1
            };

            string[] descriptions = new string[testCaseNumber]
            {
                "bardzo prosty test",
                "prosty test",
                "tablica jednoelementowa",
                "tablica pusta",
                "tablica posortowana",
                "dane losowe 1",
                "dane losowe 2",
                "dane losowe 3",
                "dane losowe 4",
            };

            TestSets["LabQuickSortTests"]    = new TestSet(new SortingMethods(), "Lab. - QuickSort");
            TestSets["LabShellSortTests"]    = new TestSet(new SortingMethods(), "Lab. - ShellSort");
            TestSets["LabHeapSortSortTests"] = new TestSet(new SortingMethods(), "Lab. - HeapSort");
            TestSets["LabMergeSortTests"]    = new TestSet(new SortingMethods(), "Lab. - MergeSort");

            for (int k = 0; k < testCaseNumber; ++k)
            {
                TestSets["LabQuickSortTests"].TestCases.Add(new SortingTestCase(limits[k], null, descriptions[k], tabs[k], sortedTabs[k], SortingAlgorithm.QuickSort));
                TestSets["LabShellSortTests"].TestCases.Add(new SortingTestCase(limits[k], null, descriptions[k], tabs[k], sortedTabs[k], SortingAlgorithm.ShellSort));
                TestSets["LabHeapSortSortTests"].TestCases.Add(new SortingTestCase(limits[k], null, descriptions[k], tabs[k], sortedTabs[k], SortingAlgorithm.HeapSort));
                TestSets["LabMergeSortTests"].TestCases.Add(new SortingTestCase(limits[k], null, descriptions[k], tabs[k], sortedTabs[k], SortingAlgorithm.MergeSort));
            }
        }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            TestSet cyclePartitionTests = new TestSet();
            TestSet matchingTests       = new TestSet();

            Graph C4 = new AdjacencyMatrixGraph(false, 4);

            C4.AddEdge(0, 1);
            C4.AddEdge(0, 3);
            C4.AddEdge(2, 1);
            C4.AddEdge(2, 3);
            cyclePartitionTests.TestCases.Add(new CyclePartitionTestCase(5, null, C4));
            matchingTests.TestCases.Add(new PerfectMatchingTestCase(5, null, C4));

            Graph DoubleC4 = new AdjacencyMatrixGraph(false, 8);

            DoubleC4.AddEdge(0, 1);
            DoubleC4.AddEdge(0, 3);
            DoubleC4.AddEdge(2, 1);
            DoubleC4.AddEdge(2, 3);

            DoubleC4.AddEdge(4, 5);
            DoubleC4.AddEdge(4, 7);
            DoubleC4.AddEdge(6, 5);
            DoubleC4.AddEdge(6, 7);

            cyclePartitionTests.TestCases.Add(new CyclePartitionTestCase(5, null, DoubleC4));
            matchingTests.TestCases.Add(new PerfectMatchingTestCase(5, null, DoubleC4));

            Graph matching = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 20);

            for (int i = 0; i < 10; i++)
            {
                matching.AddEdge((3 * i) % 20, (3 * i + 10) % 20);
            }

            matchingTests.TestCases.Add(new PerfectMatchingTestCase(5, null, matching));

            Graph tripleC6 = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 18);

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    tripleC6.AddEdge(6 * i + j, 6 * i + (j + 1) % 6);
                }
            }

            cyclePartitionTests.TestCases.Add(new CyclePartitionTestCase(5, null, tripleC6));
            matchingTests.TestCases.Add(new PerfectMatchingTestCase(5, null, tripleC6));

            Graph C4free = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 54);

            for (int c = 0; c < 3; c++)
            {
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 6; j++)
                    {
                        C4free.AddEdge(18 * c + 6 * i + j, 18 * c + 6 * i + (j + 1) % 6);
                    }
                }
            }
            for (int c = 0; c < 3; c++)
            {
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 6; j += 2)
                    {
                        C4free.AddEdge(18 * c + 6 * i + j, 18 * c + 6 * ((i + 1) % 3) + (j + 1) % 6);
                    }
                }
            }
            for (int c = 0; c < 3; c++)
            {
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 6; j += 2)
                    {
                        C4free.AddEdge(18 * c + 6 * i + j, 18 * ((c + 1) % 3) + 6 * ((i + 1) % 3) + (j + 1) % 6);
                    }
                }
            }

            cyclePartitionTests.TestCases.Add(new CyclePartitionTestCase(5, null, C4free));
            matchingTests.TestCases.Add(new PerfectMatchingTestCase(5, null, C4free));

            cyclePartitionTests.TestCases.Add(new CyclePartitionTestCase(5, null, randomRegularBipartite(100, 10, 13)));
            cyclePartitionTests.TestCases.Add(new CyclePartitionTestCase(5, null, randomRegularBipartite(100, 40, 14)));
            cyclePartitionTests.TestCases.Add(new CyclePartitionTestCase(5, null, randomRegularBipartite(200, 8, 15)));
            cyclePartitionTests.TestCases.Add(new CyclePartitionTestCase(5, null, randomRegularBipartite(100, 16, 16)));


            matchingTests.TestCases.Add(new PerfectMatchingTestCase(5, null, randomRegularBipartite(300, 4, 13)));
            matchingTests.TestCases.Add(new PerfectMatchingTestCase(5, null, randomRegularBipartite(200, 8, 14)));
            matchingTests.TestCases.Add(new PerfectMatchingTestCase(5, null, randomRegularBipartite(200, 16, 15)));
            matchingTests.TestCases.Add(new PerfectMatchingTestCase(5, null, randomRegularBipartite(100, 32, 16)));

            Console.WriteLine("***************************   Cycle partition tests  ***************************");
            cyclePartitionTests.PreformTests(true, false);

            Console.WriteLine("***************************  Perfect matching tests  ***************************");
            matchingTests.PreformTests(true, false);
        }
        public override void PrepareTestSets()
        {
            // Performance Level 1
            int[] threeRelevant = new int[7000];
            for (int i = 0; i < threeRelevant.Length; i++)
            {
                threeRelevant[i] = rand.Next(100000, 500000);
            }
            threeRelevant[10] = 10;
            threeRelevant[threeRelevant.Length / 2]  = 10;
            threeRelevant[threeRelevant.Length - 10] = 20;

            int[] ones = new int[6000];
            for (int i = 0; i < ones.Length; i++)
            {
                ones[i] = 1;
            }

            int[] bigOnes = new int[100000];
            for (int i = 0; i < bigOnes.Length; i++)
            {
                bigOnes[i] = 1;
            }

            int[] bigNumbers = new int[18];
            for (int i = 0; i < bigNumbers.Length; i++)
            {
                bigNumbers[i] = 2000002;
            }
            bigNumbers[1]  = 200000002;
            bigNumbers[3]  = 100000001;
            bigNumbers[16] = 700000007;
            bigNumbers[17] = 300000003;

            // Performance Level 2
            int[] relevantAtBeginning = new int[100000];
            for (int i = 5; i < relevantAtBeginning.Length; i++)
            {
                relevantAtBeginning[i] = rand.Next(61, 1000);
            }
            relevantAtBeginning[0] = 40;
            relevantAtBeginning[1] = 20;
            relevantAtBeginning[2] = 60;
            relevantAtBeginning[3] = 30;
            relevantAtBeginning[4] = 30;

            int[] twoPower = new int[9 * 2 - 1];
            int   actNum   = 1;

            for (int i = 0; i < twoPower.Length; i += 2)
            {
                twoPower[twoPower.Length - 1 - i] = actNum;
                if (i + 1 < twoPower.Length)
                {
                    twoPower[twoPower.Length - 2 - i] = actNum;
                }
                actNum <<= 1;
            }


            TestSets["Lvl1"] = new TestSet(new WorkManager(), "Workers with blocks of equal sum");
            TestSets["Lvl1"].TestCases.Add(new DivideWorkersWorkTestCase(1, null, "", new int[] { 2 }, 2, false));
            TestSets["Lvl1"].TestCases.Add(new DivideWorkersWorkTestCase(1, null, "", new int[] { 1, 1 }, 1, true));
            TestSets["Lvl1"].TestCases.Add(new DivideWorkersWorkTestCase(1, null, "", new int[] { 1, 2, 2, 2, 7, 1, 3, 2 }, 3, true));
            TestSets["Lvl1"].TestCases.Add(new DivideWorkersWorkTestCase(1, null, "", new int[] { 2, 4, 8, 6, 7 }, 2, false));
            TestSets["Lvl1"].TestCases.Add(new DivideWorkersWorkTestCase(1, null, "", new int[] { 2, 4, 8, 6, 7 }, 10, true));
            TestSets["Lvl1"].TestCases.Add(new DivideWorkersWorkTestCase(1, null, "", new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }, 18, true));
            TestSets["Lvl1"].TestCases.Add(new DivideWorkersWorkTestCase(1, null, "", new int[] { 1, 2, 3, 4, 5, 6 }, 11, false));
            TestSets["Lvl1"].TestCases.Add(new DivideWorkersWorkTestCase(1, null, "", new int[] { 1, 1, 1, 1, 1, 1 }, 3, true));
            TestSets["Lvl1"].TestCases.Add(new DivideWorkersWorkTestCase(1, null, "", new int[] { 1, 1, 1, 1, 1, 1, 1 }, 4, false));
            TestSets["Lvl1"].TestCases.Add(new DivideWorkersWorkTestCase(1, null, "", new int[] { 5, 6, 2, 7 }, 10, false));

            TestSets["Lvl1perf"] = new TestSet(new WorkManager(), "Workers with blocks of equal sum - Performance tests");
            TestSets["Lvl1perf"].TestCases.Add(new DivideWorkersWorkTestCase(1, null, "3 numbers below expected sum", threeRelevant, 20, true));
            TestSets["Lvl1perf"].TestCases.Add(new DivideWorkersWorkTestCase(1, null, "Array of ones", ones, ones.Length / 2, true));
            TestSets["Lvl1perf"].TestCases.Add(new DivideWorkersWorkTestCase(35, null, "", bigNumbers, 300000003, true));
            TestSets["Lvl1perf"].TestCases.Add(new DivideWorkersWorkTestCase(30, null, "", GenerateRandomArray(660, 12345671), 4520, true));
            TestSets["Lvl1perf"].TestCases.Add(new DivideWorkersWorkTestCase(30, null, "", GenerateRandomArray(2276, 345679), 1303, false));

            TestSets["Lvl2"] = new TestSet(new WorkManager(), "Workers with closest block count");
            TestSets["Lvl2"].TestCases.Add(new DivideWorkersWorkWithEqualSumTestCase(1, null, "", new int[] { 2, 1, 8, 1, 2, 2 }, 2, 0, true));
            TestSets["Lvl2"].TestCases.Add(new DivideWorkersWorkWithEqualSumTestCase(1, null, "", new int[] { 2, 1, 8, 1, 2, 2 }, 8, 4, true));
            TestSets["Lvl2"].TestCases.Add(new DivideWorkersWorkWithEqualSumTestCase(1, null, "", new int[] { 4, 3, 1, 1, 1, 1, 1, 1, 1, 1 }, 4, 0, true));
            TestSets["Lvl2"].TestCases.Add(new DivideWorkersWorkWithEqualSumTestCase(1, null, "", new int[] { 1, 3, 2, 4 }, 4, 1, true));
            TestSets["Lvl2"].TestCases.Add(new DivideWorkersWorkWithEqualSumTestCase(1, null, "", new int[] { 1, 3, 2, 4 }, 5, 0, true));
            TestSets["Lvl2"].TestCases.Add(new DivideWorkersWorkWithEqualSumTestCase(1, null, "", new int[] { 1, 2, 3 }, 4, 0, false));

            TestSets["Lvl2perf"] = new TestSet(new WorkManager(), "Workers with closest block count - Performance tests");
            TestSets["Lvl2perf"].TestCases.Add(new DivideWorkersWorkWithEqualSumTestCase(1, null, "Answer in 5 first elements of array", relevantAtBeginning, 60, 0, true));
            TestSets["Lvl2perf"].TestCases.Add(new DivideWorkersWorkWithEqualSumTestCase(25, null, "...16 16 4 4 2 2 1 1", twoPower, twoPower[0], 1, true));
            TestSets["Lvl2perf"].TestCases.Add(new DivideWorkersWorkWithEqualSumTestCase(1, null, "Array of ones, expected sum not achievable", bigOnes, bigOnes.Length / 2 + 1, 0, false));
            TestSets["Lvl2perf"].TestCases.Add(new DivideWorkersWorkWithEqualSumTestCase(100, null, "", GenerateRandomArray(122, 12345673), 15434, 0, false));
            TestSets["Lvl2perf"].TestCases.Add(new DivideWorkersWorkWithEqualSumTestCase(60, null, "", GenerateRandomArray(900, 12345674, 100), 1555, 0, true));
        }
Ejemplo n.º 18
0
        static void Main(string[] args)
        {
            TestSet cyclePartitionTests = new TestSet();
            TestSet matchingTests       = new TestSet();

            Graph C4 = new AdjacencyMatrixGraph(false, 4);

            C4.AddEdge(0, 1);
            C4.AddEdge(0, 3);
            C4.AddEdge(2, 1);
            C4.AddEdge(2, 3);
            cyclePartitionTests.TestCases.Add(new CyclePartitionTestCase(5, null, C4));
            matchingTests.TestCases.Add(new PerfectMatchingTestCase(5, null, C4));

            Graph DoubleC4 = new AdjacencyMatrixGraph(false, 8);

            DoubleC4.AddEdge(0, 1);
            DoubleC4.AddEdge(0, 3);
            DoubleC4.AddEdge(2, 1);
            DoubleC4.AddEdge(2, 3);

            DoubleC4.AddEdge(4, 5);
            DoubleC4.AddEdge(4, 7);
            DoubleC4.AddEdge(6, 5);
            DoubleC4.AddEdge(6, 7);

            cyclePartitionTests.TestCases.Add(new CyclePartitionTestCase(5, null, DoubleC4));
            matchingTests.TestCases.Add(new PerfectMatchingTestCase(5, null, DoubleC4));

            Graph matching = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 20);

            for (int i = 0; i < 10; i++)
            {
                matching.AddEdge((3 * i) % 20, (3 * i + 10) % 20);
            }

            matchingTests.TestCases.Add(new PerfectMatchingTestCase(5, null, matching));

            Graph tripleC6 = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 18);

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    tripleC6.AddEdge(6 * i + j, 6 * i + (j + 1) % 6);
                }
            }

            cyclePartitionTests.TestCases.Add(new CyclePartitionTestCase(5, null, tripleC6));
            matchingTests.TestCases.Add(new PerfectMatchingTestCase(5, null, tripleC6));

            Graph C4free = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 54);

            for (int c = 0; c < 3; c++)
            {
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 6; j++)
                    {
                        C4free.AddEdge(18 * c + 6 * i + j, 18 * c + 6 * i + (j + 1) % 6);
                    }
                }
            }
            for (int c = 0; c < 3; c++)
            {
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 6; j += 2)
                    {
                        C4free.AddEdge(18 * c + 6 * i + j, 18 * c + 6 * ((i + 1) % 3) + (j + 1) % 6);
                    }
                }
            }
            for (int c = 0; c < 3; c++)
            {
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 6; j += 2)
                    {
                        C4free.AddEdge(18 * c + 6 * i + j, 18 * ((c + 1) % 3) + 6 * ((i + 1) % 3) + (j + 1) % 6);
                    }
                }
            }

            cyclePartitionTests.TestCases.Add(new CyclePartitionTestCase(5, null, C4free));
            matchingTests.TestCases.Add(new PerfectMatchingTestCase(5, null, C4free));

            cyclePartitionTests.TestCases.Add(new CyclePartitionTestCase(5, null, randomRegularBipartite(100, 10, 13)));
            cyclePartitionTests.TestCases.Add(new CyclePartitionTestCase(5, null, randomRegularBipartite(100, 40, 14)));
            cyclePartitionTests.TestCases.Add(new CyclePartitionTestCase(5, null, randomRegularBipartite(200, 8, 15)));
            cyclePartitionTests.TestCases.Add(new CyclePartitionTestCase(5, null, randomRegularBipartite(100, 16, 16)));


            matchingTests.TestCases.Add(new PerfectMatchingTestCase(5, null, randomRegularBipartite(300, 4, 13)));
            matchingTests.TestCases.Add(new PerfectMatchingTestCase(5, null, randomRegularBipartite(200, 8, 14)));
            matchingTests.TestCases.Add(new PerfectMatchingTestCase(5, null, randomRegularBipartite(200, 16, 15)));
            matchingTests.TestCases.Add(new PerfectMatchingTestCase(5, null, randomRegularBipartite(100, 32, 16)));

            Console.WriteLine("***************************   Cycle partition tests  ***************************");
            cyclePartitionTests.PreformTests(true, false);

            Console.WriteLine("***************************  Perfect matching tests  ***************************");
            matchingTests.PreformTests(true, false);



            Console.WriteLine("**************************   Custom tests *************************");
            Console.WriteLine("Timing a boilerplate task");
            long boilerplateTaskTimeElapsed = PerformBoilerplateTask();

            Console.WriteLine("Boilerplate task done. Results will be shown below");



            int     baseSeed             = 15; // will be incremented for every test
            int     customTestSetSize    = 15;
            TestSet customPartitionTests = new TestSet();
            TestSet customMatchingTests  = new TestSet();

            Console.WriteLine("Generating test cases, this may take a while");
            for (int i = 0; i < customTestSetSize; i++)
            {
                Random r        = new Random(baseSeed);
                int    vertices = r.Next(100, 400);
                int    degree   = 2 * r.Next(2, 40);
                customPartitionTests.TestCases.Add(new CyclePartitionTestCase(5, null, randomRegularBipartite(vertices, degree, baseSeed++)));
            }

            for (int i = 0; i < customTestSetSize; i++)
            {
                Random r        = new Random(baseSeed);
                int    vertices = r.Next(100, 400);
                int    degree   = (int)Math.Pow(2, r.Next(2, 7));
                customMatchingTests.TestCases.Add(new PerfectMatchingTestCase(5, null, randomRegularBipartite(vertices, degree, baseSeed++)));
            }

            var stopwatch = System.Diagnostics.Stopwatch.StartNew();

            // Preform tests... (Why do they have a typo in the test library? Even after a month)
            customPartitionTests.PreformTests(true, false);
            stopwatch.Stop();

            long partitionTestsTimeElapsed = stopwatch.ElapsedMilliseconds;

            stopwatch.Restart();
            customMatchingTests.PreformTests(true, false);
            stopwatch.Stop();
            long matchingTestsTimeElapsed = stopwatch.ElapsedMilliseconds;

            Console.WriteLine("Custom tests performance metrics");
            Console.WriteLine("Boilerplate task: {0,5} ms", boilerplateTaskTimeElapsed);
            Console.WriteLine("Partition tests: {0,5} ms        ({1:F3} times the boilerplate time)", partitionTestsTimeElapsed, (double)partitionTestsTimeElapsed / boilerplateTaskTimeElapsed);
            Console.WriteLine("Matching tests:  {0,5} ms        ({1:F3} times the boilerplate time)", matchingTestsTimeElapsed, (double)matchingTestsTimeElapsed / boilerplateTaskTimeElapsed);
        }
Ejemplo n.º 19
0
        public override void PrepareTestSets()
        {
            var rgg = new RandomGraphGenerator(2018);
            int n   = 14;
            int n1  = 8;

            Graph[]  graphs       = new Graph[n];
            string[] descriptions = new string[n];

            // do czesci 1
            int[]  sizes        = new int[n];
            bool[] bool_results = new bool[n];
            int[]  limits1      = new int[n];
            // do czesci 2
            double[] maximal_results = new double[n];
            int[]    limits2         = new int[n];


            //przyklady z zajec
            //sciezka P10
            graphs[0] = new AdjacencyMatrixGraph(false, 10);
            graphs[0].AddEdge(0, 1, 5);
            graphs[0].AddEdge(1, 2, 4);
            graphs[0].AddEdge(2, 3, 3);
            graphs[0].AddEdge(3, 4, 2);
            graphs[0].AddEdge(4, 5, 3);
            graphs[0].AddEdge(5, 6, 1);
            graphs[0].AddEdge(6, 7, 6);
            graphs[0].AddEdge(7, 8, 2);
            graphs[0].AddEdge(8, 9, 1);
            descriptions[0]    = "Sciezka P10";
            sizes[0]           = 3;
            bool_results[0]    = true;
            maximal_results[0] = 13;

            //cykl C5
            graphs[1] = new AdjacencyMatrixGraph(false, 5);
            graphs[1].AddEdge(0, 1, 1);
            graphs[1].AddEdge(1, 2, 2);
            graphs[1].AddEdge(2, 3, 3);
            graphs[1].AddEdge(3, 4, 4);
            graphs[1].AddEdge(4, 0, 0);
            descriptions[1]    = "Cykl C5";
            sizes[1]           = 2;
            bool_results[1]    = false;
            maximal_results[1] = 4;

            //cykl C10
            graphs[2] = new AdjacencyMatrixGraph(false, 10);
            graphs[2].AddEdge(0, 1, 1.08);
            graphs[2].AddEdge(1, 2, 6.52);
            graphs[2].AddEdge(2, 3, 3);
            graphs[2].AddEdge(3, 4, 4);
            graphs[2].AddEdge(4, 5, 0);
            graphs[2].AddEdge(5, 6, 1.99);
            graphs[2].AddEdge(6, 7, 2.56);
            graphs[2].AddEdge(7, 8, 3.9);
            graphs[2].AddEdge(8, 9, 4.12);
            graphs[2].AddEdge(9, 0, 0);
            descriptions[2]    = "Cykl C10";
            sizes[2]           = 2;
            bool_results[2]    = true;
            maximal_results[2] = 12.63;

            //klika K5
            graphs[3]          = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 5, 1, -9, -1);
            descriptions[3]    = "Klika K5";
            sizes[3]           = 1;
            bool_results[3]    = true;
            maximal_results[3] = 0;

            //prawie klika K10 (bez kilku krawedzi)
            graphs[4]       = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 10, 1, -9, 99);
            descriptions[4] = "Klika K10 bez kilku krawedzi";
            graphs[4].DelEdge(0, 1);
            graphs[4].DelEdge(0, 2);
            graphs[4].DelEdge(0, 3);
            graphs[4].DelEdge(4, 5);
            graphs[4].DelEdge(4, 6);
            graphs[4].DelEdge(4, 7);
            sizes[4]           = 1;
            bool_results[4]    = true;
            maximal_results[4] = 98;

            //jakis sobie graf
            graphs[5] = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 9);
            graphs[5].AddEdge(0, 1, 0.33);
            graphs[5].AddEdge(1, 3, 1.5);
            graphs[5].AddEdge(1, 6, 10.1);
            graphs[5].AddEdge(2, 3, 1);
            graphs[5].AddEdge(2, 4, 1);
            graphs[5].AddEdge(2, 5, 1);
            graphs[5].AddEdge(2, 8, 3);
            graphs[5].AddEdge(3, 7, 3.33);
            graphs[5].AddEdge(4, 5, 3.7);
            graphs[5].AddEdge(7, 8, 0.7);
            descriptions[5]    = "Pewien graf o 9 wierzcholkach";
            sizes[5]           = 3;
            bool_results[5]    = true;
            maximal_results[5] = 14.5;

            //graf dwudzielny
            graphs[6] = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 10);
            graphs[6].AddEdge(0, 5, 3);
            graphs[6].AddEdge(0, 6, 3);
            graphs[6].AddEdge(1, 7, 4);
            graphs[6].AddEdge(1, 8, 4);
            graphs[6].AddEdge(2, 6, 1);
            graphs[6].AddEdge(2, 8, 1);
            graphs[6].AddEdge(2, 9, 1);
            graphs[6].AddEdge(3, 9, 2);
            graphs[6].AddEdge(4, 9, 3);
            descriptions[6]    = "Graf dwudzielny o 10 wierzcholkach";
            sizes[6]           = 3;
            bool_results[6]    = true;
            maximal_results[6] = 10;

            //gwiazda
            int g7vc = 200;

            graphs[7] = new AdjacencyListsGraph <AVLAdjacencyList>(false, g7vc);
            for (int i = 1; i < g7vc; ++i)
            {
                graphs[7].AddEdge(0, i, i);
            }
            descriptions[7]    = "Nieskierowana gwiazda";
            sizes[7]           = 2;
            bool_results[7]    = false;
            maximal_results[7] = 199;


            //Wieksze testy, z wydajnoscia
            //gesty duzy graf losowy nr 1
            int g8vc = 250;

            rgg.SetSeed(123451);
            graphs[8]          = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), g8vc, 0.9, -9, 9);
            descriptions[8]    = "Gesty graf losowy nr 1";
            sizes[8]           = 3;
            bool_results[8]    = true;
            maximal_results[8] = 21;
            limits1[8]         = 3;
            limits2[8]         = 60;

            //gesty duzy graf losowy nr 2
            int g9vc = 200;

            rgg.SetSeed(123452);
            graphs[9]          = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), g9vc, 0.95, -9, 99);
            descriptions[9]    = "Gesty graf losowy nr 2";
            sizes[9]           = 3;
            bool_results[9]    = false;
            maximal_results[9] = 194;
            limits1[9]         = 12;
            limits2[9]         = 12;

            //rzadki graf losowy nr 1
            int g10vc = 45;

            rgg.SetSeed(123453);
            graphs[10]          = rgg.UndirectedGraph(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), g10vc, 0.1, -9, 99);
            descriptions[10]    = "Rzadki graf losowy nr 1";
            sizes[10]           = 5;
            bool_results[10]    = true;
            maximal_results[10] = 743;
            limits1[10]         = 1;
            limits2[10]         = 65;

            //rzadki graf losowy nr 2
            int g11vc = 45;

            rgg.SetSeed(123454);
            graphs[11]          = rgg.UndirectedGraph(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), g11vc, 0.04, -9, 99);
            descriptions[11]    = "Rzadki graf losowy nr 2";
            sizes[11]           = 7;
            bool_results[11]    = true;
            maximal_results[11] = 675;
            limits1[11]         = 1;
            limits2[11]         = 12;

            //cykl C35
            int g12vc = 35;

            graphs[12] = new AdjacencyListsGraph <HashTableAdjacencyList>(false, g12vc);
            for (int i = 1; i < g12vc; ++i)
            {
                graphs[12].AddEdge(i - 1, i, i);
            }
            graphs[12].AddEdge(g12vc - 1, 0, 1);
            descriptions[12]    = "Cykl C35";
            sizes[12]           = 11;
            bool_results[12]    = true;
            maximal_results[12] = 209;
            limits1[12]         = 1;
            limits2[12]         = 22;

            //duza klika K200
            int g13vc = 200;

            rgg.SetSeed(123455);
            graphs[13]          = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), g13vc, 1, -9, 99);
            descriptions[13]    = "Klika K200";
            sizes[13]           = 100;
            bool_results[13]    = false;
            maximal_results[13] = 99;
            limits1[13]         = 10;
            limits2[13]         = 10;

            TestSets["LabInducedMatchingTests"]                   = new TestSet(new Lab09(), "Part 1 - induced matching with given size [1.5]");
            TestSets["LabMaximalInducedMatchingTests"]            = new TestSet(new Lab09(), "Part 2 - maximal induced matching [1.5]");
            TestSets["LabInducedMatchingPerformanceTests"]        = new TestSet(new Lab09(), "Part 1 - induced matching with given size - performance tests[0.5]");
            TestSets["LabMaximalInducedMatchingPerformanceTests"] = new TestSet(new Lab09(), "Part 2 - maximal induced matching - performance tests[0.5]");

            for (int i = 0; i < n; ++i)
            {
                if (i < n1)
                {
                    TestSets["LabInducedMatchingTests"].TestCases.Add(new InducedMatchingTestCase(1, null, descriptions[i], graphs[i], sizes[i], bool_results[i]));
                    TestSets["LabMaximalInducedMatchingTests"].TestCases.Add(new MaximalInducedMatchingTestCase(1, null, descriptions[i], graphs[i], maximal_results[i]));
                }
                else
                {
                    TestSets["LabInducedMatchingPerformanceTests"].TestCases.Add(new InducedMatchingTestCase(limits1[i], null, descriptions[i], graphs[i], sizes[i], bool_results[i]));
                    TestSets["LabMaximalInducedMatchingPerformanceTests"].TestCases.Add(new MaximalInducedMatchingTestCase(limits2[i], null, descriptions[i], graphs[i], maximal_results[i]));
                }
            }
        }
Ejemplo n.º 20
0
        public override void PrepareTestSets()
        {
            string m1 = "XSOOOOO\n"
                        + "XXXXXOX\n"
                        + "OOOOOOO\n"
                        + "OXXXXXX\n"
                        + "OOOEXOO";

            string m2 = "SOOOOXX\n"
                        + "OXXOXXX\n"
                        + "OXXOXOO\n"
                        + "OOOOXXO\n"
                        + "OXXXOOE";

            string m3 = "SE";

            string m4 = "OEOOOOO\n"
                        + "OOOOOOO\n"
                        + "OOOOOOO\n"
                        + "OOOOOSO\n"
                        + "OOOOOOO";

            string m5 = "OOOOOOOOOOOOOOOOOOOOO\n"
                        + "OXXXXXXXXXXXXXXXXXXXO\n"
                        + "OXOOOOOOOOOOOOOOOOOXO\n"
                        + "OXOXXXXXXXXXXXXXXXOXO\n"
                        + "OXOXOOOOOOOOOOOOOXOXO\n"
                        + "OXOXOXXXXXXXXXXXOXOXO\n"
                        + "OXOXOXEOOOOOOOOXOXOXO\n"
                        + "OXOXOXXXXXXXXXOXOXOXO\n"
                        + "OXOXOOOOOOOOOOOXOXOXO\n"
                        + "OXOXXXXXXXXXXXXXOXOXO\n"
                        + "OXOOOOOOOOOOOOOOOXOXO\n"
                        + "OXXXXXXXXXXXXXXXXXOXO\n"
                        + "OOOOOOOOOOOOOOOOOOOXS";

            string m6 = "OOOOOOOOOOOOOOOOOOOOS\n"
                        + "OXXXXXXXXXXXXXXXXXXXX\n"
                        + "OOOOOOOOOOOOOOOOOOOOO\n"
                        + "XXXXXXXXXXXXXXXXXXXXO\n"
                        + "OOOOOOOOOOOOOOOOOOOOO\n"
                        + "OXXXXXXXXXXXXXXXXXXXX\n"
                        + "OOOOOOOOOOOOOOOOOOOOO\n"
                        + "XXXXXXXXXXXXXXXXXXXXO\n"
                        + "OOOOOOOOOOOOOOOOOOOOO\n"
                        + "OXXXXXXXXXXXXXXXXXXXX\n"
                        + "OOOOOOOOOOOOOOOOOOOOE\n"
                        + "XXXXXXXXXXXXXXXXXXXXO";

            string m7 = "XOOOOXXXOOOOXXXEOOOX\n"
                        + "XOXXOOOOOXXOXXXOXXOX\n"
                        + "XOXXOXXXOXXOOOOOXXOX\n"
                        + "XOOOOXXXOOOOXXXOOOOO\n"
                        + "XXXXXXXXXXXXXXXXXXXO\n"
                        + "XXXXXXXXXXOXXXXXXXXO\n"
                        + "XOOOOXXXOOOOXXXOOOOO\n"
                        + "XOXXOOOOOXXOXXXOXXOX\n"
                        + "XOXXOXXXOXXOOOOOXXOX\n"
                        + "XOSOOXXXOOOOXXXOOOOX";

            //losowy duży test
            Random        rand = new Random(777);
            StringBuilder m8SB = new StringBuilder();
            int           n    = 200;

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (i == 1 && j == 1)
                    {
                        m8SB.Append('S');
                    }
                    else if (i == n - 2 && j == n - 2)
                    {
                        m8SB.Append('E');
                    }
                    else if (rand.NextDouble() < 0.4)
                    {
                        m8SB.Append('X');
                    }
                    else
                    {
                        m8SB.Append('O');
                    }
                }
                m8SB.Append('\n');
            }
            m8SB.Remove(m8SB.Length - 1, 1);

            string m8 = m8SB.ToString();

            string[] mazes = new string[] { m1, m2, m3, m4, m5, m6, m7, m8 };

            //--- Wersja I ---
            TestSets["v1Tests"] = new TestSet(new Maze(), "Wersja I", null, false);
            int[] v1ExpectedValues = new int[] { 16, -1, 1, 7, 152, 130, 34, -1 };
            for (int i = 0; i < mazes.Length; i++)
            {
                TestSets["v1Tests"].TestCases.Add(new FindShortestPathTestCase(20, null, "", mazeStringToCharArray(mazes[i]), false, 0, v1ExpectedValues[i], checkPath));
            }

            //--- Wersja II ---
            TestSets["v2Tests"] = new TestSet(new Maze(), "Wersja II", null, false);
            int[] v2ExpectedValues = new int[] { 10, 13, 1, 7, 29, 22, 23, 488 };
            int[] v2tValues        = new int[] { 3, 4, 5, 3, 4, 5, 2, 10, 3 };
            for (int i = 0; i < mazes.Length; i++)
            {
                TestSets["v2Tests"].TestCases.Add(new FindShortestPathTestCase(20, null, "", mazeStringToCharArray(mazes[i]), true, v2tValues[i], v2ExpectedValues[i], checkPath));
            }

            //--- Wersja III ---
            TestSets["v3Tests"] = new TestSet(new Maze(), "Wersja III", null, false);
            int[] v3ExpectedValues = new int[] { 10, 12, 1, 7, 96, 94, 27, -1 };
            int[] v3tValues        = new int[] { 3, 3, 4, 4, 5, 5, 6, 6, 8 };
            for (int i = 0; i < mazes.Length; i++)
            {
                TestSets["v3Tests"].TestCases.Add(new FindShortestPathWithKDynamites(20, null, "", mazeStringToCharArray(mazes[i]), 1, v3tValues[i], v3ExpectedValues[i], checkPath));
            }

            //--- Wersja IV ---
            TestSets["v4Tests"] = new TestSet(new Maze(), "Wersja IV", null, false);
            int[] v4ExpectedValues = new int[] { 12, -1, 1, 7, 56, 52, 34, 440 };
            int[] v4tValues        = new int[] { 5, 5, 3, 3, 5, 2, 3, 4 };
            int[] dynamites        = new int[] { 2, 0, 2, 5, 2, 2, 0, 8 };
            for (int i = 0; i < mazes.Length; i++)
            {
                TestSets["v4Tests"].TestCases.Add(new FindShortestPathWithKDynamites(20, null, "", mazeStringToCharArray(mazes[i]), dynamites[i], v4tValues[i], v4ExpectedValues[i], checkPath));
            }
        }
Ejemplo n.º 21
0
        public override void PrepareTestSets()
        {
            TestSets["LabSimpleListTestsAdd"]     = new TestSet(new OperationExecutor(), "Lab. SimpleList Tests - Add (0.5p)");
            TestSets["LabSimpleListTestsAll"]     = new TestSet(new OperationExecutor(), "Lab. SimpleList Tests - All (0.5p)");
            TestSets["LabSortedListTestsAdd"]     = new TestSet(new OperationExecutor(), "Lab. SortedList Tests - Add (1.0p)");
            TestSets["LabSortedListTestsAll"]     = new TestSet(new OperationExecutor(), "Lab. SortedList Tests - All (0.5p)");
            TestSets["LabMoveToHeadListTestsAdd"] = new TestSet(new OperationExecutor(), "Lab. MoveToHeadList Tests - Add (0.5p)");
            TestSets["LabMoveToHeadListTestsAll"] = new TestSet(new OperationExecutor(), "Lab. MoveToHeadList Tests - All (1.0p)");

            {
                int             n      = 3;
                OperationInfo[] oper   = new OperationInfo[2 * n + 1];
                int[]           final1 = new int[2 * n + 1];
                int[]           final2 = new int[2 * n + 1];
                int[]           final3 = new int[2 * n + 1];
                for (int i = -n; i <= n; ++i)
                {
                    oper[i + n].oper   = 'a';
                    oper[i + n].val    = i;
                    oper[i + n].expRes = true;
                    final1[i + n]      = final2[i + n] = i;
                    final3[-i + n]     = i;
                }
                TestSets["LabSimpleListTestsAdd"].TestCases.Add(new DictionaryTestCase(1, null, "tylko dodawanie - elementy posortowane", new SimpleList(), oper, final1));
                TestSets["LabSortedListTestsAdd"].TestCases.Add(new DictionaryTestCase(1, null, "tylko dodawanie - elementy posortowane", new SortedList(), oper, final2));
                TestSets["LabMoveToHeadListTestsAdd"].TestCases.Add(new DictionaryTestCase(1, null, "tylko dodawanie - elementy posortowane", new MoveToHeadList(), oper, final3));
            }

            {
                int             n      = 3;
                OperationInfo[] oper   = new OperationInfo[2 * n + 1];
                int[]           final1 = new int[2 * n + 1];
                int[]           final2 = new int[2 * n + 1];
                int[]           final3 = new int[2 * n + 1];
                for (int i = -n; i <= n; ++i)
                {
                    oper[i + n].oper   = 'a';
                    oper[i + n].val    = -i;
                    oper[i + n].expRes = true;
                    final1[i + n]      = -i;
                    final2[i + n]      = i;
                    final3[-i + n]     = -i;
                }
                TestSets["LabSimpleListTestsAdd"].TestCases.Add(new DictionaryTestCase(1, null, "tylko dodawanie - elementy odwrotnie posortowane", new SimpleList(), oper, final1));
                TestSets["LabSortedListTestsAdd"].TestCases.Add(new DictionaryTestCase(1, null, "tylko dodawanie - elementy odwrotnie posortowane", new SortedList(), oper, final2));
                TestSets["LabMoveToHeadListTestsAdd"].TestCases.Add(new DictionaryTestCase(1, null, "tylko dodawanie - elementy odwrotnie posortowane", new MoveToHeadList(), oper, final3));
            }

            {
                OperationInfo[] oper = new OperationInfo[] {
                    new OperationInfo('a', 2, true),
                    new OperationInfo('a', 5, true),
                    new OperationInfo('a', 3, true),
                    new OperationInfo('a', 3, false),
                    new OperationInfo('a', 2, false),
                    new OperationInfo('a', 7, true),
                    new OperationInfo('a', 5, false),
                    new OperationInfo('a', -1, true),
                };
                int[] final1 = new int[] { 2, 5, 3, 7, -1 };
                int[] final2 = new int[] { -1, 2, 3, 5, 7 };
                int[] final3 = new int[] { -1, 5, 7, 2, 3 };
                TestSets["LabSimpleListTestsAdd"].TestCases.Add(new DictionaryTestCase(1, null, "tylko dodawanie - z powtorzeniami", new SimpleList(), oper, final1));
                TestSets["LabSortedListTestsAdd"].TestCases.Add(new DictionaryTestCase(1, null, "tylko dodawanie - z powtorzeniami", new SortedList(), oper, final2));
                TestSets["LabMoveToHeadListTestsAdd"].TestCases.Add(new DictionaryTestCase(1, null, "tylko dodawanie - z powtorzeniami", new MoveToHeadList(), oper, final3));
            }

            {
                OperationInfo[] oper = new OperationInfo[] {
                    new OperationInfo('s', 2, false),  //  0
                    new OperationInfo('a', 2, true),   //  1
                    new OperationInfo('s', 2, true),   //  2
                    new OperationInfo('s', 6, false),  //  3
                    new OperationInfo('a', 5, true),   //  4
                    new OperationInfo('s', -3, false), //  5
                    new OperationInfo('s', 6, false),  //  6
                    new OperationInfo('a', 3, true),   //  7
                    new OperationInfo('a', 3, false),  //  8
                    new OperationInfo('a', 2, false),  //  9
                    new OperationInfo('a', 7, true),   // 10
                    new OperationInfo('s', 5, true),   // 11
                    new OperationInfo('a', -1, true),  // 12
                    new OperationInfo('s', 3, true),   // 13
                    new OperationInfo('s', 5, true),   // 14
                };
                int[] final1 = new int[] { 2, 5, 3, 7, -1 };
                int[] final2 = new int[] { -1, 2, 3, 5, 7 };
                int[] final3 = new int[] { 5, 3, -1, 7, 2 };
                TestSets["LabSimpleListTestsAll"].TestCases.Add(new DictionaryTestCase(1, null, "dodawanie i wyszukiwanie", new SimpleList(), oper, final1));
                TestSets["LabSortedListTestsAll"].TestCases.Add(new DictionaryTestCase(1, null, "dodawanie i wyszukiwanie", new SortedList(), oper, final2));
                TestSets["LabMoveToHeadListTestsAll"].TestCases.Add(new DictionaryTestCase(1, null, "dodawanie i wyszukiwanie", new MoveToHeadList(), oper, final3));
            }

            {
                OperationInfo[] oper = new OperationInfo[] {
                    new OperationInfo('d', 2, false),  //  0
                    new OperationInfo('a', 2, true),   //  1
                    new OperationInfo('d', 2, true),   //  2
                    new OperationInfo('a', 2, true),   //  3
                    new OperationInfo('d', 6, false),  //  4
                    new OperationInfo('a', 5, true),   //  5
                    new OperationInfo('d', -3, false), //  6
                    new OperationInfo('d', 6, false),  //  7
                    new OperationInfo('a', 6, true),   //  8
                    new OperationInfo('a', 3, true),   //  9
                    new OperationInfo('a', 3, false),  // 10
                    new OperationInfo('a', 2, false),  // 11
                    new OperationInfo('a', 7, true),   // 12
                    new OperationInfo('d', 5, true),   // 13
                    new OperationInfo('a', -1, true),  // 14
                    new OperationInfo('d', 7, true),   // 15
                    new OperationInfo('d', -1, true),  // 16
                    new OperationInfo('d', 2, true),   // 17
                };
                int[] final1 = new int[] { 6, 3 };
                int[] final2 = new int[] { 3, 6 };
                int[] final3 = new int[] { 3, 6 };
                TestSets["LabSimpleListTestsAll"].TestCases.Add(new DictionaryTestCase(1, null, "dodawanie i usuwanie", new SimpleList(), oper, final1));
                TestSets["LabSortedListTestsAll"].TestCases.Add(new DictionaryTestCase(1, null, "dodawanie i usuwanie", new SortedList(), oper, final2));
                TestSets["LabMoveToHeadListTestsAll"].TestCases.Add(new DictionaryTestCase(1, null, "dodawanie i usuwanie", new MoveToHeadList(), oper, final3));
            }
        }
        public override void PrepareTestSets()
        {
            LZ77 solver = new LZ77();

            string DecodingTests = "DecodingTestsLab";

            TestSets[DecodingTests] = new TestSet(solver, "Decoding correctness tests (Lab)");
            TestSets[DecodingTests].TestCases.Add(new DecodingTestCase(1, "Empty list", "", new List <EncodingTriple>()));
            List <EncodingTriple> aababac = new List <EncodingTriple>(new EncodingTriple[] { new EncodingTriple(0, 0, 'a'), new EncodingTriple(0, 1, 'b'), new EncodingTriple(1, 3, 'c') });

            TestSets[DecodingTests].TestCases.Add(new DecodingTestCase(1, "aababac", "aababac", aababac));
            TestSets[DecodingTests].TestCases.Add(new DecodingTestCase(1, "abacaba", makeZimin(3), makeZiminEncoded(3)));
            TestSets[DecodingTests].TestCases.Add(new DecodingTestCase(1, "abcdef", "abcdef", makeSillyEncoding("abcdef")));
            List <EncodingTriple> aaaabaaabaacacacacb = new List <EncodingTriple>();

            aaaabaaabaacacacacb.Add(new EncodingTriple(0, 0, 'a'));
            aaaabaaabaacacacacb.Add(new EncodingTriple(0, 3, 'b'));
            aaaabaaabaacacacacb.Add(new EncodingTriple(3, 6, 'c'));
            aaaabaaabaacacacacb.Add(new EncodingTriple(1, 6, 'b'));
            TestSets[DecodingTests].TestCases.Add(new DecodingTestCase(1, "aaaabaaabaacacacacb", "aaaabaaabaacacacacb", aaaabaaabaacacacacb));
            TestSets[DecodingTests].TestCases.Add(new DecodingTestCase(1, "Random 1", makeRandomLowEntropy(400, 2, 3, 5, 13), makeRandomLowEntropyEncoded(400, 2, 3, 5, 13)));
            TestSets[DecodingTests].TestCases.Add(new DecodingTestCase(1, "Random 2", makeRandomLowEntropy(1400, 7, 5, 20, 14), makeRandomLowEntropyEncoded(1400, 7, 5, 20, 14)));


            string DecodingTestsPerformance = "DecodingTestsPerformanceLab";

            TestSets[DecodingTestsPerformance] = new TestSet(solver, "Decoding performance tests (Lab)");
            List <EncodingTriple> allA = new List <EncodingTriple>();

            for (int i = 0; i < 2000000; i++)
            {
                allA.Add(new EncodingTriple(0, 0, 'a'));
            }
            List <EncodingTriple> allA2 = new List <EncodingTriple>();

            for (int i = 0; i < 400000; i++)
            {
                allA2.Add(new EncodingTriple(0, (i == 0 ? 0 : 9), 'a'));
            }
            List <EncodingTriple> allA3 = new List <EncodingTriple>();

            for (int i = 0; i < 10; i++)
            {
                allA3.Add(new EncodingTriple(0, (i == 0 ? 0 : 999999), 'a'));
            }
            TestSets[DecodingTestsPerformance].TestCases.Add(new DecodingTestCase(60, "a^N (by single characters)", new string('a', 2000000), allA));
            TestSets[DecodingTestsPerformance].TestCases.Add(new DecodingTestCase(15, "a^N (multiple repetitions)", new string('a', 4000000 - 9), allA2));
            TestSets[DecodingTestsPerformance].TestCases.Add(new DecodingTestCase(1.55, "a^N (super long repetitions)", new string('a', 10000000 - 999999), allA3));
            TestSets[DecodingTestsPerformance].TestCases.Add(new DecodingTestCase(1.55, "23th Zimin word", makeZimin(23), makeZiminEncoded(23)));
            TestSets[DecodingTestsPerformance].TestCases.Add(new DecodingTestCase(30, "Big random 1", makeRandomLowEntropy(3000000, 2, 3, 5, 13), makeRandomLowEntropyEncoded(3000000, 2, 3, 5, 13)));
            TestSets[DecodingTestsPerformance].TestCases.Add(new DecodingTestCase(1.4, "Big random 2", makeRandomLowEntropy(8000000, 5, 3, 500000, 14), makeRandomLowEntropyEncoded(8000000, 5, 3, 500000, 14)));



            string Correctness = "CorrectnessLab";

            TestSets[Correctness] = new TestSet(solver, "Encoding correctness tests (Lab)");
            TestSets[Correctness].TestCases.Add(new EncodingTestCase(1, "a", "a", 1, 1));
            TestSets[Correctness].TestCases.Add(new EncodingTestCase(1, "aa", "aa", 1, 2));
            TestSets[Correctness].TestCases.Add(new EncodingTestCase(1, "abc", "abc", 1, 3));
            TestSets[Correctness].TestCases.Add(new EncodingTestCase(1, "aab", "aab", 5, 2));
            TestSets[Correctness].TestCases.Add(new EncodingTestCase(1, "a^31", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 14, 2));
            TestSets[Correctness].TestCases.Add(new EncodingTestCase(1, "xaabaabcaabaa", "xaabaabcaabaa", 6, 5));
            TestSets[Correctness].TestCases.Add(new EncodingTestCase(1, "xaabaabcaabaa (maxP=5)", "xaabaabcaabaa", 5, 6));
            TestSets[Correctness].TestCases.Add(new EncodingTestCase(1, "aababaababaabaababaab", "aababaababaabaababaab", 14, 5));
            TestSets[Correctness].TestCases.Add(new EncodingTestCase(1, "aaabcabcabdabcabdx", "aaabcabcabdabcabdx", 9, 5));
            TestSets[Correctness].TestCases.Add(new EncodingTestCase(1, "aababaaaaxaaabbaaay", "aababaaaaxaaabbaaay", 12, 6));
            TestSets[Correctness].TestCases.Add(new EncodingTestCase(1, "Random 1", makeRandom(3000, 2, 13), 50, 423));
            TestSets[Correctness].TestCases.Add(new EncodingTestCase(1, "Random 2", makeRandom(200, 3, 14), 50, 45));
            TestSets[Correctness].TestCases.Add(new EncodingTestCase(1, "Random 3", makeRandom(200, 4, 15), 50, 58));
            TestSets[Correctness].TestCases.Add(new EncodingTestCase(1, "Random low entropy 1", makeRandomLowEntropy(200, 2, 20, 50, 16), 50, 6));
            TestSets[Correctness].TestCases.Add(new EncodingTestCase(1, "4th Zimin word", makeZimin(4), 32, 5));


            string Performance = "PerformanceLab";

            TestSets[Performance] = new TestSet(solver, "Basic encoding performance tests (Lab)");
            TestSets[Performance].TestCases.Add(new EncodingTestCase(5.6, "19th Zimin word", makeZimin(19), int.MaxValue, 20));
            TestSets[Performance].TestCases.Add(new EncodingTestCase(7.7, "Big random 1", makeRandom(10000, 3, 18), 2000, 1300));
            TestSets[Performance].TestCases.Add(new EncodingTestCase(3.5, "(ababc)^n+x+(ababc)^n", repeat("ababc", 100000) + "x" + repeat("ababc", 100000), 50000, 6));
            TestSets[Performance].TestCases.Add(new EncodingTestCase(7, "Mostly a, rare b", makeRandomMostlyA(100000, 1000, 17), 50000, 99));
            TestSets[Performance].TestCases.Add(new EncodingTestCase(7, "Random islands", makeIslands(250000, 2, 2000, 19), int.MaxValue, 42));
            TestSets[Performance].TestCases.Add(new EncodingTestCase(7, "Expanded islands", makeExpandedIslands(250000, 50, 30000, 20), int.MaxValue, 19));
        }
        public override void PrepareTestSets()
        {
            const int testCaseNumber = 7;

            string[]   text     = new string[testCaseNumber];
            string[][] codes    = new string[testCaseNumber][];
            int[]      expected = new int[testCaseNumber];

            text[0]     = "abca";
            codes[0]    = new string[] { "a", "abc", "ab", "ca" };
            expected[0] = 2;

            text[1]     = "aaaaa";
            codes[1]    = new string[] { "a" };
            expected[1] = 1;

            text[2]     = "a";
            codes[2]    = new string[] { "b" };
            expected[2] = 0;

            text[3]     = "a";
            codes[3]    = new string[] { };
            expected[3] = 0;

            text[4]     = "abca";
            codes[4]    = new string[] { "a", "b", "c", "ab", "ca", "abca" };
            expected[4] = 5;

            text[5]     = "123123";
            codes[5]    = new string[] { "123", "1", "231", "23", "12", "312", "3", "123123", "2" };
            expected[5] = 21;

            text[6]     = "121212";
            codes[6]    = new string[] { "12", "21", "1", "2" };
            expected[6] = 13;

            /*
             * text[7] =                 "aaaaaaaaaaaaaaaaaa";  // 18 liter a
             * codes[7] = new string[] { "aaaaaaaaaaaaaaaaaa",
             *                    "aaaaaaaaaaaaaaaaa",
             *                    "aaaaaaaaaaaaaaaa",
             *                    "aaaaaaaaaaaaaaa",
             *                    "aaaaaaaaaaaaaa",
             *                    "aaaaaaaaaaaaa",
             *                    "aaaaaaaaaaaa",
             *                    "aaaaaaaaaaa",
             *                    "aaaaaaaaaa",
             *                    "aaaaaaaaa",
             *                    "aaaaaaaa",
             *                    "aaaaaaa",
             *                    "aaaaaa",
             *                    "aaaaa",
             *                    "aaaa",
             *                    "aaa",
             *                    "aa",
             *                    "a",
             *                  };
             * expected[7] = 1<<17;
             */
            //double[] limits = new double[testCaseNumber] { 1, 1, 1, 1, 1, 1, 1, 15 };
            double[] limits = new double[testCaseNumber] {
                1, 1, 1, 1, 1, 1, 1
            };

            string[] descriptions = new string[testCaseNumber]
            {
                "prosty test 1",
                "tekst=\"aaaaa\", kod=\"a\"",
                "brak rozwiazania",
                "pusty zbior kodow",
                "prosty test 2",
                "test \"123\"",
                "test \"12\"",
                //"duuuuuzo a",
            };

            TestSets["LabTestsWithoutSequences"] = new TestSet(new CodesCounting(), "Lab. tests - numbers of codings only", null, false);
            TestSets["LabTestsWithSequences"]    = new TestSet(new CodesCounting(), "Lab. tests - with coding sequences", null, true);

            for (int k = 0; k < testCaseNumber; ++k)
            {
                TestSets["LabTestsWithoutSequences"].TestCases.Add(new CodingTestCase(limits[k], null, descriptions[k], text[k], codes[k], expected[k]));
                TestSets["LabTestsWithSequences"].TestCases.Add(new CodingTestCase(limits[k], null, descriptions[k], text[k], codes[k], expected[k]));
            }
        }
Ejemplo n.º 24
0
            public override void PrepareTestSets()
            {
                List <(int, string, int[], int[], int[], int, int, int)> findOptTests = new List <(int, string, int[], int[], int[], int, int, int)>();
                List <(int, string, int[], int[], int[], int, int, int)> findSeqTests = new List <(int, string, int[], int[], int[], int, int, int)>();

                int    time = 1;
                string description;

                int[]  money;
                int[]  carrots;
                int[]  dist;
                int    maxCarrots;
                int    startingCarrots;
                int    expectedResult;
                Random rnd;

                //1
                description     = "prosty test trzyelementowy";
                money           = new int[] { 1, 2, 3 };
                carrots         = new int[] { 1, 2, 3 };
                dist            = new int[] { 0, 1, 1 };
                startingCarrots = 1;
                maxCarrots      = 5;
                expectedResult  = 4;
                findOptTests.Add((time, description, money, carrots, dist, maxCarrots, startingCarrots, expectedResult));

                //2
                description     = "cały czas trzeba brać marchewki";
                money           = new int[] { 100, 100, 100, 100, 0 };
                carrots         = new int[] { 10, 10, 10, 10, 10 };
                dist            = new int[] { 0, 1, 1, 1, 37 };
                startingCarrots = 0;
                maxCarrots      = 50;
                expectedResult  = 0;
                findOptTests.Add((time, description, money, carrots, dist, maxCarrots, startingCarrots, expectedResult));

                //3
                description     = "nie da się dojechać";
                money           = new int[] { 100, 100, 100, 100, 0 };
                carrots         = new int[] { 1, 1, 1, 1, 1 };
                dist            = new int[] { 0, 1, 1, 1, 2 };
                startingCarrots = 0;
                maxCarrots      = 1;
                expectedResult  = -1;
                findOptTests.Add((time, description, money, carrots, dist, maxCarrots, startingCarrots, expectedResult));

                //4
                description     = "musimy odrzucać marchewki";
                money           = new int[] { 100, 100, 100, 100, 100, 100, 100, 100, 0 };
                carrots         = new int[] { 10, 10, 10, 10, 10, 10, 10, 10, 4 };
                dist            = new int[] { 0, 5, 1, 5, 1, 4, 1, 4, 2 };
                startingCarrots = 4;
                maxCarrots      = 5;
                expectedResult  = 200;
                findOptTests.Add((time, description, money, carrots, dist, maxCarrots, startingCarrots, expectedResult));

                //5
                description     = "nietrywialny przykład";
                money           = new int[] { 10, 5, 15, 12, 6, 13, 5, 4, 10 };
                carrots         = new int[] { 5, 2, 3, 6, 3, 2, 6, 3, 5 };
                dist            = new int[] { 0, 2, 4, 2, 1, 10, 3, 2, 4 };
                startingCarrots = 10;
                maxCarrots      = 100;
                expectedResult  = 33;
                findOptTests.Add((time, description, money, carrots, dist, maxCarrots, startingCarrots, expectedResult));

                //6
                description     = "nietrywialny przykład, na starcie mamy zero marchewek, małe max carrots";
                money           = new int[] { 10, 5, 15, 12, 6, 13, 5, 4, 10 };
                carrots         = new int[] { 5, 2, 3, 6, 3, 2, 6, 3, 1 };
                dist            = new int[] { 0, 2, 4, 2, 1, 4, 3, 2, 3 };
                startingCarrots = 0;
                maxCarrots      = 6;
                expectedResult  = 20;
                findOptTests.Add((time, description, money, carrots, dist, maxCarrots, startingCarrots, expectedResult));

                //7
                description     = "większy przykład z rozwiązaniem";
                money           = new int[] { 5, 3, 6, 7, 8, 2, 1, 1, 6, 7, 3, 2, 4, 1, 9, 6, 2, 8, 9, 1, 6, 2, 3 };
                carrots         = new int[] { 3, 2, 5, 1, 6, 4, 2, 6, 5, 3, 7, 1, 5, 3, 8, 7, 6, 1, 5, 3, 5, 5, 0 };
                dist            = new int[] { 0, 6, 5, 3, 6, 2, 3, 1, 2, 3, 4, 1, 1, 1, 5, 3, 6, 2, 5, 1, 8, 2, 6 };
                startingCarrots = 10;
                maxCarrots      = 20;
                expectedResult  = 37;
                findOptTests.Add((time, description, money, carrots, dist, maxCarrots, startingCarrots, expectedResult));

                //8
                description     = "większy przykład bez rozwiązania";
                money           = new int[] { 5, 3, 6, 7, 8, 2, 1, 1, 6, 7, 3, 2, 4, 1, 9, 6, 2, 8, 9, 1, 6, 2, 3 };
                carrots         = new int[] { 3, 2, 5, 1, 6, 4, 2, 6, 5, 3, 7, 1, 5, 3, 8, 7, 6, 1, 5, 3, 5, 5, 0 };
                dist            = new int[] { 0, 6, 5, 3, 6, 2, 3, 1, 2, 3, 4, 1, 1, 1, 5, 3, 6, 2, 5, 1, 8, 2, 6 };
                startingCarrots = 11;
                maxCarrots      = 11;
                expectedResult  = -1;
                findOptTests.Add((time, description, money, carrots, dist, maxCarrots, startingCarrots, expectedResult));

                //9
                rnd         = new Random(100);
                description = "duży test losowy";
                int n = 200;

                money           = new int[n];
                carrots         = new int[n];
                dist            = new int[n];
                startingCarrots = 20;
                maxCarrots      = 30;

                for (int i = 0; i < n; ++i)
                {
                    money[i]   = 1 + rnd.Next(20);
                    dist[i]    = 1 + rnd.Next(5);
                    carrots[i] = 1 + rnd.Next(10);
                }
                dist[0]        = 0;
                expectedResult = 1680;
                findOptTests.Add((time, description, money, carrots, dist, maxCarrots, startingCarrots, expectedResult));

                //10
                rnd             = new Random(200);
                description     = "duży test losowy";
                n               = 300;
                money           = new int[n];
                carrots         = new int[n];
                dist            = new int[n];
                startingCarrots = 10;
                maxCarrots      = 100;

                for (int i = 0; i < n; ++i)
                {
                    money[i]   = 1 + rnd.Next(20);
                    dist[i]    = 1 + rnd.Next(15);
                    carrots[i] = 1 + rnd.Next(20);
                }
                dist[0]        = 0;
                expectedResult = 1688;
                findOptTests.Add((time, description, money, carrots, dist, maxCarrots, startingCarrots, expectedResult));


                TestSets["LabOnlyMax"] = new TestSet(new TaxCollectorManager(), "Cześć 1 : znalezienie ilości złota (3 pkt)", null, false);
                TestSets["LabFullSol"] = new TestSet(new TaxCollectorManager(), "Cześć 2 : znalezienie optymalnego planu (1 pkt)", null, true);


                foreach (var(t, desc, mon, car, dis, mCar, sCar, eRes) in findOptTests)
                {
                    TestSets["LabOnlyMax"].TestCases.Add(new MaxTaxTestCase(t, desc, mon, car, dis, mCar, sCar, eRes));
                    TestSets["LabFullSol"].TestCases.Add(new MaxTaxTestCase(t, desc, mon, car, dis, mCar, sCar, eRes));
                }
            }
Ejemplo n.º 25
0
        static void Main(string[] args)
        {
            GraphExport          ge  = new GraphExport();
            RandomGraphGenerator rgg = new RandomGraphGenerator();

            Graph[] directedGraphs = new Graph[8];
            directedGraphs[0] = new AdjacencyListsGraph <AVLAdjacencyList>(true, 3)
            {
                new Edge(0, 1), new Edge(1, 2), new Edge(2, 0)
            };
            directedGraphs[1] = new AdjacencyListsGraph <SimpleAdjacencyList>(true, 3)
            {
                new Edge(0, 1), new Edge(1, 2), new Edge(2, 1)
            };
            directedGraphs[2] = new AdjacencyMatrixGraph(true, 4)
            {
                new Edge(0, 1), new Edge(0, 2), new Edge(1, 3), new Edge(2, 3)
            };
            directedGraphs[3] = new AdjacencyListsGraph <HashTableAdjacencyList>(true, 10);
            directedGraphs[4] = new AdjacencyMatrixGraph(true, 10)
            {
                new Edge(0, 1), new Edge(0, 2), new Edge(0, 3), new Edge(2, 4), new Edge(2, 5), new Edge(2, 6),
                new Edge(5, 7), new Edge(5, 8), new Edge(5, 9), new Edge(6, 5), new Edge(7, 8), new Edge(8, 2)
            };
            rgg.SetSeed(111);
            directedGraphs[5] = rgg.DirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.2);
            rgg.SetSeed(222);
            directedGraphs[6] = rgg.DirectedCycle(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), 1000);
            rgg.SetSeed(333);
            directedGraphs[7] = rgg.DAG(typeof(AdjacencyMatrixGraph), 200, 0.2, 1, 1);

            TestSet findCycleDirected = new TestSet();

            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[0], true));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[1], true));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[2], false));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[3], false));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[4], true));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[5], true));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[6], true));
            findCycleDirected.TestCases.Add(new FindCycleTestCase(5, null, directedGraphs[7], false));

            Graph[] undirectedGraphs = new Graph[6];
            undirectedGraphs[0] = new AdjacencyListsGraph <AVLAdjacencyList>(false, 3)
            {
                new Edge(0, 1), new Edge(1, 2), new Edge(2, 0)
            };
            undirectedGraphs[1] = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 4)
            {
                new Edge(0, 1), new Edge(1, 2), new Edge(2, 3), new Edge(3, 1)
            };
            undirectedGraphs[2] = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 10);
            undirectedGraphs[3] = new AdjacencyMatrixGraph(false, 10)
            {
                new Edge(0, 1), new Edge(0, 2), new Edge(0, 3), new Edge(2, 4), new Edge(2, 5), new Edge(2, 6),
                new Edge(5, 7), new Edge(5, 8), new Edge(5, 9), new Edge(8, 2)
            };
            rgg.SetSeed(444);
            undirectedGraphs[4] = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.2);
            rgg.SetSeed(555);
            undirectedGraphs[5] = rgg.TreeGraph(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), 1000, 1.0);

            TestSet findCycleUndirected = new TestSet();

            findCycleUndirected.TestCases.Add(new FindCycleTestCase(5, null, undirectedGraphs[0], true));
            findCycleUndirected.TestCases.Add(new FindCycleTestCase(5, null, undirectedGraphs[1], true));
            findCycleUndirected.TestCases.Add(new FindCycleTestCase(5, null, undirectedGraphs[2], false));
            findCycleUndirected.TestCases.Add(new FindCycleTestCase(5, null, undirectedGraphs[3], true));
            findCycleUndirected.TestCases.Add(new FindCycleTestCase(5, null, undirectedGraphs[4], true));
            findCycleUndirected.TestCases.Add(new FindCycleTestCase(5, null, undirectedGraphs[5], false));

            Graph[] trees = new Graph[10];
            trees[0] = new AdjacencyListsGraph <AVLAdjacencyList>(false, 3)
            {
                new Edge(0, 1), new Edge(1, 2)
            };
            trees[1] = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 4)
            {
                new Edge(0, 1), new Edge(1, 2), new Edge(2, 3)
            };
            trees[2] = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 1);
            trees[3] = new AdjacencyListsGraph <HashTableAdjacencyList>(false, 2)
            {
                new Edge(0, 1)
            };
            trees[4] = new AdjacencyMatrixGraph(false, 5)
            {
                new Edge(1, 3), new Edge(2, 4)
            };
            trees[5] = new AdjacencyMatrixGraph(true, 3)
            {
                new Edge(0, 1), new Edge(0, 2)
            };
            rgg.SetSeed(777);
            trees[6] = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.2);
            rgg.SetSeed(888);
            trees[7] = rgg.TreeGraph(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), 1000, 1.0);
            rgg.SetSeed(999);
            trees[8] = rgg.TreeGraph(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), 1001, 1.0);
            trees[9] = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 10);
            for (int i = 1; i < 10; ++i)
            {
                trees[9].AddEdge(i - 1, i);
            }

            TestSet treeCenter = new TestSet();

            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[0], true, new int[] { 1 }));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[1], true, new int[] { 1, 2 }));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[2], true, new int[] { 0 }));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[3], true, new int[] { 0, 1 }));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[4], false, null));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, new ArgumentException(), trees[5], false, null));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[6], false, null));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[7], true, new int[] { 305, 786 }));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[8], true, new int[] { 60 }));
            treeCenter.TestCases.Add(new TreeCenterTestCase(5, null, trees[9], true, new int[] { 4, 5 }));

            //
            // Odkomentuj odpowiednią linię aby zobaczyć wybrany graf
            // Pamiętaj, że przykłady numerowane są od 1
            //
//        ge.Export(directedGraphs[0]);
//        ge.Export(directedGraphs[1]);
//        ge.Export(directedGraphs[2]);
//        ge.Export(directedGraphs[3]);
//        ge.Export(directedGraphs[4]);
//        ge.Export(directedGraphs[5]);
//        ge.Export(directedGraphs[6]);
//        ge.Export(directedGraphs[7]);
//        ge.Export(undirectedGraphs[0]);
//        ge.Export(undirectedGraphs[1]);
//        ge.Export(undirectedGraphs[2]);
//        ge.Export(undirectedGraphs[3]);
//        ge.Export(undirectedGraphs[4]);
//        ge.Export(undirectedGraphs[5]);
//        ge.Export(trees[0]);
//        ge.Export(trees[1]);
//        ge.Export(trees[2]);
//        ge.Export(trees[3]);
//        ge.Export(trees[4]);
//        ge.Export(trees[5]);
//        ge.Export(trees[6]);
//        ge.Export(trees[7]);
//        ge.Export(trees[8]);

            Console.WriteLine("\nCycle Finding\n");

            FindCycleTestCase.ResultOnly = true;
            Console.WriteLine("\nDirected Graphs - result only");
            findCycleDirected.PreformTests(verbose: true, checkTimeLimit: false);
            Console.WriteLine("\nUndirected Graphs - result only");
            findCycleUndirected.PreformTests(verbose: true, checkTimeLimit: false);

            FindCycleTestCase.ResultOnly = false;
            Console.WriteLine("\nDirected Graphs - full funcionality");
            findCycleDirected.PreformTests(verbose: true, checkTimeLimit: false, forceExecution: false);
            Console.WriteLine("\nUndirected Graphs - full funcionality");
            findCycleUndirected.PreformTests(verbose: true, checkTimeLimit: false, forceExecution: false);

            Console.WriteLine("\nTree Center\n");
            TreeCenterTestCase.ResultOnly = true;
            Console.WriteLine("\nResult only");
            treeCenter.PreformTests(verbose: true, checkTimeLimit: false);
            Console.WriteLine("\nFull funcionality");
            TreeCenterTestCase.ResultOnly = false;
            treeCenter.PreformTests(verbose: true, checkTimeLimit: false, forceExecution: false);
        }
Ejemplo n.º 26
0
        public static void Main()
        {
            // Przyklady testowe dla SimpleList

            TestSet simpleListAdd = new TestSet();

            simpleListAdd.TestCases.Add(new ListTestCase(5, null, new SimpleList(), new ListTestCaseParams[] {
                new ListTestCaseParams('a', 10, true, new int[] { 10 }),
                new ListTestCaseParams('a', 10, false, new int[] { 10 }),
                new ListTestCaseParams('a', 5, true, new int[] { 10, 5 }),
                new ListTestCaseParams('a', 10, false, new int[] { 10, 5 }),
                new ListTestCaseParams('a', 5, false, new int[] { 10, 5 }),
                new ListTestCaseParams('a', 15, true, new int[] { 10, 5, 15 }),
                new ListTestCaseParams('a', 5, false, new int[] { 10, 5, 15 }),
                new ListTestCaseParams('a', 15, false, new int[] { 10, 5, 15 }),
                new ListTestCaseParams('a', 10, false, new int[] { 10, 5, 15 }),
                new ListTestCaseParams('a', 20, true, new int[] { 10, 5, 15, 20 }),
            }));

            TestSet simpleListAddSearch = new TestSet();

            simpleListAddSearch.TestCases.Add(new ListTestCase(5, null, new SimpleList(), new ListTestCaseParams[] {
                new ListTestCaseParams('s', 10, false, new int[] { }),
                new ListTestCaseParams('a', 10, true, new int[] { 10 }),
                new ListTestCaseParams('s', 10, true, new int[] { 10 }),
                new ListTestCaseParams('s', 20, false, new int[] { 10 }),
                new ListTestCaseParams('a', 10, false, new int[] { 10 }),
                new ListTestCaseParams('a', 5, true, new int[] { 10, 5 }),
                new ListTestCaseParams('s', 5, true, new int[] { 10, 5 }),
                new ListTestCaseParams('s', 20, false, new int[] { 10, 5 }),
                new ListTestCaseParams('a', 10, false, new int[] { 10, 5 }),
                new ListTestCaseParams('a', 5, false, new int[] { 10, 5 }),
                new ListTestCaseParams('a', 15, true, new int[] { 10, 5, 15 }),
                new ListTestCaseParams('s', 15, true, new int[] { 10, 5, 15 }),
                new ListTestCaseParams('s', 20, false, new int[] { 10, 5, 15 }),
                new ListTestCaseParams('a', 5, false, new int[] { 10, 5, 15 }),
                new ListTestCaseParams('a', 15, false, new int[] { 10, 5, 15 }),
                new ListTestCaseParams('a', 10, false, new int[] { 10, 5, 15 }),
                new ListTestCaseParams('a', 20, true, new int[] { 10, 5, 15, 20 }),
                new ListTestCaseParams('s', 20, true, new int[] { 10, 5, 15, 20 }),
            }));

            TestSet    simpleListAddRemove = new TestSet();
            SimpleList list = new SimpleList();

            simpleListAddRemove.TestCases.Add(new ListTestCase(5, null, list, new ListTestCaseParams[] {
                new ListTestCaseParams('r', 10, false, new int[] { }),
                new ListTestCaseParams('a', 10, true, new int[] { 10 }),
                new ListTestCaseParams('r', 15, false, new int[] { 10 }),
                new ListTestCaseParams('a', 20, true, new int[] { 10, 20 }),
                new ListTestCaseParams('r', 15, false, new int[] { 10, 20 }),
                new ListTestCaseParams('r', 10, true, new int[] { 20 }),
                new ListTestCaseParams('a', 15, true, new int[] { 20, 15 }),
                new ListTestCaseParams('a', 25, true, new int[] { 20, 15, 25 }),
                new ListTestCaseParams('r', 15, true, new int[] { 20, 25 }),
                new ListTestCaseParams('a', 30, true, new int[] { 20, 25, 30 }),
                new ListTestCaseParams('r', 40, false, new int[] { 20, 25, 30 }),
                new ListTestCaseParams('r', 30, true, new int[] { 20, 25 }),
                new ListTestCaseParams('a', 15, true, new int[] { 20, 25, 15 }),
                new ListTestCaseParams('r', 25, true, new int[] { 20, 15 }),
                new ListTestCaseParams('r', 15, true, new int[] { 20 }),
                new ListTestCaseParams('a', 10, true, new int[] { 20, 10 }),
                new ListTestCaseParams('r', 20, true, new int[] { 10 }),
                new ListTestCaseParams('r', 10, true, new int[] { }),
                new ListTestCaseParams('a', 15, true, new int[] { 15 }),
            }));

            TestSet simpleListAddSearchRemove = new TestSet();

            simpleListAddSearchRemove.TestCases.Add(new ListTestCase(5, null, new SimpleList(), new ListTestCaseParams[] {
                new ListTestCaseParams('r', 10, false, new int[] { }),
                new ListTestCaseParams('s', 10, false, new int[] { }),
                new ListTestCaseParams('a', 10, true, new int[] { 10 }),
                new ListTestCaseParams('r', 15, false, new int[] { 10 }),
                new ListTestCaseParams('a', 20, true, new int[] { 10, 20 }),
                new ListTestCaseParams('s', 20, true, new int[] { 10, 20 }),
                new ListTestCaseParams('r', 15, false, new int[] { 10, 20 }),
                new ListTestCaseParams('r', 10, true, new int[] { 20 }),
                new ListTestCaseParams('a', 15, true, new int[] { 20, 15 }),
                new ListTestCaseParams('s', 20, true, new int[] { 20, 15 }),
                new ListTestCaseParams('a', 25, true, new int[] { 20, 15, 25 }),
                new ListTestCaseParams('r', 15, true, new int[] { 20, 25 }),
                new ListTestCaseParams('a', 30, true, new int[] { 20, 25, 30 }),
                new ListTestCaseParams('r', 40, false, new int[] { 20, 25, 30 }),
                new ListTestCaseParams('s', 15, false, new int[] { 20, 25, 30 }),
                new ListTestCaseParams('r', 30, true, new int[] { 20, 25 }),
                new ListTestCaseParams('r', 25, true, new int[] { 20 }),
                new ListTestCaseParams('r', 20, true, new int[] { }),
            }));

            // Przyklady testowe dla MoveToFrontList

            TestSet moveToFrontListAdd = new TestSet();

            moveToFrontListAdd.TestCases.Add(new ListTestCase(5, null, new MoveToFrontList(), new ListTestCaseParams[] {
                new ListTestCaseParams('a', 10, true, new int[] { 10 }),
                new ListTestCaseParams('a', 10, false, new int[] { 10 }),
                new ListTestCaseParams('a', 15, true, new int[] { 15, 10 }),
                new ListTestCaseParams('a', 10, false, new int[] { 10, 15 }),
                new ListTestCaseParams('a', 15, false, new int[] { 15, 10 }),
                new ListTestCaseParams('a', 25, true, new int[] { 25, 15, 10 }),
                new ListTestCaseParams('a', 15, false, new int[] { 15, 25, 10 }),
                new ListTestCaseParams('a', 10, false, new int[] { 10, 15, 25 }),
                new ListTestCaseParams('a', 20, true, new int[] { 20, 10, 15, 25 }),
            }));

            TestSet moveToFrontListAddSearch = new TestSet();

            moveToFrontListAddSearch.TestCases.Add(new ListTestCase(5, null, new MoveToFrontList(), new ListTestCaseParams[] {
                new ListTestCaseParams('s', 10, false, new int[] { }),
                new ListTestCaseParams('a', 10, true, new int[] { 10 }),
                new ListTestCaseParams('s', 10, true, new int[] { 10 }),
                new ListTestCaseParams('s', 20, false, new int[] { 10 }),
                new ListTestCaseParams('a', 10, false, new int[] { 10 }),
                new ListTestCaseParams('a', 15, true, new int[] { 15, 10 }),
                new ListTestCaseParams('s', 15, true, new int[] { 15, 10 }),
                new ListTestCaseParams('s', 20, false, new int[] { 15, 10 }),
                new ListTestCaseParams('a', 10, false, new int[] { 10, 15 }),
                new ListTestCaseParams('a', 15, false, new int[] { 15, 10 }),
                new ListTestCaseParams('a', 25, true, new int[] { 25, 15, 10 }),
                new ListTestCaseParams('s', 25, true, new int[] { 25, 15, 10 }),
                new ListTestCaseParams('s', 20, false, new int[] { 25, 15, 10 }),
                new ListTestCaseParams('a', 15, false, new int[] { 15, 25, 10 }),
                new ListTestCaseParams('a', 25, false, new int[] { 25, 15, 10 }),
                new ListTestCaseParams('a', 10, false, new int[] { 10, 25, 15 }),
                new ListTestCaseParams('a', 20, true, new int[] { 20, 10, 25, 15 }),
                new ListTestCaseParams('s', 25, true, new int[] { 25, 20, 10, 15 }),
            }));

            TestSet moveToFrontListAddRemove = new TestSet();

            moveToFrontListAddRemove.TestCases.Add(new ListTestCase(5, null, new MoveToFrontList(), new ListTestCaseParams[] {
                new ListTestCaseParams('r', 10, false, new int[] { }),
                new ListTestCaseParams('a', 10, true, new int[] { 10 }),
                new ListTestCaseParams('r', 15, false, new int[] { 10 }),
                new ListTestCaseParams('a', 20, true, new int[] { 20, 10 }),
                new ListTestCaseParams('r', 15, false, new int[] { 20, 10 }),
                new ListTestCaseParams('r', 10, true, new int[] { 20 }),
                new ListTestCaseParams('a', 15, true, new int[] { 15, 20 }),
                new ListTestCaseParams('a', 25, true, new int[] { 25, 15, 20 }),
                new ListTestCaseParams('r', 15, true, new int[] { 25, 20 }),
                new ListTestCaseParams('a', 30, true, new int[] { 30, 25, 20 }),
                new ListTestCaseParams('r', 40, false, new int[] { 30, 25, 20 }),
                new ListTestCaseParams('r', 30, true, new int[] { 25, 20 }),
                new ListTestCaseParams('r', 25, true, new int[] { 20 }),
                new ListTestCaseParams('r', 20, true, new int[] { }),
            }));

            TestSet moveToFrontListAddSearchRemove = new TestSet();

            moveToFrontListAddSearchRemove.TestCases.Add(new ListTestCase(5, null, new MoveToFrontList(), new ListTestCaseParams[] {
                new ListTestCaseParams('r', 10, false, new int[] { }),
                new ListTestCaseParams('s', 10, false, new int[] { }),
                new ListTestCaseParams('a', 10, true, new int[] { 10 }),
                new ListTestCaseParams('r', 15, false, new int[] { 10 }),
                new ListTestCaseParams('a', 20, true, new int[] { 20, 10 }),
                new ListTestCaseParams('s', 10, true, new int[] { 10, 20 }),
                new ListTestCaseParams('r', 15, false, new int[] { 10, 20 }),
                new ListTestCaseParams('r', 10, true, new int[] { 20 }),
                new ListTestCaseParams('a', 15, true, new int[] { 15, 20 }),
                new ListTestCaseParams('s', 20, true, new int[] { 20, 15 }),
                new ListTestCaseParams('a', 25, true, new int[] { 25, 20, 15 }),
                new ListTestCaseParams('r', 15, true, new int[] { 25, 20 }),
                new ListTestCaseParams('a', 30, true, new int[] { 30, 25, 20 }),
                new ListTestCaseParams('r', 40, false, new int[] { 30, 25, 20 }),
                new ListTestCaseParams('s', 15, false, new int[] { 30, 25, 20 }),
                new ListTestCaseParams('r', 25, true, new int[] { 30, 20 }),
                new ListTestCaseParams('r', 20, true, new int[] { 30 }),
                new ListTestCaseParams('r', 30, true, new int[] { }),
            }));

            // Testy dla SimpleList

            Console.WriteLine("\n*** Test 1.1");
            Console.WriteLine("SimpleList - Add");
            simpleListAdd.PreformTests(verbose: true, checkTimeLimit: false);

            Console.WriteLine("\n*** Test 1.2");
            Console.WriteLine("SimpleList - Add,Search");
            simpleListAddSearch.PreformTests(verbose: true, checkTimeLimit: false);

            Console.WriteLine("\n*** Test 1.3");
            Console.WriteLine("SimpleList - Add,Remove");
            simpleListAddRemove.PreformTests(verbose: true, checkTimeLimit: false);

            Console.WriteLine("\n*** Test 1.4");
            Console.WriteLine("SimpleList - Add,Search,Remove");
            simpleListAddSearchRemove.PreformTests(verbose: true, checkTimeLimit: false);

            // Testy dla MoveToFrontList

            Console.WriteLine("\n*** Test 2.1");
            Console.WriteLine("MoveToFrontList - Add");
            moveToFrontListAdd.PreformTests(verbose: true, checkTimeLimit: false);

            Console.WriteLine("\n*** Test 2.2");
            Console.WriteLine("MoveToFrontList - Add,Search");
            moveToFrontListAddSearch.PreformTests(verbose: true, checkTimeLimit: false);

            Console.WriteLine("\n*** Test 2.3");
            Console.WriteLine("MoveToFrontList - Add,Remove");
            moveToFrontListAddRemove.PreformTests(verbose: true, checkTimeLimit: false);

            Console.WriteLine("\n*** Test 2.4");
            Console.WriteLine("MoveToFrontList - Add,Search,Remove");
            moveToFrontListAddSearchRemove.PreformTests(verbose: true, checkTimeLimit: false);
        }
Ejemplo n.º 27
0
        static void Main(string[] args)
        {
            Graph g1, g2, g3, g4, g5, g6;

            // test 1 -- graf pełny
            g1 = new AdjacencyMatrixGraph(false, 20);
            for (int i = 0; i < 20; ++i)
            {
                for (int j = i + 1; j < 20; ++j)
                {
                    g1.AddEdge(i, j);
                }
            }

            //test 2 -- graf pusty
            g2 = new AdjacencyMatrixGraph(false, 20);

            // test 3
            g3 = new AdjacencyMatrixGraph(false, 8);

            for (int i = 1; i < 6; ++i)
            {
                g3.AddEdge(i - 1, i);
            }
            g3.AddEdge(6, 1);
            g3.AddEdge(7, 4);

            // test 4 -- K_n,n - skojarzenie doskonałe, nieparzyste i parzyste w osobnych klasach dwudzielności

            g4 = new AdjacencyMatrixGraph(false, 20);
            for (int i = 0; i < 10; ++i)
            {
                for (int j = 0; j < 10; ++j)
                {
                    if (i != j)
                    {
                        g4.AddEdge(2 * i, 2 * j + 1);
                    }
                }
            }

            // test 5 -- prismoid - przypadek dla SL

            g5 = new AdjacencyMatrixGraph(false, 8);

            g5.AddEdge(0, 1);
            g5.AddEdge(0, 2);
            g5.AddEdge(0, 4);
            g5.AddEdge(0, 6);
            g5.AddEdge(1, 2);
            g5.AddEdge(1, 3);
            g5.AddEdge(1, 7);
            g5.AddEdge(2, 3);
            g5.AddEdge(2, 4);
            g5.AddEdge(3, 5);
            g5.AddEdge(3, 7);
            g5.AddEdge(4, 5);
            g5.AddEdge(4, 6);
            g5.AddEdge(5, 6);
            g5.AddEdge(5, 7);
            g5.AddEdge(6, 7);

            //http://cs.stackexchange.com/questions/42973/counter-example-to-graph-coloring-heuristic-using-bfs
            g6 = new AdjacencyMatrixGraph(false, 6);

            g6.AddEdge(0, 1);
            g6.AddEdge(0, 2);
            g6.AddEdge(1, 3);
            g6.AddEdge(3, 4);
            g6.AddEdge(3, 5);
            g6.AddEdge(2, 4);
            g6.AddEdge(2, 5);
            g6.AddEdge(4, 5);

            RandomGraphGenerator rgg = new RandomGraphGenerator();

            rgg.SetSeed(111);
            Graph g7 = rgg.UndirectedCycle(typeof(AdjacencyMatrixGraph), 100);

            rgg.SetSeed(222);
            Graph g8 = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.3);

            rgg.SetSeed(333);
            Graph g9 = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.5);

            rgg.SetSeed(444);
            Graph g10 = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 100, 0.7);

            rgg.SetSeed(666);
            Graph g11 = rgg.UndirectedGraph(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), 17000, 0.001);

            Graph[] graphs = { g1, g2, g3, g4, g5, g6, g7, g8, g9, g10, g11 };

            DataContractSerializer dcs    = new DataContractSerializer(typeof(ProperResult[]));
            FileStream             greedy = new FileStream("greedy.dat", FileMode.Open);

            ProperResult[] greedyProperResults = (ProperResult[])dcs.ReadObject(greedy);
            greedy.Close();
            FileStream bfs = new FileStream("bfs.dat", FileMode.Open);

            ProperResult[] bfsProperResults = (ProperResult[])dcs.ReadObject(bfs);
            bfs.Close();
            FileStream back = new FileStream("back.dat", FileMode.Open);

            ProperResult[] backProperResults = (ProperResult[])dcs.ReadObject(back);
            back.Close();
            FileStream color = new FileStream("color.dat", FileMode.Open);

            ProperResult[] colorProperResults = (ProperResult[])dcs.ReadObject(color);
            color.Close();
            FileStream incremental = new FileStream("incremental.dat", FileMode.Open);

            ProperResult[] incrementalProperResults = (ProperResult[])dcs.ReadObject(incremental);
            incremental.Close();

            TestSet setSG = new TestSet();

            setSG.TestCases.Add(new GreedyColoringGraphColoringTestCase(5, g1, greedyProperResults[0]));
            setSG.TestCases.Add(new GreedyColoringGraphColoringTestCase(5, g2, greedyProperResults[1]));
            setSG.TestCases.Add(new GreedyColoringGraphColoringTestCase(5, g3, greedyProperResults[2]));
            setSG.TestCases.Add(new GreedyColoringGraphColoringTestCase(5, g4, greedyProperResults[3]));
            setSG.TestCases.Add(new GreedyColoringGraphColoringTestCase(5, g5, greedyProperResults[4]));
            setSG.TestCases.Add(new GreedyColoringGraphColoringTestCase(5, g6, greedyProperResults[5]));
            setSG.TestCases.Add(new GreedyColoringGraphColoringTestCase(5, g7, greedyProperResults[6]));
            setSG.TestCases.Add(new GreedyColoringGraphColoringTestCase(5, g8, greedyProperResults[7]));
            setSG.TestCases.Add(new GreedyColoringGraphColoringTestCase(5, g9, greedyProperResults[8]));
            setSG.TestCases.Add(new GreedyColoringGraphColoringTestCase(5, g10, greedyProperResults[9]));
            setSG.TestCases.Add(new GreedyColoringGraphColoringTestCase(5, g11, greedyProperResults[10]));
            Console.WriteLine("\nGreedy Coloring");
            setSG.PreformTests(verbose: true, checkTimeLimit: false);

            TestSet setBFS = new TestSet();

            setBFS.TestCases.Add(new BFSGraphColoringTestCase(5, g1, bfsProperResults[0]));
            setBFS.TestCases.Add(new BFSGraphColoringTestCase(5, g2, bfsProperResults[1]));
            setBFS.TestCases.Add(new BFSGraphColoringTestCase(5, g3, bfsProperResults[2]));
            setBFS.TestCases.Add(new BFSGraphColoringTestCase(5, g4, bfsProperResults[3]));
            setBFS.TestCases.Add(new BFSGraphColoringTestCase(5, g5, bfsProperResults[4]));
            setBFS.TestCases.Add(new BFSGraphColoringTestCase(5, g6, bfsProperResults[5]));
            setBFS.TestCases.Add(new BFSGraphColoringTestCase(5, g7, bfsProperResults[6]));
            setBFS.TestCases.Add(new BFSGraphColoringTestCase(5, g8, bfsProperResults[7]));
            setBFS.TestCases.Add(new BFSGraphColoringTestCase(5, g9, bfsProperResults[8]));
            setBFS.TestCases.Add(new BFSGraphColoringTestCase(5, g10, bfsProperResults[9]));
            setBFS.TestCases.Add(new BFSGraphColoringTestCase(5, g11, bfsProperResults[10]));
            Console.WriteLine("\nBFS Coloring");
            setBFS.PreformTests(verbose: true, checkTimeLimit: false);

            TestSet setLBD = new TestSet();

            setLBD.TestCases.Add(new LargestBackDegreeGraphColoringTestCase(5, g1, backProperResults[0]));
            setLBD.TestCases.Add(new LargestBackDegreeGraphColoringTestCase(5, g2, backProperResults[1]));
            setLBD.TestCases.Add(new LargestBackDegreeGraphColoringTestCase(5, g3, backProperResults[2]));
            setLBD.TestCases.Add(new LargestBackDegreeGraphColoringTestCase(5, g4, backProperResults[3]));
            setLBD.TestCases.Add(new LargestBackDegreeGraphColoringTestCase(5, g5, backProperResults[4]));
            setLBD.TestCases.Add(new LargestBackDegreeGraphColoringTestCase(5, g6, backProperResults[5]));
            setLBD.TestCases.Add(new LargestBackDegreeGraphColoringTestCase(5, g7, backProperResults[6]));
            setLBD.TestCases.Add(new LargestBackDegreeGraphColoringTestCase(5, g8, backProperResults[7]));
            setLBD.TestCases.Add(new LargestBackDegreeGraphColoringTestCase(5, g9, backProperResults[8]));
            setLBD.TestCases.Add(new LargestBackDegreeGraphColoringTestCase(5, g10, backProperResults[9]));
            setLBD.TestCases.Add(new LargestBackDegreeGraphColoringTestCase(5, g11, backProperResults[10]));
            Console.WriteLine("\nLargest Back Degree");
            setLBD.PreformTests(verbose: true, checkTimeLimit: false);

            TestSet setDS = new TestSet();

            setDS.TestCases.Add(new ColorDegreeOrderingGraphColoringTestCase(5, g1, colorProperResults[0]));
            setDS.TestCases.Add(new ColorDegreeOrderingGraphColoringTestCase(5, g2, colorProperResults[1]));
            setDS.TestCases.Add(new ColorDegreeOrderingGraphColoringTestCase(5, g3, colorProperResults[2]));
            setDS.TestCases.Add(new ColorDegreeOrderingGraphColoringTestCase(5, g4, colorProperResults[3]));
            setDS.TestCases.Add(new ColorDegreeOrderingGraphColoringTestCase(5, g5, colorProperResults[4]));
            setDS.TestCases.Add(new ColorDegreeOrderingGraphColoringTestCase(5, g6, colorProperResults[5]));
            setDS.TestCases.Add(new ColorDegreeOrderingGraphColoringTestCase(5, g7, colorProperResults[6]));
            setDS.TestCases.Add(new ColorDegreeOrderingGraphColoringTestCase(5, g8, colorProperResults[7]));
            setDS.TestCases.Add(new ColorDegreeOrderingGraphColoringTestCase(5, g9, colorProperResults[8]));
            setDS.TestCases.Add(new ColorDegreeOrderingGraphColoringTestCase(5, g10, colorProperResults[9]));
            setDS.TestCases.Add(new ColorDegreeOrderingGraphColoringTestCase(5, g11, colorProperResults[10]));
            Console.WriteLine("\nColor Degree Ordering");
            setDS.PreformTests(verbose: true, checkTimeLimit: false);

            TestSet setInc = new TestSet();

            setInc.TestCases.Add(new IncrementalGraphColoringTestCase(5, g1, incrementalProperResults[0]));
            setInc.TestCases.Add(new IncrementalGraphColoringTestCase(5, g2, incrementalProperResults[1]));
            setInc.TestCases.Add(new IncrementalGraphColoringTestCase(5, g3, incrementalProperResults[2]));
            setInc.TestCases.Add(new IncrementalGraphColoringTestCase(5, g4, incrementalProperResults[3]));
            setInc.TestCases.Add(new IncrementalGraphColoringTestCase(5, g5, incrementalProperResults[4]));
            setInc.TestCases.Add(new IncrementalGraphColoringTestCase(5, g6, incrementalProperResults[5]));
            setInc.TestCases.Add(new IncrementalGraphColoringTestCase(5, g7, incrementalProperResults[6]));
            setInc.TestCases.Add(new IncrementalGraphColoringTestCase(5, g8, incrementalProperResults[7]));
            setInc.TestCases.Add(new IncrementalGraphColoringTestCase(5, g9, incrementalProperResults[8]));
            setInc.TestCases.Add(new IncrementalGraphColoringTestCase(5, g10, incrementalProperResults[9]));
            setInc.TestCases.Add(new IncrementalGraphColoringTestCase(5, g11, incrementalProperResults[10]));
            Console.WriteLine("\nIncremental");
            setInc.PreformTests(verbose: true, checkTimeLimit: false);
        }
        public override void PrepareTestSets()
        {
            var rgg = new RandomGraphGenerator();
            int n1  = 12;
            int n2  = 9;
            int n2t = 7;

            int[][]  sequences     = new int[n1][];
            bool[]   is_graphic    = new bool[n1];
            string[] descriptions1 = new string[n1];

            int n3 = 13;

            Graph[]  graphs          = new Graph[n3];
            string[] descriptions3   = new string[n3];
            double[] expected_weight = new double[n3];
            double[] limits          = Enumerable.Repeat(1.0, n3).ToArray();
            limits[7]  = 2;    // cykl
            limits[10] = 2;    // niech bedzie z zapasem
            limits[12] = 300;  // duzy rzadki graf

            //Testy ciagu grafowego
            sequences[0]     = new int[] { 0 };
            is_graphic[0]    = true;
            descriptions1[0] = "{ 0 }";

            sequences[1]     = new int[] { 1, 1, 1, 1 };
            is_graphic[1]    = true;
            descriptions1[1] = "{ 1, 1, 1, 1 }";

            sequences[2]     = new int[] { 5, 5, 5, 5, 5, 5 };
            is_graphic[2]    = true;
            descriptions1[2] = "{ 5, 5, 5, 5, 5, 5 }";

            sequences[3]     = new int[] { 1, 3, 5, 2, 3, 3, 3, 1, 3, 5, 2, 3, 3, 3 };
            is_graphic[3]    = true;
            descriptions1[3] = "{ 1, 3, 5, 2, 3, 3, 3, 1, 3, 5, 2, 3, 3, 3 }";

            sequences[4]     = new int[] { 5, 5, 5, 0, 5, 5, 5 };
            is_graphic[4]    = true;
            descriptions1[4] = "{ 5, 5, 5, 0, 5, 5, 5 }";

            sequences[5]     = new int[] { 4, 4, 3, 3, 2 };
            is_graphic[5]    = true;
            descriptions1[5] = "{ 4, 4, 3, 3, 2 }";

            sequences[6]     = new int[] { 2, 3, 2, 3, 2 };
            is_graphic[6]    = true;
            descriptions1[6] = "{ 2, 3, 2, 3, 2 }";

            sequences[7]     = new int[] { 1, 1, 1, 1, 3 };
            is_graphic[7]    = false;
            descriptions1[7] = "{ 1, 1, 1, 1, 3 }";

            sequences[8]     = new int[] { 1, 1, -1, 1 };
            is_graphic[8]    = false;
            descriptions1[8] = "{ 1, 1, -1, 1 }";

            sequences[9]     = new int[] { 1, 1, 1, 1, 6 };
            is_graphic[9]    = false;
            descriptions1[9] = "{ 1, 1, 1, 1, 6 }";

            sequences[10]     = new int[] { 4, 4, 3, 2, 1 };
            is_graphic[10]    = false;
            descriptions1[10] = "{ 4, 4, 3, 2, 1 }";

            sequences[11]     = new int[] { 1, 3, 1, 2, 4 };
            is_graphic[11]    = false;
            descriptions1[11] = "{ 1, 3, 1, 2, 4 }";



            //Testy drzewa rozpinajacego
            //przyklady z zajec

            //graf o jednym wierzcholku izolowanym
            graphs[0]          = new AdjacencyMatrixGraph(false, 1);
            descriptions3[0]   = "Graf o jednym wierzcholku izolowanym";
            expected_weight[0] = 0;

            //graf bez krawedzi
            graphs[1]          = new AdjacencyListsGraph <SimpleAdjacencyList>(false, 10);
            descriptions3[1]   = "Graf bez krawedzi";
            expected_weight[1] = 0;

            //pewien maly graf
            graphs[2] = new AdjacencyMatrixGraph(false, 5);
            graphs[2].AddEdge(0, 1, 1);
            graphs[2].AddEdge(0, 3, -1);
            graphs[2].AddEdge(1, 2, -3);
            graphs[2].AddEdge(2, 0, 2);
            graphs[2].AddEdge(2, 3, 2);
            graphs[2].AddEdge(3, 4, 10);
            descriptions3[2]   = "Pewien maly graf";
            expected_weight[2] = 7;

            //sciezka P6
            graphs[3] = new AdjacencyMatrixGraph(false, 6);
            graphs[3].AddEdge(0, 1, 1);
            graphs[3].AddEdge(1, 2, 2);
            graphs[3].AddEdge(2, 3, 3);
            graphs[3].AddEdge(3, 4, 4);
            graphs[3].AddEdge(4, 5, 5);
            descriptions3[3]   = "Sciezka P6";
            expected_weight[3] = 15;

            //klika K5
            rgg.SetSeed(12345);
            graphs[4]          = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), 5, 1.0);
            descriptions3[4]   = "Klika K5";
            expected_weight[4] = 4;

            //cykl C5
            graphs[5] = new AdjacencyMatrixGraph(false, 5);
            graphs[5].AddEdge(0, 1, 1.5);
            graphs[5].AddEdge(1, 2, -1.5);
            graphs[5].AddEdge(2, 3, 3.2);
            graphs[5].AddEdge(3, 4, 4.8);
            graphs[5].AddEdge(4, 0, 2.3);
            descriptions3[5]   = "Cykl C5";
            expected_weight[5] = 5.5;

            //cykl
            int g6vc = 500;

            graphs[6] = new AdjacencyListsGraph <SimpleAdjacencyList>(false, g6vc);
            for (int i = 1; i < g6vc; ++i)
            {
                graphs[6].AddEdge(i - 1, i);
            }
            graphs[6].AddEdge(g6vc - 1, 0);
            descriptions3[6]   = "Cykl";
            expected_weight[6] = 499;

            //graf niespojny
            graphs[7] = new AdjacencyMatrixGraph(false, 12);
            graphs[7].AddEdge(0, 3, 3);
            graphs[7].AddEdge(0, 7, 2);
            graphs[7].AddEdge(3, 8, 3);
            graphs[7].AddEdge(7, 11, 2);
            graphs[7].AddEdge(11, 8, 4);
            graphs[7].AddEdge(7, 8, 5);
            graphs[7].AddEdge(1, 2, 1);
            graphs[7].AddEdge(2, 10, 5);
            graphs[7].AddEdge(1, 10, 3);
            graphs[7].AddEdge(2, 9, 4);
            graphs[7].AddEdge(4, 5, 1);
            graphs[7].AddEdge(5, 6, 2);
            graphs[7].AddEdge(4, 6, 3);
            descriptions3[7]   = "Graf niespojny";
            expected_weight[7] = 21;

            //grafy losowe

            int g8vc = 200;

            rgg.SetSeed(123451);
            graphs[8]          = rgg.UndirectedGraph(typeof(AdjacencyMatrixGraph), g8vc, 0.1, -100, -1);
            descriptions3[8]   = "Graf losowy o wagach ujemnych";
            expected_weight[8] = -18599;

            int g9vc = 200;

            rgg.SetSeed(123452);
            graphs[9]          = rgg.UndirectedGraph(typeof(AdjacencyListsGraph <SimpleAdjacencyList>), g9vc, 0.05, 1, 30);
            descriptions3[9]   = "Graf losowy o wagach dodatnich";
            expected_weight[9] = 867;

            int g10vc = 300;

            rgg.SetSeed(123453);
            graphs[10]          = rgg.UndirectedGraph(typeof(AdjacencyListsGraph <HashTableAdjacencyList>), g10vc, 0.02, -10, 40);
            descriptions3[10]   = "Graf losowy o wagach calkowitych";
            expected_weight[10] = 238;

            //graf skierowany
            graphs[11] = new AdjacencyMatrixGraph(true, 5);
            graphs[11].AddEdge(0, 1, 1);
            graphs[11].AddEdge(0, 3, -1);
            graphs[11].AddEdge(1, 2, -3);
            graphs[11].AddEdge(2, 0, 2);
            graphs[11].AddEdge(2, 3, 2);
            graphs[11].AddEdge(3, 4, 10);
            descriptions3[11]   = "Pewien maly graf skierowany";
            expected_weight[11] = 0;

            // graf dodatkowy
            int g12vc = 20000;

            graphs[12] = new AdjacencyListsGraph <SimpleAdjacencyList>(false, g12vc);
            for (int i = 0; i < g12vc - 1; i += 4)
            {
                graphs[12].AddEdge(i, i + 1);
                graphs[12].AddEdge(i + 1, i + 2);
            }
            descriptions3[12]   = "duzy rzadki graf";
            expected_weight[12] = 10000;


            TestSets["LabIsGraphic"]           = new TestSet(new Lab03(), "Część 1 - czy ciąg jest grafowy (0.5 pkt)");
            TestSets["LabConstructGraph"]      = new TestSet(new Lab03(), "Część 2 - skonstruowanie grafu (1.5 pkt)");
            TestSets["LabMinimumSpanningTree"] = new TestSet(new Lab03(), "Część 3 - drzewo rozpinające, algorytm Kruskala (2 pkt)");

            for (int k = 0; k < n1; ++k)
            {
                TestSets["LabIsGraphic"].TestCases.Add(new IsGraphicTestCase(1, null, descriptions1[k], sequences[k], is_graphic[k]));
                if (k < n2)
                {
                    TestSets["LabConstructGraph"].TestCases.Add(new ConstructGraph(1, null, descriptions1[k], sequences[k], k < n2t));
                }
            }
            for (int k = 0; k < n3; ++k)
            {
                TestSets["LabMinimumSpanningTree"].TestCases.Add(new MinimumSpanningTreeTestCase(limits[k], graphs[k].Directed ? new ArgumentException("") : null, descriptions3[k], graphs[k], expected_weight[k]));
            }
        }
Ejemplo n.º 29
0
        public override void PrepareTestSets()
        {
            List <int[, ]> tables          = new List <int[, ]>();
            List <int>     thereRes        = new List <int>();
            List <int>     thereAndBackRes = new List <int>();
            List <string>  descriptions    = new List <string>();

            int[,] M;

            // test bez żadnych utrudnień
            M = new int[5, 5];
            for (int i = 0; i < 5; ++i)
            {
                M[0, i] = M[i, 4] = 2;
                M[i, 0] = M[4, i] = 1;
            }
            M[0, 0] = M[4, 4] = 0;
            tables.Add(M);
            thereRes.Add(14);
            thereAndBackRes.Add(21);
            descriptions.Add("dwie ścieżki, żadnego wyboru, żadnych utrudnień");

            // test bez skarbów
            M = new int[10, 10];
            tables.Add(M);
            thereRes.Add(0);
            thereAndBackRes.Add(0);
            descriptions.Add("test bez skarbów");

            // test, który sprawdza czy poprawnie zbieramy
            // skarby ze startu i mety
            M = new int[5, 5];
            for (int i = 0; i < 5; ++i)
            {
                M[0, i] = M[i, 4] = 2;
                M[i, 0] = M[4, i] = 1;
            }
            M[0, 0] = 10;
            M[4, 4] = 10;
            tables.Add(M);
            thereRes.Add(34);
            thereAndBackRes.Add(41);
            descriptions.Add("test, który sprawdza czy poprawnie zbieramy  skarby ze startu i mety");

            // test zdegenerowany - 1 element
            M = new int[1, 1] {
                { 1 }
            };
            tables.Add(M);
            thereRes.Add(1);
            thereAndBackRes.Add(1);
            descriptions.Add("test zdegenerowany: 1 element");

            // test zdegenerowany  w jednym wymiarze
            M = new int[1, 5] {
                { 1, 1, 1, 1, 1 }
            };
            tables.Add(M);
            thereRes.Add(5);
            thereAndBackRes.Add(5);
            descriptions.Add("test zdegenerowany: 1 x 5");

            // test zdegenerowany w drugim wymiarze
            M = new int[5, 1] {
                { 1 }, { 1 }, { 1 }, { 1 }, { 1 }
            };
            tables.Add(M);
            thereRes.Add(5);
            thereAndBackRes.Add(5);
            descriptions.Add("test zdegenerowany: 5 x 1");


            // test niesymetryczny X<Y
            M = new int[5, 10];
            for (int i = 0; i < 5; ++i)
            {
                for (int j = 0; j < 10; ++j)
                {
                    M[i, j] = (i + j) % 5;
                }
            }

            tables.Add(M);
            thereRes.Add(26);
            thereAndBackRes.Add(49);
            descriptions.Add("test niesymetryczny: 5 x 10");

            // test niesymetryczny X>Y
            M = new int[10, 5];
            for (int i = 0; i < 10; ++i)
            {
                for (int j = 0; j < 5; ++j)
                {
                    M[i, j] = (i + j) % 6;
                }
            }

            tables.Add(M);
            thereRes.Add(31);
            thereAndBackRes.Add(61);
            descriptions.Add("test niesymetryczny: 10 x 5");

            // test w którym nie opłaca się dwa razy szukać optymalnej ścieżki, ale trzeba szukać ich naraz
            tables.Add(new int[3, 3] {
                { 5, 2, 9 }, { 1, 10, 1 }, { 0, 1, 5 }
            });
            thereRes.Add(23);
            thereAndBackRes.Add(34);
            descriptions.Add("test, w którym nie opłaca się dwa razy szukać optymalnej ścieżki, ale trzeba szukać ich naraz");


            // kilka większych testów losowych
            Random rnd = new Random(2018);
            int    Z   = 20;

            M = new int[Z, Z];
            for (int i = 0; i < Z; ++i)
            {
                for (int j = 0; j < Z; ++j)
                {
                    M[i, j] = rnd.Next() % 20;
                }
            }
            tables.Add(M);
            thereRes.Add(542);
            thereAndBackRes.Add(1004);
            descriptions.Add("test losowy 20 x 20");

            Z = 50;
            M = new int[Z, Z];
            for (int i = 0; i < Z; ++i)
            {
                for (int j = 0; j < Z; ++j)
                {
                    M[i, j] = rnd.Next() % 20;
                }
            }
            tables.Add(M);
            thereRes.Add(1368);
            thereAndBackRes.Add(2673);
            descriptions.Add("test losowy 50 x 50");

            Z = 70;
            M = new int[Z, Z];
            for (int i = 0; i < Z; ++i)
            {
                for (int j = 0; j < Z; ++j)
                {
                    M[i, j] = rnd.Next() % 20;
                }
            }
            tables.Add(M);
            thereRes.Add(1937);
            thereAndBackRes.Add(3769);
            descriptions.Add("test losowy 70 x 70");

            Z = 100;
            M = new int[Z, Z];
            for (int i = 0; i < Z; ++i)
            {
                for (int j = 0; j < Z; ++j)
                {
                    M[i, j] = rnd.Next() % 20;
                }
            }
            tables.Add(M);
            thereRes.Add(2869);
            thereAndBackRes.Add(5644);
            descriptions.Add("test losowy 100 x 100");


            TestSets["LabPathThereTests"]        = new TestSet(new AdventurePlanner(), "Part 1 - path there [1.5 + 0.5]", null, false);
            TestSets["LabPathThereAndBackTests"] = new TestSet(new AdventurePlanner(), "Part 2 - path there and back [1.5 + 0.5]", null, false);

            //for (int i = 0; i < 1; ++i)// < tables.Count; ++i)
            for (int i = 0; i < tables.Count; ++i)// < tables.Count; ++i)
            {
                //if (i == 1)
                {
                    TestSets["LabPathThereTests"].TestCases.Add(new PathThereTestCase(1, null, "", tables[i], thereRes[i]));
                    TestSets["LabPathThereAndBackTests"].TestCases.Add(new PathThereAndBackTestCase(1, null, "", tables[i], thereAndBackRes[i]));
                }
            }
        }
        private void PrepareCycleTestSets()
        {
            List <(Graph, bool, string)> cycleTests = new List <(Graph, bool, string)>();
            Graph  g;
            bool   expectNull;
            string desc;

            //1
            desc = "skierowany cykl";
            g    = new AdjacencyMatrixGraph(true, 3);
            g.AddEdge(0, 1);
            g.AddEdge(1, 2);
            g.AddEdge(2, 0);
            expectNull = false;
            cycleTests.Add((g, expectNull, desc));


            //2
            desc = "dag";
            g    = new AdjacencyMatrixGraph(true, 4);
            g.AddEdge(0, 1);
            g.AddEdge(1, 2);
            g.AddEdge(2, 3);
            g.AddEdge(0, 2);
            g.AddEdge(0, 3);
            g.AddEdge(1, 3);
            expectNull = true;
            cycleTests.Add((g, expectNull, desc));

            //3
            desc = "cykl + dużo izolowanych wierzchołków";
            g    = new AdjacencyListsGraph <AVLAdjacencyList>(true, 14);
            g.AddEdge(10, 11);
            g.AddEdge(11, 12);
            g.AddEdge(12, 10);
            expectNull = false;
            cycleTests.Add((g, expectNull, desc));

            //4
            desc = "dwie nietrywialne składowe, jedna ma cykl a druga nie";
            g    = new AdjacencyListsGraph <AVLAdjacencyList>(true, 6);
            g.AddEdge(0, 1);
            g.AddEdge(0, 2);
            g.AddEdge(1, 2);

            g.AddEdge(3, 4);
            g.AddEdge(4, 5);
            g.AddEdge(5, 3);
            expectNull = false;
            cycleTests.Add((g, expectNull, desc));


            //5
            desc = "jest jeden cykl, dwuelementowy";
            g    = new AdjacencyListsGraph <HashTableAdjacencyList>(true, 4);
            g.AddEdge(0, 1);
            g.AddEdge(1, 2);
            g.AddEdge(2, 3);
            g.AddEdge(0, 2);
            g.AddEdge(0, 3);
            g.AddEdge(1, 3);
            g.AddEdge(3, 1);
            expectNull = false;
            cycleTests.Add((g, expectNull, desc));


            TestSets["CycleTests"] = new TestSet(new RoutePlanner(), "Część 1 - znajdowanie cyklu");

            foreach (var(gr, ce, des) in cycleTests)
            {
                TestSets["CycleTests"].TestCases.Add(new FindCycleTestCase(1, null, des, gr, ce));
            }
        }