Test for Pruner
This commit is contained in:
61
test/pruner_test.rb
Normal file
61
test/pruner_test.rb
Normal file
@@ -0,0 +1,61 @@
|
||||
require 'minitest/autorun'
|
||||
require_relative 'test_helper'
|
||||
require_relative '../lib/pruner'
|
||||
|
||||
|
||||
class TestPruner < MiniTest::Test
|
||||
|
||||
def test_prune_happy_path
|
||||
correct_tree = json_fixture('fixtures/correct_tree.json')
|
||||
pruner = Pruning::Processing::Pruner.new(correct_tree)
|
||||
tree = pruner.prune_tree([299])
|
||||
expected = [{"id"=>1, "name"=>"Urban Extent",
|
||||
"sub_themes"=>[{"categories"=>[{"id"=>1,
|
||||
"indicators"=>[{"id"=>299, "name"=>"Total"}],
|
||||
"name"=>"Area",
|
||||
"unit"=>"(sq. km.)"}],
|
||||
"id"=>1,
|
||||
"name"=>"Administrative"}]}]
|
||||
|
||||
assert_equal(expected, tree)
|
||||
end
|
||||
|
||||
def test_different_top_level_nodes
|
||||
correct_tree = json_fixture('fixtures/correct_tree.json')
|
||||
pruner = Pruning::Processing::Pruner.new(correct_tree)
|
||||
tree = pruner.prune_tree([299, 131])
|
||||
expected = [{"id"=>1, "name"=>"Urban Extent",
|
||||
"sub_themes"=>[{"categories"=>[{"id"=>1, "indicators"=>[{"id"=>299, "name"=>"Total"}],
|
||||
"name"=>"Area", "unit"=>"(sq. km.)"}], "id"=>1, "name"=>"Administrative"}]},
|
||||
{"id"=>8, "name"=>"Business",
|
||||
"sub_themes"=>[{"categories"=>[{"id"=>55, "indicators"=>[{"id"=>131, "name"=>"6-9"}],
|
||||
"name"=>"Non-agriculture enterprises by size", "unit"=>"(percent of establishments)"}],
|
||||
"id"=>24, "name"=>"Economic census"}]}]
|
||||
|
||||
|
||||
assert_equal(expected, tree)
|
||||
end
|
||||
|
||||
def test_no_indicators
|
||||
correct_tree = json_fixture('fixtures/correct_tree.json')
|
||||
pruner = Pruning::Processing::Pruner.new(correct_tree)
|
||||
tree = pruner.prune_tree([])
|
||||
assert_equal([], tree)
|
||||
end
|
||||
|
||||
|
||||
def test_with_nonexistant_ids
|
||||
correct_tree = json_fixture('fixtures/correct_tree.json')
|
||||
pruner = Pruning::Processing::Pruner.new(correct_tree)
|
||||
tree = pruner.prune_tree([6000, 7000])
|
||||
assert_equal([], tree)
|
||||
end
|
||||
|
||||
def test_broken_tree
|
||||
missing_indicators_tree = json_fixture('fixtures/missing_indicators.json')
|
||||
pruner = Pruning::Processing::Pruner.new(missing_indicators_tree)
|
||||
tree = pruner.prune_tree([299])
|
||||
assert_equal([], tree)
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user