예제 #1
0
    def test_can_object_be_placed(self):
        _board_object = FitBoard(5, 10)
        _side_a = ((1, 0), (1, 0), (1, 1), (1, 0))
        _side_b = ((1, 0), (1, 1), (1, 1), (1, 0))
        _fit_object = FitObject(_side_a, _side_b)
        _board_object.add_object(_fit_object, 0, 0)
        self.assertFalse(_board_object.can_object_be_placed(_fit_object, 0, 0))
        self.assertFalse(_board_object.can_object_be_placed(_fit_object, 1, 0))
        self.assertTrue(_board_object.can_object_be_placed(_fit_object, 2, 0))
        self.assertTrue(_board_object.can_object_be_placed(_fit_object, 3, 0))
        self.assertTrue(_board_object.can_object_be_placed(_fit_object, 4, 0))
        self.assertFalse(_board_object.can_object_be_placed(_fit_object, 9, 0))
        self.assertFalse(_board_object.can_object_be_placed(_fit_object, 0, 4))
        _side_a_2 = ((1, 1), (1, 1), (0, 1), (1, 1))
        _side_b_2 = ((1, 0), (1, 1), (1, 1), (1, 0))
        _fit_object_2 = FitObject(_side_a_2, _side_b_2)
        _board_object.add_object(_fit_object_2, 1, 0)
        _expected_board = [[1, 1, 1, 0, 0, 0, 0, 0, 0, 0],
                           [1, 1, 1, 0, 0, 0, 0, 0, 0, 0],
                           [1, 1, 1, 0, 0, 0, 0, 0, 0, 0],
                           [1, 1, 1, 0, 0, 0, 0, 0, 0, 0],
                           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
        self._test_matrix(_board_object.board, _expected_board)
        self.assertEqual(2, len(_board_object.objects_list))

        with self.assertRaises(Exception) as _ex:
            _board_object.add_object(_fit_object_2, 1, 0)

        self.assertEqual(
            _ex.exception.args[0],
            'Object can\'t be placed on board with coordinates 1, 0')
        print(_board_object.objects_list)
예제 #2
0
 def test_rotate_left(self):
     _side_a = ((1, 0), (1, 0), (1, 1), (1, 0))
     _side_b = ((1, 0), (1, 1), (1, 1), (1, 0))
     _side_a_rotated = ((0, 0, 1, 0), (1, 1, 1, 1))
     _side_b_rotated = ((0, 1, 1, 0), (1, 1, 1, 1))
     _object = FitObject(_side_a, _side_b)
     _object.rotate_left()
     self.assertTupleEqual(_side_a_rotated, _object.side_a)
     self.assertTupleEqual(_side_b_rotated, _object.side_b)
예제 #3
0
 def test_switch_active_side(self):
     _side_a = ((1, 0), (1, 0), (1, 1), (1, 0))
     _side_b = ((1, 0), (1, 1), (1, 1), (1, 0))
     _object = FitObject(_side_a, _side_b)
     self.assertTupleEqual(_side_a, _object.active_side)
     self.assertEqual('a', _object.active_side_name)
     _object.switch_active_side()
     self.assertTupleEqual(_side_b, _object.active_side)
     self.assertEqual('b', _object.active_side_name)
예제 #4
0
    def test_add_object(self):
        _board_object = FitBoard(5, 10)
        _side_a = ((1, 0), (1, 0), (1, 1), (1, 0))
        _side_b = ((1, 0), (1, 1), (1, 1), (1, 0))
        _fit_object = FitObject(_side_a, _side_b)
        _board_object.add_object(_fit_object, 0, 0)
        _expected_board = [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                           [1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                           [1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
                           [1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                           [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
        self._test_matrix(_board_object.board, _expected_board)

        _fit_object.switch_active_side()
        self.assertEqual('b', _fit_object.active_side_name)
        self.assertEqual(1, len(_board_object.objects_list))
        self.assertEqual(
            'a', _board_object.objects_list[0].fit_object.active_side_name)
예제 #5
0
 def test_rotate_left_4_times(self):
     _side_a = ((1, 0), (1, 0), (1, 1), (1, 0))
     _side_b = ((1, 0), (1, 1), (1, 1), (1, 0))
     _object = FitObject(_side_a, _side_b)
     _object.rotate_left()
     _object.rotate_left()
     _object.rotate_left()
     _object.rotate_left()
     self.assertTupleEqual(_side_a, _object.side_a)
     self.assertTupleEqual(_side_b, _object.side_b)
예제 #6
0
 def test_create_object(self):
     FitObject(((1, 0), (1, 0), (1, 1), (1, 0)),
               ((1, 0), (1, 1), (1, 1), (1, 0)))