Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Created June 4, 2010 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshCheek/425975 to your computer and use it in GitHub Desktop.
Save JoshCheek/425975 to your computer and use it in GitHub Desktop.
# test suite for http://www.rubyproblems.com/problems/2010/04/geography_lesson
def run_test( input , x , y )
it "should return [#{x},#{y}] when given #{input.inspect}" do
LatLon.to_xy(input).should == [ x , y ]
end
end
describe 'LatLon.to_xy' do
describe 'Signed Decimal Degrees' do
[ ["45.1234 36.2345" , 36.2345 , 45.1234 ],
["+45.1234 +36.2345" , 36.2345 , 45.1234 ],
["-45.1234 -36.2345" , -36.2345 , -45.1234 ],
["45.1234 -36.2345" , -36.2345 , 45.1234 ],
["-45.1234 36.2345" , 36.2345 , -45.1234 ],
].each &method(:run_test)
end
describe 'Decimal Degrees with Directions' do
[ ["45.1234 N 36.2345 E" , 36.2345 , 45.1234 ],
["45.1234 S 36.2345 W" , -36.2345 , -45.1234 ],
["45.1234 N 36.2345 W" , -36.2345 , 45.1234 ],
["45.1234 S 36.2345 E" , 36.2345 , -45.1234 ],
["N 45.1234 E 36.2345" , 36.2345 , 45.1234 ],
["S 45.1234 W 36.2345" , -36.2345 , -45.1234 ],
["N 45.1234 W 36.2345" , -36.2345 , 45.1234 ],
["S 45.1234 E 36.2345" , 36.2345 , -45.1234 ],
].each &method(:run_test)
end
describe 'Decimal Degrees and Minutes' do
[ ["40 30.6 N 65 36.36 E" , 65.606 , 40.51 ],
["40 30.6 S 65 36.36 W" , -65.606 , -40.51 ],
["40 30.6 N 65 36.36 W" , -65.606 , 40.51 ],
["N 40 30.6 E 65 36.36" , 65.606 , 40.51 ],
["S 40 30.6 W 65 36.36" , -65.606 , -40.51 ],
["N 40 30.6 W 65 36.36" , -65.606 , 40.51 ],
["40 30.6 65 36.36" , 65.606 , 40.51 ],
["+40 30.6 +65 36.36" , 65.606 , 40.51 ],
["-40 30.6 -65 36.36" , -65.606 , -40.51 ],
["40 30.6 -65 36.36" , -65.606 , 40.51 ],
["-40 30.6 65 36.36" , 65.606 , -40.51 ],
].each &method(:run_test)
end
describe 'Decimal Degrees, Minutes, and Seconds' do
[ ["45 45 4.5 N 38 30 10.8 E" , 38.503 , 45.75125 ],
["45 45 4.5 S 38 30 10.8 W" , -38.503 , -45.75125 ],
["45 45 4.5 N 38 30 10.8 W" , -38.503 , 45.75125 ],
["N 45 45 4.5 E 38 30 10.8" , 38.503 , 45.75125 ],
["S 45 45 4.5 W 38 30 10.8" , -38.503 , -45.75125 ],
["N 45 45 4.5 W 38 30 10.8" , -38.503 , 45.75125 ],
["45 45 4.5 38 30 10.8" , 38.503 , 45.75125 ],
["-45 45 4.5 -38 30 10.8" , -38.503 , -45.75125 ],
["45 45 4.5 -38 30 10.8" , -38.503 , 45.75125 ],
["-45 45 4.5 38 30 10.8" , 38.503 , -45.75125 ],
].each &method(:run_test)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment