Lolly 1.4.27
Loading...
Searching...
No Matches
Functions | Variables
list_test.cpp File Reference
#include "a_lolly_test.hpp"
#include "list.hpp"
#include "string.hpp"
Include dependency graph for list_test.cpp:

Go to the source code of this file.

Functions

static list< longgen (int64_t n)
 
 TEST_CASE ("is nil")
 
 TEST_CASE ("is atom")
 
 TEST_CASE ("access")
 
 TEST_CASE ("operate on the last")
 
 TEST_CASE ("size")
 
 TEST_CASE ("copy")
 
 TEST_CASE ("append")
 
 TEST_CASE ("head and tail")
 
 TEST_CASE ("reverse")
 
 TEST_CASE ("remove")
 
 TEST_CASE ("contains")
 

Variables

auto the_nil_list = list<string> ()
 
auto the_atom_list = list<long> (1)
 
auto normal = list<long> (1, 2, 3, list<long> ())
 

Function Documentation

◆ gen()

static list< long > gen ( int64_t n)
static

Definition at line 17 of file list_test.cpp.

17 {
18 auto normal= list<long> ();
19 for (long i= 0; i < n; i++)
20 normal << i;
21 return normal;
22}
The list class represents a linked list.
Definition list.hpp:48
auto normal
Definition list_test.cpp:26

◆ TEST_CASE() [1/11]

TEST_CASE ( "is nil" )

Definition at line 28 of file list_test.cpp.

28 {
30 CHECK_EQ (is_nil (the_atom_list), false);
31}
bool is_nil(blackbox x)
Definition blackbox.hpp:29
auto the_nil_list
Definition list_test.cpp:24
auto the_atom_list
Definition list_test.cpp:25

◆ TEST_CASE() [2/11]

TEST_CASE ( "is atom" )

Definition at line 33 of file list_test.cpp.

33 {
34 CHECK_EQ (is_atom (the_nil_list), false);
36}
bool is_atom(list< T > l)
Check if a list is an atom (i.e., a single item).
Definition list.hpp:146

◆ TEST_CASE() [3/11]

TEST_CASE ( "access" )

Definition at line 42 of file list_test.cpp.

42 {
43 // QVERIFY_EXCEPTION_THROWN (the_nil_list[0], string);
44
45 CHECK_EQ (the_atom_list[0], 1L);
46
47 CHECK_EQ (normal[0], 1L);
48 CHECK_EQ (normal[1], 2L);
49 CHECK_EQ (normal[2], 3L);
50}

◆ TEST_CASE() [4/11]

TEST_CASE ( "operate on the last" )

Definition at line 56 of file list_test.cpp.

56 {
57 // QVERIFY_EXCEPTION_THROWN (access_last (the_nil_list), string);
58 // QVERIFY_EXCEPTION_THROWN (suppress_last (the_nil_list), string);
59 // QVERIFY_EXCEPTION_THROWN (last_item (the_nil_list), string);
60
67
68 auto normal_copy = copy (normal);
74}
int copy(int x)
Returns a copy of an integer.
Definition basic.hpp:249
T last_item(list< T > l)
Return the last item of the list. The input list must not be an empty list.
Definition list.ipp:79
T & access_last(list< T > &l)
Get a reference to the last item in a list.
Definition list.ipp:89
list< T > & suppress_last(list< T > &l)
Remove the last item from a list.
Definition list.ipp:97

◆ TEST_CASE() [5/11]

TEST_CASE ( "size" )

Definition at line 80 of file list_test.cpp.

80 {
81 CHECK_EQ (N (the_nil_list), 0);
83 CHECK_EQ (N (normal), 3);
84 for (auto i= 4; i <= 100; i++) {
85 auto list= gen (i);
86 CHECK_EQ (N (list), i);
87 }
88}
int N(array< T > a)
Get the length of the array.
Definition array.hpp:170
static list< long > gen(int64_t n)
Definition list_test.cpp:17

◆ TEST_CASE() [6/11]

TEST_CASE ( "copy" )

Definition at line 90 of file list_test.cpp.

◆ TEST_CASE() [7/11]

TEST_CASE ( "append" )

Definition at line 96 of file list_test.cpp.

96 {
97 auto appended= the_nil_list * string ("a");
98 CHECK_EQ (appended, list<string> (string ("a")));
99
100 auto to_append= list<string> ("a");
102
105
107
108 CHECK_EQ (list<long> (1L, 2L, list<long> ()) * list<long> (3L), normal);
109 CHECK_EQ (list<long> (1L) * list<long> (2L, 3L, list<long> ()), normal);
110}

◆ TEST_CASE() [8/11]

TEST_CASE ( "head and tail" )

Definition at line 112 of file list_test.cpp.

112 {
113 // QVERIFY_EXCEPTION_THROWN (head (the_nil_list), string);
114 // QVERIFY_EXCEPTION_THROWN (tail (the_nil_list), string);
115
118
120 CHECK_EQ (tail (normal), list<long> (2, 3, list<long> ()));
121}
list< T > tail(list< T > l, int n=1)
Get all but the first n items of a list.
Definition list.ipp:193
list< T > head(list< T > l, int n=1)
Get the first n items of a list.
Definition list.ipp:185

◆ TEST_CASE() [9/11]

TEST_CASE ( "reverse" )

Definition at line 123 of file list_test.cpp.

123 {
126 CHECK_EQ (reverse (normal), list<long> (3, 2, 1, list<long> ()));
127}
array< T > reverse(array< T > a)
Reverse an array.
Definition array.ipp:195

◆ TEST_CASE() [10/11]

TEST_CASE ( "remove" )

Definition at line 129 of file list_test.cpp.

129 {
130 CHECK_EQ (remove (the_nil_list, string ("a")), the_nil_list);
132 CHECK_EQ (remove (normal, 2L), list<long> (1, 3, list<long> ()));
133}
list< T > remove(list< T > l, T what)
Create a new list with a specific item removed.
Definition list.ipp:214

◆ TEST_CASE() [11/11]

TEST_CASE ( "contains" )

Definition at line 135 of file list_test.cpp.

135 {
136 CHECK_EQ (contains (the_nil_list, string ("a")), false);
137 CHECK_EQ (contains (the_atom_list, 1L), true);
138 CHECK_EQ (contains (normal, 1L), true);
139
140 CHECK_EQ (contains (normal, 2L), true);
141 CHECK_EQ (contains (normal, 3L), true);
142}
bool contains(T a, array< T > b)
Check if an array contains a specified element.

Variable Documentation

◆ the_nil_list

auto the_nil_list = list<string> ()

Definition at line 24 of file list_test.cpp.

◆ the_atom_list

auto the_atom_list = list<long> (1)

Definition at line 25 of file list_test.cpp.

◆ normal

auto normal = list<long> (1, 2, 3, list<long> ())

Definition at line 26 of file list_test.cpp.