source: tests/list/dlist-insert-remove-2.cfa @ 9e2341b4

arm-ehenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 9e2341b4 was 9e2341b4, checked in by Michael Brooks <mlbrooks@…>, 19 months ago

Baseline commit of new linked-list implementation and test.

Using a separate header with intention to port old uses first, then rename.

  • Property mode set to 100644
File size: 44.8 KB
Line 
1#include <containers/list2.hfa>
2#include <fstream.hfa>
3#include <assert.h>
4
5// Section 1:  replaced by above include list.hfa
6
7
8////////////////////////////////////////////////////////////
9//
10// Section 2
11//
12// Structure definitions
13//
14// Example of declaration-side user code
15//
16////////////////////////////////////////////////////////////
17
18// a fred belongs to two doubly-linked lists: mine and yours
19struct fred {
20        float adatum;
21        inline struct mine { inline dlink(fred); };
22        inline struct yours { inline dlink(fred); };
23};
24P9_EMBEDDED(fred, fred.mine)
25P9_EMBEDDED(fred, fred.yours)
26P9_EMBEDDED(fred.mine, dlink(fred))
27P9_EMBEDDED(fred.yours, dlink(fred))
28
29
30void ?{}(fred &this, float adatum) {
31        (this.adatum){adatum};
32}
33
34// a mary belongs to just one doubly-linked list: hers
35struct mary {
36        float anotherdatum;
37        inline dlink(mary);
38};
39
40P9_EMBEDDED(mary, dlink(mary))
41
42void ?{}(mary &this, float anotherdatum) {
43        (this.anotherdatum){anotherdatum};
44}
45
46////////////////////////////////////////////////////////////
47//
48// Section 3
49//
50// Test helpers to traverse and print lists.
51//
52// These consume framework-provided accessor functions and
53// do not modify their parameter lists.
54//
55////////////////////////////////////////////////////////////
56
57void printMyFredsFwd(diref(fred, fred.mine) f) {
58        do {
59                sout | f.adatum;
60        } while (f`moveNext);
61}
62
63void printMyFredsRev(diref(fred, fred.mine) f) {
64        do {
65                sout | f.adatum;
66        } while (f`movePrev);
67}
68
69
70void printMyFreddies(fred &f1, fred &f2, int isBefore) {
71        if (isBefore) {
72                sout | "==== fred by MINE before ";
73        } else {
74                sout | "==== fred by MINE after ";
75        }
76        if (&f1) {
77                printMyFredsFwd(f1`from);       sout | '-';
78                printMyFredsRev(f1`from);       sout | '-';
79        } else {
80                sout | '-'; sout | '-';
81        }
82        if (&f2) {
83                printMyFredsFwd(f2`from);       sout | '-';
84                printMyFredsRev(f2`from);       sout | '-';
85        } else {
86                sout | '-'; sout | '-';
87        }
88}
89
90void printYourFredsFwd(diref(fred, fred.yours) f) {
91        do {
92                sout | f.adatum;
93        } while (f`moveNext);
94}
95
96void printYourFredsRev(diref(fred, fred.yours) f) {
97        do {
98                sout | f.adatum;
99        } while (f`movePrev);
100}
101
102void printYourFreddies(fred &f1, fred &f2, int isBefore) {
103        if (isBefore) {
104                sout | "==== fred by YOURS before ";
105        } else {
106                sout | "==== fred by YOURS after ";
107        }
108        if (&f1) {
109                printYourFredsFwd(f1`from);     sout | '-';
110                printYourFredsRev(f1`from);     sout | '-';
111        } else {
112                sout | '-'; sout | '-';
113        }
114        if (&f2) {
115                printYourFredsFwd(f2`from);     sout | '-';
116                printYourFredsRev(f2`from);     sout | '-';
117        } else {
118                sout | '-'; sout | '-';
119        }
120}
121
122void printMariesFwd(mary &m) {
123        do {
124                sout | m.anotherdatum;
125        } while (m`moveNext);
126}
127
128void printMariesRev(mary &m) {
129        do {
130                sout | m.anotherdatum;
131        } while (m`movePrev);
132}
133
134void printMariatheotokos(mary &m1, mary &m2, int isBefore) {
135        if (isBefore) {
136                sout | "==== mary before ";
137        } else {
138                sout | "==== mary after ";
139        }
140        if (&m1) {
141                printMariesFwd(m1);     sout | '-';
142                printMariesRev(m1);     sout | '-';
143        } else {
144                sout | '-'; sout | '-';
145        }
146        if (&m2) {
147                printMariesFwd(m2);     sout | '-';
148                printMariesRev(m2);     sout | '-';
149        } else {
150                sout | '-'; sout | '-';
151        }
152}
153
154////////////////////////////////////////////////////////////
155//
156// Section 4a.i
157//
158// Test cases of insert_after on headless list
159//
160// Example of call-side user code
161//
162////////////////////////////////////////////////////////////
163
164// All three tests exercise the case of merging two singleton lists into (their respective
165// positions in) one common list of two elements.
166
167// Note that the factoring of sect 4 (vs 3 and 5) keeps section 4 free of strings and IO,
168// and so keeps its assembly easy to inspect.
169
170// Throughout all the 4s, all the print functions called from these tests print:
171//  - from list position #1 moving forward  (a)
172//  - from list position #1 moving backward (b)
173//  - from list position #2 moving forward  (c)
174//  - from list position #2 moving backward (d)
175// The expected-output comments are in form a;b;c;d where a::=num,num,num
176#if 0
177void test__insertafter_singleton_on_singleton__fred_mine () {
178        fred f1 = {3.14};
179        fred f2 = {0.5};
180
181        printMyFreddies(f1, f2, 1);     // 3.14; 3.14; 0.5; 0.5
182        printYourFreddies(f1, f2, 1);   // 3.14; 3.14; 0.5; 0.5
183
184        diref(fred, fred.mine) f1_mine = f1`from;
185        insert_after(f1_mine, f2);
186
187        printMyFreddies(f1, f2, 0);     // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified)
188        printYourFreddies(f1, f2, 0);   // 3.14; 3.14; 0.5; 0.5 (unmodified)
189}
190
191void test__insertafter_singleton_on_singleton__fred_yours () {
192        fred f1 = {3.14};
193        fred f2 = {0.5};
194
195        printMyFreddies(f1, f2, 1);     // 3.14; 3.14; 0.5; 0.5
196        printYourFreddies(f1, f2, 1);   // 3.14; 3.14; 0.5; 0.5
197
198        diref(fred, fred.yours) f1_yours = f1`from;
199        insert_after(f1_yours, f2);
200
201        printMyFreddies(f1, f2, 0);     // 3.14; 3.14; 0.5; 0.5 (unmodified)
202        printYourFreddies(f1, f2, 0);   // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified)
203}
204
205void test__insertafter_singleton_on_singleton__mary () {
206        mary m1 = {3.14};
207        mary m2 = {0.5};
208
209        printMariatheotokos(m1, m2, 1); // 3.14; 3.14; 0.5; 0.5
210
211        insert_after(m1, m2);
212
213        printMariatheotokos(m1, m2, 0); // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified)
214}
215
216////////////////////////////////////////////////////////////
217//
218// Section 4a.ii
219//
220// Test cases of insert_before on headless list
221//
222// Example of call-side user code
223//
224////////////////////////////////////////////////////////////
225
226void test__insertbefore_singleton_on_singleton__fred_mine () {
227        fred f1 = {3.14};
228        fred f2 = {0.5};
229
230        printMyFreddies(f1, f2, 1);     // 3.14; 3.14; 0.5; 0.5
231        printYourFreddies(f1, f2, 1);   // 3.14; 3.14; 0.5; 0.5
232
233        diref(fred, fred.mine) f2_mine = f2`from;
234        insert_before(f2_mine, f1);
235
236        printMyFreddies(f1, f2, 0);     // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified)
237        printYourFreddies(f1, f2, 0);   // 3.14; 3.14; 0.5; 0.5 (unmodified)
238}
239
240void test__insertbefore_singleton_on_singleton__fred_yours () {
241        fred f1 = {3.14};
242        fred f2 = {0.5};
243
244        printMyFreddies(f1, f2, 1);     // 3.14; 3.14; 0.5; 0.5
245        printYourFreddies(f1, f2, 1);   // 3.14; 3.14; 0.5; 0.5
246
247        diref(fred, fred.yours) f2_yours = f2`from;
248        insert_before(f2_yours, f1);
249
250        printMyFreddies(f1, f2, 0);     // 3.14; 3.14; 0.5; 0.5 (unmodified)
251        printYourFreddies(f1, f2, 0);   // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified)
252}
253
254void test__insertbefore_singleton_on_singleton__mary () {
255        mary m1 = {3.14};
256        mary m2 = {0.5};
257
258        printMariatheotokos(m1, m2, 1); // 3.14; 3.14; 0.5; 0.5
259
260        insert_before(m2, m1);
261
262        printMariatheotokos(m1, m2, 0); // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified)
263}
264#endif
265////////////////////////////////////////////////////////////
266//
267// Section 4b.i
268//
269// Test cases of insert_first (necessarily headed list)
270//
271// Example of call-side user code
272//
273////////////////////////////////////////////////////////////
274
275// All three tests exercise the case of creating an empty container and
276// adding two items to it.
277
278void test__insertfirst_two_on_empty__fred_mine() {
279
280        fred f1 = {3.14};
281        fred f2 = {0.5};
282
283        dlist(fred, fred.mine) lf;
284
285        verify(validate(lf));
286
287        printMyFreddies(f1, f2, 1);     // 3.14; 3.14; 0.5; 0.5
288        printYourFreddies(f1, f2, 1);   // 3.14; 3.14; 0.5; 0.5
289
290        insert_first(lf, f2);
291        insert_first(lf, f1);
292
293        verify(validate(lf));
294
295        printMyFreddies(f1, f2, 0);     // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified)
296        printYourFreddies(f1, f2, 0);   // 3.14; 3.14; 0.5; 0.5 (unmodified)
297}
298
299void test__insertfirst_two_on_empty__fred_yours() {
300
301        fred f1 = {3.14};
302        fred f2 = {0.5};
303
304        dlist(fred, fred.yours) lf;
305
306        verify(validate(lf));
307
308        printMyFreddies(f1, f2, 1);     // 3.14; 3.14; 0.5; 0.5
309        printYourFreddies(f1, f2, 1);   // 3.14; 3.14; 0.5; 0.5
310
311        insert_first(lf, f2);
312        insert_first(lf, f1);
313
314        verify(validate(lf));
315
316        printMyFreddies(f1, f2, 0);     // 3.14; 3.14; 0.5; 0.5 (unmodified)
317        printYourFreddies(f1, f2, 0);   // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified)
318}
319
320void test__insertfirst_two_on_empty__mary() {
321
322        mary m1 = {3.14};
323        mary m2 = {0.5};
324
325        dlist(mary, mary) lm;
326
327        verify(validate(lm));
328        printMariatheotokos(m1, m2, 1); // 3.14; 3.14; 0.5; 0.5
329
330        insert_first(lm, m2);
331        insert_first(lm, m1);
332
333        printMariatheotokos(m1, m2, 0); // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified)
334        verify(validate(lm));
335}
336
337////////////////////////////////////////////////////////////
338//
339// Section 4b.ii
340//
341// Test cases of insert_last (necessarily headed list)
342//
343// Example of call-side user code
344//
345////////////////////////////////////////////////////////////
346
347void test__insertlast_two_on_empty__fred_mine() {
348
349        fred f1 = {3.14};
350        fred f2 = {0.5};
351
352        dlist(fred, fred.mine) lf;
353
354        verify(validate(lf));
355
356        printMyFreddies(f1, f2, 1);     // 3.14; 3.14; 0.5; 0.5
357        printYourFreddies(f1, f2, 1);   // 3.14; 3.14; 0.5; 0.5
358
359        insert_last(lf, f1);
360        insert_last(lf, f2);
361
362        verify(validate(lf));
363
364        printMyFreddies(f1, f2, 0);     // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified)
365        printYourFreddies(f1, f2, 0);   // 3.14; 3.14; 0.5; 0.5 (unmodified)
366}
367
368void test__insertlast_two_on_empty__fred_yours() {
369
370        fred f1 = {3.14};
371        fred f2 = {0.5};
372
373        dlist(fred, fred.yours) lf;
374
375        verify(validate(lf));
376
377        printMyFreddies(f1, f2, 1);     // 3.14; 3.14; 0.5; 0.5
378        printYourFreddies(f1, f2, 1);   // 3.14; 3.14; 0.5; 0.5
379
380        insert_last(lf, f1);
381        insert_last(lf, f2);
382
383        verify(validate(lf));
384
385        printMyFreddies(f1, f2, 0);     // 3.14; 3.14; 0.5; 0.5 (unmodified)
386        printYourFreddies(f1, f2, 0);   // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified)
387}
388
389void test__insertlast_two_on_empty__mary() {
390
391        mary m1 = {3.14};
392        mary m2 = {0.5};
393
394        dlist(mary, mary) lm;
395
396        verify(validate(lm));
397        printMariatheotokos(m1, m2, 1); // 3.14; 3.14; 0.5; 0.5
398
399        insert_last(lm, m1);
400        insert_last(lm, m2);
401
402        verify(validate(lm));
403        printMariatheotokos(m1, m2, 0); // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified)
404}
405
406////////////////////////////////////////////////////////////
407//
408// Section 4c.i
409//
410// Test cases of insert_after on headed list
411//
412// Example of call-side user code
413//
414////////////////////////////////////////////////////////////
415
416void test__insertafter_after_last__fred_mine() {
417
418        fred f1 = {3.14};
419        fred f2 = {0.5};
420
421        dlist(fred, fred.mine) lf;
422
423        assert(! lf`first);
424        assert(! lf`last);
425
426        insert_first(lf, f1);
427
428        assert(DUMB_COMPARE(lf`first, & f1));
429        assert(DUMB_COMPARE(lf`last , & f1));
430
431        verify(validate(lf));
432
433        diref(fred, fred.mine) f1_mine = f1`from;
434        insert_after(f1_mine, f2);
435
436        verify(validate(lf));
437
438        printMyFreddies(f1, f2, 0);     // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified)
439        printYourFreddies(f1, f2, 0);   // 3.14; 3.14; 0.5; 0.5 (unmodified)
440
441        assert(DUMB_COMPARE(lf`first, & f1));
442        assert(DUMB_COMPARE(lf`last , & f2));
443}
444
445void test__insertafter_after_last__fred_yours() {
446
447        fred f1 = {3.14};
448        fred f2 = {0.5};
449
450        dlist(fred, fred.yours) lf;
451
452        assert(! lf`first);
453        assert(! lf`last);
454
455        insert_first(lf, f1);
456
457        assert(DUMB_COMPARE(lf`first, & f1));
458        assert(DUMB_COMPARE(lf`last , & f1));
459
460        verify(validate(lf));
461
462        diref(fred, fred.yours) f1_yours = f1`from;
463        insert_after(f1_yours, f2);
464
465        verify(validate(lf));
466
467        printMyFreddies(f1, f2, 0);     // 3.14; 3.14; 0.5; 0.5 (unmodified)
468        printYourFreddies(f1, f2, 0);   // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified)
469
470        assert(DUMB_COMPARE(lf`first, & f1));
471        assert(DUMB_COMPARE(lf`last , & f2));
472}
473
474void test__insertafter_after_last__mary() {
475
476        mary m1 = {3.14};
477        mary m2 = {0.5};
478
479        dlist(mary, mary) lm;
480
481        assert(! lm`first);
482        assert(! lm`last);
483
484        insert_first(lm, m1);
485
486        assert(DUMB_COMPARE(lm`first, & m1));
487        assert(DUMB_COMPARE(lm`last , & m1));
488
489        verify(validate(lm));
490
491        insert_after(m1, m2);
492
493        verify(validate(lm));
494
495        printMariatheotokos(m1, m2, 0); // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified)
496
497        assert(DUMB_COMPARE(lm`first, & m1));
498        assert(DUMB_COMPARE(lm`last , & m2));
499}
500
501////////////////////////////////////////////////////////////
502//
503// Section 4c.ii
504//
505// Test cases of insert_before on headed list
506//
507// Example of call-side user code
508//
509////////////////////////////////////////////////////////////
510
511void test__insertbefore_before_first__fred_mine() {
512
513        fred f1 = {3.14};
514        fred f2 = {0.5};
515
516        dlist(fred, fred.mine) lf;
517
518        assert(! lf`first);
519        assert(! lf`last);
520
521        insert_last(lf, f2);
522
523        assert(DUMB_COMPARE(lf`first, & f2));
524        assert(DUMB_COMPARE(lf`last , & f2));
525
526        verify(validate(lf));
527
528        diref(fred, fred.mine) f2_mine = f2`from;
529        insert_before(f2_mine, f1);
530
531        verify(validate(lf));
532
533        printMyFreddies(f1, f2, 0);     // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified)
534        printYourFreddies(f1, f2, 0);   // 3.14; 3.14; 0.5; 0.5 (unmodified)
535
536        assert(DUMB_COMPARE(lf`first, & f1));
537        assert(DUMB_COMPARE(lf`last , & f2));
538}
539
540void test__insertbefore_before_first__fred_yours() {
541
542        fred f1 = {3.14};
543        fred f2 = {0.5};
544
545        dlist(fred, fred.yours) lf;
546
547        assert(! lf`first);
548        assert(! lf`last);
549
550        insert_last(lf, f2);
551
552        assert(DUMB_COMPARE(lf`first, & f2));
553        assert(DUMB_COMPARE(lf`last , & f2));
554
555        verify(validate(lf));
556
557        diref(fred, fred.yours) f2_yours = f2`from;
558        insert_before(f2_yours, f1);
559
560        verify(validate(lf));
561
562        printMyFreddies(f1, f2, 0);     // 3.14; 3.14; 0.5; 0.5 (unmodified)
563        printYourFreddies(f1, f2, 0);   // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified)
564
565        assert(DUMB_COMPARE(lf`first, & f1));
566        assert(DUMB_COMPARE(lf`last , & f2));
567}
568
569void test__insertbefore_before_first__mary() {
570
571        mary m1 = {3.14};
572        mary m2 = {0.5};
573
574        dlist(mary, mary) lm;
575
576        assert(! lm`first);
577        assert(! lm`last);
578
579        insert_last(lm, m2);
580
581        assert(DUMB_COMPARE(lm`first, & m2));
582        assert(DUMB_COMPARE(lm`last , & m2));
583
584        verify(validate(lm));
585
586        insert_before(m2, m1);
587
588        verify(validate(lm));
589
590        printMariatheotokos(m1, m2, 0); // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified)
591
592        assert(DUMB_COMPARE(lm`first, & m1));
593        assert(DUMB_COMPARE(lm`last , & m2));
594}
595
596#if 0
597
598////////////////////////////////////////////////////////////
599//
600// Section 4d.i
601//
602// Test cases of remove, from middle of headless list
603//
604// Example of call-side user code
605//
606////////////////////////////////////////////////////////////
607
608// These tests, in the fred cases, set up the my/your lists initially identical,
609// act on one list, and expect the other unaffected.
610
611void test__remove_mid__fred_mine() {
612
613        fred f1 = {1.7};
614        fred f2 = {2.7};
615        fred f3 = {3.7};
616
617        insert_after(f1`in_mine, f2);
618        insert_after(f2`in_mine, f3);
619
620        insert_after(f1`in_yours, f2);
621        insert_after(f2`in_yours, f3);
622
623        printMyFreddies(f1, f3, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
624        printYourFreddies(f1, f3, 1);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
625
626        remove(f2`in_mine);
627
628        printMyFreddies(f1, f3, 0);     // 1.7, 3.7;       1.7;  3.7;  3.7, 1.7      (modified)
629        printYourFreddies(f1, f3, 0);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7 (unmodified)
630
631        // observe f2 is now solo in mine; in yours, it was just traversed
632        printMyFreddies(f2, *0p, 0);    // 2.7; 2.7; ;
633
634        // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics
635        assert(f2.$links_mine.next.is_terminator == false);
636        assert(f2.$links_mine.prev.is_terminator == false);
637}
638
639void test__remove_mid__fred_yours() {
640
641        fred f1 = {1.7};
642        fred f2 = {2.7};
643        fred f3 = {3.7};
644
645        insert_after(f1`in_mine, f2);
646        insert_after(f2`in_mine, f3);
647
648        insert_after(f1`in_yours, f2);
649        insert_after(f2`in_yours, f3);
650
651        printMyFreddies(f1, f3, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
652        printYourFreddies(f1, f3, 1);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
653
654        remove(f2`in_yours);
655
656        printMyFreddies(f1, f3, 0);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7 (unmodified)
657        printYourFreddies(f1, f3, 0);   // 1.7, 3.7;       1.7;  3.7;  3.7, 1.7      (modified)
658
659        // observe f2 is now solo in yours; in mine, it was just traversed
660        printYourFreddies(f2, *0p, 0);    // 2.7; 2.7; ;
661
662        // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics
663        assert(f2.$links_yours.next.is_terminator == false);
664        assert(f2.$links_yours.prev.is_terminator == false);
665}
666
667void test__remove_mid__mary() {
668
669        mary m1 = {1.7};
670        mary m2 = {2.7};
671        mary m3 = {3.7};
672
673        insert_after(m1, m2);
674        insert_after(m2, m3);
675
676        printMariatheotokos(m1, m3, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
677
678        remove(m2);
679
680        printMariatheotokos(m1, m3, 0);     // 1.7, 3.7;  1.7;  3.7;  3.7, 1.7 (modified)
681
682        // observe m2 is now solo
683        printMariatheotokos(m2, *0p, 0);    // 2.7; 2.7; ;
684
685        // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics
686        assert(m2.$links.next.is_terminator == false);
687        assert(m2.$links.prev.is_terminator == false);
688}
689
690////////////////////////////////////////////////////////////
691//
692// Section 4d.ii
693//
694// Test cases of remove, from first position of headless list
695//
696// Example of call-side user code
697//
698////////////////////////////////////////////////////////////
699
700// TODO: validate headless semantic: remove of a neighbourless element is valid and no-op
701
702void test__remove_at_first__fred_mine() {
703
704        fred f1 = {1.7};
705        fred f2 = {2.7};
706        fred f3 = {3.7};
707
708        insert_after(f1`in_mine, f2);
709        insert_after(f2`in_mine, f3);
710
711        insert_after(f1`in_yours, f2);
712        insert_after(f2`in_yours, f3);
713
714        printMyFreddies(f1, f3, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
715        printYourFreddies(f1, f3, 1);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
716
717        remove(f1`in_mine);
718
719        printMyFreddies(f2, f3, 0);     // 2.7, 3.7;       2.7;  3.7;  3.7, 2.7      (modified)
720        printYourFreddies(f1, f3, 0);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7 (unmodified)
721
722        // observe f1 is now solo in mine; in yours, it was just traversed
723        printMyFreddies(f1, *0p, 0);    // 1.7; 1.7; ;
724
725        // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics
726        assert(f1.$links_mine.next.is_terminator == false);
727        assert(f1.$links_mine.prev.is_terminator == false);
728}
729
730void test__remove_at_first__fred_yours() {
731
732        fred f1 = {1.7};
733        fred f2 = {2.7};
734        fred f3 = {3.7};
735
736        insert_after(f1`in_mine, f2);
737        insert_after(f2`in_mine, f3);
738
739        insert_after(f1`in_yours, f2);
740        insert_after(f2`in_yours, f3);
741
742        printMyFreddies(f1, f3, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
743        printYourFreddies(f1, f3, 1);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
744
745        remove(f1`in_yours);
746
747        printMyFreddies(f1, f3, 0);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7 (unmodified)
748        printYourFreddies(f2, f3, 0);   // 2.7, 3.7;       2.7;  3.7;  3.7, 2.7      (modified)
749
750        // observe f1 is now solo in yours; in mine, it was just traversed
751        printYourFreddies(f1, *0p, 0);    // 1.7; 1.7; ;
752
753        // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics
754        assert(f1.$links_yours.next.is_terminator == false);
755        assert(f1.$links_yours.prev.is_terminator == false);
756}
757
758void test__remove_at_first__mary() {
759
760        mary m1 = {1.7};
761        mary m2 = {2.7};
762        mary m3 = {3.7};
763
764        insert_after(m1, m2);
765        insert_after(m2, m3);
766
767        printMariatheotokos(m1, m3, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
768
769        remove(m1);
770
771        printMariatheotokos(m2, m3, 0);     // 2.7, 3.7;  2.7;  3.7;  3.7, 2.7 (modified)
772
773        // observe m2 is now solo
774        printMariatheotokos(m1, *0p, 0);    // 1.7; 1.7; ;
775
776        // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics
777        assert(m1.$links.next.is_terminator == false);
778        assert(m1.$links.prev.is_terminator == false);
779}
780
781////////////////////////////////////////////////////////////
782//
783// Section 4d.iii
784//
785// Test cases of remove, from last position of headless list
786//
787// Example of call-side user code
788//
789////////////////////////////////////////////////////////////
790
791void test__remove_at_last__fred_mine() {
792
793        fred f1 = {1.7};
794        fred f2 = {2.7};
795        fred f3 = {3.7};
796
797        insert_after(f1`in_mine, f2);
798        insert_after(f2`in_mine, f3);
799
800        insert_after(f1`in_yours, f2);
801        insert_after(f2`in_yours, f3);
802
803        printMyFreddies(f1, f3, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
804        printYourFreddies(f1, f3, 1);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
805
806        remove(f3`in_mine);
807
808        printMyFreddies(f1, f2, 0);     // 1.7, 2.7;       1.7;  2.7;  2.7, 1.7      (modified)
809        printYourFreddies(f1, f3, 0);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7 (unmodified)
810
811        // observe f3 is now solo in mine; in yours, it was just traversed
812        printMyFreddies(f3, *0p, 0);    // 3.7; 3.7; ;
813
814        // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics
815        assert(f3.$links_mine.next.is_terminator == false);
816        assert(f3.$links_mine.prev.is_terminator == false);
817}
818
819void test__remove_at_last__fred_yours() {
820
821        fred f1 = {1.7};
822        fred f2 = {2.7};
823        fred f3 = {3.7};
824
825        insert_after(f1`in_mine, f2);
826        insert_after(f2`in_mine, f3);
827
828        insert_after(f1`in_yours, f2);
829        insert_after(f2`in_yours, f3);
830
831        printMyFreddies(f1, f3, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
832        printYourFreddies(f1, f3, 1);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
833
834        remove(f3`in_yours);
835
836        printMyFreddies(f1, f3, 0);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7 (unmodified)
837        printYourFreddies(f1, f2, 0);   // 1.7, 2.7;       1.7;  2.7;  2.7, 1.7      (modified)
838
839        // observe f3 is now solo in yours; in mine, it was just traversed
840        printYourFreddies(f3, *0p, 0);    // 3.7; 3.7; ;
841
842        // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics
843        assert(f3.$links_yours.next.is_terminator == false);
844        assert(f3.$links_yours.prev.is_terminator == false);
845}
846
847void test__remove_at_last__mary() {
848
849        mary m1 = {1.7};
850        mary m2 = {2.7};
851        mary m3 = {3.7};
852
853        insert_after(m1, m2);
854        insert_after(m2, m3);
855
856        printMariatheotokos(m1, m3, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
857
858        remove(m3);
859
860        printMariatheotokos(m1, m2, 0);     // 1.7, 2.7;  1.7;  2.7;  2.7, 1.7 (modified)
861
862        // observe m3 is now solo
863        printMariatheotokos(m3, *0p, 0);    // 3.7; 3.7; ;
864
865        // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics
866        assert(m1.$links.next.is_terminator == false);
867        assert(m1.$links.prev.is_terminator == false);
868}
869
870////////////////////////////////////////////////////////////
871//
872// Section 4e.i
873//
874// Test cases of remove, from first position of headed list
875//
876// Example of call-side user code
877//
878////////////////////////////////////////////////////////////
879#endif
880void test__remove_at_head__fred_mine() {
881
882        fred f1 = {1.7};
883        fred f2 = {2.7};
884        fred f3 = {3.7};
885
886        dlist(fred, fred.mine) flm;
887        insert_last(flm, f1);
888        insert_last(flm, f2);
889        insert_last(flm, f3);
890
891        dlist(fred, fred.yours) fly;
892        insert_last(fly, f1);
893        insert_last(fly, f2);
894        insert_last(fly, f3);
895
896        printMyFreddies(flm`first, flm`last, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
897        printYourFreddies(fly`first, fly`last, 1);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
898
899        verify(validate(fly));
900        verify(validate(flm));
901
902        diref(fred, fred.mine) f1_mine = f1`from;
903        remove(f1_mine);
904
905        verify(validate(fly));
906        verify(validate(flm));
907
908        printMyFreddies(flm`first, flm`last, 0);     // 2.7, 3.7;       2.7;  3.7;  3.7, 2.7      (modified)
909        printYourFreddies(fly`first, fly`last, 0);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7 (unmodified)
910
911        // observe f1 is now solo in mine; in yours, it was just traversed
912        printMyFreddies(f1, *0p, 0);    // 1.7; 1.7; ;
913
914        // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics
915        // assert(f1.$links_mine.next.is_terminator == false);
916        // assert(f1.$links_mine.prev.is_terminator == false);
917}
918
919void test__remove_at_head__fred_yours() {
920
921        fred f1 = {1.7};
922        fred f2 = {2.7};
923        fred f3 = {3.7};
924
925        dlist(fred, fred.mine) flm;
926        insert_last(flm, f1);
927        insert_last(flm, f2);
928        insert_last(flm, f3);
929
930        dlist(fred, fred.yours) fly;
931        insert_last(fly, f1);
932        insert_last(fly, f2);
933        insert_last(fly, f3);
934
935        printMyFreddies(flm`first, flm`last, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
936        printYourFreddies(fly`first, fly`last, 1);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
937
938        verify(validate(fly));
939        verify(validate(flm));
940
941        diref(fred, fred.yours) f1_yours = f1`from;
942        remove(f1_yours);
943
944        verify(validate(fly));
945        verify(validate(flm));
946
947        printMyFreddies(flm`first, flm`last, 0);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7 (unmodified)
948        printYourFreddies(fly`first, fly`last, 0);   // 2.7, 3.7;       2.7;  3.7;  3.7, 2.7      (modified)
949
950        // observe f1 is now solo in yours; in mine, it was just traversed
951        printYourFreddies(f1, *0p, 0);    // 1.7; 1.7; ;
952
953        // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics
954        // assert(f1.$links_yours.next.is_terminator == false);
955        // assert(f1.$links_yours.prev.is_terminator == false);
956}
957
958void test__remove_at_head__mary() {
959
960        mary m1 = {1.7};
961        mary m2 = {2.7};
962        mary m3 = {3.7};
963
964        dlist(mary, mary) ml;
965        insert_last(ml, m1);
966        insert_last(ml, m2);
967        insert_last(ml, m3);
968
969        printMariatheotokos(ml`first, ml`last, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
970
971        verify(validate(ml));
972
973        remove(m1);
974
975        verify(validate(ml));
976
977        printMariatheotokos(ml`first, ml`last, 0);     // 2.7, 3.7;       2.7;  3.7;  3.7, 2.7      (modified)
978
979        // observe m1 is now solo
980        printMariatheotokos(m1, *0p, 0);               // 1.7; 1.7; ;
981
982        // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics
983        // assert(m1.$links.next.is_terminator == false);
984        // assert(m1.$links.prev.is_terminator == false);
985}
986
987////////////////////////////////////////////////////////////
988//
989// Section 4e.ii
990//
991// Test cases of remove, from last position of headed list
992//
993// Example of call-side user code
994//
995////////////////////////////////////////////////////////////
996
997void test__remove_at_tail__fred_mine() {
998
999        fred f1 = {1.7};
1000        fred f2 = {2.7};
1001        fred f3 = {3.7};
1002
1003        dlist(fred, fred.mine) flm;
1004        insert_last(flm, f1);
1005        insert_last(flm, f2);
1006        insert_last(flm, f3);
1007
1008        dlist(fred, fred.yours) fly;
1009        insert_last(fly, f1);
1010        insert_last(fly, f2);
1011        insert_last(fly, f3);
1012
1013        printMyFreddies(flm`first, flm`last, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
1014        printYourFreddies(fly`first, fly`last, 1);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
1015
1016        verify(validate(fly));
1017        verify(validate(flm));
1018
1019        diref(fred, fred.mine) f3_mine = f3`from;
1020        remove(f3_mine);
1021
1022        verify(validate(fly));
1023        verify(validate(flm));
1024
1025        printMyFreddies(flm`first, flm`last, 0);     // 1.7, 2.7;       1.7;  2.7;  2.7, 1.7      (modified)
1026        printYourFreddies(fly`first, fly`last, 0);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7 (unmodified)
1027
1028        // observe f3 is now solo in mine; in yours, it was just traversed
1029        printMyFreddies(f3, *0p, 0);    // 3.7; 3.7; ;
1030
1031        // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics
1032        // assert(f3.$links_mine.next.is_terminator == false);
1033        // assert(f3.$links_mine.prev.is_terminator == false);
1034}
1035
1036void test__remove_at_tail__fred_yours() {
1037
1038        fred f1 = {1.7};
1039        fred f2 = {2.7};
1040        fred f3 = {3.7};
1041
1042        dlist(fred, fred.mine) flm;
1043        insert_last(flm, f1);
1044        insert_last(flm, f2);
1045        insert_last(flm, f3);
1046
1047        dlist(fred, fred.yours) fly;
1048        insert_last(fly, f1);
1049        insert_last(fly, f2);
1050        insert_last(fly, f3);
1051
1052        printMyFreddies(flm`first, flm`last, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
1053        printYourFreddies(fly`first, fly`last, 1);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
1054
1055        verify(validate(fly));
1056        verify(validate(flm));
1057
1058        diref(fred, fred.yours) f3_yours = f3`from;
1059        remove(f3_yours);
1060
1061        verify(validate(fly));
1062        verify(validate(flm));
1063
1064        printMyFreddies(flm`first, flm`last, 0);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7 (unmodified)
1065        printYourFreddies(fly`first, fly`last, 0);   // 1.7, 2.7;       1.7;  2.7;  2.7, 1.7      (modified)
1066
1067        // observe f3 is now solo in yours; in mine, it was just traversed
1068        printYourFreddies(f3, *0p, 0);               // 3.7; 3.7; ;
1069
1070        // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics
1071        // assert(f3.$links_yours.next.is_terminator == false);
1072        // assert(f3.$links_yours.prev.is_terminator == false);
1073}
1074
1075void test__remove_at_tail__mary() {
1076
1077        mary m1 = {1.7};
1078        mary m2 = {2.7};
1079        mary m3 = {3.7};
1080
1081        dlist(mary, mary) ml;
1082        insert_last(ml, m1);
1083        insert_last(ml, m2);
1084        insert_last(ml, m3);
1085
1086        printMariatheotokos(ml`first, ml`last, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
1087
1088        verify(validate(ml));
1089
1090        remove(m3);
1091
1092        verify(validate(ml));
1093
1094        printMariatheotokos(ml`first, ml`last, 0);     // 1.7, 2.7;       1.7;  2.7;  2.7, 1.7      (modified)
1095
1096        // observe m3 is now solo
1097        printMariatheotokos(m3, *0p, 0);               //3.7; 3.7; ;
1098
1099        // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics
1100        // assert(m3.$links.next.is_terminator == false);
1101        // assert(m3.$links.prev.is_terminator == false);
1102}
1103
1104////////////////////////////////////////////////////////////
1105//
1106// Section 4e.iii
1107//
1108// Test cases of remove, of sole element of headed list
1109//
1110// Example of call-side user code
1111//
1112////////////////////////////////////////////////////////////
1113
1114void test__remove_of_sole__fred_mine() {
1115
1116        fred f = {0.7};
1117
1118        dlist(fred, fred.mine) flm;
1119        insert_last(flm, f);
1120
1121        dlist(fred, fred.yours) fly;
1122        insert_last(fly, f);
1123
1124        printMyFreddies(flm`first, flm`last, 1);     // 0.7; 0.7; 0.7; 0.7
1125        printYourFreddies(fly`first, fly`last, 1);   // 0.7; 0.7; 0.7; 0.7
1126
1127        verify(validate(fly));
1128        verify(validate(flm));
1129
1130        diref(fred, fred.mine) f_mine = f`from;
1131        remove(f_mine);
1132
1133        verify(validate(fly));
1134        verify(validate(flm));
1135
1136        assert(! flm`first);
1137        assert(! flm`last);
1138
1139        printYourFreddies(fly`first, fly`last, 0);   // 0.7; 0.7; 0.7; 0.7 (unmodified)
1140
1141        // observe f is solo in mine (now unlisted); in yours, it was just traversed
1142        printMyFreddies(f, *0p, 0);    // 0.7; 0.7; ;
1143
1144        // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics
1145        // assert(f.$links_mine.next.is_terminator == false);
1146        // assert(f.$links_mine.prev.is_terminator == false);
1147
1148        insert_last(flm, f);
1149        verify(validate(fly));
1150        verify(validate(flm));
1151        printMyFreddies(flm`first, flm`last, 0);     // 0.7; 0.7; 0.7; 0.7
1152}
1153
1154void test__remove_of_sole__fred_yours() {
1155
1156        fred f = {0.7};
1157
1158        dlist(fred, fred.mine) flm;
1159        insert_last(flm, f);
1160
1161        dlist(fred, fred.yours) fly;
1162        insert_last(fly, f);
1163
1164        printMyFreddies(flm`first, flm`last, 1);     // 0.7; 0.7; 0.7; 0.7
1165        printYourFreddies(fly`first, fly`last, 1);   // 0.7; 0.7; 0.7; 0.7
1166
1167        verify(validate(fly));
1168        verify(validate(flm));
1169
1170        diref(fred, fred.yours) f_yours = f`from;
1171        remove(f_yours);
1172
1173        verify(validate(fly));
1174        verify(validate(flm));
1175
1176        assert(! fly`first);
1177        assert(! fly`last);
1178
1179        printYourFreddies(flm`first, flm`last, 0);   // 0.7; 0.7; 0.7; 0.7 (unmodified)
1180
1181        // observe f is solo in yours (now unlisted); in mine, it was just traversed
1182        printYourFreddies(f, *0p, 0);    // 0.7; 0.7; ;
1183
1184        // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics
1185        // assert(f.$links_yours.next.is_terminator == false);
1186        // assert(f.$links_yours.prev.is_terminator == false);
1187
1188        insert_last(fly, f);
1189        verify(validate(fly));
1190        verify(validate(flm));
1191        printYourFreddies(fly`first, fly`last, 0);     // 0.7; 0.7; 0.7; 0.7
1192}
1193
1194void test__remove_of_sole__mary() {
1195
1196        mary m = {0.7};
1197
1198        dlist(mary, mary) ml;
1199        insert_last(ml, m);
1200
1201        printMariatheotokos(ml`first, ml`last, 1);     // 0.7; 0.7; 0.7; 0.7
1202
1203        verify(validate(ml));
1204
1205        remove(m);
1206
1207        verify(validate(ml));
1208
1209        assert(! ml`first);
1210        assert(! ml`last);
1211
1212        // observe f is solo in mine (now unlisted); in yours, it was just traversed
1213        printMariatheotokos(m, *0p, 0);    // 0.7; 0.7; ;
1214
1215        // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics
1216        // assert(m.$links.next.is_terminator == false);
1217        // assert(m.$links.prev.is_terminator == false);
1218
1219        insert_last(ml, m);
1220        verify(validate(ml));
1221        printMariatheotokos(ml`first, ml`last, 0);     // 0.7; 0.7; 0.7; 0.7
1222}
1223
1224////////////////////////////////////////////////////////////
1225//
1226// Section 4f
1227//
1228// Test cases of pop_first, pop_last
1229//
1230// Example of call-side user code
1231//
1232////////////////////////////////////////////////////////////
1233
1234// These cases assume element removal at first-last is correct
1235
1236void test__pop_first__fred_mine() {
1237
1238        fred f1 = {1.7};
1239        fred f2 = {2.7};
1240        fred f3 = {3.7};
1241
1242        dlist(fred, fred.mine) flm;
1243        insert_last(flm, f1);
1244        insert_last(flm, f2);
1245        insert_last(flm, f3);
1246
1247        dlist(fred, fred.yours) fly;
1248        insert_last(fly, f1);
1249        insert_last(fly, f2);
1250        insert_last(fly, f3);
1251
1252        printMyFreddies(flm`first, flm`last, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
1253        printYourFreddies(fly`first, fly`last, 1);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
1254
1255        verify(validate(fly));
1256        verify(validate(flm));
1257
1258        fred & popped = remove(flm`first);
1259
1260        verify(validate(fly));
1261        verify(validate(flm));
1262
1263        printMyFreddies(flm`first, flm`last, 0);     // 2.7, 3.7;       2.7;  3.7;  3.7, 2.7      (modified)
1264        printYourFreddies(fly`first, fly`last, 0);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7 (unmodified)
1265
1266        // observe f1 is now solo in mine; in yours, it was just traversed
1267        printMyFreddies(f1, *0p, 0);    // 1.7; 1.7; ;
1268
1269        assert( &popped == & f1 );
1270}
1271
1272void test__pop_first__fred_yours() {
1273
1274        fred f1 = {1.7};
1275        fred f2 = {2.7};
1276        fred f3 = {3.7};
1277
1278        dlist(fred, fred.mine) flm;
1279        insert_last(flm, f1);
1280        insert_last(flm, f2);
1281        insert_last(flm, f3);
1282
1283        dlist(fred, fred.yours) fly;
1284        insert_last(fly, f1);
1285        insert_last(fly, f2);
1286        insert_last(fly, f3);
1287
1288        printMyFreddies(flm`first, flm`last, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
1289        printYourFreddies(fly`first, fly`last, 1);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
1290
1291        verify(validate(fly));
1292        verify(validate(flm));
1293
1294        fred & popped = remove(fly`first);
1295
1296        verify(validate(fly));
1297        verify(validate(flm));
1298
1299        printMyFreddies(flm`first, flm`last, 0);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7 (unmodified)
1300        printYourFreddies(fly`first, fly`last, 0);   // 2.7, 3.7;       2.7;  3.7;  3.7, 2.7      (modified)
1301
1302        // observe f1 is now solo in yours; in mine, it was just traversed
1303        printYourFreddies(f1, *0p, 0);    // 1.7; 1.7; ;
1304
1305        assert( &popped == &f1 );
1306}
1307
1308void test__pop_first__maries() {
1309
1310        mary m1 = {1.7};
1311        mary m2 = {2.7};
1312        mary m3 = {3.7};
1313
1314        dlist(mary, mary) ml;
1315        insert_last(ml, m1);
1316        insert_last(ml, m2);
1317        insert_last(ml, m3);
1318
1319        printMariatheotokos(ml`first, ml`last, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
1320
1321        verify(validate(ml));
1322
1323        mary & popped = remove(ml`first);
1324
1325        verify(validate(ml));
1326
1327        printMariatheotokos(ml`first, ml`last, 0);     // 2.7, 3.7;       2.7;  3.7;  3.7, 2.7      (modified)
1328
1329        // observe m1 is now solo
1330        printMariatheotokos(m1, *0p, 0);               // 1.7; 1.7; ;
1331
1332        assert( &popped == &m1 );
1333}
1334
1335void test__pop_last__fred_mine() {
1336
1337        fred f1 = {1.7};
1338        fred f2 = {2.7};
1339        fred f3 = {3.7};
1340
1341        dlist(fred, fred.mine) flm;
1342        insert_last(flm, f1);
1343        insert_last(flm, f2);
1344        insert_last(flm, f3);
1345
1346        dlist(fred, fred.yours) fly;
1347        insert_last(fly, f1);
1348        insert_last(fly, f2);
1349        insert_last(fly, f3);
1350
1351        printMyFreddies(flm`first, flm`last, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
1352        printYourFreddies(fly`first, fly`last, 1);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
1353
1354        verify(validate(fly));
1355        verify(validate(flm));
1356
1357        fred & popped = remove(flm`last);
1358
1359        verify(validate(fly));
1360        verify(validate(flm));
1361
1362        printMyFreddies(flm`first, flm`last, 0);     // 1.7, 2.7;       1.7;  2.7;  2.7, 1.7      (modified)
1363        printYourFreddies(fly`first, fly`last, 0);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7 (unmodified)
1364
1365        // observe f3 is now solo in mine; in yours, it was just traversed
1366        printMyFreddies(f3, *0p, 0);    // 3.7; 3.7; ;
1367
1368        assert( &popped == & f3 );
1369}
1370
1371void test__pop_last__fred_yours() {
1372
1373        fred f1 = {1.7};
1374        fred f2 = {2.7};
1375        fred f3 = {3.7};
1376
1377        dlist(fred, fred.mine) flm;
1378        insert_last(flm, f1);
1379        insert_last(flm, f2);
1380        insert_last(flm, f3);
1381
1382        dlist(fred, fred.yours) fly;
1383        insert_last(fly, f1);
1384        insert_last(fly, f2);
1385        insert_last(fly, f3);
1386
1387        printMyFreddies(flm`first, flm`last, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
1388        printYourFreddies(fly`first, fly`last, 1);   // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
1389
1390        verify(validate(fly));
1391        verify(validate(flm));
1392
1393        fred & popped = remove(fly`last);
1394
1395        verify(validate(fly));
1396        verify(validate(flm));
1397
1398        printMyFreddies(flm`first, flm`last, 0);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7 (unmodified)
1399        printYourFreddies(fly`first, fly`last, 0);   // 1.7, 2.7;       1.7;  2.7;  2.7, 1.7      (modified)
1400
1401        // observe f3 is now solo in yours; in mine, it was just traversed
1402        printYourFreddies(f3, *0p, 0);    // 3.7; 3.7; ;
1403
1404        assert( &popped == & f3 );
1405}
1406
1407void test__pop_last__maries() {
1408
1409        mary m1 = {1.7};
1410        mary m2 = {2.7};
1411        mary m3 = {3.7};
1412
1413        dlist(mary, mary) ml;
1414        insert_last(ml, m1);
1415        insert_last(ml, m2);
1416        insert_last(ml, m3);
1417
1418        printMariatheotokos(ml`first, ml`last, 1);     // 1.7, 2.7, 3.7;  1.7;  3.7;  3.7, 2.7, 1.7
1419
1420        verify(validate(ml));
1421
1422        mary & popped = remove(ml`last);
1423
1424        verify(validate(ml));
1425
1426        printMariatheotokos(ml`first, ml`last, 0);     // 1.7, 1.7;       1.7;  2.7;  2.7, 1.7      (modified)
1427
1428        // observe m1 is now solo
1429        printMariatheotokos(m3, *0p, 0);               // 3.7; 3.7; ;
1430
1431        assert( &popped == &m3 );
1432}
1433
1434////////////////////////////////////////////////////////////
1435//
1436// Section 5
1437//
1438// Simple driver with the inter-scario printing
1439//
1440////////////////////////////////////////////////////////////
1441
1442int main() {
1443#if 0
1444        sout | "~~~~~~~~~~~~~~~~~ Headless List Tests - insert_after ~~~~~~~~~~~~~~~~";
1445        sout | "";
1446
1447        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1448        sout | "Test 1-i:  Modifying Freds on MINE ";
1449        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1450        test__insertafter_singleton_on_singleton__fred_mine();
1451
1452        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1453        sout | "Test 2-i.  Modifying Freds on YOURS";
1454        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1455        test__insertafter_singleton_on_singleton__fred_yours();
1456
1457        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1458        sout | "Test 3-i.  Modifying Maries";
1459        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1460        test__insertafter_singleton_on_singleton__mary();
1461
1462        sout | "";
1463        sout | "~~~~~~~~~~~~~~~~ Headless List Tests - insert_before ~~~~~~~~~~~~~~~~";
1464        sout | "";
1465
1466        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1467        sout | "Test 1-ii:  Modifying Freds on MINE ";
1468        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1469        test__insertbefore_singleton_on_singleton__fred_mine();
1470
1471        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1472        sout | "Test 2-ii.  Modifying Freds on YOURS";
1473        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1474        test__insertbefore_singleton_on_singleton__fred_yours();
1475
1476        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1477        sout | "Test 3-ii.  Modifying Maries";
1478        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1479        test__insertbefore_singleton_on_singleton__mary();
1480#endif
1481        sout | "";
1482        sout | "~~~~~~~~~~~~~~~~~ Headed List Tests - insert_first ~~~~~~~~~~~~~~~~~~";
1483        sout | "";
1484
1485        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1486        sout | "Test 4-i:  Modifying Freds on MINE ";
1487        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1488        test__insertfirst_two_on_empty__fred_mine();
1489
1490        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1491        sout | "Test 5-i:  Modifying Freds on YOURS ";
1492        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1493        test__insertfirst_two_on_empty__fred_yours();
1494
1495        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1496        sout | "Test 6-i.  Modifying Maries";
1497        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1498        test__insertfirst_two_on_empty__mary();
1499
1500        sout | "";
1501        sout | "~~~~~~~~~~~~~~~~~ Headed List Tests - insert_last ~~~~~~~~~~~~~~~~~~~";
1502        sout | "";
1503
1504        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1505        sout | "Test 4-ii:  Modifying Freds on MINE ";
1506        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1507        test__insertlast_two_on_empty__fred_mine();
1508
1509        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1510        sout | "Test 5-ii:  Modifying Freds on YOURS ";
1511        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1512        test__insertlast_two_on_empty__fred_yours();
1513
1514        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1515        sout | "Test 6-ii.  Modifying Maries";
1516        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1517        test__insertlast_two_on_empty__mary();
1518
1519        sout | "";
1520        sout | "~~~~~~~~~~~ Element ops on Headed List Tests: after, last ~~~~~~~~~~~";
1521        sout | "";
1522
1523        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1524        sout | "Test 7-i.  Modifying Freds on MINE";
1525        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1526        test__insertafter_after_last__fred_mine();
1527
1528        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1529        sout | "Test 8-i.  Modifying Freds on YOURS";
1530        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1531        test__insertafter_after_last__fred_yours();
1532
1533        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~";
1534        sout | "Test 9-i.  Modifying Maries";
1535        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~";
1536        test__insertafter_after_last__mary();
1537
1538        sout | "";
1539        sout | "~~~~~~~~~~ Element ops on Headed List Tests: before, first ~~~~~~~~~~";
1540        sout | "";
1541
1542        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1543        sout | "Test 7-ii.  Modifying Freds on MINE";
1544        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1545        test__insertbefore_before_first__fred_mine();
1546
1547        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1548        sout | "Test 8-ii.  Modifying Freds on YOURS";
1549        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1550        test__insertbefore_before_first__fred_yours();
1551
1552        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1553        sout | "Test 9-ii.  Modifying Maries";
1554        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1555        test__insertbefore_before_first__mary();
1556#if 0
1557
1558        sout | "";
1559        sout | "~~~~~~~~~~ Element removal tests on Headless List: mid ~~~~~~~~~~";
1560        sout | "";
1561
1562        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1563        sout | "Test 10-i.  Modifying Freds on MINE";
1564        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1565        test__remove_mid__fred_mine();
1566
1567        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1568        sout | "Test 11-i.  Modifying Freds on YOURS";
1569        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1570        test__remove_mid__fred_yours();
1571
1572        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1573        sout | "Test 12-i.  Modifying Maries";
1574        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1575        test__remove_mid__mary();
1576
1577        sout | "";
1578        sout | "~~~~~~~~~~ Element removal tests on Headless List: at first ~~~~~~~~~~";
1579        sout | "";
1580
1581        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1582        sout | "Test 10-ii.  Modifying Freds on MINE";
1583        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1584        test__remove_at_first__fred_mine();
1585
1586        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1587        sout | "Test 11-ii.  Modifying Freds on YOURS";
1588        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1589        test__remove_at_first__fred_yours();
1590
1591        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1592        sout | "Test 12-ii.  Modifying Maries";
1593        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1594        test__remove_at_first__mary();
1595
1596        sout | "";
1597        sout | "~~~~~~~~~~ Element removal tests on Headless List: at last ~~~~~~~~~~";
1598        sout | "";
1599
1600        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1601        sout | "Test 10-iii.  Modifying Freds on MINE";
1602        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1603        test__remove_at_last__fred_mine();
1604
1605        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1606        sout | "Test 11-iii.  Modifying Freds on YOURS";
1607        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1608        test__remove_at_last__fred_yours();
1609
1610        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1611        sout | "Test 12-iii.  Modifying Maries";
1612        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1613        test__remove_at_last__mary();
1614#endif
1615        sout | "";
1616        sout | "~~~~~~~~~~ Element removal tests on Headed List: at first ~~~~~~~~~~";
1617        sout | "";
1618
1619        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1620        sout | "Test 13-i.  Modifying Freds on MINE";
1621        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1622        test__remove_at_head__fred_mine();
1623
1624        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1625        sout | "Test 14-i.  Modifying Freds on YOURS";
1626        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1627        test__remove_at_head__fred_yours();
1628
1629        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1630        sout | "Test 15-i.  Modifying Maries";
1631        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1632        test__remove_at_head__mary();
1633
1634        sout | "";
1635        sout | "~~~~~~~~~~ Element removal tests on Headed List: at last ~~~~~~~~~~";
1636        sout | "";
1637
1638        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1639        sout | "Test 13-ii.  Modifying Freds on MINE";
1640        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1641        test__remove_at_tail__fred_mine();
1642
1643        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1644        sout | "Test 14-ii.  Modifying Freds on YOURS";
1645        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1646        test__remove_at_tail__fred_yours();
1647
1648        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1649        sout | "Test 15-ii.  Modifying Maries";
1650        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1651        test__remove_at_tail__mary();
1652
1653        sout | "";
1654        sout | "~~~~~~~~~~ Element removal tests on Headed List: of sole ~~~~~~~~~~";
1655        sout | "";
1656
1657        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1658        sout | "Test 13-iii.  Modifying Freds on MINE";
1659        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1660        test__remove_of_sole__fred_mine();
1661
1662        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1663        sout | "Test 14-iii.  Modifying Freds on YOURS";
1664        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1665        test__remove_of_sole__fred_yours();
1666
1667        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1668        sout | "Test 15-iii.  Modifying Maries";
1669        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1670        test__remove_of_sole__mary();
1671
1672        sout | "";
1673        sout | "~~~~~~~~~~ End removal tests on Headed List: First ~~~~~~~~~~";
1674        sout | "";
1675
1676        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1677        sout | "Test 16-i.  Modifying Freds on MINE";
1678        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1679        test__pop_first__fred_mine();
1680
1681        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1682        sout | "Test 16-ii.  Modifying Freds on YOURS";
1683        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1684        test__pop_first__fred_yours();
1685
1686        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1687        sout | "Test 16-iii.  Modifying Maries";
1688        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1689        test__pop_first__maries();
1690
1691        sout | "";
1692        sout | "~~~~~~~~~~ End removal tests on Headed List: Last ~~~~~~~~~~";
1693        sout | "";
1694
1695        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1696        sout | "Test 17-i.  Modifying Freds on MINE";
1697        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1698        test__pop_last__fred_mine();
1699
1700        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1701        sout | "Test 17-ii.  Modifying Freds on YOURS";
1702        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1703        test__pop_last__fred_yours();
1704
1705        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1706        sout | "Test 17-iii.  Modifying Maries";
1707        sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
1708        test__pop_last__maries();
1709
1710        return 0;
1711}
Note: See TracBrowser for help on using the repository browser.