13 Ms
*a
= new(struct Ms
);
14 ms_init(a
, NULL
, NULL
);
18 int ok
= ms_append(a
, &i
);
19 assertf(a
->len
== 1, "a should contain one item");
20 assertf(ok
, "should be added");
22 ok
= ms_append(a
, &i
);
23 assertf(a
->len
== 2, "a should contain two items");
24 assertf(ok
, "should be added");
27 assertf(a
->len
== 0, "a should be empty");
36 Ms
*a
= new(struct Ms
);
37 ms_init(a
, NULL
, NULL
);
43 int ok
= ms_remove(a
, &j
);
44 assertf(!ok
, "j should not be removed");
46 ok
= ms_remove(a
, &i
);
47 assertf(ok
, "i should be removed");
49 ok
= ms_remove(a
, &i
);
50 assertf(!ok
, "i was already removed");
52 assertf(a
->len
== 0, "a should be empty");
61 Ms
*a
= new(struct Ms
);
62 ms_init(a
, NULL
, NULL
);
66 int ok
= ms_contains(a
, &i
);
67 assertf(ok
, "i should be in a");
70 ok
= ms_contains(a
, &j
);
71 assertf(!ok
, "j should not be in a");
79 cttest_ms_clear_empty()
82 Ms
*a
= new(struct Ms
);
83 ms_init(a
, NULL
, NULL
);
86 assertf(a
->len
== 0, "a should be empty");
94 Ms
*a
= new(struct Ms
);
95 ms_init(a
, NULL
, NULL
);
104 n
= (int *)ms_take(a
);
105 assertf(n
== &i
, "n should point to i");
107 n
= (int *)ms_take(a
);
108 assertf(n
== &j
, "n should point to j");
110 n
= (int *)ms_take(a
);
111 assertf(n
== NULL
, "n should be NULL; ms is empty");
118 cttest_ms_take_sequence()
121 int s
[] = {1, 2, 3, 4, 5, 6};
122 int e
[] = {1, 2, 3, 6, 5, 4};
124 Ms
*a
= new(struct Ms
);
125 ms_init(a
, NULL
, NULL
);
127 size_t n
= sizeof(s
)/sizeof(s
[0]);
128 for (i
= 0; i
< n
; i
++)
131 for (i
= 0; i
< n
; i
++) {
132 int *got
= (int *)ms_take(a
);
133 assert(*got
== e
[i
]);