Saturday 15 December 2018

TravelTimeCalculator: Improving Database

After being able to add a simple entry to the database, I want to add more modes of transport to the same origin and destination pair.

The first thing I saw was that the database isn't cleared automatically between the two test cases. I needed to add a method for tearing down the database between the test cases.

The setup method doesn't do anything for now.
The tearDown method clears the database.
If needed, I'll add more code later.

Test: Testing reversed directions

In order to reduce the number of Google Directions Queries that are sent, I'll assume that the transport durations and distances are similar in both directions. For example, I assume that the duration/distance between Trafalgar Square and Picadilly Circus in London is the same in both directions. When checking on Google Maps, it is not exactly the same, but close enough.

The test case looks like this:
The first test checks
In dbHelper, a query is first done in the intended direction (Trafalgar Square to Picadilly Circus) . If no entries are found, a query is done in the other direction (Picadilly Circus to Trafalgar Square). If nothing is found after that, 0 is returned.

Test: Check if dbHelper can add information to an existing entry.
Currently, dbHelper can add one entry for one mode. When trying to add a second entry for the same coordinates but with different mode, the database rejects that query since there is already an entry.

The second entry is currently rejected, since there is already one row in the database. 
The dbHelper needs to check if the entry exists. If it does, it shall run an UPDATE command, otherwise it shall INSERT into the database. I'll describe this in the next blog post.

No comments:

Post a Comment