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

Go to the source code of this file.

Functions

static array< int > gen_array (int n)
 
 TEST_CASE ("test access")
 
 TEST_CASE ("test multiply")
 
 TEST_CASE ("test divide")
 
 TEST_CASE ("test range")
 
 TEST_CASE ("test size")
 
 TEST_CASE ("test copy")
 
 TEST_CASE ("test append")
 
 TEST_CASE ("test reverse")
 
 TEST_CASE ("test contains")
 
 TEST_CASE ("array of string")
 
 TEST_CASE ("test iteration")
 

Variables

auto zero_elem = array<int> ()
 
auto one_elem = append (1, zero_elem)
 
auto two_elem = array<int> (1, 2)
 
auto three_elem = array<int> (1, 2, 3)
 
auto four_elem = array<int> (1, 2, 3, 4)
 
auto five_elem = array<int> (1, 2, 3, 4, 5)
 

Function Documentation

◆ gen_array()

static array< int > gen_array ( int n)
static

Definition at line 6 of file array_test.cpp.

6 {
7 auto normal= array<int> ();
8 for (auto i= 1; i <= n; i++) {
9 normal << i;
10 }
11 return normal;
12}
The list class represents a linked list.
Definition list.hpp:48
auto normal
Definition list_test.cpp:26

◆ TEST_CASE() [1/11]

TEST_CASE ( "test access" )

Definition at line 21 of file array_test.cpp.

21 {
22 CHECK_EQ (five_elem[0], 1);
23 CHECK_EQ (five_elem[1], 2);
24 CHECK_EQ (five_elem[2], 3);
25 CHECK_EQ (five_elem[3], 4);
26 CHECK_EQ (five_elem[4], 5);
27 CHECK_EQ (one_elem[0], 1);
28}
auto one_elem
auto five_elem

◆ TEST_CASE() [2/11]

TEST_CASE ( "test multiply" )

Definition at line 30 of file array_test.cpp.

30 {
31 auto mulu4= array<int> ();
32 for (auto i= 1; i < 6; i++) {
33 mulu4 << (i * 4);
34 }
36}

◆ TEST_CASE() [3/11]

TEST_CASE ( "test divide" )

Definition at line 38 of file array_test.cpp.

38 {
39 auto mulu4= array<int> ();
40 for (auto i= 1; i < 6; i++) {
41 mulu4 << (i * 4);
42 }
44}

◆ TEST_CASE() [4/11]

TEST_CASE ( "test range" )

Definition at line 46 of file array_test.cpp.

46 {
47 CHECK_EQ (range (gen_array (10), 0, 5), five_elem);
49}
array< T > range(array< T > a, int i, int j)
Get a subarray of an array.
Definition array.ipp:184
auto four_elem
static array< int > gen_array(int n)
Definition array_test.cpp:6

◆ TEST_CASE() [5/11]

TEST_CASE ( "test size" )

Definition at line 51 of file array_test.cpp.

51 {
52 CHECK_EQ (N (zero_elem), 0);
53 CHECK_EQ (N (one_elem), 1);
54 CHECK_EQ (N (two_elem), 2);
55 CHECK_EQ (N (three_elem), 3);
56 CHECK_EQ (N (four_elem), 4);
57 CHECK_EQ (N (five_elem), 5);
58 for (auto i= 6; i < 200; i++) {
59 auto array_test= gen_array (i);
60 CHECK_EQ (N (array_test), i);
61 }
62}
int N(array< T > a)
Get the length of the array.
Definition array.hpp:170
auto zero_elem
auto two_elem
auto three_elem

◆ TEST_CASE() [6/11]

TEST_CASE ( "test copy" )

Definition at line 64 of file array_test.cpp.

64 {
71}
int copy(int x)
Returns a copy of an integer.
Definition basic.hpp:249

◆ TEST_CASE() [7/11]

TEST_CASE ( "test append" )

Definition at line 73 of file array_test.cpp.

73 {
80
81 auto one2ten= gen_array (10);
82 auto six2ten= array<int> (6, 7, 8, 9, 10);
83 for (auto i= 1; i <= 10; i++) {
84 CHECK_EQ (one2ten[i - 1], i);
85 }
87}
array< T > append(T a, array< T > b)
Append an element to the beginning of an array.

◆ TEST_CASE() [8/11]

TEST_CASE ( "test reverse" )

Definition at line 89 of file array_test.cpp.

89 {
92 auto rev_five= array<int> (5, 4, 3, 2, 1);
94}
array< T > reverse(array< T > a)
Reverse an array.
Definition array.ipp:195

◆ TEST_CASE() [9/11]

TEST_CASE ( "test contains" )

Definition at line 96 of file array_test.cpp.

96 {
97 CHECK_EQ (contains (1, zero_elem), false);
98 CHECK_EQ (contains (1, one_elem), true);
99 CHECK_EQ (contains (3, two_elem), false);
100 CHECK_EQ (contains (1, five_elem), true);
101 CHECK_EQ (contains (2, five_elem), true);
102 CHECK_EQ (contains (3, five_elem), true);
103}
bool contains(T a, array< T > b)
Check if an array contains a specified element.

◆ TEST_CASE() [10/11]

TEST_CASE ( "array of string" )

Definition at line 105 of file array_test.cpp.

105 {
106 auto arr= array<string> ();
107 arr << "Hello"
108 << "1"
109 << "2"
110 << "3";
111 CHECK (contains (string ("Hello"), arr));
112 arr << "】";
113 CHECK (contains (string ("】"), arr));
114}

◆ TEST_CASE() [11/11]

TEST_CASE ( "test iteration" )

Definition at line 116 of file array_test.cpp.

116 {
117 int expectedIndex= 0;
118 for (const auto element : five_elem) {
121 }
123
124 expectedIndex= 0;
125 for (const auto element : zero_elem) {
128 }
130}

Variable Documentation

◆ zero_elem

auto zero_elem = array<int> ()

Definition at line 14 of file array_test.cpp.

◆ one_elem

auto one_elem = append (1, zero_elem)

Definition at line 15 of file array_test.cpp.

◆ two_elem

auto two_elem = array<int> (1, 2)

Definition at line 16 of file array_test.cpp.

◆ three_elem

auto three_elem = array<int> (1, 2, 3)

Definition at line 17 of file array_test.cpp.

◆ four_elem

auto four_elem = array<int> (1, 2, 3, 4)

Definition at line 18 of file array_test.cpp.

◆ five_elem

auto five_elem = array<int> (1, 2, 3, 4, 5)

Definition at line 19 of file array_test.cpp.