Files
old-pruning-excersise/test/pruner_test.rb
2018-08-13 18:54:12 +02:00

62 lines
2.3 KiB
Ruby

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