tsearch.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1999-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#include "dttest.h"
{ 0, sizeof(long), -1,
};
{ 0, sizeof(long), -1,
};
tmain()
{
long i, k, count[1000];
/* testing Dtoset */
terror("Insert 7");
terror("Insert 1");
terror("Insert 3");
terror("Insert 4");
terror("Insert 2");
terror("Insert 6");
terror("Insert 7,2");
terror("Should have found 4");
terror("Should have found 6");
terror("Insert 5");
terror("Should have found 5");
terror("Should have found 3");
for(i = 1; i <= 7; ++i)
terror("Dtoset search");
terror("Dtoset flatten");
if(i != k)
terror("Dtoset backwalk");
/* reverse ordering */
for(i = 7; i >= 1; --i)
terror("Dtoset search 2");
if(i != k)
terror("Dtoset backwalk 2");
terror("Dtoset flatten 2");
terror("Fail extracting Dtoset");
terror("Fail restoring Dtoset");
terror("Dtoset size after extract");
terror("Dtoset flatten after extract");
/* change to hashing */
for(i = 1; i <= 7; ++i)
terror("Dtset search");
i += 1;
if(i != 7)
terror("Dtset flatten");
k += 1;
if(k != 7)
terror("Dtset flatten 2");
terror("Fail extracting Dtset");
terror("Fail restoring Dtset");
terror("Dtset size after extract");
k += 1;
if(k != 7)
terror("Dtset flatten after extract");
for(i = 1; i <= 7; ++i)
terror("Dtset search 2");
i += 1;
if(i != 7)
terror("Dtset flatten 2");
terror("Dtsize");
/* testing Dtlist */
terror("Dtlist insert 1.1");
terror("Dtlist insert 3.1");
terror("Dtlist insert 2.1");
terror("Dtlist insert 3.2");
terror("Dtlist insert 2.2");
terror("Dtlist insert 3.3");
terror("Dtlist insert 1.2");
/* check multiplicities */
for(i = 1; i <= 3; ++i)
count[i] = 0;
count[i] += 1;
terror("Dtlist count 1");
terror("Dtlist count 2");
terror("Dtlist count 3");
terror("Dtsize");
/* testing Dtbag */
terror("Dtlist insert 1.1");
terror("Dtlist insert 3.1");
terror("Dtlist insert 2.1");
terror("Dtlist insert 3.2");
terror("Dtlist insert 2.2");
terror("Dtlist insert 3.3");
terror("Dtlist insert 1.2");
/* check multiplicities */
for(i = 1; i <= 3; ++i)
count[i] = 0;
count[i] += 1;
terror("Dtbag count 1");
terror("Dtbag count 2");
terror("Dtbag count 3");
/* change method to Dtobag */
/* check multiplicities */
for(i = 1; i <= 3; ++i)
count[i] = 0;
count[i] += 1;
terror("Dtobag count 1");
terror("Dtobag count 2");
terror("Dtobag count 3");
/* test consecutive 1's */
terror("Dtobag search 1");
terror("Dtobag next 1");
terror("Dtobag next should be 2");
/* test consecutive 2's */
terror("Dtobag search 2");
terror("Dtobag next 2");
terror("Dtobag next should be 3");
/* test consecutive 3's */
terror("Dtobag search 3");
terror("Dtobag prev 3");
terror("Dtobag prev 3.2");
terror("Dtobag prev not expecting 3");
/* test large set of values */
for(i = 1; i < 20000; ++i)
terror("Can't insert");
if(i != k)
terror("Bad value");
/* test walking Dtrhset */
for(i = 1; i < 100; ++i)
terror("Can't insert");
for(i = 1; i < 100; ++i)
terror("Can't find %d", i);
count[k] += 1;
for(i = 1; i < 100; ++i)
if(count[i] != 1)
texit(0);
}