| 1 | package atmsdriver.model; |
|---|
| 2 | |
|---|
| 3 | import atmsdriver.ATMSDriver; |
|---|
| 4 | import atmsdriver.model.Station.DIRECTION; |
|---|
| 5 | import java.io.File; |
|---|
| 6 | import java.io.FileWriter; |
|---|
| 7 | import java.io.PrintWriter; |
|---|
| 8 | import java.nio.file.FileSystems; |
|---|
| 9 | import java.nio.file.Files; |
|---|
| 10 | import java.nio.file.Path; |
|---|
| 11 | import java.util.ArrayList; |
|---|
| 12 | import junit.framework.TestCase; |
|---|
| 13 | |
|---|
| 14 | /** |
|---|
| 15 | * |
|---|
| 16 | * @author jdalbey |
|---|
| 17 | */ |
|---|
| 18 | public class LoadHighwaysTest extends TestCase { |
|---|
| 19 | |
|---|
| 20 | public LoadHighwaysTest(String testName) { |
|---|
| 21 | super(testName); |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | @Override |
|---|
| 25 | protected void setUp() throws Exception { |
|---|
| 26 | super.setUp(); |
|---|
| 27 | PrintWriter writer = null; |
|---|
| 28 | try { |
|---|
| 29 | writer = new PrintWriter(new FileWriter("test/atmsdriver/model/lds_loadhighways_sample.txt")); |
|---|
| 30 | |
|---|
| 31 | writer.println("lds_id line drop sch lineinfo system_key sch_seq glo_seq count freeway Dir ca_pm lds_name"); |
|---|
| 32 | writer.println("1203081 6 17 2 2 1123005691 26491 1357639 19 55 N 4.58 BRISTOL"); |
|---|
| 33 | writer.println("1210163 6 20 2 2 1123005691 26491 1357639 19 55 N 5.51 PAULARINO 1"); |
|---|
| 34 | writer.println("1203244 50 4 13 13 1123005873 24148 1357650 19 55 N 10 MCFADDEN"); |
|---|
| 35 | writer.println("1203211 50 5 13 13 1123005873 24148 1357650 19 55 N 9.41 EDINGER 2"); |
|---|
| 36 | |
|---|
| 37 | writer.println("1203261 23 14 23 21 1123005995 26479 1357626 18 55 S 10.4 S OF 5"); |
|---|
| 38 | writer.println("1203083 6 18 2 2 1123005691 26491 1357639 19 55 S 4.7 BAKER 1"); |
|---|
| 39 | writer.println("1210174 6 19 2 2 1123005691 26491 1357639 19 55 S 5.06 BAKER 2"); |
|---|
| 40 | writer.println("1203270 23 15 23 21 1123005995 26479 1357626 18 55 S 10.5 N OF 5"); |
|---|
| 41 | |
|---|
| 42 | writer.println("1205238 22 16 4 4 1123005726 26490 1357624 19 5 S 32.25 17TH 1"); |
|---|
| 43 | writer.println("1205208 22 17 4 4 1123005726 26490 1357624 19 5 S 31.6 GRAND 1"); |
|---|
| 44 | writer.println("1205270 5 19 1 1 1123005673 26492 1357648 20 5 S 33 MAIN 1 "); |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | writer.close(); |
|---|
| 48 | } catch (Exception e) { |
|---|
| 49 | e.printStackTrace(); |
|---|
| 50 | } |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | @Override |
|---|
| 54 | protected void tearDown() throws Exception { |
|---|
| 55 | super.tearDown(); |
|---|
| 56 | Path path = FileSystems.getDefault().getPath("test/atmsdriver/model", "lds_loadhighways_sample.txt"); |
|---|
| 57 | Files.delete(path); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | /** |
|---|
| 61 | * Test of toXML method, of class Network. |
|---|
| 62 | */ |
|---|
| 63 | public void testLoadHighways() { |
|---|
| 64 | System.out.println("toXML"); |
|---|
| 65 | Highways highways = new Highways( |
|---|
| 66 | "test/atmsdriver/model/lds_loadhighways_sample.txt", |
|---|
| 67 | "config/vds_data/loop.txt", |
|---|
| 68 | "config/vds_data/highwaysMeta.txt", |
|---|
| 69 | "localhost", 8080); |
|---|
| 70 | |
|---|
| 71 | // Test for correct number of highways |
|---|
| 72 | ArrayList<Highway> result = highways.getHighways(); |
|---|
| 73 | assertEquals(3, result.size()); |
|---|
| 74 | |
|---|
| 75 | // Test 55 N was loaded |
|---|
| 76 | Highway fiftyfiveN = result.get(2); |
|---|
| 77 | assertEquals(new Integer(55), fiftyfiveN.highwayNumber); |
|---|
| 78 | |
|---|
| 79 | // Test 55 N stations are sorted by postmile |
|---|
| 80 | ArrayList<Station> stations = fiftyfiveN.stations; |
|---|
| 81 | ArrayList<Double> stationsPostmiles = new ArrayList<>(); |
|---|
| 82 | for(Station station : stations) |
|---|
| 83 | { |
|---|
| 84 | stationsPostmiles.add(station.getPostmile()); |
|---|
| 85 | } |
|---|
| 86 | ArrayList<Double> expectedStationsPostmiles = new ArrayList<>(); |
|---|
| 87 | expectedStationsPostmiles.add(new Double(4.58)); |
|---|
| 88 | expectedStationsPostmiles.add(new Double(5.51)); |
|---|
| 89 | expectedStationsPostmiles.add(new Double(9.41)); |
|---|
| 90 | expectedStationsPostmiles.add(new Double(10)); |
|---|
| 91 | for(int i = 0; i < 4; i++) |
|---|
| 92 | { |
|---|
| 93 | assertEquals(expectedStationsPostmiles.get(i), |
|---|
| 94 | stationsPostmiles.get(i)); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | // Test 55 S was loaded |
|---|
| 98 | Highway fiftyfiveS = result.get(0); |
|---|
| 99 | assertEquals(new Integer(55), fiftyfiveS.highwayNumber); |
|---|
| 100 | |
|---|
| 101 | // Test 55 S stations are sorted by postmile |
|---|
| 102 | stations = fiftyfiveS.stations; |
|---|
| 103 | stationsPostmiles.clear(); |
|---|
| 104 | for(Station station : stations) |
|---|
| 105 | { |
|---|
| 106 | stationsPostmiles.add(station.getPostmile()); |
|---|
| 107 | } |
|---|
| 108 | expectedStationsPostmiles.clear(); |
|---|
| 109 | expectedStationsPostmiles.add(new Double(4.7)); |
|---|
| 110 | expectedStationsPostmiles.add(new Double(5.06)); |
|---|
| 111 | expectedStationsPostmiles.add(new Double(10.4)); |
|---|
| 112 | expectedStationsPostmiles.add(new Double(10.5)); |
|---|
| 113 | for(int i = 0; i < 4; i++) |
|---|
| 114 | { |
|---|
| 115 | assertEquals(expectedStationsPostmiles.get(i), |
|---|
| 116 | stationsPostmiles.get(i)); |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | Highway fiveS = result.get(1); |
|---|
| 120 | assertEquals(new Integer(5), fiveS.highwayNumber); |
|---|
| 121 | |
|---|
| 122 | // Test 5 S stations are sorted by postmile |
|---|
| 123 | stations = fiveS.stations; |
|---|
| 124 | stationsPostmiles.clear(); |
|---|
| 125 | for(Station station : stations) |
|---|
| 126 | { |
|---|
| 127 | stationsPostmiles.add(station.getPostmile()); |
|---|
| 128 | } |
|---|
| 129 | expectedStationsPostmiles.clear(); |
|---|
| 130 | expectedStationsPostmiles.add(new Double(31.6)); |
|---|
| 131 | expectedStationsPostmiles.add(new Double(32.25)); |
|---|
| 132 | expectedStationsPostmiles.add(new Double(33)); |
|---|
| 133 | for(int i = 0; i < 2; i++) |
|---|
| 134 | { |
|---|
| 135 | assertEquals(expectedStationsPostmiles.get(i), |
|---|
| 136 | stationsPostmiles.get(i)); |
|---|
| 137 | } |
|---|
| 138 | } |
|---|
| 139 | } |
|---|