1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 
5 module tanya.algorithm.tests.iteration;
6 
7 import tanya.algorithm.iteration;
8 import tanya.range;
9 import tanya.test.stub;
10 
11 // Singleton range is bidirectional and random-access
12 @nogc nothrow pure @safe unittest
13 {
14     static assert(isBidirectionalRange!(typeof(singleton('a'))));
15     static assert(isRandomAccessRange!(typeof(singleton('a'))));
16 
17     assert({ char a; return isBidirectionalRange!(typeof(singleton(a))); });
18     assert({ char a; return isRandomAccessRange!(typeof(singleton(a))); });
19 }
20 
21 @nogc nothrow pure @safe unittest
22 {
23     char a = 'a';
24     auto single = singleton(a);
25 
26     assert(single.front == 'a');
27     assert(single.back == 'a');
28     assert(single[0] == 'a');
29     assert(single.length == 1);
30     assert(!single.empty);
31 }
32 
33 // popFront makes SingletonByRef empty
34 @nogc nothrow pure @safe unittest
35 {
36     char a = 'a';
37     auto single = singleton(a);
38 
39     single.popFront();
40     assert(single.empty);
41     assert(single.length == 0);
42     assert(single.empty);
43 }
44 
45 // popBack makes SingletonByRef empty
46 @nogc nothrow pure @safe unittest
47 {
48     char a = 'b';
49     auto single = singleton(a);
50 
51     single.popBack();
52     assert(single.empty);
53     assert(single.length == 0);
54     assert(single.empty);
55 }