def test_new_line_horizontal(self): line = Line(Point(3, 5), Point(8, 5)) self.assertEqual(line.direction, 'HORIZONTAL') self.assertEqual(line.min_x, 3) self.assertEqual(line.max_x, 8) self.assertEqual(line.min_y, 5) self.assertEqual(line.max_y, 5)
def test_new_line_vertical(self): line = Line(Point(10, 3), Point(10, 10)) self.assertEqual(line.direction, 'VERTICAL') self.assertEqual(line.min_x, 10) self.assertEqual(line.max_x, 10) self.assertEqual(line.min_y, 3) self.assertEqual(line.max_y, 10)
def test_cut_lines(self): hor = Line(Point(3, 5), Point(8, 5)) ver = Line(Point(6, 3), Point(6, 10)) cut_point = hor.intersected_by(ver) self.assertEqual(cut_point.isExist(), True) self.assertEqual(cut_point.x, 6) self.assertEqual(cut_point.y, 5)
def getSize(): #Возвращает значимые параметры bmp из файла с его размерами. with open("size.txt", 'r') as f: arr = np.asfarray(f.readlines(), float) f.close() listOfObjects = Point() listOfObjects.i = arr[0] listOfObjects.j = arr[1] return listOfObjects
def test_long_path(self): start_time = datetime.datetime.now() shortest_path = self.cavern.path_length(Point(2, 2), Point(53, 3)) end_time = datetime.datetime.now() expected_result = PathStep(51, Point(3, 2)) self.assertEqual(shortest_path, expected_result) running_time = (end_time - start_time).total_seconds() time_threshold_seconds = 1 self.assertTrue( running_time <= time_threshold_seconds, msg= "Test did not complete in a reasonable time ({threshold} seconds). {elapsed} seconds elapsed." .format(threshold=time_threshold_seconds, elapsed=running_time))
def setUp(self): app.config.from_pyfile('test_config.py') self.test_point = Point(pointName="test", pointLatitude=0., pointLongitude=0.) db.create_all() self.client = app.test_client()
def test_full_round_equal_distance(self): self.cavern_2.step(1) # Check all the units moved correctly self.assertIsNone(self.cavern_2.unit_at(Point(4, 1))) self.assertTrue(type(self.cavern_2.unit_at(Point(4, 2))) == Goblin) self.assertIsNone(self.cavern_2.unit_at(Point(1, 4))) self.assertTrue(type(self.cavern_2.unit_at(Point(2, 4))) == Goblin) self.assertIsNone(self.cavern_2.unit_at(Point(4, 4))) self.assertTrue(type(self.cavern_2.unit_at(Point(4, 3))) == Elf) # Now check that all the units (apart from the first Goblin) have 200 HP self.assertTrue(self.cavern_2.unit_at(Point(4, 2)).hp == 197) self.assertTrue(self.cavern_2.unit_at(Point(2, 4)).hp == 200) self.assertTrue(self.cavern_2.unit_at(Point(4, 3)).hp == 200)
def test_is_Between_horizontal(self): pointA = Point(3, 5) pointB = Point(5, 5) pointC = Point(8, 5) bIsBetween = pointB.isBetween(pointA, pointC) self.assertEqual(bIsBetween, True) aIsBetween = pointA.isBetween(pointB, pointC) self.assertEqual(aIsBetween, False)
def test_is_Between_vertical(self): pointA = Point(10, 3) pointB = Point(10, 7) pointC = Point(10, 10) bIsBetween = pointB.isBetween(pointA, pointC) self.assertEqual(bIsBetween, True) aIsBetween = pointA.isBetween(pointB, pointC) self.assertEqual(aIsBetween, False)
def test_part_two(self): TestData = namedtuple("TestData", "wire_one,wire_two,expected") inputs = [ TestData( ["R75", "D30", "R83", "U83", "L12", "D49", "R71", "U7", "L72"], ["U62", "R66", "U55", "R34", "D71", "R55", "D58", "R83"], 610, ), TestData( [ "R98", "U47", "R26", "D63", "R33", "U87", "L62", "D20", "R33", "U53", "R51", ], [ "U98", "R91", "D20", "R16", "D67", "R40", "U7", "R15", "U6", "R7" ], 410, ), TestData(["R8", "U5", "L5", "D3"], ["U7", "R6", "D4", "L4"], 30), ] for data in inputs: with self.subTest(data=data): points1 = generate_points(Point(0, 0), data.wire_one) points2 = generate_points(Point(0, 0), data.wire_two) intersections = get_intersections(points1, points2) assert data.expected == part_two(intersections, points1, points2)
def test_path_with_overlapping_paths(self): shortest_path_forward = self.cavern.path_length( Point(1, 6), Point(4, 8)) expected_result_forward = PathStep(4, Point(2, 6)) shortest_path_backward = self.cavern.path_length( Point(4, 8), Point(1, 6)) expected_result_backward = PathStep(4, Point(3, 8)) self.assertEqual(shortest_path_forward, expected_result_forward) self.assertEqual(shortest_path_backward, expected_result_backward)
def test_4th_5th_lines(): points = [ Point(10, 1), Point(10, 2), Point(10, 3), Point(11, 4), Point(11, 5), Point(11, 6) ] manager = Manager(points) manager.process() assert 2 == manager.count_line()
def test_2nd_3rd_lines(): points = [ Point(7, 1), Point(7, 2), Point(8, 3), Point(8, 4), Point(9, 5), Point(9, 6) ] manager = Manager(points) manager.process() assert 2 == manager.count_line()
def test_first_line(): points = [ Point(1, 1), Point(2, 2), Point(3, 3), Point(4, 4), Point(5, 5), Point(6, 6) ] manager = Manager(points) manager.process() assert 1 == manager.count_line()
def test_nextPoint_with_0_0(self): centralPoint = Point(0, 0) nxPoint = centralPoint.nextPoint('R8') self.assertEqual(nxPoint.x, 8) self.assertEqual(nxPoint.y, 0) nxPoint = centralPoint.nextPoint('U5') self.assertEqual(nxPoint.x, 0) self.assertEqual(nxPoint.y, 5) nxPoint = centralPoint.nextPoint('L8') self.assertEqual(nxPoint.x, -8) self.assertEqual(nxPoint.y, 0) nxPoint = centralPoint.nextPoint('D5') self.assertEqual(nxPoint.x, 0) self.assertEqual(nxPoint.y, -5)
def test_number_of_steps(self): point = Point(3, 3) points1 = generate_points(Point(0, 0), ["R8", "U5", "L5", "D3"]) expected = 20 actual = steps_taken(point, points1) assert expected == actual points2 = generate_points(Point(0, 0), ["U7", "R6", "D4", "L4"]) actual = steps_taken(point, points2) assert expected == actual point = Point(6, 5) points1 = generate_points(Point(0, 0), ["R8", "U5", "L5", "D3"]) expected = 15 actual = steps_taken(point, points1) assert expected == actual points2 = generate_points(Point(0, 0), ["U7", "R6", "D4", "L4"]) actual = steps_taken(point, points2) assert expected == actual
def test_periphery_of_larger_room(self): x = Room(Point(0,0), 3, 3) p = list(x.periphery()) expected = 8 # should be 3 at top, 3 at bottom, and 2 at middle (center point isn't peripheral) self.assertEqual(expected, len(p), "Too many points counted as periphery")
def test_periphery(self): x = Room(Point(0, 0), 2, 5) expected = { Point(0,0), Point(1,0), Point(0,1), Point(1,1), Point(0,2), Point(1,2), Point(0,3), Point(1,3), Point(0,4), Point(1,4) } self.assertSetEqual(expected, set(x.periphery()))
def test_clear(self): point = Point(3, 56, '6') point.clear() self.assertEqual(point.symbol, ' ')
def test_move(self): self.assertRaises(ValueError, Point(1, 0, 'd').move, 1, Directions.top) point = Point(1, 0, 'd') point.move(1, Directions.bottom) self.assertEqual(point, Point(1, 1, 'd'))
def test_path_with_unit_obstruction(self): shortest_path = self.cavern.path_length(Point(6, 2), Point(6, 4)) expected_result = PathStep(5, Point(7, 2)) self.assertEqual(shortest_path, expected_result)
def test_valid_route_with_two_paths(self): shortest_path = self.cavern.path_length(Point(1, 1), Point(4, 1)) expected_result = PathStep(6, Point(2, 1)) self.assertEqual(shortest_path, expected_result)
def test_empty_path(self): shortest_path = self.cavern.path_length(Point(2, 3), Point(4, 2)) expected_result = PathStep(2, Point(3, 3)) self.assertEqual(shortest_path, expected_result)
def test_is_rb(self): tr = Triangle(Point(0, 0), Point(3, 0), Point(0, 3)) self.assertTrue(tr.is_rb()) tr = Triangle(Point(4.5, 4.5), Point(3, 0), Point(0, 3)) self.assertTrue(tr.is_rb()) tr = Triangle(Point(0, 0), Point(0, 0), Point(0, 0)) self.assertFalse(tr.is_rb()) tr = Triangle(Point(0, 1.23), Point(0, 1.23), Point(0, 6)) self.assertFalse(tr.is_rb()) tr = Triangle(Point(0, 1), Point(0, 3), Point(0, 6)) self.assertFalse(tr.is_rb())
def test_periphery_of_ten_by_ten_room(self): x = Room(Point(0,0), 10, 10) p = set(x.periphery()) expected = 10 + (2*8) + 10 self.assertEqual(expected, len(p), "Unexpected number of periphery points") self.assertIn((0,1), p)
def test_add(self): self.assertEqual(Point(2, 3) + Point(3, 3), (5, 6)) self.assertEqual(Point(2.5, 3.0) + Point(1.2, 3.2), (3.7, 6.2)) self.assertEqual(Point(-2, -3) + Point(2, 3), (0, 0))
def test_is_triangle(self): tr = Triangle(Point(0, 0), Point(0, 3), Point(4, 0)) self.assertTrue(tr.is_triangle()) tr = Triangle(Point(0, 0), Point(0, 3), Point(10, 0)) self.assertTrue(tr.is_triangle()) tr = Triangle(Point(0, 1.5), Point(3, 0), Point(1.5, 1)) self.assertTrue(tr.is_triangle()) tr = Triangle(Point(0, 1), Point(0, 3), Point(0, 6)) self.assertFalse(tr.is_triangle()) tr = Triangle(Point(0, 1.23), Point(0, 1.23), Point(0, 6)) self.assertFalse(tr.is_triangle()) tr = Triangle(Point(0, 0), Point(0, 0), Point(0, 0)) self.assertFalse(tr.is_triangle())
def test_path_unreachable_because_unit(self): shortest_path = self.cavern.path_length(Point(10, 3), Point(12, 3)) expected_result = None self.assertEqual(shortest_path, expected_result)
def test_square(self): tr = Triangle(Point(0, 1), Point(0, 3), Point(0, 6)) self.assertEqual(tr.square(), -1) tr = Triangle(Point(0, 0), Point(3, 0), Point(0, 3)) self.assertEqual(tr.square(), 4.5) tr = Triangle(Point(0, 0), Point(10.1, 0), Point(0, 10.1)) self.assertEqual(tr.square(), 51.005) tr = Triangle(Point(0, 0), Point(0, 0), Point(0, 0)) self.assertEqual(tr.square(), -1) tr = Triangle(Point(0, 1.23), Point(0, 1.23), Point(0, 6)) self.assertEqual(tr.square(), -1) tr = Triangle(Point(0, 1), Point(0, 3), Point(0, 6)) self.assertEqual(tr.square(), -1)
def test_path_ends_on_wall(self): shortest_path = self.cavern.path_length(Point(2, 1), Point(2, 0)) expected_result = None self.assertEqual(shortest_path, expected_result)
def test_str(self): tr = Triangle(Point(0, 0), Point(3, 0), Point(0, 3)) self.assertEqual(str(tr), "0 0 3 0 0 3")
def test_path_ends_on_unit(self): shortest_path = self.cavern.path_length(Point(1, 2), Point(1, 1)) expected_result = PathStep(0, Point(1, 1)) self.assertEqual(shortest_path, expected_result)