Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. package comp125;
  2.  
  3. import static org.junit.Assert.*;
  4.  
  5. import java.io.IOException;
  6.  
  7. import org.junit.Test;
  8.  
  9. /**
  10. * A Class that looks at all the CSVs in a directory
  11. *
  12. * @author josh.soutar
  13. *
  14. */
  15.  
  16. public class TrackLogTest {
  17.  
  18. /**
  19. * Tests the creation and size of a directory
  20. *
  21. * @param
  22. */
  23.  
  24. @Test
  25. public void testTrackLogString() throws IOException {
  26. // test that we can make a tracklog from a directory full of
  27. // csv files
  28. final String directory = "data";
  29. TrackLog tl = new TrackLog(directory);
  30. assertEquals(8, tl.size());
  31.  
  32. }
  33.  
  34. /**
  35. * Arrange Test that takes a sample of expected string values which will
  36. * fail if the sample is not contained within the string
  37. *
  38. * @param
  39. */
  40.  
  41. @Test
  42. public void testToString() throws IOException {
  43.  
  44. TrackLog logs = new TrackLog("data");
  45. String trackSummary = logs.toString();
  46.  
  47. // Track summary of first log
  48. assertTrue(trackSummary
  49. .contains("Filename: data/bobbin-head.csv, Distance: 9.03199518670082, Elevation: 218.00000000000074, Timestamp: 2014-08-06T21:01:50Z,"));
  50.  
  51. // Track summary of middle log
  52. assertTrue(trackSummary
  53. .contains("Filename: data/offroad.csv, Distance: 19.569013073057786, Elevation: 78.4, Timestamp: 2014-06-01T09:14:18Z, "));
  54.  
  55. // Track summary of last log
  56. assertTrue(trackSummary
  57. .contains("Filename: data/ttt.csv, Distance: 17.54949730369033, Elevation: 283.0, Timestamp: 2014-07-19T02:44:26Z,"));
  58.  
  59. }
  60.  
  61. /**
  62. * Test the order of TrackLog array based on shortest distance
  63. *
  64. * @param value
  65. * @throws IOException
  66. * Report if input file is bad
  67. */
  68.  
  69. // Check if every distance element is greater than the one before it
  70. @Test
  71. public void testSortDistance() throws IOException {
  72.  
  73. final String directory = "data";
  74. TrackLog tl = new TrackLog(directory);
  75.  
  76. TrackLog.sortDistance(TrackLog.tracksTest);
  77.  
  78. for (int i = 1; i < tl.size(); i++) {
  79.  
  80. assertTrue(TrackLog.tracksTest[i].getDistance() >= TrackLog.tracksTest[i - 1]
  81. .getDistance());
  82. System.out.println("index " + i + " - "
  83. + TrackLog.tracksTest[i].getDistance() + " >= " + "index "
  84. + (i - 1) + " - "
  85. + TrackLog.tracksTest[i - 1].getDistance());
  86.  
  87. }
  88. }
  89.  
  90. /**
  91. * Arrange time stamp summaries based on earliest time to latest
  92. *
  93. * @param
  94. */
  95.  
  96. // Check if every time stamp element is greater than the one before it
  97. @Test
  98. public void testSortTimestamp() throws IOException {
  99.  
  100. final String directory = "data";
  101. TrackLog tl = new TrackLog(directory);
  102.  
  103. TrackLog.sortTimestamp(TrackLog.tracksTest);
  104.  
  105. for (int i = 1; i < tl.size(); i++) {
  106.  
  107. System.out.println("index " + i + " - "
  108. + TrackLog.tracksTest[i].getTimestamp() + " >= " + "index "
  109. + (i - 1) + " - "
  110. + TrackLog.tracksTest[i - 1].getTimestamp());
  111. assertTrue(TrackLog.tracksTest[i].getTimestamp().compareTo(
  112. TrackLog.tracksTest[i - 1].getTimestamp()) >= 0);
  113.  
  114. }
  115. }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement