Re: Useful failures for set inequality in plunit

Ross Boylan <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <1376194417.4084.54.camel@localhost>
On Sat, 2013-08-10 at 17:21 -0700, Ross Boylan wrote:
> 
> 2) It would be more useful to have the shorter output of values
> expected
> and not found, and then values found but not expected.  The test could
> code that, but is there a more elegant approach?
> 
> I suppose I could compute the asymmetric differences in the code and
> then make the true option for the test work in terms of those
> differences.  But it still seems a bit manual. 
Here's what that looks like:
<code>
% return asymmetric set differences
% inputs are an expected list
% and an actual ordered set
% real_vs_ideal(+Actual, +Expected, -real_ideal(JustActual,
JustExpected))
real_vs_ideal(Actual, Expected, real_ideal(JustActual, JustExpected)) :-
	is_ordset(Actual),
	list_to_ord_set(Expected, ExpectedSet),
	ord_subtract(Actual, ExpectedSet, JustActual),
	ord_subtract(ExpectedSet, Actual, JustExpected).

test(content1, [true(X == real_ideal([], []))]) :-
	content_ancestors(path(['ossecond1', 'archive']), when(date(2011, 6,
1), seq(10)), Graph),
	graph_ordered_nodes(Graph, ActualNodes),
	% It's not clear if /home/ross should be here, but algorithm currently
includes it.
	% xda1 is also marginal
	real_vs_ideal(ActualNodes,
		      [xdb1, xda2, xda1, path(['osfirst1', 'home']), path(['osfirst1',
'home', 'ross']),
		       path(['osfirst1', 'mnt']), path(['osfirst1', 'sillyfile']),
path(['ossecond1', 'archive'])],
		      X).
</code>

<output>
ERROR: /home/ross/disks/rulesTest.plt:69:
	test content1: wrong answer (compared using ==)
ERROR:     Expected: real_ideal([],[])
ERROR:     Got:      real_ideal([path([osfirst1,oldhome])],[xda1])
</output>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.