-
Notifications
You must be signed in to change notification settings - Fork 7
/
utils_tests.pl
112 lines (92 loc) · 3.67 KB
/
utils_tests.pl
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
54
55
56
57
58
59
60
61
62
63
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/***********************************************************************
Program : Kalah game in PROLOG
Written by : Ken Egozi
File : utils_tests.pl
Description : unit tests for utils.pl
***********************************************************************/
tests_in_utils_module([
test__is_in_range,
test__in_range,
test__create_list,
test__conc,
test__copy_list_and_add
]).
/***********************************************************************
is_in_range(X,Min-Max)
***********************************************************************/
test__is_in_range__when_given_correct_input__satisfied:-
is_in_range(2, 1-3).
test__is_in_range__when_equal_to_min__satisfied:-
is_in_range(1, 1-2).
test__is_in_range__when_equal_to_max__satisfied:-
is_in_range(2, 1-2).
test__is_in_range__when_given_out_of_range_input__fails:-
not is_in_range(4, 1-3).
test__is_in_range(`is_in_range`,[
test__is_in_range__when_given_correct_input__satisfied,
test__is_in_range__when_equal_to_min__satisfied,
test__is_in_range__when_equal_to_max__satisfied,
test__is_in_range__when_given_out_of_range_input__fails
]).
/***********************************************************************
in_range(X/Min-Max)
***********************************************************************/
test__in_range__when_given_correct_input__generates:-
bagof(X, in_range(X, 1-3), Xs),
Xs = [1,2,3].
test__in_range__when_given_incorrect_input__fails:-
not bagof(X, in_range(X, 3-1), _).
test__in_range(`in_range`,[
test__in_range__when_given_correct_input__generates,
test__in_range__when_given_incorrect_input__fails
]).
/***********************************************************************
create_list(List, Length, Value)
***********************************************************************/
test__create_list__always_creates_the_list_with_the_correct_values:-
create_list(List, 3, 2),
assert_all_members_equal_to(List, 2).
test__create_list__always_creates_the_list_with_the_correct_length:-
create_list(List, 3, 2),
length(List, 3).
test__create_list(`create_list`,[
test__create_list__always_creates_the_list_with_the_correct_values,
test__create_list__always_creates_the_list_with_the_correct_length
]).
/***********************************************************************
conc/3
***********************************************************************/
test__conc__empty_and_empty_returns_empty:-
conc([], [], []).
test__conc__empty_and_nonempty_returns_L2:-
conc([], [1,2], [1,2]).
test__conc___nonempty_and_empty_returns_L1:-
conc([1,2], [], [1,2]).
test__conc__nonempty_and_nonempty_returns_L1_concatenated_with_L2:-
conc([1,2], [3,4], [1,2,3,4]).
test__conc(`conc`,[
test__conc__empty_and_empty_returns_empty,
test__conc__empty_and_nonempty_returns_L2,
test__conc___nonempty_and_empty_returns_L1,
test__conc__nonempty_and_nonempty_returns_L1_concatenated_with_L2
]).
/***********************************************************************
copy_list_and_add(List, Skip, ToAdd, NewList) conc/3
***********************************************************************/
test__copy_list_and_add__can_process_part_of_the_list:-
setof(Skip/ToAdd, (MaxToAdd/X/L/L_AsFunctor)^(
in_range(Skip, 0-3),
MaxToAdd is 4 - Skip,
in_range(ToAdd, 0-MaxToAdd),
copy_list_and_add([0,0,0,0], Skip, ToAdd, L),
L_AsFunctor =.. [list|L],
in_range(X, 1-4),
( X =< Skip,
arg(X, L_AsFunctor, 0)
;
arg(X, L_AsFunctor, 1)
)), Options),
Options = [0/1,0/2,0/3,0/4,1/0,1/1,1/2,1/3,2/0,2/1,2/2,3/0,3/1].
test__copy_list_and_add(`copy_list_and_add`,[
test__copy_list_and_add__can_process_part_of_the_list
]).