diff options
author | Gary E. Miller <gem@rellim.com> | 2019-02-21 15:46:22 -0800 |
---|---|---|
committer | Gary E. Miller <gem@rellim.com> | 2019-02-21 15:46:22 -0800 |
commit | 0e4684abb7058f36eea60abba5124d019f9bc01b (patch) | |
tree | 769afff5404b5fd970afdca596f9a152ec52ca9d | |
parent | c40b62c5b409aa97acfa397e94dfb40198c62ea0 (diff) | |
download | gpsd-0e4684abb7058f36eea60abba5124d019f9bc01b.tar.gz |
deg_to_s(): Add more tests. Not all 'good'.
deg_to_s() needs to do better rounding.
-rw-r--r-- | SConstruct | 2 | ||||
-rw-r--r-- | gpsdclient.c | 4 | ||||
-rw-r--r-- | tests/test_gpsdclient.c | 29 |
3 files changed, 31 insertions, 4 deletions
@@ -2061,7 +2061,7 @@ bits_regress = Utility('bits-regress', [test_bits], [ '$SRCDIR/tests/test_bits --quiet' ]) -# Unit-test the deg_to_str() extractor +# Unit-test the deg_to_str() converter bits_regress = Utility('deg-regress', [test_gpsdclient], [ '$SRCDIR/tests/test_gpsdclient' ]) diff --git a/gpsdclient.c b/gpsdclient.c index 880206ef..8ca605d4 100644 --- a/gpsdclient.c +++ b/gpsdclient.c @@ -35,6 +35,10 @@ static struct exportmethod_t exportmethods[] = { * deg_ddmm : return DD MM.mmmmmm' * deg_ddmmss : return DD MM' SS.sssss" * + * returns 'nan' for 0 > f or 360 < f + * + * NOTE: degrees must be positive. + * * for cm level accuracy we need degrees to 7+ decimal places * Ref: https://en.wikipedia.org/wiki/Decimal_degrees * diff --git a/tests/test_gpsdclient.c b/tests/test_gpsdclient.c index 95308cd4..6f81633f 100644 --- a/tests/test_gpsdclient.c +++ b/tests/test_gpsdclient.c @@ -31,9 +31,32 @@ struct test tests[] = { " 1 01' 01.99899\""}, /* 1 deg, 2 min, 2.0999 sec */ {(1.0 + 2.0/60.0 + 2.999/3600.0), - " 1.03416638", - " 1 02.049983'", - " 1 02' 02.99900\""}, + " 1.03416638", + " 1 02.049983'", + " 1 02' 02.99900\""}, + /* 44.99999994, should not be rounded up */ + {44.99999994, + " 44.99999994", + " 44 59.999996'", + " 44 59' 59.99978\""}, + /* 44.99999999999 */ + /* FIXME: s/b rounded */ + {44.99999999999, + " 44.99999999", + " 44 59.999999'", + " 44 59' 59.99999\""}, + /* -44.99999999999 */ + /* FIXME: should not be nan? */ + {-44.99999999999, + "nan", + "nan", + "nan"}, + /* 359.99999999999 */ + /* FIXME: s/b rounded */ + {359.99999999999, + "359.99999999", + "359 59.999999'", + "359 59' 59.99999\""}, }; |