summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary E. Miller <gem@rellim.com>2019-02-21 15:46:22 -0800
committerGary E. Miller <gem@rellim.com>2019-02-21 15:46:22 -0800
commit0e4684abb7058f36eea60abba5124d019f9bc01b (patch)
tree769afff5404b5fd970afdca596f9a152ec52ca9d
parentc40b62c5b409aa97acfa397e94dfb40198c62ea0 (diff)
downloadgpsd-0e4684abb7058f36eea60abba5124d019f9bc01b.tar.gz
deg_to_s(): Add more tests. Not all 'good'.
deg_to_s() needs to do better rounding.
-rw-r--r--SConstruct2
-rw-r--r--gpsdclient.c4
-rw-r--r--tests/test_gpsdclient.c29
3 files changed, 31 insertions, 4 deletions
diff --git a/SConstruct b/SConstruct
index bd63541f..6b96f7de 100644
--- a/SConstruct
+++ b/SConstruct
@@ -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\""},
};