1gap> q := PlistDeque(1000);
2<deque with 0/1000 entries>
3gap> q := PlistDeque(1000, "haar");
4Error, <factor> must be a rational greater than 1
5gap> q := PlistDeque((1,2,3));
6Error, <capacity> must be a positive integer
7gap> q := PlistDeque(1,2,3,4,5);
8Error, usage: PlistDeque( [ <capacity>, [ <factor> ] ])
9gap> q := PlistDeque();
10<deque with 0/64 entries>
11gap> PlistDequePushFront(q, fail);
12Error, <item> must not equal 'fail'
13gap> PlistDequePushBack(q, fail);
14Error, <item> must not equal 'fail'
15
16#
17gap> PlistDequePeekFront(q);
18fail
19gap> PlistDequePeekBack(q);
20fail
21gap> PlistDequePopBack(q);
22fail
23gap> PlistDequePopFront(q);
24fail
25gap> PlistDequePushFront(q, 15);
26gap> PlistDequePeekFront(q);
2715
28gap> PlistDequePeekBack(q);
2915
30gap> PlistDequePushBack(q,"haar");
31gap> PlistDequePeekBack(q);
32"haar"
33gap> PlistDequePopBack(q);
34"haar"
35gap> PlistDequePeekBack(q);
3615
37gap> PlistDequePopFront(q);
3815
39gap> PlistDequePushBack(q, 15);
40gap> PlistDequePopBack(q);
4115
42gap> IsEmpty(q);
43true
44
45# test size, make sure it is bigger than
46# initial capacity so that expansion happens
47gap> N := 1000;;
48gap> q := PlistDeque(QuoInt(N, 3));;
49
50# add at the front, pop at the back
51gap> for i in [1..N] do PushFront(q,i); od;
52gap> IsEmpty(q);
53false
54gap> Size(q) = N;
55true
56gap> out := List([1..N], x -> PopBack(q));;
57gap> out = [1..N];
58true
59gap> IsEmpty(q);
60true
61
62# add at the front, pop at the front
63gap> for i in [1..N] do PushFront(q,i); od;
64gap> IsEmpty(q);
65false
66gap> Size(q) = N;
67true
68gap> out := List([1..N], x -> PopFront(q));;
69gap> out = [N,N-1..1];
70true
71gap> IsEmpty(q);
72true
73
74# add at the back, pop at the front
75gap> for i in [1..N] do PushBack(q,i); od;
76gap> IsEmpty(q);
77false
78gap> Size(q) = N;
79true
80gap> out := List([1..N], x -> PopFront(q));;
81gap> out = [1..N];
82true
83gap> IsEmpty(q);
84true
85
86# add at the back, pop at the back
87gap> for i in [1..N] do PushBack(q,i); od;
88gap> IsEmpty(q);
89false
90gap> Size(q) = N;
91true
92gap> out := List([1..N], x -> PopBack(q));;
93gap> out = [N,N-1..1];
94true
95gap> IsEmpty(q);
96true
97
98# do some alternating fron/back pushes/pops
99gap> for i in [1..N] do PushBack(q,i); od;
100gap> for i in [1..QuoInt(N, 2)] do PushFront(q,i); od;
101gap> out1 := List([1..QuoInt(N, 3)], x -> PopBack(q));;
102gap> out2 := List([1..QuoInt(N, 3)], x -> PopFront(q));;
103gap> for i in [1..N] do PushBack(q,i);; od;
104gap> out3 := List([1..QuoInt(N, 3)], x -> PopFront(q));;
105gap> while not IsEmpty(q) do PopFront(q); od;
106gap> out1 = [N,N-1..N - QuoInt(N, 3) + 1];
107true
108
109# Test Resizing factor
110gap> q := PlistDeque(10, 3/2);
111<deque with 0/10 entries>
112gap> for i in [1..10] do PushBack(q, i); od;;
113gap> q;
114<deque with 10/15 entries>
115gap> for i in [11..20] do PushBack(q, i); od;;
116gap> q;
117<deque with 20/22 entries>
118gap> for i in [21..30] do PushBack(q, i); od;;
119gap> q;
120<deque with 30/33 entries>
121gap> out := [];; r := PopFront(q);; while r <> fail do Add(out, r); r := PopFront(q); od;;
122gap> out = [1..30];
123true
124gap> q := PlistDeque(1, 11/10);
125<deque with 0/1 entries>
126gap> PushBack(q, 1);
127gap> q;
128<deque with 1/1 entries>
129gap> PushBack(q, 1);
130gap> q;
131<deque with 1/6 entries>
132gap> PlistDequePeekBack(q);
1331
134gap> PlistDequePeekFront(q);
1351
136