summaryrefslogtreecommitdiff
path: root/src/Q10/TrainTimeTableTest.java
blob: 021703003b5481de10214b9768f090dc6a96f543 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package ca.mokhan.test;

import Q10.*;
import java.io.*;
import java.text.*;
import java.util.*;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

public class TrainTimeTableTest extends TestCase {
  private TrainTimeTable subject;
  private LinkedList<Station> stations =
      new LinkedList<Station>(
          Arrays.asList(
              new Station("Vancouver", null, new Date(1546374600000L), 1),
              new Station("Kamloops", new Date(1546408800000L), new Date(1546410900000L), 2),
              new Station("Jasper", new Date(1546444800000L), new Date(1546450200000L), 2),
              new Station("Edmonton", new Date(1546470000000L), new Date(1546473540000L), 2),
              new Station("Saskatchewan", new Date(1546502400000L), new Date(1546503900000L), 3),
              new Station("Winnipeg", new Date(1546548300000L), new Date(1546554600000L), 3),
              new Station("Sioux Lookout", new Date(1546578120000L), new Date(1546580520000L), 4),
              new Station("Hornepayne", new Date(1546616100000L), new Date(1546618200000L), 4),
              new Station("Capreol", new Date(1546647480000L), new Date(1546649280000L), 5),
              new Station("Toronto", new Date(1546680600000L), null, 5)));

  public TrainTimeTableTest(String testName) {
    super(testName);
    this.subject = new TrainTimeTable(this.stations);
  }

  public static Test suite() {
    return new TestSuite(TrainTimeTableTest.class);
  }

  public void test_delay_edmonton_30minutes() {
    this.subject.delay("Edmonton", 30);

    Station station = this.subject.stationIn("Edmonton");
    assertNotNull(station);
    assertEquals("Edmonton", station.getCity());
    assertEquals("23:30", station.getArrival());
    assertEquals("00:29", station.getDeparture());
    assertEquals(3, station.getDay());

    station = this.subject.stationIn("Saskatchewan");
    assertNotNull(station);
    assertEquals("Saskatchewan", station.getCity());
    assertEquals("08:30", station.getArrival());
    assertEquals("08:55", station.getDeparture());
    assertEquals(3, station.getDay());

    station = this.subject.stationIn("Winnipeg");
    assertNotNull(station);
    assertEquals("Winnipeg", station.getCity());
    assertEquals("21:15", station.getArrival());
    assertEquals("23:00", station.getDeparture());
    assertEquals(3, station.getDay());

    station = this.subject.stationIn("Sioux Lookout");
    assertNotNull(station);
    assertEquals("Sioux Lookout", station.getCity());
    assertEquals("05:32", station.getArrival());
    assertEquals("06:12", station.getDeparture());
    assertEquals(4, station.getDay());

    station = this.subject.stationIn("Hornepayne");
    assertNotNull(station);
    assertEquals("Hornepayne", station.getCity());
    assertEquals("16:05", station.getArrival());
    assertEquals("16:40", station.getDeparture());
    assertEquals(4, station.getDay());

    station = this.subject.stationIn("Capreol");
    assertNotNull(station);
    assertEquals("Capreol", station.getCity());
    assertEquals("00:48", station.getArrival());
    assertEquals("01:18", station.getDeparture());
    assertEquals(5, station.getDay());

    station = this.subject.stationIn("Toronto");
    assertNotNull(station);
    assertEquals("Toronto", station.getCity());
    assertEquals("10:00", station.getArrival());
    assertEquals("-", station.getDeparture());
    assertEquals(5, station.getDay());
  }

  public void test_stationIn() {
    assertNotNull(this.subject.stationIn("Edmonton"));
    assertEquals("Edmonton", this.subject.stationIn("Edmonton").getCity());
  }

  public void test_stationIn_lowercase() {
    assertNotNull(this.subject.stationIn("edmonton"));
    assertEquals("Edmonton", this.subject.stationIn("edmonton").getCity());
  }
}