Web Dev Training with #WeGotCoders: Week 3
This past week weāve been looking at TDD with Minitest & Rspec. Ā
We were working on a flight calculator, that takes coordinates and flight details and works out the distance between two airports and the estimated time of arrival. Ā We used Minitest to drive the development and were looking to refactor the calculator with SRP, extensibility and re-usability of code in mind. Ā
A separation of concerns lead us to create two classes ā flight, that contained knowledge of its own airline, flight number, destination etc, and Coordinates ā Ā which was responsible for calculating the distance between two point using longitudes, latitudes and radians.
Weāre now working on persisting the data, and producing reports of incoming flight information in html, csv and text formats. Ā Weāve created extra Reports classes and sub classes to handle the report generation.
Hereās some of our tests for the Coordinate class:
describe "Coordinates" do
Ā before do
Ā Ā @lhr = Coordinates.new(lat: 51.4700223, lng: -0.4542955)
Ā Ā @jfk = Coordinates.new(lat: 40.6413111, lng: -73.77813909999999)
Ā end
Ā it "has objects which know their own latitude and longitude" do
Ā Ā @lhr.lat.must_equal 51.4700223
Ā Ā @lhr.lng.must_equal -0.4542955
Ā Ā @jfk.lat.must_equal 40.6413111
Ā Ā @jfk.lng.must_equal -73.77813909999999
Ā end
Ā it "converts lat and lng into radians" do
Ā Ā @lhr.to_radians(51.4700223).must_equal 0.8983213552099045
Ā Ā @lhr.to_radians(-0.4542955).must_equal -0.0079289522519939
Ā Ā @jfk.to_radians(40.6413111).must_equal 0.7093246910223184
Ā Ā @jfk.to_radians(-73.77813909999999).must_equal -1.287671443289366
Ā end
Ā it "calculates the distance to another coordinate object" do
Ā Ā @lhr.distance_to(@jfk).must_equal 5540.01265634309
Ā end
end