Skip to content

Commit

Permalink
[2_3] add tree test
Browse files Browse the repository at this point in the history
  • Loading branch information
tangdouer1005 authored Aug 17, 2023
1 parent 85a8b88 commit 967a84d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 9 deletions.
10 changes: 1 addition & 9 deletions Kernel/Types/tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,7 @@ tree replace (tree t, tree w, tree b);
* Miscellaneous
******************************************************************************/

tree correct (tree t);
int hash (tree t);

class formatted {
public:
tree rep;
inline formatted (tree t) : rep (t) {}
inline formatted (const formatted& f) : rep (f.rep) {}
};
int hash (tree t);

struct less_eq_associate {
static inline bool leq (tree& a, tree& b) {
Expand Down
60 changes: 60 additions & 0 deletions tests/Kernel/Types/tree_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ TEST_CASE ("test A()") {
CHECK (A (tree (0, 1, 2, 3))[2] == 3);
}

TEST_CASE ("test AR()") {
tree a = tree (2, tree (3), tree (4));
AR (a)[0]= tree (5);
CHECK (A (a)[0] == tree (5));

CHECK (N (A (a)) == 2);
AR (a)= append (tree (5), AR (a));
CHECK (N (A (a)) == 3);
}

TEST_CASE ("test operator==") {
CHECK (tree (0, 1, 2) != 1);
CHECK (tree (0, 1, 2) != 2);
Expand All @@ -116,3 +126,53 @@ TEST_CASE ("test strong_equal") {
CHECK (!strong_equal (tree (0, 1, 2), tree (3, tree ())));
CHECK (!strong_equal (tree (0, 1, 2), tree (4, tree ())));
}

TEST_CASE ("test replace") {
tree la= tree (1, tree (2, tree (3), tree (3)));
tree ra= tree (1, tree (2, tree (4), tree (5)));
tree a = tree (1, la, ra);

tree lb= tree (1, tree (2, tree (6), tree (6)));
tree rb= tree (1, tree (2, tree (4), tree (5)));
tree b = tree (1, lb, rb);

a= replace (a, tree (3), tree (6));
CHECK (a == b);
b= replace (b, tree (4), tree (7));
CHECK (a != b);
b= replace (b, tree (7), tree (4));
CHECK (a == b);
}

TEST_CASE ("test operator=") {
tree a= tree (3, tree (2));

tree b= a;
CHECK (b == tree (3, tree (2)));

CHECK (a[0] == tree (2));
b[0]= tree (4);
CHECK (a[0] == tree (4));
}

TEST_CASE ("tree (const tree& x)") {
tree a= tree (3, tree (2));

tree b (a);
CHECK (b == tree (3, tree (2)));

CHECK (a[0] == tree (2));
b[0]= tree (4);
CHECK (a[0] == tree (4));
}

TEST_CASE ("copy") {
tree a= tree (3, tree (2));

tree b= copy (a);
CHECK (b == tree (3, tree (2)));

CHECK (a[0] == tree (2));
b[0]= tree (4);
CHECK (a[0] == tree (2));
}

0 comments on commit 967a84d

Please sign in to comment.