From 9ecb661af9dedfd14ddacc6fd66839f8edf159f5 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Thu, 15 Jan 2015 23:41:11 +0100 Subject: First commit. --- test/test_postcodes.rb | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/test_postcodes.rb (limited to 'test') diff --git a/test/test_postcodes.rb b/test/test_postcodes.rb new file mode 100644 index 0000000..1c4f368 --- /dev/null +++ b/test/test_postcodes.rb @@ -0,0 +1,55 @@ +require 'minitest/autorun' +require_relative '../lib/norwegian-postcodes' + +describe PostCodes::PostCode do + before do + @postcode = PostCodes::PostCode.new('1234', 'MYTOWN', '1378', 'MY MUNICIPALITY', 'G') + end + + it "compares to a postcode" do + (@postcode >= '1233').must_equal true + (@postcode >= '1234').must_equal true + (@postcode >= '1235').must_equal false + end + + it "has a county" do + @postcode.county.must_equal [13, '(BERGEN)'] + end + + it "can print it's original form" do + @postcode.to_s.must_equal "1234\tMYTOWN\t1378\tMY MUNICIPALITY\tG" + end +end + +describe 'PostCodes::county' do + it "must give the right county names" do + PostCodes.county(1).must_equal('ØSTFOLD') + PostCodes.county(2).must_equal('AKERSHUS') + PostCodes.county(3).must_equal('OSLO') + PostCodes.county(4).must_equal('HEDMARK') + PostCodes.county(5).must_equal('OPPLAND') + PostCodes.county(6).must_equal('BUSKERUD') + PostCodes.county(7).must_equal('VESTFOLD') + PostCodes.county(8).must_equal('TELEMARK') + PostCodes.county(9).must_equal('AUST-AGDER') + PostCodes.county(10).must_equal('VEST-AGDER') + PostCodes.county(11).must_equal('ROGALAND') + PostCodes.county(12).must_equal('HORDALAND') + PostCodes.county(13).must_equal('(BERGEN)') + PostCodes.county(14).must_equal('SOGN OG FJORDANE') + PostCodes.county(15).must_equal('MØRE OG ROMSDAL') + PostCodes.county(16).must_equal('SØR-TRØNDELAG') + PostCodes.county(17).must_equal('NORD-TRØNDELAG') + PostCodes.county(18).must_equal('NORDLAND') + PostCodes.county(19).must_equal('TROMS') + PostCodes.county(20).must_equal('FINNMARK') + PostCodes.county(21).must_equal('SVALBARD') + PostCodes.county(22).must_equal('JAN MAYEN') + PostCodes.county(23).must_equal('KONTINENTALSOKKELEN') + end + + it "must fail on invalid county codes" do + PostCodes.county(0).must_equal nil + PostCodes.county(25).must_equal nil + end +end \ No newline at end of file -- cgit v1.2.3