From 9c632321e0831123c9450eed1855630d02d9e98b Mon Sep 17 00:00:00 2001 From: Reuben Gardos Reid <5456207+ReubenJ@users.noreply.github.com> Date: Tue, 26 Nov 2024 19:17:10 +0300 Subject: [PATCH] Add tests --- Project.toml | 6 ------ src/HerbCore.jl | 4 ++++ test/Project.toml | 4 ++++ test/runtests.jl | 21 +++++++++++++++++++++ 4 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 test/Project.toml diff --git a/Project.toml b/Project.toml index 8fcea03..0fa0d58 100644 --- a/Project.toml +++ b/Project.toml @@ -9,9 +9,3 @@ AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" [compat] AbstractTrees = "0.4.5" julia = "^1.8" - -[extras] -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - -[targets] -test = ["Test"] diff --git a/src/HerbCore.jl b/src/HerbCore.jl index 1f7b8f8..941f168 100644 --- a/src/HerbCore.jl +++ b/src/HerbCore.jl @@ -32,4 +32,8 @@ export have_same_shape, AbstractConstraint, AbstractGrammar +# AbstractTrees interface +children, +nodevalue + end # module HerbCore diff --git a/test/Project.toml b/test/Project.toml new file mode 100644 index 0000000..7084a9f --- /dev/null +++ b/test/Project.toml @@ -0,0 +1,4 @@ +[deps] +AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" +HerbGrammar = "4ef9e186-2fe5-4b24-8de7-9f7291f24af7" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/runtests.jl b/test/runtests.jl index 06d0c01..7543f08 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,8 +1,29 @@ +using AbstractTrees: children, nodevalue, treeheight using HerbCore +using HerbGrammar: @csgrammar using Test @testset "HerbCore.jl" verbose=true begin + @testset "AbstractTrees Interface" begin + @show typeof(nodevalue(RuleNode(1))) + @test nodevalue(RuleNode(1)) == 1 + @test isempty(children(RuleNode(1))) + @test length(children(RuleNode(1, [RuleNode(2), RuleNode(2)]))) == 2 + @test treeheight(RuleNode(1)) == 0 + @test treeheight(RuleNode(1, [RuleNode(2), RuleNode(2)])) == 1 + end + @testset "RuleNode tests" begin + @testset "Constructors with Grammar" begin + g = @csgrammar begin + A = B + B + B = 2 + end + + r = RuleNode(1, g) + @test get_children(r)[1].domain == [0, 1] + @test get_children(r)[2].domain == [0, 1] + end @testset "Equality tests" begin @test RuleNode(1) == RuleNode(1)