public
Description: PROLOG implementation for the kalah game. Created as a project for "PROLOG - aspects for AI" of the Israeli Open University
Homepage: http://www.kenegozi.com/Blog/2008/07/24/unit-testing-in-prolog.aspx
Clone URL: git://github.com/kenegozi/kalah-prolog.git
Search Repo:
is_in_range / in_range

tests fixed
kenegozi (author)
Fri Jul 25 01:19:24 -0700 2008
commit  11552929e9cf2d49d27cbc0303230f146ba1122a
tree    f03c13e47949d7088dba91253028c059e1cb930f
parent  6a6bf5095c1ca34390babb3791349beed96d4adf
...
1
2
3
4
5
6
7
8
9
10
11
12
13
 
14
15
16
17
18
19
20
 
 
 
 
 
21
22
23
24
 
 
25
26
27
 
 
28
29
30
 
 
31
32
33
 
 
34
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
37
38
...
49
50
51
52
 
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
 
 
55
56
57
...
94
95
96
97
 
98
99
100
101
102
...
109
110
111
112
 
113
114
115
116
117
...
120
121
122
123
124
 
125
126
127
128
129
130
131
 
132
133
134
...
1
2
 
3
 
4
 
5
6
7
8
9
 
10
11
 
 
 
 
 
 
12
13
14
15
16
17
18
 
 
19
20
21
 
 
22
23
24
 
 
25
26
27
 
 
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
...
64
65
66
 
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
...
133
134
135
 
136
137
 
138
139
140
...
147
148
149
 
150
151
 
152
153
154
...
157
158
159
 
 
160
161
162
163
164
165
 
 
166
167
168
 
0
@@ -1,38 +1,53 @@
0
 /***********************************************************************
0
   Program  :  Kalah game in PROLOG
0
-
0
   Written by  :  Ken Egozi
0
-
0
   File    :  test_fixtures.pl
0
-
0
   Description  :  unit tests
0
 ***********************************************************************/
0
 
0
 
0
 /***********************************************************************
0
-% utils.pl
0
+% utils/is_in_range
0
 ***********************************************************************/
