aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_postcodes.rb
blob: e3f20809d7fda3209f6c711c8307407ccc3bb38a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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(24).must_equal nil
  end
end