Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Commit

Permalink
* Included tests for "flush" methods. #41
Browse files Browse the repository at this point in the history
  • Loading branch information
garciparedes committed Sep 1, 2019
1 parent 341c53d commit 76de8c9
Showing 1 changed file with 137 additions and 19 deletions.
156 changes: 137 additions & 19 deletions tests/test_models/test_stops.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,45 @@
from tests.utils import (
generate_one_vehicle,
generate_one_position,
)
generate_one_route)


class TestStop(unittest.TestCase):

def test_creation(self):
vehicle = generate_one_vehicle()
route = jit.Route(vehicle)
@classmethod
def setUpClass(cls) -> None:
cls.vehicle = generate_one_vehicle()
cls.route = jit.Route(cls.vehicle)

cls.position = generate_one_position()

position = generate_one_position()
stop = jit.Stop(route, position, None)
def test_creation(self):
stop = jit.Stop(self.route, self.position, None)

self.assertEqual(stop.route, route)
self.assertEqual(stop.position, position)
self.assertEqual(stop.route, self.route)
self.assertEqual(stop.position, self.position)
self.assertEqual(stop.previous, None)
self.assertEqual(stop.previous_position, vehicle.initial)
self.assertEqual(stop.previous_departure_time, vehicle.earliest)
self.assertEqual(stop.navigation_time, stop.position.time_to(vehicle.initial, stop.previous_departure_time))
self.assertEqual(stop.previous_position, self.vehicle.initial)
self.assertEqual(stop.previous_departure_time, self.vehicle.earliest)
self.assertEqual(
stop.navigation_time,
stop.position.time_to(self.vehicle.initial, stop.previous_departure_time),
)
self.assertEqual(stop.waiting_time, 0.0)
self.assertEqual(stop.down_time, 0.0)
self.assertEqual(stop.load_time, 0.0)

def test_creation_with_previous(self):
vehicle = generate_one_vehicle()
route = jit.Route(vehicle)

previous_position = generate_one_position()
previous_stop = jit.Stop(route, previous_position, None)
previous_stop = jit.Stop(self.route, previous_position, None)

position = generate_one_position()
stop = jit.Stop(route, position, previous_stop)
stop = jit.Stop(self.route, self.position, previous_stop)
previous_stop.following = stop

self.assertEqual(previous_stop.following, stop)

self.assertEqual(stop.route, route)
self.assertEqual(stop.position, position)
self.assertEqual(stop.route, self.route)
self.assertEqual(stop.position, self.position)
self.assertEqual(stop.previous, previous_stop)
self.assertEqual(stop.distance, stop.position.distance_to(previous_stop.position))
self.assertEqual(stop.previous_position, previous_stop.position)
Expand All @@ -51,6 +53,122 @@ def test_creation_with_previous(self):
stop.position.time_to(previous_stop.position, stop.previous_departure_time),
)

def test_stops(self):
route = generate_one_route()
stop = route.stops[0]
self.assertEqual(route.stops, stop.stops)

def test_flush(self):
stop = jit.Stop(self.route, self.position, None)

self.assertIsNone(stop._down_time)
self.assertIsNone(stop._load_time)
self.assertIsNone(stop._earliest)
self.assertIsNone(stop._arrival_time)

self.assertIsInstance(stop.departure_time, float)

self.assertIsNotNone(stop._down_time)
self.assertIsNotNone(stop._load_time)
self.assertIsNotNone(stop._earliest)
self.assertIsNotNone(stop._arrival_time)

stop.flush()

self.assertIsNone(stop._down_time)
self.assertIsNone(stop._load_time)
self.assertIsNone(stop._earliest)
self.assertIsNone(stop._arrival_time)

def test_all_following(self):
stop0 = jit.Stop(self.route, self.position, None)

stop1 = jit.Stop(self.route, generate_one_position(), stop0)
stop0.following = stop1

stop2 = jit.Stop(self.route, generate_one_position(), stop1)
stop1.following = stop2

stop3 = jit.Stop(self.route, generate_one_position(), stop2)
stop2.following = stop3

stop4 = jit.Stop(self.route, generate_one_position(), stop3)
stop3.following = stop4

stops = [stop0, stop1, stop2, stop3, stop4]

for stop in stops:
self.assertIsNone(stop._down_time)
self.assertIsNone(stop._load_time)
self.assertIsNone(stop._earliest)
self.assertIsNone(stop._arrival_time)

self.assertIsInstance(stops[-1].departure_time, float)

for stop in stops:
self.assertIsNotNone(stop._down_time)
self.assertIsNotNone(stop._load_time)
self.assertIsNotNone(stop._earliest)
self.assertIsNotNone(stop._arrival_time)

stop2.flush_all_following()

for stop in stops[:2]:
self.assertIsNotNone(stop._down_time)
self.assertIsNotNone(stop._load_time)
self.assertIsNotNone(stop._earliest)
self.assertIsNotNone(stop._arrival_time)
for stop in stops[2:]:
self.assertIsNone(stop._down_time)
self.assertIsNone(stop._load_time)
self.assertIsNone(stop._earliest)
self.assertIsNone(stop._arrival_time)

def test_all_previous(self):
stop0 = jit.Stop(self.route, self.position, None)

stop1 = jit.Stop(self.route, generate_one_position(), stop0)
stop0.following = stop1

stop2 = jit.Stop(self.route, generate_one_position(), stop1)
stop1.following = stop2

stop3 = jit.Stop(self.route, generate_one_position(), stop2)
stop2.following = stop3

stop4 = jit.Stop(self.route, generate_one_position(), stop3)
stop3.following = stop4

stops = [stop0, stop1, stop2, stop3, stop4]

for stop in stops:
self.assertIsNone(stop._down_time)
self.assertIsNone(stop._load_time)
self.assertIsNone(stop._earliest)
self.assertIsNone(stop._arrival_time)

self.assertIsInstance(stops[-1].departure_time, float)

for stop in stops:
self.assertIsNotNone(stop._down_time)
self.assertIsNotNone(stop._load_time)
self.assertIsNotNone(stop._earliest)
self.assertIsNotNone(stop._arrival_time)

stop2.flush_all_previous()

for stop in stops[:3]:
self.assertIsNone(stop._down_time)
self.assertIsNone(stop._load_time)
self.assertIsNone(stop._earliest)
self.assertIsNone(stop._arrival_time)

for stop in stops[3:]:
self.assertIsNotNone(stop._down_time)
self.assertIsNotNone(stop._load_time)
self.assertIsNotNone(stop._earliest)
self.assertIsNotNone(stop._arrival_time)


if __name__ == '__main__':
unittest.main()

0 comments on commit 76de8c9

Please sign in to comment.