1
1
#include " moe_doctests.hpp"
2
2
#include " tree.hpp"
3
+ const int label= 123 ; // 123 can be a number != 0, thus the tree is compound.
3
4
4
5
TEST_CASE (" test_is_atomic" ) {
5
6
CHECK (is_atomic (tree ()));
@@ -55,10 +56,13 @@ TEST_CASE ("test_is_string") {
55
56
}
56
57
57
58
TEST_CASE (" test N()" ) {
58
- CHECK (N (tree ()) == 0 );
59
- CHECK (N (tree (0 , tree ())) == 1 );
60
- CHECK (N (tree (0 , tree (), tree ())) == 2 );
61
- CHECK (N (tree (0 , tree (), tree (), tree ())) == 3 );
59
+ CHECK_EQ (N (tree ()), 0 );
60
+ CHECK_EQ (N (tree (" " )), 0 );
61
+ CHECK_EQ (N (tree (" atomic tree" )), 11 );
62
+ CHECK_EQ (N (tree (1 )), 0 );
63
+ CHECK_EQ (N (tree (1 , tree ())), 1 );
64
+ CHECK_EQ (N (tree (1 , tree (), tree ())), 2 );
65
+ CHECK_EQ (N (tree (1 , tree (), tree (), tree ())), 3 );
62
66
}
63
67
64
68
TEST_CASE (" test_arity" ) {
@@ -107,8 +111,31 @@ TEST_CASE ("test operator==") {
107
111
CHECK (tree (" hello" ) == string (" hello" ));
108
112
}
109
113
114
+ TEST_CASE (" tree operator*" ) {
115
+ CHECK_EQ (tree (label) * tree (label, " 1" , " 2" , " 4" ),
116
+ tree (label, " 1" , " 2" , " 4" ));
117
+ CHECK_EQ (tree (" str" ) * tree (label, " 1" , " 2" , " 4" ),
118
+ tree (label, " str" , " 1" , " 2" , " 4" ));
119
+ CHECK_EQ (tree (label, " 1" , " 2" , " 4" ) * tree (" str" ),
120
+ tree (label, " 1" , " 2" , " 4" , " str" ));
121
+ tree string_concat= tree (" str" ) * tree (" ing" );
122
+ CHECK_EQ (string_concat->op , 0 );
123
+ CHECK_EQ (N (string_concat), 2 );
124
+ CHECK_EQ (A (string_concat), array<tree> (" str" , " ing" ));
125
+ }
126
+
127
+ TEST_CASE (" tree operator()" ) {
128
+ tree whole= tree (label, " str" , " ing" , " 1" , " 2" , " 4" );
129
+ CHECK_EQ (whole (2 , N (whole)), tree (label, " 1" , " 2" , " 4" ));
130
+ CHECK_EQ (whole (0 , 4 ), tree (label, " str" , " ing" , " 1" , " 2" ));
131
+ CHECK_EQ (whole (0 , N (whole)), whole);
132
+
133
+ // tree atomic_tree= tree ("str"); this will cause crash!
134
+ // CHECK_EQ (atomic_tree (0, 1), atomic_tree);
135
+ }
136
+
110
137
TEST_CASE (" tree operator<<" ) {
111
- tree t= tree (123 ); // 123 can be a number > 1
138
+ tree t= tree (label);
112
139
t << " 1"
113
140
<< " 2"
114
141
<< " 4" ;
@@ -125,6 +152,7 @@ TEST_CASE ("test strong_equal") {
125
152
auto a= tree (0 , tree ());
126
153
auto b= &a;
127
154
CHECK (strong_equal (a, *b));
155
+ CHECK (!strong_equal (tree (label, 1 , 2 ), tree (label, 1 , 2 )));
128
156
CHECK (!strong_equal (tree (0 , 1 , 2 ), tree (3 , tree ())));
129
157
CHECK (!strong_equal (tree (0 , 1 , 2 ), tree (4 , tree ())));
130
158
}
0 commit comments