source: tests/list/dlist-insert-remove.cfa @ 4ef08f7

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 4ef08f7 was f2d05e9, checked in by Michael Brooks <mlbrooks@…>, 4 years ago

Dlist API getting pop_first, pop_last, ?`is_empty on the list head.

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