From 4b9f352ea1bedd83a775a5623215a360d563186d Mon Sep 17 00:00:00 2001 From: fdai7848 Date: Sat, 3 Feb 2024 19:42:50 +0100 Subject: [PATCH] add tests for radians function --- src/reihen.c | 2 +- src/reihen.h | 1 + test/test_reihen.c | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/reihen.c b/src/reihen.c index b31d063..258638c 100644 --- a/src/reihen.c +++ b/src/reihen.c @@ -38,7 +38,7 @@ double squashDegreesTo360(double x){ } double radians(double d){ - return d / PI * 180; + return d * PI / 180; } double pi(double eps){ diff --git a/src/reihen.h b/src/reihen.h index 36d8468..19f4b35 100644 --- a/src/reihen.h +++ b/src/reihen.h @@ -4,5 +4,6 @@ double exponential(double x); double euler(); double pi(); +double radians(double d); #endif // reihen.h \ No newline at end of file diff --git a/test/test_reihen.c b/test/test_reihen.c index 1329b6f..2a30593 100644 --- a/test/test_reihen.c +++ b/test/test_reihen.c @@ -44,4 +44,23 @@ void test_pi(void){ TEST_ASSERT_DOUBLE_WITHIN(0.0000001, 3.14159265, r1); } +void test_degrees_to_radians(){ + double r1, r2, r3, r4; + + r1 = radians(90.0); + r2 = radians(180.0); + r3 = radians(51.6); + r4 = radians(36.97); + + printf("%lf\n", r1); + printf("%lf\n", r2); + printf("%lf\n", r3); + printf("%lf\n", r4); + + TEST_ASSERT_DOUBLE_WITHIN(0.000001, 1.570796, r1); + TEST_ASSERT_DOUBLE_WITHIN(0.000001, pi(1e-8), r2); + TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.900589, r3); + TEST_ASSERT_DOUBLE_WITHIN(0.000001, 0.645248, r4); +} + #endif // TEST \ No newline at end of file