2
2
3
3
from queen_attack import Queen
4
4
5
-
6
5
# Tests adapted from `problem-specifications//canonical-data.json` @ v2.3.0
7
6
8
- class QueenAttackTest (unittest .TestCase ):
9
7
8
+ class QueenAttackTest (unittest .TestCase ):
10
9
# Test creation of Queens with valid and invalid positions
11
- def test_queen_valid_position (self ):
12
- try :
13
- Queen (2 , 2 )
14
- except ValueError :
15
- self .fail ("Unexpected Exception" )
10
+ def test_queen_with_a_valid_position (self ):
11
+ Queen (2 , 2 )
16
12
17
- def test_queen_negative_row (self ):
13
+ def test_queen_must_have_positive_row (self ):
18
14
with self .assertRaisesWithMessage (ValueError ):
19
15
Queen (- 2 , 2 )
20
16
21
- def test_queen_invalid_row (self ):
17
+ def test_queen_must_have_row_on_board (self ):
22
18
with self .assertRaisesWithMessage (ValueError ):
23
19
Queen (8 , 4 )
24
20
25
- def test_queen_negative_column (self ):
21
+ def test_queen_must_have_positive_column (self ):
26
22
with self .assertRaisesWithMessage (ValueError ):
27
23
Queen (2 , - 2 )
28
24
29
- def test_queen_invalid_column (self ):
25
+ def test_queen_must_have_column_on_board (self ):
30
26
with self .assertRaisesWithMessage (ValueError ):
31
27
Queen (4 , 8 )
32
28
33
29
# Test the ability of one queen to attack another
34
- def test_attack_false (self ):
30
+ def test_can_not_attack (self ):
35
31
self .assertIs (Queen (2 , 4 ).can_attack (Queen (6 , 6 )), False )
36
32
37
- def test_attack_same_row (self ):
33
+ def test_can_attack_on_same_row (self ):
38
34
self .assertIs (Queen (2 , 4 ).can_attack (Queen (2 , 6 )), True )
39
35
40
- def test_attack_same_column (self ):
36
+ def test_can_attack_on_same_column (self ):
41
37
self .assertIs (Queen (4 , 5 ).can_attack (Queen (2 , 5 )), True )
42
38
43
- def test_attack_diagonal1 (self ):
39
+ def test_can_attack_on_first_diagonal (self ):
44
40
self .assertIs (Queen (2 , 2 ).can_attack (Queen (0 , 4 )), True )
45
41
46
- def test_attack_diagonal2 (self ):
42
+ def test_can_attack_on_second_diagonal (self ):
47
43
self .assertIs (Queen (2 , 2 ).can_attack (Queen (3 , 1 )), True )
48
44
49
- def test_attack_diagonal3 (self ):
45
+ def test_can_attack_on_third_diagonal (self ):
50
46
self .assertIs (Queen (2 , 2 ).can_attack (Queen (1 , 1 )), True )
51
47
52
- def test_attack_diagonal4 (self ):
48
+ def test_can_attack_on_fourth_diagonal (self ):
53
49
self .assertIs (Queen (1 , 7 ).can_attack (Queen (0 , 6 )), True )
54
50
55
51
# Track-specific tests
@@ -62,5 +58,5 @@ def assertRaisesWithMessage(self, exception):
62
58
return self .assertRaisesRegex (exception , r".+" )
63
59
64
60
65
- if __name__ == ' __main__' :
61
+ if __name__ == " __main__" :
66
62
unittest .main ()
0 commit comments