• R/O
  • HTTP
  • SSH
  • HTTPS

transunit: Commit

Transunit repository


Commit MetaInfo

Revision865e339a6fca16c69f61781378c5187a8b182789 (tree)
Zeit2019-09-12 14:15:51
AutorAlaskanEmily <emily@alas...>
CommiterAlaskanEmily

Log Message

Add support for std pair's in comparison tests

Ändern Zusammenfassung

Diff

--- a/transunit.compare.m
+++ b/transunit.compare.m
@@ -30,6 +30,7 @@
3030
3131 :- use_module bool.
3232 :- use_module rbtree.
33+:- use_module pair.
3334 :- use_module array.
3435 :- use_module array2d.
3536 :- use_module set.
@@ -41,6 +42,7 @@
4142 :- instance to_string(float).
4243 :- instance to_string(bool.bool).
4344 :- instance to_string(maybe.maybe(T)) <= to_string(T).
45+:- instance to_string(pair.pair(A, B)) <= (to_string(A), to_string(B)).
4446
4547 %------------------------------------------------------------------------------%
4648
@@ -53,6 +55,7 @@
5355 :- instance compare(float).
5456 :- instance compare(bool.bool).
5557 :- instance compare(maybe.maybe(T)) <= (to_string(T), compare(T)).
58+:- instance compare(pair.pair(A, B)) <= (to_string(A), to_string(B), compare(A), compare(B)).
5659 :- instance compare(array.array(T)) <= (to_string(T), compare(T)).
5760 :- instance compare(array2d.array2d(T)) <= (to_string(T), compare(T)).
5861 :- instance compare(maybe.maybe_error(T, E))
@@ -142,6 +145,13 @@
142145 (to_string(maybe.no) = "maybe.no")
143146 ].
144147
148+:- instance to_string(pair.pair(A, B)) <= (to_string(A), to_string(B)) where [
149+ to_string(P) =
150+ string.append(string.append(
151+ to_string(pair.fst(P)), " - "),
152+ to_string(pair.snd(P)))
153+].
154+
145155 %------------------------------------------------------------------------------%
146156
147157 generic_compare(A, B) = Result :-
@@ -250,6 +260,48 @@ accumulate_mismatch(A, B, !List, I, int.plus(I, 1)) :-
250260 ( compare(maybe.yes(A), maybe.yes(B)) = compare(A, B) )
251261 ].
252262
263+:- instance compare(pair.pair(A, B)) <= (to_string(A), to_string(B), compare(A), compare(B)) where [
264+ ( compare(A, B) = Result :-
265+ A1 = pair.fst(A),
266+ B1 = pair.fst(B),
267+ A2 = pair.snd(A),
268+ B2 = pair.snd(B),
269+
270+ compare(A1, B1) = Cmp1,
271+ compare(A2, B2) = Cmp2,
272+ (
273+ Cmp1 = maybe.ok,
274+ (
275+ Cmp2 = maybe.ok,
276+ Result = maybe.ok
277+ ;
278+ Cmp2 = maybe.error(Err),
279+ Result = maybe.error(string.append(string.append(string.append(
280+ to_string(A), " != "),
281+ " For second element:"),
282+ Err))
283+ )
284+ ;
285+ Cmp1 = maybe.error(Err1),
286+ (
287+ Cmp2 = maybe.ok,
288+ Result = maybe.error(string.append(string.append(string.append(
289+ to_string(A), " != "),
290+ " For first element:"),
291+ Err1))
292+ ;
293+ Cmp2 = maybe.error(Err2),
294+ string.first_char(Err2Tail, ',', Err2),
295+ Result = maybe.error(string.append(string.append(string.append(string.append(
296+ to_string(A), " != "),
297+ " For both elements element:"),
298+ Err1),
299+ Err2Tail))
300+ )
301+ )
302+ )
303+].
304+
253305 :- instance compare(array.array(T)) <= (to_string(T), compare(T)) where [
254306 ( compare(A, B) = Result :-
255307 array.size(A, ALen), array.size(B, BLen),
Show on old repository browser