/* * Implementation of nested-int-list-test.h. It's far from complete at this * point, but does enough quick testing to see if the key stuff works. * The underlying implmentation in nested-int-list.c is derived from a * fully-tested c++ implementation. The C++ testing needs to be migrated into * this suite. */ #include #include #include "nested-int-list-test.h" bool Ini(List* l, int i) {return InListWithFunction(l, NewIntDatum(i), EqualsFunc);} List* L(List* l, int i) {PutList(l, NewIntDatum(i));} List* Ni(int i) {NewList1(NewIntDatum(i));} List* Ll(List* l, List* ld) {PutList(l, NewSubListDatum(ld));} List* Nl(List* l) {NewList1(NewSubListDatum(l));} /* * The main function does some basic testing. It needs to be explanded to * cover everything. */ int main(int argc, char** argv) { List* l1, *l2, *l3, *l1c, *l1nc, *l2c; l1 = L(L(L(L(L(Ni(1),2),3),4),5),6); l1c = CopyList(l1); l1nc = L(L(L(L(L(Ni(1),2),3),4),5),6); l2 = Ni(10); Ll(l2, l1); Ll(l2, l1); Ll(l2, l1c); l2c = CopyListWithFunction(l2, CopyFunc); printf("l1 = "); PrintList(l1, PrintFunc); printf("\n"); printf("l1c = "); PrintList(l1c, PrintFunc); printf("\n"); printf("l1nc = "); PrintList(l1nc, PrintFunc); printf("\n"); printf("l2 = "); PrintList(l2, PrintFunc); printf("\n"); printf("l2c = "); PrintList(l2c, PrintFunc); printf("\n"); printf("lengths (should be 6,4,6,6): %d,%d,%d,%d\n", ListLen(l1), ListLen(l2), ListLen(l3=(((NestedIntListElemData*) GetListNth(l2, 2))->sublist)), ListLen(l1c)); printf("l2 equals l2c? (should be 1): %d\n", ListEqualsWithFunction(l2, l2c, EqualsFunc)); printf("l3[3] = (should be 3): %d\n", ((NestedIntListElemData*) DelListNth(l3, 3))->data); printf("l2 equals l2c? (should be 0): %d\n", ListEqualsWithFunction(l2, l2c, EqualsFunc)); printf("lengths (should be 5,4,5,6): %d,%d,%d,%d\n", ListLen(l1), ListLen(l2), ListLen(l3=(((NestedIntListElemData*) GetListNth(l2, 2))->sublist)), ListLen(l1c)); printf("l1 eq l1? (should be 1): %d\n", ListEquals(l1, l1)); printf("l1 ea l1nc? (should be 0): %d\n", ListEquals(l1, l1nc)); printf("l1 eq CopyList(l1)? (should be 1): %d\n", ListEquals(l1, CopyList(l1))); printf("l1c equals l1nc? (should be 1): %d\n", ListEqualsWithFunction(l1c, l1nc, EqualsFunc)); printf("Ni(1) == Ni(1) (should be 0): %d\n", Ni(1) == Ni(1)); printf("Ni(1) eq Ni(1) (should be 0): %d\n", ListEquals(Ni(1), Ni(1))); printf("Ni(1) equals Ni(1) (should be 1): %d\n", ListEqualsWithFunction(Ni(1), Ni(1), EqualsFunc)); printf("4 in l1 (should be 3): %d\n", Ini(l1, 4)); printf("4 in l1c (should be 4): %d\n", Ini(l1c, 4)); }