require 'test/unit' # # # class TC_Type_Conversions < Test::Unit::TestCase YearInput = Struct.new(:te_year, :available_years) def setup @inst = LocalImport.new end def test_closest_year puts("testing") # YearInput => expected chosen year cases = { YearInput.new(2001, []) => nil, YearInput.new(2001, [2001]) => 2001, YearInput.new(2001, [2001, 2002]) => 2001, YearInput.new(2001, [2001, 2000]) => 2001, # When distances are equal, take the latest year. YearInput.new(2002, [2001, 2003]) => 2003, YearInput.new(2002, [2003, 2001]) => 2003, YearInput.new(2001, [2002, 2003]) => 2002, YearInput.new(2000, [1234, 2001]) => 2001, YearInput.new(2000, [1234, 1235]) => 1235 } cases.each { |input, expected| output = @inst.send(:closest_year, input.te_year, input.available_years) puts("TEMP: testing") assert_equal(expected, output) } end end