Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1_8] improve test of tree, add tests for edge cases #36

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions tests/Kernel/Types/tree_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "moe_doctests.hpp"
#include "tree.hpp"
const int label= 123; // 123 can be a number != 0, thus the tree is compound.

TEST_CASE ("test_is_atomic") {
CHECK (is_atomic (tree ()));
Expand Down Expand Up @@ -55,10 +56,13 @@ TEST_CASE ("test_is_string") {
}

TEST_CASE ("test N()") {
CHECK (N (tree ()) == 0);
CHECK (N (tree (0, tree ())) == 1);
CHECK (N (tree (0, tree (), tree ())) == 2);
CHECK (N (tree (0, tree (), tree (), tree ())) == 3);
CHECK_EQ (N (tree ()), 0);
CHECK_EQ (N (tree ("")), 0);
CHECK_EQ (N (tree ("atomic tree")), 11);
CHECK_EQ (N (tree (1)), 0);
CHECK_EQ (N (tree (1, tree ())), 1);
CHECK_EQ (N (tree (1, tree (), tree ())), 2);
CHECK_EQ (N (tree (1, tree (), tree (), tree ())), 3);
}

TEST_CASE ("test_arity") {
Expand Down Expand Up @@ -107,8 +111,31 @@ TEST_CASE ("test operator==") {
CHECK (tree ("hello") == string ("hello"));
}

TEST_CASE ("tree operator*") {
CHECK_EQ (tree (label) * tree (label, "1", "2", "4"),
tree (label, "1", "2", "4"));
CHECK_EQ (tree ("str") * tree (label, "1", "2", "4"),
tree (label, "str", "1", "2", "4"));
CHECK_EQ (tree (label, "1", "2", "4") * tree ("str"),
tree (label, "1", "2", "4", "str"));
tree string_concat= tree ("str") * tree ("ing");
CHECK_EQ (string_concat->op, 0);
CHECK_EQ (N (string_concat), 2);
CHECK_EQ (A (string_concat), array<tree> ("str", "ing"));
}

TEST_CASE ("tree operator()") {
tree whole= tree (label, "str", "ing", "1", "2", "4");
CHECK_EQ (whole (2, N (whole)), tree (label, "1", "2", "4"));
CHECK_EQ (whole (0, 4), tree (label, "str", "ing", "1", "2"));
CHECK_EQ (whole (0, N (whole)), whole);

// tree atomic_tree= tree ("str"); this will cause crash!
// CHECK_EQ (atomic_tree (0, 1), atomic_tree);
}

TEST_CASE ("tree operator<<") {
tree t= tree (123); // 123 can be a number > 1
tree t= tree (label);
t << "1"
<< "2"
<< "4";
Expand All @@ -125,6 +152,7 @@ TEST_CASE ("test strong_equal") {
auto a= tree (0, tree ());
auto b= &a;
CHECK (strong_equal (a, *b));
CHECK (!strong_equal (tree (label, 1, 2), tree (label, 1, 2)));
CHECK (!strong_equal (tree (0, 1, 2), tree (3, tree ())));
CHECK (!strong_equal (tree (0, 1, 2), tree (4, tree ())));
}
Expand Down
Loading