Skip to content

Commit

Permalink
Tests to run against sample lists of postcodes. If you have the PostZ…
Browse files Browse the repository at this point in the history
…on file, you can generate a list and put it in test/samples/postzon.list to test against it.
  • Loading branch information
threedaymonk committed Jan 9, 2010
1 parent 16182e3 commit 95f0b6e
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/samples/postzon.list
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ spec = Gem::Specification.new do |s|

s.has_rdoc = true

s.files = %w(Rakefile README.md) + Dir.glob("{bin,test,lib}/**/*")
s.files = %w(Rakefile README.md) + Dir.glob("{bin,test,lib}/**/*") - ["test/samples/postzon.list"]
s.executables = FileList["bin/**"].map { |f| File.basename(f) }

s.require_paths = ["lib"]
Expand Down
36 changes: 36 additions & 0 deletions test/samples/wikipedia.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Special postcodes listed in http://en.wikipedia.org/wiki/UK_postcode

SW1A 0AA
SW1A 1AA
SW1A 2AA
BS98 1TL
BX1 1LT
BX5 5AT
CF99 1NA
DH99 1NS
E16 1XL
E98 1NW
E98 1SN
E98 1ST
E98 1TT
EC4Y 0HQ
EH99 1SP
EN8 9SL
G58 1SB
GIR 0AA
L30 4GB
LS98 1FD
M2 5BE
N81 1ER
S2 4SU
S6 1SW
SE1 8UJ
SE9 2UG
SN38 1NW
SW1A 0PW
SW1A 2HQ
SW1W 0DT
TS1 3BA
W1A 1AA
W1F 9DJ
GIR 0AA
28 changes: 28 additions & 0 deletions test/test_samples.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
require "test/unit"
require "shoulda"
require "uk_postcode"

class UKPostcodeTest < Test::Unit::TestCase

Dir[File.join(File.dirname(__FILE__), "samples", "*.list")].each do |path|
context "in sample file #{File.basename(path, ".list")}" do
setup do
@file = open(path)
end

teardown do
@file.close
end

should "be valid for each line in sample file" do
@file.each_line do |line|
next if line =~ /^#|^$/
sample = line.chomp.sub(/\s+/, "")
postcode = UKPostcode.new(sample)
assert postcode.valid?, "'#{sample}' should be valid"
end
end
end
end
end

0 comments on commit 95f0b6e

Please sign in to comment.