datacamp / sqlwhat

https://sqlwhat.readthedocs.io
GNU Affero General Public License v3.0
3 stars 8 forks source link

Allow test_column to specify tolerance, so floating point doesn't fail #94

Closed colinricardo closed 7 years ago

colinricardo commented 7 years ago

For example:

AVG(duration) / 60 and AVG(duration / 60) should both be accepted.

Is the best way to do this using test_or() with test_student_typed()?

machow commented 7 years ago

Sorry, I didn't see this--it sounds like what you mean by should be accepted is that they produce the same result. So, if possible, it seems like you should check the result. If not possible for some reason, test_or sounds right, but let me know if there's a case I didn't think about!

colinricardo commented 7 years ago

Thanks! It seems that check_result() doesn't deem them equal because of rounding differences so test_or() might be easiest:

select avg(duration) / 60.0
from films

gives 1.7991321897073663

select avg(duration / 60.0) 
from films   

gives 1.79913218970736629689

machow commented 7 years ago

Ah, thanks for clarifying! It seems like adding a tolerance parameter to test_column should do the trick.