[Index for tmp_for_tar/misc]
[Return to Master Index]
test_connect
(tmp_for_tar/misc/test_connect.m)
Help text
test that connect() works
WARNING : Errors may be reported even if result is correct because
correct result is defined up to ordering and correctness is checked by
comparing result with a particular correct result
Last modified: April 2001
Cross-Reference Information
This calls
- sayif tmp_for_tar/misc/sayif.m
Listing of file tmp_for_tar/misc/test_connect.m
##
## test that connect() works
##
## WARNING : Errors may be reported even if result is correct because
## correct result is defined up to ordering and correctness is checked by
## comparing result with a particular correct result
## Author: Etienne Grossmann <etienne@isr.ist.utl.pt>
## Last modified: April 2001
ok = 1;
if ! exist ("verbose"), verbose = 0; end
if ! exist ("inspect"), inspect = 0; end
sayif (verbose, "Testing the function 'connect'\n");
cnt = 0;
good = 0;
# 1
[l,ii] = connect ([1],[2],[2 7 5],[1 3],[4 6 8 2]);
l0 = list ([1,3], [2,4,5,6,7,8]);
cnt++;
if length (l) != length (l0),
ok = 0;
sayif (verbose, "not ok %3i (length of result)\n",cnt);
if inspect, keyboard; end
else
for i = 1:length (l)
a = nth (l0,i);
b = nth (l,i);
ok0 = 1;
if any (size (a) != size (b)),
ok0 = ok = 0;
sayif (verbose, "not ok %3i (size of set %i)\n",cnt,i);
if inspect, keyboard; end
elseif any (a(:) != b(:)),
ok0 = ok = 0;
if inspect, keyboard; end
sayif (verbose, "not ok %3i (values of set %i)\n",cnt,i);
end
end
sayif (verbose && ok0, "ok %3i\n",cnt);
if ok0, good++ ; end
end
# 2
[l,ii]= connect ([1],[2],[2 7 5],[1 3],[4 6 8 2],[1 2]);
l0 = list ([1,2,3,4,5,6,7,8]);
cnt++;
if length (l) != length (l0),
ok = 0;
sayif (verbose, "not ok %3i (length of result)\n",cnt);
if inspect, keyboard; end
else
for i = 1:length (l)
a = nth (l0,i);
b = nth (l,i);
ok0 = 1;
if any (size (a) != size (b)),
ok0 = ok = 0;
sayif (verbose, "not ok %3i (size of set %i)\n",cnt,i);
if inspect, keyboard; end
elseif any (a(:) != b(:)),
ok0 = ok = 0;
sayif (verbose, "not ok %3i (values of set %i)\n",cnt,i);
if inspect, keyboard; end
end
end
sayif (verbose && ok0, "ok %3i\n",cnt);
if ok0, good++ ; end
end
# 3
[l,ii]= connect (list([1],[2],[2 7 5],[1 3],[4 6 8 2],[1 2]));
l0 = list ([1,2,3,4,5,6,7,8]);
cnt++;
if length (l) != length (l0),
ok = 0;
sayif (verbose, "not ok %3i (length of result)\n",cnt);
if inspect, keyboard; end
else
for i = 1:length (l)
a = nth (l0,i);
b = nth (l,i);
ok0 = 1;
if any (size (a) != size (b)),
ok0 = ok = 0;
sayif (verbose, "not ok %3i (size of set %i)\n",cnt,i);
if inspect, keyboard; end
elseif any (a(:) != b(:)),
ok0 = ok = 0;
sayif (verbose, "not ok %3i (values of set %i)\n",cnt,i);
if inspect, keyboard; end
end
end
sayif (verbose && ok0, "ok %3i\n",cnt);
if ok0, good++ ; end
end
# 4
[l,ii]= connect (list ([1],[2],[2 7 5]), [1 3],list ([4 6 8 2],[1 2]));
l0 = list ([1,2,3,4,5,6,7,8]);
cnt++;
if length (l) != length (l0),
ok = 0;
sayif (verbose, "not ok %3i (length of result)\n",cnt);
else
for i = 1:length (l)
a = nth (l0,i);
b = nth (l,i);
ok0 = 1;
if any (size (a) != size (b)),
ok0 = ok = 0;
sayif (verbose, "not ok %3i (size of set %i)\n",cnt,i);
if inspect, keyboard; end
elseif any (a(:) != b(:)),
ok0 = ok = 0;
sayif (verbose, "not ok %3i (values of set %i)\n",cnt,i);
if inspect, keyboard; end
end
end
sayif (verbose && ok0, "ok %3i\n",cnt);
if ok0, good++ ; end
end
# 5
[l,ii]= connect (list ([1,2],[3,4],[5,6]),[4,5],list ([2,3],[7,8]));
l0 = list ([1,2,3,4,5,6],[7,8]);
cnt++;
if length (l) != length (l0),
ok = 0;
sayif (verbose, "not ok %3i (length of result)\n",cnt);
if inspect, keyboard; end
else
for i = 1:length (l)
a = nth (l0,i);
b = nth (l,i);
ok0 = 1;
if any (size (a) != size (b)),
ok0 = ok = 0;
sayif (verbose, "not ok %3i (size of set %i)\n",cnt,i);
if inspect, keyboard; end
elseif any (a(:) != b(:)),
ok0 = ok = 0;
sayif (verbose, "not ok %3i (values of set %i)\n",cnt,i);
if inspect, keyboard; end
end
end
sayif (verbose && ok0, "ok %3i\n",cnt);
if ok0, good++ ; end
end
# Create random sets
ntest = 10;
nsets = 10;
maxsetlen = 5;
maxsetval = ceil (nsets^2/2);
for i = 1:ntest
ll = list ();
for j = 1:nsets
len = ceil (maxsetlen*rand(1));
ll(j) = floor (maxsetval*rand(1,len));
end
# Compute intersection of sets
inters = zeros (nsets);
for j = 2:nsets
for k = j+1:nsets
inters(j,k) = ! isempty (intersection (nth (ll,j), nth(ll,k)));
end
inters += inters' + eye(nsets);
end
[l,ii] = connect (ll);
cnt++;
ok0 = 1;
# Check that rows(ii) == length(l) and
# columns(ii) == length (ll)
if rows(ii) != length (l) || columns (ii) != length (ll)
sayif (verbose, "not ok %3i sizes of l, ll and ii\n",cnt);
if inspect, keyboard; end
ok0 = 0;
end
# Check l for disjunction
inter2 = zeros (nsets);
for j = 2:length(l)
for k = j+1:length(l)
inter2(j,k) = ! isempty (intersection (nth (l,j), nth(l,k)));
end
end
inter2 += inter2 ;
if any (inter2(:)),
sayif (verbose, "not ok %3i (intersecting sets in result)\n",cnt);
if inspect, keyboard; end
ok0 = 0;
end
# Check l for abusive gluing of sets
for i = 1:rows(ii)
jj = find(ii(i,:));
if ! all (any (inters(jj,jj)))
sayif (verbose, "not ok %3i (abusive gluing of sets)\n",cnt);
if inspect, keyboard; end
ok0 = 0;
end
end
if ! ok0, ok = 0; end
good += ok0;
sayif (verbose && ok0, "ok %3i\n",cnt);
end
if verbose,
printf ("test_connect : %i out of %i tests are successful\n",good,cnt);
end
Produced by oct2html on Sat Apr 28 21:14:54 2001
Cross-Directory links are: ON