-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make route comparator tolerate all kinds of data #124
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
063439a
refactor(route-viewer): make route comparator tolerate all kinds of data
evansiroky 0d49d08
refactor(itinerary): improve route comparator functions
evansiroky 9186539
refactor: address PR comments
evansiroky 8fa6088
Add route sort comparator for route type
evansiroky 8e481e9
refactor: change order of some route types
evansiroky 4fdc1d2
refactor: add alphabetic shortName comparator, always use integer sho…
evansiroky 3a46a3d
refactor: rename a test and remove a test that's no longer needed
evansiroky f9f208d
test: add test case with alphanumeric shortNames
evansiroky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`util > itinerary routeComparator should prioritize routes with shortNames over those with just longNames 1`] = ` | ||
Array [ | ||
Object { | ||
"longName": "B-line", | ||
"shortName": "B", | ||
"sortOrder": -999, | ||
}, | ||
Object { | ||
"longName": "A meandering route", | ||
"sortOrder": -999, | ||
}, | ||
] | ||
`; | ||
|
||
exports[`util > itinerary routeComparator should prioritize routes with valid integer shortNames 1`] = ` | ||
Array [ | ||
Object { | ||
"longName": "Loop route", | ||
"shortName": "2", | ||
"sortOrder": -999, | ||
}, | ||
Object { | ||
"longName": "A-line", | ||
"shortName": "A", | ||
"sortOrder": -999, | ||
}, | ||
] | ||
`; | ||
|
||
exports[`util > itinerary routeComparator should prioritize routes with valid sortOrder 1`] = ` | ||
Array [ | ||
Object { | ||
"longName": "Around town", | ||
"shortName": "20", | ||
"sortOrder": 2, | ||
}, | ||
Object { | ||
"longName": "Around another town", | ||
"shortName": "3", | ||
"sortOrder": -999, | ||
}, | ||
] | ||
`; | ||
|
||
exports[`util > itinerary routeComparator should skip integer short name criteria when specified 1`] = ` | ||
Array [ | ||
Object { | ||
"longName": "Variation of express route", | ||
"shortName": "30", | ||
"sortOrder": 2, | ||
}, | ||
Object { | ||
"longName": "Local route", | ||
"shortName": "6", | ||
"sortOrder": 2, | ||
}, | ||
] | ||
`; | ||
|
||
exports[`util > itinerary routeComparator should sort routes based off of integer shortName 1`] = ` | ||
Array [ | ||
Object { | ||
"longName": "Loop route", | ||
"shortName": "2", | ||
"sortOrder": -999, | ||
}, | ||
Object { | ||
"longName": "Around another town", | ||
"shortName": "3", | ||
"sortOrder": -999, | ||
}, | ||
] | ||
`; | ||
|
||
exports[`util > itinerary routeComparator should sort routes based off of integer shortName with routes with same sortOrder 1`] = ` | ||
Array [ | ||
Object { | ||
"longName": "Around town", | ||
"shortName": "20", | ||
"sortOrder": 2, | ||
}, | ||
Object { | ||
"longName": "Zig-zagging route", | ||
"shortName": "30", | ||
"sortOrder": 2, | ||
}, | ||
] | ||
`; | ||
|
||
exports[`util > itinerary routeComparator should sort routes based off of longNames 1`] = ` | ||
Array [ | ||
Object { | ||
"longName": "Express route", | ||
"shortName": "30", | ||
"sortOrder": 2, | ||
}, | ||
Object { | ||
"longName": "Variation of express route", | ||
"shortName": "30", | ||
"sortOrder": 2, | ||
}, | ||
] | ||
`; | ||
|
||
exports[`util > itinerary routeComparator should sort routes based off of shortNames 1`] = ` | ||
Array [ | ||
Object { | ||
"longName": "A-line", | ||
"shortName": "A", | ||
"sortOrder": -999, | ||
}, | ||
Object { | ||
"longName": "B-line", | ||
"shortName": "B", | ||
"sortOrder": -999, | ||
}, | ||
] | ||
`; | ||
|
||
exports[`util > itinerary routeComparator should sort routes based off of sortOrder 1`] = ` | ||
Array [ | ||
Object { | ||
"longName": "Around town", | ||
"shortName": "20", | ||
"sortOrder": 2, | ||
}, | ||
Object { | ||
"longName": "Across town", | ||
"shortName": "10", | ||
"sortOrder": 10, | ||
}, | ||
] | ||
`; | ||
|
||
exports[`util > itinerary routeComparator should sort routes on all of the criteria at once 1`] = ` | ||
Array [ | ||
Object { | ||
"longName": "Around town", | ||
"shortName": "20", | ||
"sortOrder": 2, | ||
}, | ||
Object { | ||
"longName": "Express route", | ||
"shortName": "30", | ||
"sortOrder": 2, | ||
}, | ||
Object { | ||
"longName": "Variation of express route", | ||
"shortName": "30", | ||
"sortOrder": 2, | ||
}, | ||
Object { | ||
"longName": "Zig-zagging route", | ||
"shortName": "30", | ||
"sortOrder": 2, | ||
}, | ||
Object { | ||
"longName": "Across town", | ||
"shortName": "10", | ||
"sortOrder": 10, | ||
}, | ||
Object { | ||
"longName": "Loop route", | ||
"shortName": "2", | ||
"sortOrder": -999, | ||
}, | ||
Object { | ||
"longName": "Around another town", | ||
"shortName": "3", | ||
"sortOrder": -999, | ||
}, | ||
Object { | ||
"longName": "A-line", | ||
"shortName": "A", | ||
"sortOrder": -999, | ||
}, | ||
Object { | ||
"longName": "B-line", | ||
"shortName": "B", | ||
"sortOrder": -999, | ||
}, | ||
Object { | ||
"longName": "A meandering route", | ||
"sortOrder": -999, | ||
}, | ||
] | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,122 @@ | ||
import {isTransit} from '../../lib/util/itinerary' | ||
import {isTransit, makeRouteComparator} from '../../lib/util/itinerary' | ||
|
||
describe('util > itinerary', () => { | ||
it('isTransit should work', () => { | ||
expect(isTransit('CAR')).toBeFalsy() | ||
}) | ||
|
||
describe('routeComparator', () => { | ||
const route1 = { | ||
evansiroky marked this conversation as resolved.
Show resolved
Hide resolved
|
||
longName: 'Across town', | ||
shortName: '10', | ||
sortOrder: 10 | ||
} | ||
const route2 = { | ||
longName: 'Around town', | ||
shortName: '20', | ||
sortOrder: 2 | ||
} | ||
const route3 = { | ||
longName: 'Around another town', | ||
shortName: '3', | ||
sortOrder: -999 | ||
} | ||
const route4 = { | ||
longName: 'Loop route', | ||
shortName: '2', | ||
sortOrder: -999 | ||
} | ||
const route5 = { | ||
longName: 'A-line', | ||
shortName: 'A', | ||
sortOrder: -999 | ||
} | ||
const route6 = { | ||
longName: 'B-line', | ||
shortName: 'B', | ||
sortOrder: -999 | ||
} | ||
const route7 = { | ||
longName: 'A meandering route', | ||
sortOrder: -999 | ||
} | ||
const route8 = { | ||
longName: 'Zig-zagging route', | ||
shortName: '30', | ||
sortOrder: 2 | ||
} | ||
const route9 = { | ||
longName: 'Express route', | ||
shortName: '30', | ||
sortOrder: 2 | ||
} | ||
const route10 = { | ||
longName: 'Variation of express route', | ||
shortName: '30', | ||
sortOrder: 2 | ||
} | ||
const route11 = { | ||
longName: 'Local route', | ||
shortName: '6', | ||
sortOrder: 2 | ||
} | ||
|
||
function sortRoutes (...routes) { | ||
routes.sort(makeRouteComparator()) | ||
return routes | ||
} | ||
|
||
it('should sort routes based off of sortOrder', () => { | ||
expect(sortRoutes(route1, route2)).toMatchSnapshot() | ||
}) | ||
|
||
it('should prioritize routes with valid sortOrder', () => { | ||
expect(sortRoutes(route2, route3)).toMatchSnapshot() | ||
}) | ||
|
||
it('should sort routes based off of integer shortName with routes with same sortOrder', () => { | ||
expect(sortRoutes(route8, route2)).toMatchSnapshot() | ||
}) | ||
|
||
it('should sort routes based off of integer shortName', () => { | ||
expect(sortRoutes(route3, route4)).toMatchSnapshot() | ||
}) | ||
|
||
it('should prioritize routes with valid integer shortNames', () => { | ||
expect(sortRoutes(route4, route5)).toMatchSnapshot() | ||
}) | ||
|
||
it('should sort routes based off of shortNames', () => { | ||
expect(sortRoutes(route5, route6)).toMatchSnapshot() | ||
}) | ||
|
||
it('should prioritize routes with shortNames over those with just longNames', () => { | ||
expect(sortRoutes(route6, route7)).toMatchSnapshot() | ||
}) | ||
|
||
it('should sort routes based off of longNames', () => { | ||
expect(sortRoutes(route9, route10)).toMatchSnapshot() | ||
}) | ||
|
||
it('should sort routes on all of the criteria at once', () => { | ||
expect(sortRoutes( | ||
route1, | ||
route2, | ||
route3, | ||
route4, | ||
route5, | ||
route6, | ||
route7, | ||
route8, | ||
route9, | ||
route10 | ||
)).toMatchSnapshot() | ||
}) | ||
|
||
it('should skip integer short name criteria when specified', () => { | ||
const routes = [route10, route11] | ||
routes.sort(makeRouteComparator(false)) | ||
expect(routes).toMatchSnapshot() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this test might need to be renamed?