예제 #1
0
 def test_incorrect_clicked_cell(self):
     wrong_inputx = "Not a number"
     wrong_inputy = -1
     expected_output = None
     self.assertRaises(
         ValueError, lambda: playingField.PlayingField().get_clicked_cell(
             wrong_inputx, wrong_inputy))
     self.assertEqual(
         expected_output,
         playingField.PlayingField().get_clicked_cell(
             wrong_inputy, wrong_inputy))
예제 #2
0
 def test_correct_change_cell_type(self):
     field = playingField.PlayingField()
     input_id = 1
     input_cell = "Circle"
     expected_output = variables.CellStatus.Circle
     self.assertEqual(expected_output,
                      field.change_cell_type(input_id, input_cell).status)
예제 #3
0
 def test_correct_get_empty_cells(self):
     field = playingField.PlayingField()
     expected_output = variables.DEFAULT_FIELD_SIZE**2
     expected_output_2 = expected_output - 1
     self.assertEqual(expected_output, len(field.get_empty_cells()))
     field.change_cell_type(1, "Circle")
     self.assertEqual(expected_output_2, len(field.get_empty_cells()))
예제 #4
0
 def test_correct_clicked_cell(self):
     correct_input_x = correct_input_y = 1
     expected_output = True
     cell = playingField.PlayingField().get_clicked_cell(
         correct_input_x, correct_input_y)
     self.assertEqual(
         expected_output,
         cell.is_click_inside(correct_input_x, correct_input_y))
예제 #5
0
 def test_incorrect_get_cell_by_id(self):
     incorrect_input_1 = -1
     incorrect_input_2 = "Not a number"
     field = playingField.PlayingField()
     expected_output = None
     self.assertEqual(expected_output,
                      field.get_cell_by_id(incorrect_input_1))
     self.assertRaises(ValueError,
                       lambda: field.get_cell_by_id(incorrect_input_2))
예제 #6
0
 def test_correct_get_cell_by_x_y(self):
     correct_inputx = correct_inputy = 1
     field = playingField.PlayingField()
     self.assertEqual(
         correct_inputx,
         field.get_cell_by_x_y(correct_inputx, correct_inputy).x)
     self.assertEqual(
         correct_inputy,
         field.get_cell_by_x_y(correct_inputx, correct_inputy).y)
예제 #7
0
 def test_correct_check_decreasing_diagonal(self):
     field = playingField.PlayingField()
     expected_output = []
     self.assertEqual(expected_output, EndValidator._check_decreasing_diagonal(field, variables.DEFAULT_FIELD_SIZE))
     field.initialize_field(3)
     c1 = field.change_cell_type(0, "Cross")
     c2 = field.change_cell_type(4, "Cross")
     c3 = field.change_cell_type(8, "Cross")
     expected_output = [c1, c2, c3]
     self.assertEqual(expected_output, EndValidator._check_decreasing_diagonal(field, 3))
예제 #8
0
 def test_incorrect_check_decreasing_diagonal(self):
     field = playingField.PlayingField()
     incorrect_input = "Not a number"
     expected_output = variables.DEFAULT_FIELD_SIZE
     result = EndValidator._check_decreasing_diagonal(field, variables.DEFAULT_FIELD_SIZE)
     self.assertNotEqual(expected_output, len(result))
     self.assertRaises(ValueError, lambda: EndValidator._check_decreasing_diagonal(field, incorrect_input))
     field.initialize_field(3)
     field.change_cell_type(0, "Cross")
     field.change_cell_type(4, "Cross")
     field.change_cell_type(8, "Circle")
     expected_output = []
     self.assertEqual(expected_output, EndValidator._check_decreasing_diagonal(field, variables.DEFAULT_FIELD_SIZE))
예제 #9
0
 def test_incorrect_get_cell_by_x_y(self):
     incorrect_inputx = incorrect_inputy = 1
     x = y = -1
     x_1 = y_1 = "Not a number"
     field = playingField.PlayingField()
     expected_value = 2
     expected_value_2 = None
     self.assertNotEqual(
         expected_value,
         field.get_cell_by_x_y(incorrect_inputx, incorrect_inputy).x)
     self.assertNotEqual(
         expected_value,
         field.get_cell_by_x_y(incorrect_inputx, incorrect_inputy).y)
     self.assertEqual(expected_value_2, field.get_cell_by_x_y(x, y))
     self.assertRaises(ValueError, lambda: field.get_cell_by_x_y(x_1, y_1))
예제 #10
0
    def test_incorrect_check_line(self):
        field = playingField.PlayingField()
        field.initialize_field(3)
        incorrect_input_1 = "Not a number"
        self.assertRaises(ValueError, lambda: EndValidator._check_line(field, incorrect_input_1, 1))
        self.assertRaises(ValueError, lambda: EndValidator._check_line(field, 1, incorrect_input_1))

        def _fill_line_wrong(line):
            c1 = field.change_cell_type(0 + line * 3, "Cross")
            c2 = field.change_cell_type(1 + line * 3, "Circle")
            c3 = field.change_cell_type(2 + line * 3, "Cross")
            return [c1, c2, c3]

        self.assertNotEqual(_fill_line_wrong(0), EndValidator._check_line(field, 3, 0))
        self.assertNotEqual(_fill_line_wrong(1), EndValidator._check_line(field, 3, 1))
        self.assertNotEqual(_fill_line_wrong(2), EndValidator._check_line(field, 3, 2))