0
-
0
-tests(utils/in_range, [
0
- in_range__when_given_correct_input__satisfied,
0
- in_range__when_equal_to_min__satisfied,
0
- in_range__when_equal_to_max__satisfied,
0
- in_range__when_given_out_of_range_input__dissatisfied
0
+tests(utils/is_in_range, [
0
+ is_in_range__when_given_correct_input__satisfied,
0
+ is_in_range__when_equal_to_min__satisfied,
0
+ is_in_range__when_equal_to_max__satisfied,
0
+ is_in_range__when_given_out_of_range_input__dissatisfied
0
 ]).
0
 
0
-in_range__when_given_correct_input__satisfied :-
0
- in_range(2, 1-3).
0
+is_in_range__when_given_correct_input__satisfied :-
0
+ is_in_range(2, 1-3).
0
 
0
-in_range__when_equal_to_min__satisfied :-
0
- in_range(1, 1-2).
0
+is_in_range__when_equal_to_min__satisfied :-
0
+ is_in_range(1, 1-2).
0
 
0
-in_range__when_equal_to_max__satisfied :-
0
- in_range(2, 1-2).
0
+is_in_range__when_equal_to_max__satisfied :-
0
+ is_in_range(2, 1-2).
0
 
0
-in_range__when_given_out_of_range_input__dissatisfied :-
0
- not in_range(4, 1-3).
0
+is_in_range__when_given_out_of_range_input__dissatisfied :-
0
+ not is_in_range(4, 1-3).
0
 
0
 
0
+/***********************************************************************
0
+% utils/in_range
0
+***********************************************************************/
0
+tests(utils/in_range, [
0
+ in_range__when_given_correct_input__generates,
0
+ in_range__when_given_incorrect_input__fails
0
+]).
0
+
0
+in_range__when_given_correct_input__generates :-
0
+ bagof(X, in_range(X, 1-3), Xs),
0
+ Xs = [1,2,3].
0
+
0
+in_range__when_given_incorrect_input__fails :-
0
+ not bagof(X, in_range(X, 3-1), _).
0
+
0
+
0
+/***********************************************************************
0
+% utils/create_list
0
+***********************************************************************/
0
 tests(utils/create_list, [
0
   create_list__always__creates_the_list_with_the_correct_data,
0
   create_list__always__creates_the_list_with_the_correct_length
0
@@ -49,9 +64,33 @@ create_list__always__creates_the_list_with_the_correct_length :-
0
 
0
 
0
 /***********************************************************************
0
-% moves.pl
0
+% utils/conc
0
 ***********************************************************************/
0
+tests(utils/conc, [
0
+ conc__empty_and_empty__return_empty,
0
+ conc__empty_and_nonempty__return_L2,
0
+ conc__nonempty_and_empty__return_L1,
0
+ conc__nonempty_and_nonempty__return_L1concL2
0
+]).
0
+
0
+conc__empty_and_empty__return_empty :-
0
+ conc([], [], []).
0
+
0
+conc__empty_and_nonempty__return_L2 :-
0
+ conc([], [1,2], [1,2]).
0
+
0
+conc__nonempty_and_empty__return_L1 :-
0
+ conc([1,2], [], [1,2]).
0
+
0
+conc__nonempty_and_nonempty__return_L1concL2 :-
0
+ conc([1,2], [3,4], [1,2,3,4]).
0
+
0
+
0
+
0
 
0
+/***********************************************************************
0
+% moves/change_list
0
+***********************************************************************/
0
 tests(moves/change_list, [
0
   change_list__add_first__works,
0
   change_list__add_middle__works,
0
@@ -94,9 +133,8 @@ change_list__add_last__works :-
0
 
0
 
0
 /***********************************************************************
0
-% moves.pl - move
0
+% moves/move
0
 ***********************************************************************/
0
-
0
 tests(moves/move, [
0
   move__when_ends_within_same_player_pits__works
0
 ]).
0
@@ -109,9 +147,8 @@ move__when_ends_within_same_player_pits__works :-
0
 
0
 
0
 /***********************************************************************
0
-% moves.pl - step
0
+% moves/step
0
 ***********************************************************************/
0
-
0
 tests(moves/step, [
0
   step__when_ends_within_same_player_pits__works,
0
   step__when_ends_within_next_player_pits__works
0
@@ -120,15 +157,12 @@ tests(moves/step, [
0
 step__when_ends_within_same_player_pits__works :-
0
   P1P=pits(player1,0,0,0,0),
0
   P2P=pits(player2,0,0,0,0),
0
- Last=player1/1,
0
- step(P1P/P2P, Last, 0, NewP1P/P2P, _, _),
0
+ step(P1P/P2P, player1/1, 1, NewP1P/P2P, _, _),
0
   NewP1P=pits(player1,0,1,0,0).
0
   
0
 step__when_ends_within_next_player_pits__works :-
0
   P1P=pits(player1,0,0,0,0),
0
   P2P=pits(player2,0,0,0,0),
0
- Last=player1/1,
0
- step(P1P/P2P, Last, 4, NewP1P/NewP2P, _, _),
0
+ step(P1P/P2P, player1/1, 4, NewP1P/NewP2P, _, _),
0
   NewP1P=pits(player1,0,1,1,1),
0
   NewP2P=pits(player2,1,0,0,0).
0
-
...
9
10
11
 
12
13
14
15
16
17
18
19
20
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
23
24
...
9
10
11
12
13
14
15
16
17
 
18
 
 
 
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
0
@@ -9,16 +9,27 @@
0
 ***********************************************************************/
0
 
0
 
0
+% Usage: conc(L1,L2,L1_concatenated_with_L2)
0
 conc([], L, L) :- !.
0
 conc([H|T1], L2, [H|T2]) :-
0
   conc(T1, L2, T2).
0
 
0
 % Usage: in_range(THE_INPUT, MINVALUE-MAXVALUE)
0
-% The predicate is non deterministic so do not use it in
0
 % a different manner
0
-in_range(X, Min-Max) :-
0
- X >= Min,
0
- X =< Max.
0
+is_in_range(X, LBound-UBound) :-
0
+ X >= LBound,
0
+ X =< UBound.
0
+
0
+% in_range(LBound, X, UBound)
0
+% The predicate is non deterministic so do not use it in
0
+in_range(X, X-X) :- !.
0
+in_range(X, X-UBound) :-
0
+ X < UBound.
0
+in_range(X, LBound-UBound) :-
0
+ LBound =< UBound,
0
+ NewLBound is LBound + 1,
0
+ in_range(X, NewLBound-UBound).
0
+
0
 
0
 % Useful to initialise a list with repeating values
0
 % Usage: create_list(LIST_TO_CREATE, LENGTH, VALUE_TO_PUT_IN_EACH_NODE)

Comments

    No one has commented yet.