1
1
#include < sstream>
2
2
#include < string>
3
- #include < type_traits>
4
3
5
4
#include < gtest/gtest.h>
6
5
7
6
#include " ../h/list.h"
8
7
9
-
10
8
using namespace ctgl ;
11
9
12
-
13
- // Convenient Type Aliases
14
- // -----------------------------------------------------------------------------
15
- template <typename T, typename U>
16
- using RemoveType = decltype(remove(T{}, U{}));
17
-
18
- template <typename T>
19
- using FrontType = decltype(front(T{}));
20
-
21
- template <typename T>
22
- using UniqueType = decltype(unique(T{}));
23
-
24
-
25
- // Unit Tests
26
- // -----------------------------------------------------------------------------
27
- // Tests for the size() function.
10
+ // Unit tests for the ctgl::list::size() function.
28
11
TEST (ListTest, Size ) {
29
- EXPECT_EQ (size (List<>{}), 0 );
30
- EXPECT_EQ (size (List<int >{}), 1 );
31
- EXPECT_EQ (size (List<int , float , double >{}), 3 );
32
- EXPECT_EQ (size (List<int , int >{}), 2 );
12
+ // Empty
13
+ EXPECT_EQ (list::size (List<>{}), 0 );
14
+
15
+ // Not Empty
16
+ EXPECT_EQ (list::size (List<int >{}), 1 );
17
+ EXPECT_EQ (list::size (List<int , int >{}), 2 );
18
+ EXPECT_EQ (list::size (List<int , float , double >{}), 3 );
33
19
}
34
20
35
- // Tests for the empty() function.
21
+ // Unit tests for the ctgl::list:: empty() function.
36
22
TEST (ListTest, Empty) {
23
+ // Empty
37
24
EXPECT_TRUE (empty (List<>{}));
25
+
26
+ // Not Empty
38
27
EXPECT_FALSE (empty (List<int >{}));
39
28
EXPECT_FALSE (empty (List<int , bool >{}));
40
29
}
41
30
42
- // Tests for the remove() function.
31
+ // Unit tests for the ctgl::list:: remove() function.
43
32
TEST (ListTest, Remove) {
44
33
// Empty
45
- EXPECT_TRUE ((std::is_same<RemoveType< int , List<>> , List<>>::value) );
34
+ EXPECT_EQ ( remove ( int {} , List<>{}) , List<>{} );
46
35
47
36
// Single
48
- EXPECT_TRUE ((std::is_same<RemoveType< int , List<int >> , List<>>::value) );
49
- EXPECT_TRUE ((std::is_same<RemoveType< bool , List<int >> , List<int >>::value) );
37
+ EXPECT_EQ ( remove ( int {} , List<int >{}) , List<>{} );
38
+ EXPECT_EQ ( remove ( bool {} , List<int >{}) , List<int >{} );
50
39
51
40
// Multiple
52
- EXPECT_TRUE ((std::is_same<RemoveType< int , List<int , int >> , List<>>::value) );
53
- EXPECT_TRUE ((std::is_same<RemoveType< int , List<int , float , int >> , List<float >>::value) );
54
- EXPECT_TRUE ((std::is_same<RemoveType< int , List<float , double >>, List<float , double >>::value ));
41
+ EXPECT_EQ ( remove ( int {} , List<int , int >{}) , List<>{} );
42
+ EXPECT_EQ ( remove ( int {} , List<int , float , int >{}) , List<float >{} );
43
+ EXPECT_EQ ( remove ( int {} , List<float , double >{}), ( List<float , double >{} ));
55
44
}
56
45
57
- // Tests for the front() function.
46
+ // Unit tests for the ctgl::list:: front() function.
58
47
TEST (ListTest, Front) {
59
- EXPECT_TRUE ((std::is_same<FrontType< List<int >> , int >::value) );
60
- EXPECT_TRUE ((std::is_same<FrontType< List<int , float , double >> , int >::value) );
48
+ EXPECT_EQ ( front ( List<int >{}) , int {} );
49
+ EXPECT_EQ ( front ( List<int , float , double >{}) , int {} );
61
50
}
62
51
63
- // Tests for the contains() function.
52
+ // Unit tests for the ctgl::list:: contains() function.
64
53
TEST (ListTest, Contains) {
65
54
// Empty
66
55
EXPECT_FALSE (contains (int {}, List<>{}));
@@ -74,22 +63,22 @@ TEST(ListTest, Contains) {
74
63
EXPECT_FALSE (contains (bool {}, List<int , float , double >{}));
75
64
}
76
65
77
- // Tests for the unique() function.
66
+ // Unit tests for the ctgl::list:: unique() function.
78
67
TEST (ListTest, Unique) {
79
68
// Empty
80
- EXPECT_TRUE ((std::is_same<UniqueType< List<>> , List<>>::value) );
69
+ EXPECT_EQ ( unique ( List<>{}) , List<>{} );
81
70
82
71
// Identity
83
- EXPECT_TRUE ((std::is_same<UniqueType< List<int >> , List<int >>::value) );
84
- EXPECT_TRUE ((std::is_same<UniqueType< List<int , double >>, List<int , double >>::value ));
72
+ EXPECT_EQ ( unique ( List<int >{}) , List<int >{} );
73
+ EXPECT_EQ ( unique ( List<int , double >{}), ( List<int , double >{} ));
85
74
86
75
// Duplicates
87
- EXPECT_TRUE ((std::is_same<UniqueType< List<int , int >> , List<int >>::value) );
88
- EXPECT_TRUE ((std::is_same<UniqueType< List<int , bool , int >>, List<bool , int >>::value ));
89
- EXPECT_TRUE ((std::is_same<UniqueType< List<bool , int , bool , int >>, List<bool , int >>::value ));
76
+ EXPECT_EQ ( unique ( List<int , int >{}) , List<int >{} );
77
+ EXPECT_EQ ( unique ( List<int , bool , int >{}), ( List<bool , int >{} ));
78
+ EXPECT_EQ ( unique ( List<bool , int , bool , int >{}), ( List<bool , int >{} ));
90
79
}
91
80
92
- // Tests for the "==" operator.
81
+ // Unit tests for the ctgl::list:: "==" operator.
93
82
TEST (ListTest, Equals) {
94
83
// Empty
95
84
EXPECT_TRUE (List<>{} == List<>{});
@@ -110,23 +99,23 @@ TEST(ListTest, Equals) {
110
99
EXPECT_FALSE ((List<int , bool >{}) == (List<bool , int >{}));
111
100
}
112
101
113
- // Tests for the "+" operator.
102
+ // Unit tests for the ctgl::list:: "+" operator.
114
103
TEST (ListTest, Plus) {
115
104
// Empty
116
- EXPECT_TRUE (List<>{} + List<>{} == List<>{});
105
+ EXPECT_EQ (List<>{} + List<>{}, List<>{});
117
106
118
107
// Single
119
- EXPECT_TRUE (int {} + List<>{} == List<int >{});
120
- EXPECT_TRUE (List<>{} + int {} == List<int >{});
108
+ EXPECT_EQ (int {} + List<>{}, List<int >{});
109
+ EXPECT_EQ (List<>{} + int {}, List<int >{});
121
110
122
111
// Multiple
123
- EXPECT_TRUE (( int {} + List<int >{} == List<int , int >{}));
124
- EXPECT_TRUE (( int {} + List<bool >{} == List<int , bool >{}));
125
- EXPECT_TRUE (( List<int >{} + bool {} == List<int , bool >{}));
126
- EXPECT_TRUE (( List<int >{} + List<bool >{} == List<int , bool >{}));
112
+ EXPECT_EQ ( int {} + List<int >{}, ( List<int , int >{}));
113
+ EXPECT_EQ ( int {} + List<bool >{}, ( List<int , bool >{}));
114
+ EXPECT_EQ ( List<int >{} + bool {}, ( List<int , bool >{}));
115
+ EXPECT_EQ ( List<int >{} + List<bool >{}, ( List<int , bool >{}));
127
116
}
128
117
129
- // Tests for the "<<" operator.
118
+ // Unit tests for the ctgl::list:: "<<" operator.
130
119
TEST (ListTest, OutputStream) {
131
120
{ // Empty
132
121
std::ostringstream stream;
0 commit comments