loading...

re: Writing Good Unit Tests: A Step By Step Tutorial VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Why is longitude and latitude splitted into two variables? When you want calculate distance in 3D, you will write a new method?
 

This is mainly to make the example simpler.

Usually, you have an option to accept latitude and longitude as separate variables, or to accept a Point{double latitude, double longitude} instance. My preference would be to use the Point, but then I would have to introduce an extra piece of code, and this is a unit testing tutorial, after all.

However, in real life I once opted for using doubles :). In that project, we were using two different libraries, and they both had Point classes - but different ones, not related to each other :-D. (And the language wasn't C++ or a similar one with a powerful template system.)

Regarding the distance in 3D, this is an interesting and difficult question. Of course, it depends on the domain area, if you want to do this at all. In many applications, this is not needed. If you had to calculate the distance on our planet with elevation, then the simple difference in elevation won't do - you would have to calculate the surface distance (not going through the mountain, but going over it, for example). Then you would have to use a much more complex formulas (and I have never done that), or calculate distance by roads (I have done that, but then it becomes a graph problem, and the total elevation change should be counted in the time spent driving, or something like that).

But then again, this is a unit testing tutorial, and for this purpose, I use a round planet with no elevation :).

 
code of conduct - report abuse