示例#1
0
文件: tqueue.c 项目: att/ast
tmain() {
    UNUSED(argc);
    UNUSED(argv);
    Dt_t *dt;

    /* testing Dtqueue */
    if (!(dt = dtopen(&Disc, Dtqueue))) terror("dtopen queue");
    if ((long)dtinsert(dt, 1L) != 1) terror("Dtqueue insert 1");
    if ((long)dtinsert(dt, 3L) != 3) terror("Dtqueue insert 3.1");
    if ((long)dtinsert(dt, 2L) != 2) terror("Dtqueue insert 2.1");
    if ((long)dtinsert(dt, 3L) != 3) terror("Dtqueue insert 3.2");
    if ((long)dtinsert(dt, 2L) != 2) terror("Dtqueue insert 2.2");
    if ((long)dtinsert(dt, 3L) != 3) terror("Dtqueue insert 3.3");

    if ((long)dtlast(dt) != 3) terror("Dtqueue dtlast");
    if ((long)dtprev(dt, 3L) != 2) terror("Dtqueue dtprev 3.3");
    if ((long)dtprev(dt, 2L) != 3) terror("Dtqueue dtprev 2.2");
    if ((long)dtprev(dt, 3L) != 2) terror("Dtqueue dtprev 3.2");
    if ((long)dtprev(dt, 2L) != 3) terror("Dtqueue dtprev 2.1");
    if ((long)dtprev(dt, 3L) != 1) terror("Dtqueue dtprev 3.1");
    if ((long)dtprev(dt, 1L) != 0) terror("Dtqueue dtprev 1");

    if ((long)dtdelete(dt, NULL) != 1) terror("Dtqueue pop 1");
    if ((long)dtdelete(dt, NULL) != 3) terror("Dtqueue delete 3.1");
    if ((long)dtdelete(dt, NULL) != 2) terror("Dtqueue delete 2");
    if ((long)dtdelete(dt, NULL) != 3) terror("Dtqueue delete 3.2");
    if ((long)dtdelete(dt, NULL) != 2) terror("Dtqueue delete 2.1");
    if ((long)dtdelete(dt, NULL) != 3) terror("Dtqueue delete 3.3");

    if (dtsize(dt) != 0) terror("Dtqueue size");

    texit(0);
}
示例#2
0
tmain()
{
	Dt_t*		dt;

	/* testing Dtstack */
	if(!(dt = dtopen(&Disc,Dtstack)) )
		terror("dtopen stack");
	if((long)dtinsert(dt,1L) != 1)
		terror("Dtstack insert 1");
	if((long)dtinsert(dt,3L) != 3)
		terror("Dtstack insert 3.1");
	if((long)dtinsert(dt,2L) != 2)
		terror("Dtstack insert 2.1");
	if((long)dtinsert(dt,3L) != 3)
		terror("Dtstack insert 3.2");
	if((long)dtinsert(dt,2L) != 2)
		terror("Dtstack insert 2.2");
	if((long)dtinsert(dt,3L) != 3)
		terror("Dtstack insert 3.3");

	if((long)dtlast(dt) != 1)
		terror("Dtstack dtlast");
	if((long)dtprev(dt,1L) != 3)
		terror("Dtstack dtprev 1");
	if((long)dtprev(dt,3L) != 2)
		terror("Dtstack dtprev 3.1");
	if((long)dtprev(dt,2L) != 3)
		terror("Dtstack dtprev 2.1");
	if((long)dtprev(dt,3L) != 2)
		terror("Dtstack dtprev 3.2");
	if((long)dtprev(dt,2L) != 3)
		terror("Dtstack dtprev 2.2");
	if((long)dtprev(dt,3L) != 0)
		terror("Dtstack dtprev 3.2");

	if((long)dtdelete(dt,NIL(Void_t*)) != 3)
		terror("Dtstack pop 3.3");

	/* search to one of the 3 */
	if((long)dtsearch(dt,3L) != 3)
		terror("Dtstack search 3.2");
	if((long)dtdelete(dt,3L) != 3)
		terror("Dtstack delete 3.2");

	if((long)dtdelete(dt,NIL(Void_t*)) != 2)
		terror("Dtstack pop 2.2");
	if((long)dtdelete(dt,NIL(Void_t*)) != 2)
		terror("Dtstack pop 2.1");
	if((long)dtdelete(dt,NIL(Void_t*)) != 3)
		terror("Dtstack pop 3.1");
	if((long)dtdelete(dt,NIL(Void_t*)) != 1)
		terror("Dtstack pop 1");

	if(dtsize(dt) != 0)
		terror("Dtstack size");

	texit(0);
}
示例#3
0
main()
{
	Dt_t*		dt;

	/* testing Dtqueue */
	if(!(dt = dtopen(&Disc,Dtqueue)) )
		terror("dtopen queue");
	if((long)dtinsert(dt,1L) != 1)
		terror("Dtqueue insert 1");
	if((long)dtinsert(dt,3L) != 3)
		terror("Dtqueue insert 3.1");
	if((long)dtinsert(dt,2L) != 2)
		terror("Dtqueue insert 2.1");
	if((long)dtinsert(dt,3L) != 3)
		terror("Dtqueue insert 3.2");
	if((long)dtinsert(dt,2L) != 2)
		terror("Dtqueue insert 2.2");
	if((long)dtinsert(dt,3L) != 3)
		terror("Dtqueue insert 3.3");

	if((long)dtlast(dt) != 3)
		terror("Dtqueue dtlast");
	if((long)dtprev(dt,3L) != 2)
		terror("Dtqueue dtprev 3.3");
	if((long)dtprev(dt,2L) != 3)
		terror("Dtqueue dtprev 2.2");
	if((long)dtprev(dt,3L) != 2)
		terror("Dtqueue dtprev 3.2");
	if((long)dtprev(dt,2L) != 3)
		terror("Dtqueue dtprev 2.1");
	if((long)dtprev(dt,3L) != 1)
		terror("Dtqueue dtprev 3.1");
	if((long)dtprev(dt,1L) != 0)
		terror("Dtqueue dtprev 1");

	if((long)dtdelete(dt,NIL(Void_t*)) != 1)
		terror("Dtqueue pop 1");
	if((long)dtdelete(dt,NIL(Void_t*)) != 3)
		terror("Dtqueue delete 3.1");
	if((long)dtdelete(dt,NIL(Void_t*)) != 2)
		terror("Dtqueue delete 2");
	if((long)dtdelete(dt,NIL(Void_t*)) != 3)
		terror("Dtqueue delete 3.2");
	if((long)dtdelete(dt,NIL(Void_t*)) != 2)
		terror("Dtqueue delete 2.1");
	if((long)dtdelete(dt,NIL(Void_t*)) != 3)
		terror("Dtqueue delete 3.3");

	if(dtsize(dt) != 0)
		terror("Dtqueue size");

	return 0;
}
示例#4
0
tmain()
{
	Dt_t		*dt;
	Dtstat_t	stat;
	Obj_t		*p, *o, *obj, proto;
	char		*name;
	long		i, k, mid, n_mid, n_obj, meth;

	/* construct repetitive objects */
	for(i = 0; i < N_OBJ; i += R_OBJ)
	{	for(k = 0; k < R_OBJ; ++k)
		{	Obj[i+k].key = i;
			Obj[i+k].ord = k;
		}
	}

	for(meth = 0; meth < 4; ++meth)
	{	switch(meth)
		{ case 0:
			name = "Dtobag";
			if(!(dt = dtopen(&Disc, Dtobag)) )
				terror("%s: Can't open dictionary", name);
			break;
		  case 1:
			name = "Dtbag";
			if(!(dt = dtopen(&Disc, Dtbag)) )
				terror("%s: Can't open dictionary", name);
			break;
		  case 2:
			name = "Dtrhbag";
			if(!(dt = dtopen(&Disc, Dtrhbag)) )
				terror("%s: Can't open dictionary", name);
			break;
		  case 3:
			name = "Dtlist";
			if(!(dt = dtopen(&Disc, Dtlist)) )
				terror("%s: Can't open dictionary", name);
			break;
		  default: terror("Unknown storage method");
			break;
		}
		tinfo("Testing method %s:", name);
		dtcustomize(dt, DT_SHARE, 1); /* make it more interesting */

		/* add all objects into dictionary */
		for(k = 0; k < R_OBJ; ++k)
		for(i = 0; i < N_OBJ/R_OBJ; ++i)
		{	obj = Obj + i*R_OBJ + k;
			o = (meth == 3 || i%2 == 0) ? dtappend(dt,obj) : dtinsert(dt,obj);
			if(o != obj)
				terror("%s: dtappend (key=%d,ord=%d) failed", name, obj->key, obj->ord);
		}

		mid = ((N_OBJ/R_OBJ)/2) * R_OBJ; /* key for middle group */
		proto.key = mid;
		proto.ord = -1;

		if(meth == 3) /* testing ATMOST/ATLEAST for Dtlist */
		{	/* note that dtappend() was used to keep objects in order of insertion */
			if(!(o = dtatmost(dt, &proto)) )
				terror("%s: dtatmost (key=%d) failed", name, mid);
			if(o->ord != 0)
				terror("%s: dtatmost (key=%d) but ord=%d > 0", name, o->key, o->ord);

			if(!(o = dtatleast(dt, &proto)) )
				terror("%s: dtatleast (key=%d) failed", name, mid);
			if(o->ord != R_OBJ-1)
				terror("%s: dtatleast (key=%d) but ord=%d > 0", name, o->key, o->ord);

			n_obj = 0; /* test ordering */
			for(p = NIL(Obj_t*), o = dtfirst(dt); o; p = o, o = dtnext(dt,o) )
			{	n_obj += 1;
				if(p && p->ord > o->ord)
					terror("%s: objects not ordered correctly p=%d > o=%d",
						name, p->ord, o->ord);
			}
			if(n_obj != N_OBJ)
				terror("%s: Bad object count %d != %d", n_obj, N_OBJ);
		}

		if(meth == 0) /* testing ordering properties of Dtobag */
		{	
			n_obj = 0; /* test atmost/next */
			for(o = dtatmost(dt, &proto); o; o = dtnext(dt,o) )
			{	if(o->key == mid)
					n_obj += 1;
				else	break;
			}
			if(n_obj != R_OBJ)
				terror("%s: dtatmost/dtnext count n_obj=%d != %d", name, n_obj, R_OBJ);

			n_obj = 0; /* test atleast/prev */
			for(o = dtatleast(dt, &proto); o; o = dtprev(dt,o) )
			{	if(o->key == mid)
					n_obj += 1;
				else	break;
			}
			if(n_obj != R_OBJ)
				terror("%s: dtatleast/dtprev count n_obj=%d != %d", name, n_obj, R_OBJ);

			n_obj = 0; /* test linear order */
			for(p = NIL(Obj_t*), o = dtfirst(dt); o; p = o, o = dtnext(dt,o) )
			{	n_obj += 1;
				if(p && p->key > o->key)
					terror("%s: objects not ordered correctly p=%d > o=%d",
						name, p->key, o->key);
			}
			if(n_obj != N_OBJ)
				terror("%s: Bad object count %d != %d", n_obj, N_OBJ);
		}

		n_mid = n_obj = 0; /* walk forward and count objects */
		for(o = dtfirst(dt); o; o = dtnext(dt,o))
		{	n_obj += 1;
			if(o->key == mid)
				n_mid += 1;
		}
		if(n_obj != N_OBJ)
			terror("%s: Walk forward n_obj=%d != %d", name, n_obj, N_OBJ);
		if(n_mid != R_OBJ)
			terror("%s: Walk forward n_mid=%d != %d", name, n_mid, R_OBJ);

		n_mid = n_obj = 0; /* walk backward and count objects */
		for(o = dtlast(dt); o; o = dtprev(dt,o))
		{	n_obj += 1;
			if(o->key == mid)
				n_mid += 1;
		}
		if(n_obj != N_OBJ)
			terror("%s: Walk backward n_obj=%d != %d", name, n_obj, N_OBJ);
		if(n_mid != R_OBJ)
			terror("%s: Walk backward n_mid=%d != %d", name, n_mid, R_OBJ);

		n_mid = n_obj = 0; /* walk flattened list and count objects */
		for(o = (Obj_t*)dtflatten(dt); o; o = (Obj_t*)dtlink(dt,o) )
		{	n_obj += 1;
			if(o->key == mid)
				n_mid += 1;
		}
		if(n_obj != N_OBJ)
			terror("%s: Walk flattened list n_obj=%d != %d", name, n_obj, N_OBJ);
		if(n_mid != R_OBJ)
			terror("%s: Walk flattened list n_mid=%d != %d", name, n_mid, R_OBJ);

		n_mid = 0; /* delete a bunch of objects */
		for(i = 0; i < N_OBJ-1; i += R_OBJ)
		{	obj = Obj + i + R_OBJ/2; /* use the one in the middle of group */

			if((o = dtremove(dt, obj)) == obj )
				n_mid += 1;
			else	terror("%s: dtremove (key=%d,ord=%d) wrongly yielded (key=%d,ord=%d)",
					name, obj->key, obj->ord, o->key, o->ord);

			if((o = dtremove(dt, obj)) != NIL(Obj_t*) )
				terror("%s: dtremove (key=%d,ord=%d) wrongly yielded (key=%d,ord=%d)",
					name, obj->key, obj->ord, o->key, o->ord);

			if((o = dtdelete(dt, obj)) != NIL(Obj_t*) )
				n_mid += 1;
			else	terror("%s: dtdelete matching object to (key=%d,ord=%d) failed",
					name, obj->key, obj->ord);
		}
示例#5
0
tmain()
{
	Dt_t*		dt;

	/* testing Dtlist */
	if(!(dt = dtopen(&Disc,Dtlist)) )
		terror("dtopen list");
	if((long)dtinsert(dt,1L) != 1)
		terror("Dtlist insert 1");
	if((long)dtappend(dt,2L) != 2)
		terror("Dtlist append 2");
	if((long)dtappend(dt,3L) != 3)
		terror("Dtlist append 3");
	if((long)dtappend(dt,1L) != 1)
		terror("Dtlist append 1");
	if((long)dtappend(dt,2L) != 2)
		terror("Dtlist append 2");
	if((long)dtappend(dt,3L) != 3)
		terror("Dtlist append 3");

	if((long)dtlast(dt) != 3)
		terror("Dtlist dtlast");
	if((long)dtprev(dt,3L) != 2)
		terror("Dtlist dtprev 2");
	if((long)dtprev(dt,2L) != 1)
		terror("Dtlist dtprev 1");
	if((long)dtprev(dt,1L) != 3)
		terror("Dtlist dtprev 3");
	if((long)dtprev(dt,3L) != 2)
		terror("Dtlist dtprev 2");
	if((long)dtprev(dt,2L) != 1)
		terror("Dtlist dtprev 1");

	/* search to the first 3 */
	if((long)dtfirst(dt) != 1)
		terror("Dtlist dtfirst 1");
	if((long)dtsearch(dt,3L) != 3)
		terror("Dtlist search 3");
	if((long)dtinsert(dt,4L) != 4)
		terror("Dtlist insert 4");
	if((long)dtnext(dt,4L) != 3)
		terror("Dtlist next 3");
	if((long)dtappend(dt,5L) != 5)
		terror("Dtlist append 5");

	if((long)dtfirst(dt) != 1)
		terror("Dtlist dtfirst 1");
	if((long)dtnext(dt,1L) != 2)
		terror("Dtlist next 2");
	if((long)dtnext(dt,2L) != 4)
		terror("Dtlist next 4");
	if((long)dtnext(dt,4L) != 3)
		terror("Dtlist next 3");
	if((long)dtnext(dt,3L) != 5)
		terror("Dtlist next 5");
	if((long)dtnext(dt,5L) != 1)
		terror("Dtlist next 1");
	if((long)dtnext(dt,1L) != 2)
		terror("Dtlist next 2");
	if((long)dtnext(dt,2L) != 3)
		terror("Dtlist next 3");

	texit(0);
}