def test_parseInputReturnsTheCorrectSetOfVertices(self):
        num_test_points = len(self.TEST_POINTS)
        input_dictionary = {}
        for i in range(0, num_test_points):
            input_dictionary[i] = self.TEST_POINTS[i]

        (actual_v, actual_e) = parse_input(input_dictionary)
        for i in range(0, num_test_points):
            self.assertTrue(i in actual_v)
    def test_verticesContainTheXYCoordinates(self):
        num_test_points = len(self.TEST_POINTS)
        input_dictionary = self.getTestInputDictionary()
        (actual_v, actual_e) = parse_input(input_dictionary)

        for key in actual_v:
            (expected_x, expected_y) = input_dictionary[key]
            (actual_x, actual_y) = actual_v[key]
            self.assertEqual(expected_x, actual_x)
            self.assertEqual(expected_y, actual_y)
    def test_parseInputReturnsEdgesWhichContainTheSourceTargetAndDistance(self):
        num_test_points = len(self.TEST_POINTS)
        input_dictionary = {}
        for i in range(0, num_test_points):
            input_dictionary[i] = self.TEST_POINTS[i]

        (actual_v, actual_e) = parse_input(input_dictionary)

        for i in range(0, num_test_points):
            for j in range(0, num_test_points):
                if i != j:
                    expected_key = (i, j)
                    expected_value = get_distance(self.TEST_POINTS[i], self.TEST_POINTS[j])
                    self.assertEqual(expected_value, actual_e[expected_key])
    def test_parseInputReturnsCompleteGraphVE(self):
        num_test_points = len(self.TEST_POINTS)
        input_dictionary = {}
        for i in range(0, num_test_points):
            input_dictionary[i] = self.TEST_POINTS[i]

        (actual_v, actual_e) = parse_input(input_dictionary)

        exp_num_v = num_test_points
        # an edge in each direction for each non-matching pair of vertexes
        exp_num_e = 2 * (exp_num_v * (exp_num_v - 1)) / 2

        act_num_v = len(actual_v)
        act_num_e = len(actual_e)

        self.assertEqual(exp_num_v, act_num_v)
        self.assertEqual(exp_num_e, act_num_e)
Beispiel #5
0
    def load(self):
        io_start = time.clock()

        try:
            self.input_file_name = get_input_file_name()
        except InvalidInputException as e:
            print "Error: %s" % str(e)
            exit(1)

        input_dictionary = FileReader(self.input_file_name).get_input()

        io_stop = time.clock()
        print "%f seconds to do file input operations" % (io_stop - io_start)

        parse_start = time.clock()
        self.graph = parse_input(input_dictionary)
        parse_stop = time.clock()
        print "%f seconds to parse graph edges" % (parse_stop - parse_start)
 def test_parseInputTakesADictionaryAndReturnsATupleOfTwoDictionaries(self):
     actual = parse_input({})
     assert isinstance(actual, tuple)
     (dict1, dict2) = actual
     assert isinstance(dict1, dict)
     assert isinstance(dict2, dict)