From fa6c02dc6cb4de175ec70c490f65bbb94468089f Mon Sep 17 00:00:00 2001 From: Dimitri Lozeve Date: Sat, 22 Feb 2020 17:28:47 +0100 Subject: [PATCH] Add tests for classifications --- test/classification.jl | 39 +++++++++++++++++++++++++++++++++++++++ test/runtests.jl | 1 + 2 files changed, 40 insertions(+) create mode 100644 test/classification.jl diff --git a/test/classification.jl b/test/classification.jl new file mode 100644 index 0000000..7b009cf --- /dev/null +++ b/test/classification.jl @@ -0,0 +1,39 @@ +using GardenOptim +using Test + +@testset "classification" begin + clf = GardenOptim.Classification( + Dict( + "type"=>"Life", + "name"=>"God", + "children"=>[ + Dict( + "type"=>"Family", + "name"=>"Homo", + "children"=>[ + Dict( + "type"=>"Species", + "name"=>"Human", + "bio"=>"Homo sapiens", + "children"=>[] + ) + ] + ) + ] + ) + ) + @testset "constructor" begin + @test_throws UndefRefError clf.parent + @test clf.children[1].parent === clf + @test length(clf.children) == 1 + @test clf.children[1].type == :family + @test clf.children[1].children[1].bio == "Homo sapiens" + @test clf.children[1].children[1].name == :human + @test clf.children[1].children[1].children == [] + end + @testset "getfirstparent" begin + @test GardenOptim.getfirstparent(:human, clf) === clf.children[1] + @test GardenOptim.getfirstparent(:homo, clf) === clf.children[1] + @test_throws UndefRefError GardenOptim.getfirstparent(:god, clf) + end +end diff --git a/test/runtests.jl b/test/runtests.jl index 8f104d0..6394948 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -33,4 +33,5 @@ using Test grid[9] = 3 @test GardenOptim.deltacost(grid, costs, 3, 8) != 0 end + include("classification.jl") end