예제 #11
0
 def test_correct_win(self):
     field = playingField.PlayingField()
     field.initialize_field(3)
     c1 = field.change_cell_type(0, "Cross")
     c2 = field.change_cell_type(1, "Cross")
     c3 = field.change_cell_type(2, "Cross")
     correct_columns = 3
     correct_input_1 = []
     correct_input_2 = [c1]
     correct_input_3 = [c1, c2]
     correct_input_4 = [c1, c2, c3]
     expected_output_true = True
     expected_output_false = False
     self.assertEqual(expected_output_false, EndValidator._win(correct_input_1, correct_columns))
     self.assertEqual(expected_output_false, EndValidator._win(correct_input_2, correct_columns))
     self.assertEqual(expected_output_false, EndValidator._win(correct_input_3, correct_columns))
     self.assertEqual(expected_output_true, EndValidator._win(correct_input_4, correct_columns))
예제 #12
0
    def test_correct_check_for_the_end(self):
        field = playingField.PlayingField()
        field.initialize_field(3)
        c1 = field.get_cell_by_id(0)
        expected_output = None
        self.assertEqual(expected_output, EndValidator.check_for_the_end(field, c1))

        def _fill_line(line):
            field.change_cell_type(0 + line * 3, "Cross")
            field.change_cell_type(1 + line * 3, "Cross")
            field.change_cell_type(2 + line * 3, "Cross")

        _fill_line(0), _fill_line(1), _fill_line(2)  # fill the entire grid
        self.assertEqual(3, len(EndValidator.check_for_the_end(field, field.get_cell_by_id(0))))
        self.assertEqual(3, len(EndValidator.check_for_the_end(field, field.get_cell_by_id(0))))
        self.assertEqual(3, len(EndValidator.check_for_the_end(field, field.get_cell_by_id(0))))
        self.assertEqual(3, len(EndValidator.check_for_the_end(field, field.get_cell_by_id(2))))
예제 #13
0
 def test_incorrect_change_cell_type(self):
     field = playingField.PlayingField()
     input_id_1 = "Wrong input"
     input_cell_1 = "Circle"
     input_id_2 = 1
     input_cell_2 = "Not a shape"
     expected_output_1 = False
     expected_output_2 = variables.CellStatus.Cross
     expected_output_3 = variables.CellStatus.Empty
     self.assertRaises(
         ValueError,
         lambda: field.change_cell_type(input_id_1, input_cell_1))
     self.assertEqual(expected_output_1,
                      field.change_cell_type(input_id_2, input_cell_2))
     self.assertNotEqual(
         expected_output_2,
         field.change_cell_type(input_id_2, input_cell_1).status)
     self.assertNotEqual(
         expected_output_3,
         field.change_cell_type(input_id_2, input_cell_1).status)
예제 #14
0
    def test_correct_check_column(self):
        field = playingField.PlayingField()
        field.initialize_field(3)
        expected_output = []
        result_1 = EndValidator._check_column(field, 3, 0)
        result_2 = EndValidator._check_column(field, 3, 1)
        result_3 = EndValidator._check_column(field, 3, 2)
        self.assertEqual(expected_output, result_1)
        self.assertEqual(expected_output, result_2)
        self.assertEqual(expected_output, result_3)

        def _fill_column(column):
            c1 = field.change_cell_type(column, "Cross")
            c2 = field.change_cell_type(column + 3, "Cross")
            c3 = field.change_cell_type(column + 6, "Cross")
            return [c1, c2, c3]

        self.assertEqual(_fill_column(0), EndValidator._check_column(field, 3, 0))
        self.assertEqual(_fill_column(1), EndValidator._check_column(field, 3, 1))
        self.assertEqual(_fill_column(2), EndValidator._check_column(field, 3, 2))
예제 #15
0
 def __init__(self, name1, name2):
     self.playing_field = playingField.PlayingField()
     self.gui = gui.Board(self)
     self.gui.bottom_frame.set_player_names(name1, name2)
     self.multi_player = None
예제 #16
0
 def test_incorrect_init(self):
     incorrect_input = "Not a number"
     self.assertRaises(
         ValueError, lambda: playingField.PlayingField().initialize_field(
             incorrect_input))
예제 #17
0
 def test_correct_init(self):
     expected_value_after_initialization = {
     }  # if it would be different it is ok
     self.assertNotEqual(expected_value_after_initialization,
                         playingField.PlayingField().field_cells)
예제 #18
0
 def test_incorrect_get_number_of_cells(self):
     field = playingField.PlayingField()
     expected_output = 0
     self.assertNotEqual(expected_output, field.get_number_of_cells())
예제 #19
0
 def test_correct_get_number_of_cells(self):
     field = playingField.PlayingField()
     expected_output = variables.DEFAULT_FIELD_SIZE**2
     self.assertEqual(expected_output, field.get_number_of_cells())
예제 #20
0
 def test_correct_get_cell_by_id(self):
     correct_input = 1
     field = playingField.PlayingField()
     self.assertEqual(correct_input,
                      field.get_cell_by_id(correct_input).cell_id)