|
1 | 1 | /*********************************************************************** |
2 | 2 | Program : Kalah game in PROLOG |
3 | | -
|
4 | 3 | Written by : Ken Egozi |
5 | | - |
6 | 4 | File : test_fixtures.pl |
7 | | -
|
8 | 5 | Description : unit tests |
9 | 6 | ***********************************************************************/ |
10 | 7 |
|
11 | 8 |
|
12 | 9 | /*********************************************************************** |
13 | | -% utils.pl |
| 10 | +% utils/is_in_range |
14 | 11 | ***********************************************************************/ |
15 | | - |
16 | | -tests(utils/in_range, [ |
17 | | - in_range__when_given_correct_input__satisfied, |
18 | | - in_range__when_equal_to_min__satisfied, |
19 | | - in_range__when_equal_to_max__satisfied, |
20 | | - in_range__when_given_out_of_range_input__dissatisfied |
| 12 | +tests(utils/is_in_range, [ |
| 13 | + is_in_range__when_given_correct_input__satisfied, |
| 14 | + is_in_range__when_equal_to_min__satisfied, |
| 15 | + is_in_range__when_equal_to_max__satisfied, |
| 16 | + is_in_range__when_given_out_of_range_input__dissatisfied |
21 | 17 | ]). |
22 | 18 |
|
23 | | -in_range__when_given_correct_input__satisfied :- |
24 | | - in_range(2, 1-3). |
| 19 | +is_in_range__when_given_correct_input__satisfied :- |
| 20 | + is_in_range(2, 1-3). |
25 | 21 |
|
26 | | -in_range__when_equal_to_min__satisfied :- |
27 | | - in_range(1, 1-2). |
| 22 | +is_in_range__when_equal_to_min__satisfied :- |
| 23 | + is_in_range(1, 1-2). |
28 | 24 |
|
29 | | -in_range__when_equal_to_max__satisfied :- |
30 | | - in_range(2, 1-2). |
| 25 | +is_in_range__when_equal_to_max__satisfied :- |
| 26 | + is_in_range(2, 1-2). |
31 | 27 |
|
32 | | -in_range__when_given_out_of_range_input__dissatisfied :- |
33 | | - not in_range(4, 1-3). |
| 28 | +is_in_range__when_given_out_of_range_input__dissatisfied :- |
| 29 | + not is_in_range(4, 1-3). |
34 | 30 |
|
35 | 31 |
|
| 32 | +/*********************************************************************** |
| 33 | +% utils/in_range |
| 34 | +***********************************************************************/ |
| 35 | +tests(utils/in_range, [ |
| 36 | + in_range__when_given_correct_input__generates, |
| 37 | + in_range__when_given_incorrect_input__fails |
| 38 | +]). |
| 39 | + |
| 40 | +in_range__when_given_correct_input__generates :- |
| 41 | + bagof(X, in_range(X, 1-3), Xs), |
| 42 | + Xs = [1,2,3]. |
| 43 | + |
| 44 | +in_range__when_given_incorrect_input__fails :- |
| 45 | + not bagof(X, in_range(X, 3-1), _). |
| 46 | + |
| 47 | + |
| 48 | +/*********************************************************************** |
| 49 | +% utils/create_list |
| 50 | +***********************************************************************/ |
36 | 51 | tests(utils/create_list, [ |
37 | 52 | create_list__always__creates_the_list_with_the_correct_data, |
38 | 53 | create_list__always__creates_the_list_with_the_correct_length |
|
49 | 64 |
|
50 | 65 |
|
51 | 66 | /*********************************************************************** |
52 | | -% moves.pl |
| 67 | +% utils/conc |
53 | 68 | ***********************************************************************/ |
| 69 | +tests(utils/conc, [ |
| 70 | + conc__empty_and_empty__return_empty, |
| 71 | + conc__empty_and_nonempty__return_L2, |
| 72 | + conc__nonempty_and_empty__return_L1, |
| 73 | + conc__nonempty_and_nonempty__return_L1concL2 |
| 74 | +]). |
| 75 | + |
| 76 | +conc__empty_and_empty__return_empty :- |
| 77 | + conc([], [], []). |
| 78 | + |
| 79 | +conc__empty_and_nonempty__return_L2 :- |
| 80 | + conc([], [1,2], [1,2]). |
| 81 | + |
| 82 | +conc__nonempty_and_empty__return_L1 :- |
| 83 | + conc([1,2], [], [1,2]). |
| 84 | + |
| 85 | +conc__nonempty_and_nonempty__return_L1concL2 :- |
| 86 | + conc([1,2], [3,4], [1,2,3,4]). |
| 87 | + |
| 88 | + |
| 89 | + |
54 | 90 |
|
| 91 | +/*********************************************************************** |
| 92 | +% moves/change_list |
| 93 | +***********************************************************************/ |
55 | 94 | tests(moves/change_list, [ |
56 | 95 | change_list__add_first__works, |
57 | 96 | change_list__add_middle__works, |
|
94 | 133 |
|
95 | 134 |
|
96 | 135 | /*********************************************************************** |
97 | | -% moves.pl - move |
| 136 | +% moves/move |
98 | 137 | ***********************************************************************/ |
99 | | - |
100 | 138 | tests(moves/move, [ |
101 | 139 | move__when_ends_within_same_player_pits__works |
102 | 140 | ]). |
|
109 | 147 |
|
110 | 148 |
|
111 | 149 | /*********************************************************************** |
112 | | -% moves.pl - step |
| 150 | +% moves/step |
113 | 151 | ***********************************************************************/ |
114 | | - |
115 | 152 | tests(moves/step, [ |
116 | 153 | step__when_ends_within_same_player_pits__works, |
117 | 154 | step__when_ends_within_next_player_pits__works |
|
120 | 157 | step__when_ends_within_same_player_pits__works :- |
121 | 158 | P1P=pits(player1,0,0,0,0), |
122 | 159 | P2P=pits(player2,0,0,0,0), |
123 | | - Last=player1/1, |
124 | | - step(P1P/P2P, Last, 0, NewP1P/P2P, _, _), |
| 160 | + step(P1P/P2P, player1/1, 1, NewP1P/P2P, _, _), |
125 | 161 | NewP1P=pits(player1,0,1,0,0). |
126 | 162 |
|
127 | 163 | step__when_ends_within_next_player_pits__works :- |
128 | 164 | P1P=pits(player1,0,0,0,0), |
129 | 165 | P2P=pits(player2,0,0,0,0), |
130 | | - Last=player1/1, |
131 | | - step(P1P/P2P, Last, 4, NewP1P/NewP2P, _, _), |
| 166 | + step(P1P/P2P, player1/1, 4, NewP1P/NewP2P, _, _), |
132 | 167 | NewP1P=pits(player1,0,1,1,1), |
133 | 168 | NewP2P=pits(player2,1,0,0,0). |
134 | | - |
|
0 commit comments