I’m getting close to new departure calculation code being ready. The implementation is in place and right now I’m focusing on testing it and fixing errors. The way I’m testing it at the moment is by building a departure list for every single stop in the entire country and then comparing it against what I know is the correct list for that stop. There’s around 30.000 stops so it takes a while but at the end I’ll be pretty sure the code works.
I ran it for the first time a couple of days ago, it didn’t even get the first stop right. I fixed that problem and tried again, it got a couple right but hit the next error almost immediately. So I fixed that problem. Then I could run a couple of hundreds before hitting an error. Now it’s just running and running and hopefully it’ll get all the way through. As I’m writing right now it’s completed 48% of all stops without any errors.
Part of what makes this tricky is that often it’s only when you try that you realize that the underlying schedules are really weird, and you have to deal with the weird cases too. For instance, one really hairy problem turned out to be caused by the schedule for Gudhjem Øvre which has a bus that leaves 05:37 on Tuesdays – and also one that leaves at 29:37 on Mondays. Really. Which is actually valid. What leaving on 29:37 on Monday means is that it actually runs at 05:37 on Tuesdays (29:37 = 24:00 + 05:37) but according to the calendar for Mondays. So if Tuesday is a public holiday and Monday isn’t, the 05:37 on Tuesday won’t run because of the holiday whereas 29:37 on Monday will because Monday isn’t a holiday. In effect what you get is two busses at 05:37 most Tuesdays which my new implementation got wrong, it returned only one. This is a mistake in the schedule of course, there is only one bus for that route at that time, but since it’s technically a valid and meaningful schedule the code should behave correctly in that case too.
One improvement of the new version is that the same code can calculate both arrival and departure lists, and it can calculate lists both forward and backwards in time. I need the forward/backward thing to be able to show the scrolling lists in the app where you can scroll infinitely forward and backwards. This means that even when I’m done testing departures for all stops I need to do it again for arrivals, and then I need to do it again for both but listing backwards. And then I’ll be pretty confident the code works. So I’m on testing duty for a while yet.
Now it’s at 90% done without errors!