-
Notifications
You must be signed in to change notification settings - Fork 21
/
dict_put_dotcall_testing.pl
54 lines (39 loc) · 1.97 KB
/
dict_put_dotcall_testing.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
% ==========
% Demonstrating/Testing SWI-Prolog dicts as described at
% https://eu.swi-prolog.org/pldoc/man?section=bidicts
% ==========
% ===
% This plunit block tests/demonstrates the .put/1 dotcall.
% ===
:- begin_tests(dict_put_dotcall).
% Helper: "Dict" is an empty dict with tag "Tag"
empty_dict(Tag,Dict) :-
dict_pairs(Dict,Tag,[]).
% Helper: "Dict" is a dict with some content and with tag "Tag"
nonempty_dict(Tag,Dict) :-
dict_pairs(Dict,Tag,[a-x,b-y,c-z]).
test(".put/1 dotcall: add nothing, using empty dict",true(DictNext == foo{})) :-
empty_dict(foo,DictCur),
DictNext = DictCur.put(_{}).
test(".put/1 dotcall: add nothing, using empty list",true(DictNext == foo{})) :-
empty_dict(foo,DictCur),
DictNext = DictCur.put([]).
test(".put/1 dotcall: add/replace something using 'list of pairs'",true(DictNext == foo{a:2,b:y,c:z,d:1})) :-
nonempty_dict(foo,DictCur),
DictNext = DictCur.put([a-2,d-1]).
test(".put/1 dotcall: add/replace something using 'list of : separated pairs'",true(DictNext == foo{a:2,b:y,c:z,d:1})) :-
nonempty_dict(foo,DictCur),
DictNext = DictCur.put([a:2,d:1]).
test(".put/1 dotcall: add/replace something using 'list of = separated_pairs'",true(DictNext == foo{a:2,b:y,c:z,d:1})) :-
nonempty_dict(foo,DictCur),
DictNext = DictCur.put([a=2,d=1]).
test(".put/1 dotcall: add/replace something using 'list of tagged values'",true(DictNext == foo{a:2,b:y,c:z,d:1})) :-
nonempty_dict(foo,DictCur),
DictNext = DictCur.put([a(2),d(1)]).
test(".put/1 dotcall: add/replace something using 'dict'",true(DictNext == foo{a:2,b:y,c:z,d:1})) :-
nonempty_dict(foo,DictCur),
DictNext = DictCur.put(_{a:2,d:1}).
test(".put/1 dotcall: add/replace something using 'dict with different tag'",true(DictNext == foo{a:2,b:y,c:z,d:1})) :-
nonempty_dict(foo,DictCur),
DictNext = DictCur.put(bar{a:2,d:1}). % tag value doesn't change anything
:- end_tests(dict_put_dotcall).