def test_validTrip(self): geocodes = {} failure = set() test_tripA = parser.Trip("P", "1:00 PM", "1", "43", "Brattle St", "CAMBRIDGE", "2138", "29", "ST. SAUVEUR CT", "CAMBRIDGE", "2138", geocodes, failure) test_tripB = parser.Trip("A", "2:00 PM", "1", "43", "Brattle St", "CAMBRIDGE", "2138", "29", "ST. SAUVEUR CT", "CAMBRIDGE", "2138", geocodes, failure) # invalid trip with an invalid drop off in San Francisco, too far test_tripInvalidDropOff = parser.Trip("A", "2:00 PM", "1", "43", "Brattle St", "CAMBRIDGE", "2138", "1999", "16TH AVENUE", "SAN FRANCISCO", "94122", geocodes, failure) # invalid trip with an invalid pickup and invalid drop off both in San Francisco, too far test_tripInvalidPickup = parser.Trip("A", "2:00 PM", "1", "277", "CIRCLE SQUARE RD", "SAN FRANCISCO", "94155", "1999", "16TH AVENUE", "SAN FRANCISCO", "94122", geocodes, failure) test_tripA.pickupcoords = (42.3742077, -71.1214233) test_tripA.dropoffcoords = (42.3772638, -71.153024) test_tripB.pickupcoords = (42.3772638, -71.153024) test_tripB.dropoffcoords = (42.3772638, -71.153024) self.assertEqual(test_tripA.valid_trip(), True) self.assertEqual(test_tripB.valid_trip(), True) self.assertEqual(test_tripInvalidDropOff.valid_trip(), False) self.assertEqual(test_tripInvalidPickup.valid_trip(), False)
def test_time_windows_pickup_arrival(self): geocodes = {} failure = set() tripa = parser.Trip("P", "1:00 PM", "1", "50", "ARSENAL ST", "WATERTOWN", "2472", "468", "ARSENAL ST", "WATERTOWN", "2472", geocodes, failure) self.assertEqual(tripa.earliestDropoff, tools.time_to_seconds("1:00 PM") - 300 + tripa.time_for_travel()) self.assertEqual(tripa.earliestPickup, tools.time_to_seconds("1:00 PM") - 300) self.assertEqual(tripa.latestDropoff, tools.time_to_seconds("1:00 PM") + 900 + tripa.time_for_travel()) self.assertEqual(tripa.latestPickup, tools.time_to_seconds("1:00 PM") + 900) self.assertEqual(tripa.earliestDropoff, 46654.956821359854) self.assertEqual(tripa.earliestPickup, 46500) self.assertEqual(tripa.latestDropoff, 47854.956821359854) self.assertEqual(tripa.latestPickup, 47700) tripb = parser.Trip("A", "2:00 PM", "1", "50", "ARSENAL ST", "WATERTOWN", "2472", "468", "ARSENAL ST", "WATERTOWN", "2472", geocodes, failure) self.assertEqual(tripb.earliestDropoff, tools.time_to_seconds("2:00 PM") - 1200) self.assertEqual(tripb.earliestPickup, tools.time_to_seconds("2:00 PM") - tripb.time_for_travel() - 1200) self.assertEqual(tripb.latestDropoff, tools.time_to_seconds("2:00 PM")) self.assertEqual(tripb.latestPickup, tools.time_to_seconds("2:00 PM") - tripb.time_for_travel()) self.assertEqual(tripb.earliestDropoff, 49200) self.assertEqual(tripb.earliestPickup, 49045.043178640146) self.assertEqual(tripb.latestDropoff, 50400) self.assertEqual(tripb.latestPickup, 50245.043178640146)
def test_GCD(self): geocodes = {} failure = set() test_tripA = parser.Trip("P", "1:00 PM", "1", "43", "Brattle St", "CAMBRIDGE", "2138", "29", "ST. SAUVEUR CT", "CAMBRIDGE", "2138", geocodes, failure) test_tripC = parser.Trip("P", "1:00 PM", "1", "43", "Brattle St", "CAMBRIDGE", "2138", "43", "Brattle St", "CAMBRIDGE", "2138", geocodes, failure) test_tripB = parser.Trip("A", "2:00 PM", "1", "43", "Brattle St", "CAMBRIDGE", "2138", "29", "ST. SAUVEUR CT", "CAMBRIDGE", "2138", geocodes, failure) self.assertEqual(abs(test_tripA.time_for_travel()), 232.68405651298116) self.assertEqual(abs(test_tripB.time_for_travel()), 232.68405651298116) self.assertEqual(abs(test_tripC.time_for_travel()), 0)
def test_geo_lookup_failDropoff(self): trip1 = parser.Trip("P", "3:00 PM", "2", "232", "SAINT PAUL ST", "BROOKLINE", "2445", "13", "Pierce St", "BROOKLINE", "2445", {"152 SUTHERLAND RD BRIGHTON 2135": "42.340794,-71.1474"}, {"13 Pierce St BROOKLINE 2445"}) self.assertEqual(None, trip1.dropoffcoords) self.assertEqual(None, trip1.geo_lookup({"152 SUTHERLAND RD BRIGHTON 2135": "42.340794,-71.1474"}, {"13 Pierce St BROOKLINE 2445"}))
def test_geo_lookup_failPickup(self): trip1 = parser.Trip("A", "6:00 PM", "1", "232", "SAINT PAUL ST", "BROOKLINE", "2445", "13", "Pierce St", "BROOKLINE", "2445", {"149 SUTHERLAND RD BRIGHTON 2135": "42.34075,-71.1474"}, {'13 Pierce St BROOKLINE 2445', '149 SUTHERLAND RD BRIGHTON 2135'}) self.assertEqual(None, trip1.pickupcoords) self.assertEqual(None, trip1.geo_lookup({"149 SUTHERLAND RD BRIGHTON 2135": "42.34075,-71.1474"}, {'13 Pierce St BROOKLINE 2445', '149 SUTHERLAND RD BRIGHTON 2135'}))
def test_one_bad_address_one_good(self): failure = set() success = {} trip1 = parser.Trip("P", "1:00 PM", "1", "43", "St", "CAMBRIDGE", "2138", "29", "ST. SAUVEUR CT", "CAMBRIDGE", "2138", success, failure) self.assertEqual(1, len(success)) self.assertEqual(1, len(failure))
def test_manhatten_distance2(self): geocodes = {} failure = set() pickup = [10, 10] dropoff = [15, 15] self.assertTrue(abs(tools.distance(pickup[0], pickup[1], dropoff[0], dropoff[1]) - 482) < 1) tripb = parser.Trip("P", "1:00 PM", "1", "75", "Liverpool St", "EAST BOSTON", "2128", "272", "BRANDYWYNE DR", "EAST BOSTON", "2128", geocodes, failure) tripb.pickupcoords = (42.3718638, -71.04096969999999) tripb.dropoffcoords = (42.3873459, -71.0134044) self.assertEqual(abs(tripb.time_for_travel()), 254.57535846730815)
def test_lookup(self): trip1 = parser.Trip("P", "3:00 PM", "2", "232", "SAINT PAUL ST", "BROOKLINE", "2445", "149", "SUTHERLAND RD", "BRIGHTON", "2135", {"149 SUTHERLAND RD BRIGHTON 2135": "42.34075,-71.1474"}, {"13 Pierce St BROOKLINE 2445"}) self.assertEqual(None, trip1.lookup("SUTHERLAND RD", 149, "SUTHERLAND RD", "BRIGHTON", 42.34075, -71.1474, {"149 SUTHERLAND RD BRIGHTON 2135"}))
def test_geo_lookup_successDropoff(self): trip1 = parser.Trip("P", "3:00 PM", "2", "232", "SAINT PAUL ST", "BROOKLINE", "2445", "149", "SUTHERLAND RD", "BRIGHTON", "2135", {"149 SUTHERLAND RD BRIGHTON 2135": "42.34075,-71.1474"}, {"13 Pierce St BROOKLINE 2445"}) self.assertEqual((42.34075, -71.1474), trip1.dropoffcoords)
def test_geo_lookup_successPickup(self): trip1 = parser.Trip("A", "6:00 PM", "1", "149", "SUTHERLAND RD", "BRIGHTON", "2135", "232", "SAINT PAUL ST", "BROOKLINE", "2445", {"149 SUTHERLAND RD BRIGHTON 2135": "42.34075,-71.1474"}, {'13 Pierce St BROOKLINE 2445', '63 EVERETT ST ALLSTON 2134'}) self.assertEqual((42.34075, -71.1474), trip1.pickupcoords)