for (i=0;i<N;i++) {
pvec[i].x[0]=myran.doub();
pvec[i].x[1]=myran.doub();
}
Minspantree minspan=new Minspantree(pvec);
localflag = (minspan.nspan != N-1);
globalflag = globalflag || localflag;
if (localflag) {
fail("*** Minspantree: Incorrect number of elements in tree");
}
// Check whether minspantree segments are in order of size
for (i=0;i<minspan.nspan-1;i++) {
localflag = dist(pvec[minspan.minsega[i]],pvec[minspan.minsegb[i]])
> dist(pvec[minspan.minsega[i+1]],pvec[minspan.minsegb[i+1]]);
globalflag = globalflag || localflag;
if (localflag) {
fail("*** Minspantree: Segments of tree are not in order of length");
}
}
// Check whether every point is actually in the tree
// (i.e. whether the combination of all minsega and minsegb
// include all numbers from 1 to N
int[] flags=new int[N];
for (i=0;i<minspan.nspan;i++) {
flags[minspan.minsega[i]]++;
flags[minspan.minsegb[i]]++;
}
min=1;
for (i=0;i<N;i++)
if (flags[i] < min) min=flags[i];
localflag = (min == 0);
globalflag = globalflag || localflag;
if (localflag) {
fail("*** Minspantree: One or more points do not appear in the tree");
}
// Put same points in a reversed order
for (i=0;i<N;i++) {
qvec[N-1-i].x[0]=pvec[i].x[0];
qvec[N-1-i].x[1]=pvec[i].x[1];
}
Minspantree minspan2=new Minspantree(qvec);
localflag = (minspan2.nspan != N-1);
globalflag = globalflag || localflag;
if (localflag) {
fail("*** Minspantree: Incorrect number of elements in second tree");