Exemplo n.º 1
0
 def test_path_tester(self):
     g = problem_io.read_problem_from_file_of_name("test_data/test1.json")
     stats = base_types.TestStatistics()
     path_tester = non_overlapping_set_tester.NonOverlappingSetTester(
         g.faulty_set, stats)
     p1 = ["2", "4", "6"]
     p2 = ["1", "4", "6"]
     p3 = ["2", "3", "6"]
     [result] = path_tester.test_paths([p1])
     self.assertFalse(
         result, "For %s path test1 should give negative result" % (p1, ))
     [result] = path_tester.test_paths([p2])
     self.assertTrue(
         result, "For %s path test1 should give positive result" % (p2, ))
     [result] = path_tester.test_paths([p3])
     self.assertTrue(
         result, "For %s path test1 should give positive result" % (p3, ))
     self.assertEquals(
         stats.get_var('positive'), 2,
         "Should be two positive queries got %d" %
         (stats.get_var('positive'), ))
     self.assertEquals(
         stats.get_var('negative'), 1,
         "Should be one negative queries got %d" %
         (stats.get_var('negative'), ))
     self.assertEquals(
         stats.get_var('all'), 3,
         "Should be 3 queries in total got %d" % (stats.get_var('all'), ))
 def test_simple_raw_testing_problem_is_solved_by_hamming(self):
     problem = problem_io.read_problem_from_file_of_name("test_data/test_gen1.json")
     statistics = base_types.TestStatistics()
     tester = non_overlapping_set_tester.NonOverlappingSetTester(problem.faulty_set, statistics)
     solver = hamming_solver.HammingGroupTestingSolver(problem, tester)
     faulty_set = solver.solve()
     self.assertEquals(faulty_set, problem.faulty_set, "Should find all nodes from faulty set %s, got only %s" %
                       (problem.faulty_set, faulty_set))
     self.assertEquals(statistics.get_var('all'), 15, "Should have 15 queries in total got %d" % (statistics.get_var('all'),))
 def test_brute_force_solver(self):
     g = problem_io.read_problem_from_file_of_name("test_data/test1.json")
     statistics = base_types.TestStatistics()
     tester = non_overlapping_set_tester.NonOverlappingSetTester(g.faulty_set, statistics)
     solver = iterative_solvers.BruteForceGCGTSolver(g, tester)
     faulty_set = solver.solve()
     self.assertEquals(faulty_set, g.faulty_set, "Should find all nodes from faulty set %s, got only %s" %
                       (g.faulty_set, faulty_set))
     self.assertEquals(statistics.get_var('all'), 8, "Should have 8 queries in total got %d" % (statistics.get_var('all'),))
     self.assertEquals(statistics.get_var('positive'), 7, "Should have 7 positive queries in total got %d" % (statistics.get_var('positive'),))
     self.assertEquals(statistics.get_var('negative'), 1, "Should have 1 negative queries in total got %d" % (statistics.get_var('negative'),))
Exemplo n.º 4
0
 def test_read_problem_from_file(self):
     g = problem_io.read_problem_from_file_of_name("test_data/test1.json")
     self.assertEquals(
         g.faulty_set, {"1", "3", "5"},
         "Faulty set read from problem description %s" % (g.faulty_set, ))
     self.assertTrue(
         graph_equal(g.problem_graph.graph, self.problem1_graph),
         "should get right graph")
     self.assertEquals(
         g.problem_graph.source, "START",
         "Source should be START but is %s" % (g.problem_graph.source))
     self.assertEquals(
         g.problem_graph.sink, "END",
         "Source should be START but is %s" % (g.problem_graph.sink))
 def test_path_tester(self):
     g = problem_io.read_problem_from_file_of_name("test_data/test1.json")
     stats = base_types.TestStatistics()
     path_tester = non_overlapping_set_tester.NonOverlappingSetTester(g.faulty_set, stats)
     p1 = ["2","4","6"]
     p2 = ["1","4","6"]
     p3 = ["2","3","6"]
     [result] = path_tester.test_paths([p1])
     self.assertFalse(result, "For %s path test1 should give negative result" % (p1,))
     [result] = path_tester.test_paths([p2])
     self.assertTrue(result, "For %s path test1 should give positive result" % (p2,))
     [result] = path_tester.test_paths([p3])
     self.assertTrue(result, "For %s path test1 should give positive result" % (p3,))
     self.assertEquals(stats.get_var('positive'), 2, "Should be two positive queries got %d" % (stats.get_var('positive'),))
     self.assertEquals(stats.get_var('negative'), 1, "Should be one negative queries got %d" % (stats.get_var('negative'),))
     self.assertEquals(stats.get_var('all'), 3, "Should be 3 queries in total got %d" % (stats.get_var('all'),))
Exemplo n.º 6
0
 def test_simple_raw_testing_problem_is_solved_by_hamming(self):
     problem = problem_io.read_problem_from_file_of_name(
         "test_data/test_gen1.json")
     statistics = base_types.TestStatistics()
     tester = non_overlapping_set_tester.NonOverlappingSetTester(
         problem.faulty_set, statistics)
     solver = hamming_solver.HammingGroupTestingSolver(problem, tester)
     faulty_set = solver.solve()
     self.assertEquals(
         faulty_set, problem.faulty_set,
         "Should find all nodes from faulty set %s, got only %s" %
         (problem.faulty_set, faulty_set))
     self.assertEquals(
         statistics.get_var('all'), 15,
         "Should have 15 queries in total got %d" %
         (statistics.get_var('all'), ))
Exemplo n.º 7
0
 def test_brute_force_solver(self):
     g = problem_io.read_problem_from_file_of_name("test_data/test1.json")
     statistics = base_types.TestStatistics()
     tester = non_overlapping_set_tester.NonOverlappingSetTester(
         g.faulty_set, statistics)
     solver = iterative_solvers.BruteForceGCGTSolver(g, tester)
     faulty_set = solver.solve()
     self.assertEquals(
         faulty_set, g.faulty_set,
         "Should find all nodes from faulty set %s, got only %s" %
         (g.faulty_set, faulty_set))
     self.assertEquals(
         statistics.get_var('all'), 8,
         "Should have 8 queries in total got %d" %
         (statistics.get_var('all'), ))
     self.assertEquals(
         statistics.get_var('positive'), 7,
         "Should have 7 positive queries in total got %d" %
         (statistics.get_var('positive'), ))
     self.assertEquals(
         statistics.get_var('negative'), 1,
         "Should have 1 negative queries in total got %d" %
         (statistics.get_var('negative'), ))
 def test_read_problem_from_file(self):
     g = problem_io.read_problem_from_file_of_name("test_data/test1.json")
     self.assertEquals(g.faulty_set, {"1","3","5"}, "Faulty set read from problem description %s" % (g.faulty_set,))
     self.assertTrue(graph_equal(g.problem_graph.graph, self.problem1_graph), "should get right graph")
     self.assertEquals(g.problem_graph.source, "START", "Source should be START but is %s" % (g.problem_graph.source))
     self.assertEquals(g.problem_graph.sink, "END", "Source should be START but is %s" % (g.problem_graph.sink))