Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package comp125;
- import static org.junit.Assert.*;
- import java.io.IOException;
- import org.junit.Test;
- /**
- * A Class that looks at all the CSVs in a directory
- *
- * @author josh.soutar
- *
- */
- public class TrackLogTest {
- /**
- * Tests the creation and size of a directory
- *
- * @param
- */
- @Test
- public void testTrackLogString() throws IOException {
- // test that we can make a tracklog from a directory full of
- // csv files
- final String directory = "data";
- TrackLog tl = new TrackLog(directory);
- assertEquals(8, tl.size());
- }
- /**
- * Arrange Test that takes a sample of expected string values which will
- * fail if the sample is not contained within the string
- *
- * @param
- */
- @Test
- public void testToString() throws IOException {
- TrackLog logs = new TrackLog("data");
- String trackSummary = logs.toString();
- // Track summary of first log
- assertTrue(trackSummary
- .contains("Filename: data/bobbin-head.csv, Distance: 9.03199518670082, Elevation: 218.00000000000074, Timestamp: 2014-08-06T21:01:50Z,"));
- // Track summary of middle log
- assertTrue(trackSummary
- .contains("Filename: data/offroad.csv, Distance: 19.569013073057786, Elevation: 78.4, Timestamp: 2014-06-01T09:14:18Z, "));
- // Track summary of last log
- assertTrue(trackSummary
- .contains("Filename: data/ttt.csv, Distance: 17.54949730369033, Elevation: 283.0, Timestamp: 2014-07-19T02:44:26Z,"));
- }
- /**
- * Test the order of TrackLog array based on shortest distance
- *
- * @param value
- * @throws IOException
- * Report if input file is bad
- */
- // Check if every distance element is greater than the one before it
- @Test
- public void testSortDistance() throws IOException {
- final String directory = "data";
- TrackLog tl = new TrackLog(directory);
- TrackLog.sortDistance(TrackLog.tracksTest);
- for (int i = 1; i < tl.size(); i++) {
- assertTrue(TrackLog.tracksTest[i].getDistance() >= TrackLog.tracksTest[i - 1]
- .getDistance());
- System.out.println("index " + i + " - "
- + TrackLog.tracksTest[i].getDistance() + " >= " + "index "
- + (i - 1) + " - "
- + TrackLog.tracksTest[i - 1].getDistance());
- }
- }
- /**
- * Arrange time stamp summaries based on earliest time to latest
- *
- * @param
- */
- // Check if every time stamp element is greater than the one before it
- @Test
- public void testSortTimestamp() throws IOException {
- final String directory = "data";
- TrackLog tl = new TrackLog(directory);
- TrackLog.sortTimestamp(TrackLog.tracksTest);
- for (int i = 1; i < tl.size(); i++) {
- System.out.println("index " + i + " - "
- + TrackLog.tracksTest[i].getTimestamp() + " >= " + "index "
- + (i - 1) + " - "
- + TrackLog.tracksTest[i - 1].getTimestamp());
- assertTrue(TrackLog.tracksTest[i].getTimestamp().compareTo(
- TrackLog.tracksTest[i - 1].getTimestamp()) >= 0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement