def test_update_color(self): circle1 = Circle(2, 50, 100, violet) circle2 = Circle(2, 50, 150, violet) circle2.add_bridge(circle1, 2) circle1.update_color() circle2.update_color() print(circle2.conections) print(circle2.value) self.assertEqual(circle1.color, max_circle) self.assertEqual(circle2.color, max_circle)
def test_if_remove_is_not_enough(self): list_bridge = list() list_circle = list() for i in range(2): list_circle.append(Circle(2, i * 100 + 50, 50, violet)) list_bridge.append(Bridge(list_circle[0], list_circle[1], violet, 1)) self.assertEqual(if_remove(list_bridge, list_circle[0], list_circle[1]), (False, 0))
def test_is_finish_true(self): list_circle = list() for i in range(3): list_circle.append(Circle(2, i * 100 + 50, i * 100 + 50, violet)) for i in range(3): list_circle[i].conections = list_circle[i].value self.assertTrue(is_finished(list_circle))
def test_if_remove_true(self): list_bridge = list() list_circle = list() for i in range(2): list_circle.append(Circle(2, i * 100 + 50, 50, violet)) list_bridge.append(Bridge(list_circle[0], list_circle[1], violet, 2)) self.assertEqual(if_remove(list_bridge, list_circle[0], list_circle[1]), (True, 0))
def test_check_one_bridge(self): list_circle = list() for i in range(2): list_circle.append(Circle(2, i * 100 + 50, 50, violet)) list_circle[0].close_neighbors.append(list_circle[1]) list_circle[1].close_neighbors.append(list_circle[0]) check(list_circle, self.game) self.assertEqual(self.game.board.user_list_bridge[0].number, 1)
def test_check_remove(self): list_circle = list() for i in range(2): list_circle.append(Circle(2, i * 100 + 50, 50, violet)) list_circle[0].close_neighbors.append(list_circle[1]) list_circle[1].close_neighbors.append(list_circle[0]) self.game.board.user_list_bridge.append(Bridge(list_circle[0], list_circle[1], violet, 2)) check(list_circle, self.game) self.assertEqual(len(self.game.board.user_list_bridge), 0)
def test_clear_bridges_two(self): list_bridge = list() list_circle = list() for i in range(2): list_circle.append(Circle(2, i * 100 + 50, 50, violet)) list_bridge.append(Bridge(list_circle[0], list_circle[1], violet, 2)) list_circle[0].add_bridge(list_circle[1], 2) clear_bridges(list_bridge) self.assertEqual(list_bridge[0].circle1.conections, 0) self.assertEqual(list_bridge[0].circle2.conections, 0)
def recognize_txt(file): """ Recognition from txt. It scales distance between each pair of circles :return: list of circles """ circle_list = list() with open(file) as file: lines = file.readlines() lenght_y = len(lines) jump_y = 500 / lenght_y for i, line in enumerate(lines): line = line.strip('\n') l = line.split(";") lenght_x = len(l) jump_x = 600 / lenght_x for j, chars in enumerate(l): if chars != 'x': circle_list.append(Circle(int(chars), j * int(jump_x) + 50, i * int(jump_y) + 50, circle_violet)) return circle_list
def recognize(file): """ Recognition from png :return: list of circle """ z = file img = cv2.imread(z, 0) img = cv2.medianBlur(img, 5) cimg = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR) circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, 1, 50, param1=100, param2=15, minRadius=10, maxRadius=30) circles = np.uint16(np.around(circles)) circle_list = list() list_value = number_recognition(file) for i in circles[0, :]: cv2.circle(cimg, (i[0], i[1]), i[2], (0, 255, 0), 2) cv2.circle(cimg, (i[0], i[1]), 2, (0, 0, 255), 3) circle_list.append(Circle(0, i[0], i[1], circle_violet)) for i in range(len(list_value)): circle_list[i].value = list_value[i] return circle_list
def test_change_color(self): circle = Circle(2, 50, 100, red) circle.change_color(violet) self.assertTrue(circle.color, violet)
def test_add_bridge(self): circle1 = Circle(2, 50, 100, violet) circle2 = Circle(3, 50, 150, violet) circle1.add_bridge(circle2, 2) self.assertTrue(circle1.conections, 2) self.assertTrue(circle2.conections, 2)
def test_if_remove_lack_of_bridge(self): list_bridge = list() list_circle = list() for i in range(2): list_circle.append(Circle(2, i * 100 + 50, 50, violet)) self.assertEqual(if_remove(list_bridge, list_circle[0], list_circle[1]), (False, 0))
def test_is_in_false(self): list_bridge = list() list_circle = list() for i in range(2): list_circle.append(Circle(2, i * 100 + 50, 50, violet)) self.assertEqual(is_in(list_bridge, list_circle[0], list_circle[1]), (False, 0))
def test_is_finish_false(self): list_circle = list() for i in range(3): list_circle.append(Circle(2, i * 100 + 50, i * 100 + 50, violet)) self.assertFalse(is_finished(list_circle))