Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/tests/cdt/tstack.c
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1999-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#include "dttest.h"
21
22
Dtdisc_t Disc =
23
{ 0, sizeof(long), -1,
24
newint, NIL(Dtfree_f), compare, hashint,
25
NIL(Dtmemory_f), NIL(Dtevent_f)
26
};
27
28
tmain()
29
{
30
Dt_t* dt;
31
32
/* testing Dtstack */
33
if(!(dt = dtopen(&Disc,Dtstack)) )
34
terror("dtopen stack");
35
if((long)dtinsert(dt,1L) != 1)
36
terror("Dtstack insert 1");
37
if((long)dtinsert(dt,3L) != 3)
38
terror("Dtstack insert 3.1");
39
if((long)dtinsert(dt,2L) != 2)
40
terror("Dtstack insert 2.1");
41
if((long)dtinsert(dt,3L) != 3)
42
terror("Dtstack insert 3.2");
43
if((long)dtinsert(dt,2L) != 2)
44
terror("Dtstack insert 2.2");
45
if((long)dtinsert(dt,3L) != 3)
46
terror("Dtstack insert 3.3");
47
48
if((long)dtlast(dt) != 1)
49
terror("Dtstack dtlast");
50
if((long)dtprev(dt,1L) != 3)
51
terror("Dtstack dtprev 1");
52
if((long)dtprev(dt,3L) != 2)
53
terror("Dtstack dtprev 3.1");
54
if((long)dtprev(dt,2L) != 3)
55
terror("Dtstack dtprev 2.1");
56
if((long)dtprev(dt,3L) != 2)
57
terror("Dtstack dtprev 3.2");
58
if((long)dtprev(dt,2L) != 3)
59
terror("Dtstack dtprev 2.2");
60
if((long)dtprev(dt,3L) != 0)
61
terror("Dtstack dtprev 3.2");
62
63
if((long)dtdelete(dt,NIL(Void_t*)) != 3)
64
terror("Dtstack pop 3.3");
65
66
/* search to one of the 3 */
67
if((long)dtsearch(dt,3L) != 3)
68
terror("Dtstack search 3.2");
69
if((long)dtdelete(dt,3L) != 3)
70
terror("Dtstack delete 3.2");
71
72
if((long)dtdelete(dt,NIL(Void_t*)) != 2)
73
terror("Dtstack pop 2.2");
74
if((long)dtdelete(dt,NIL(Void_t*)) != 2)
75
terror("Dtstack pop 2.1");
76
if((long)dtdelete(dt,NIL(Void_t*)) != 3)
77
terror("Dtstack pop 3.1");
78
if((long)dtdelete(dt,NIL(Void_t*)) != 1)
79
terror("Dtstack pop 1");
80
81
if(dtsize(dt) != 0)
82
terror("Dtstack size");
83
84
texit(0);
85
}
86
87