tkrajina/gpxpy

Wrong use of cca() in test.py

simon-d-b opened this issue · 1 comments

I was looking at the tests and noticed the not so descriptively named function cca(number1, number2), defined as:

def cca(number1: float, number2: float) -> bool:
    return 1 - number1 / number2 < 0.999

This is essentially the same as:

def cca(number1: float, number2: float) -> bool:
    return number1/number2 > 0.001

After looking at where it is used, it seems as if cca is meant to check for almost eqaulity. What it indeed does but it returns True for a much larger range of inputs and thus resulting in possible wrong test outcomes.
Using the function assertAlmostEqual from unittest itself seems much more appropriate since it is correct and gives more information on failed tests.

Agreed, in my part of the world cca usually stays for circa (latin for "almost" or "around"). I renamed it now and made it more strict.

assertAlmostEqual is maybe a bit too strict, because a couple of tests fail because of changes in the 7th digit.