From d11c1e585da03ad11c636303991d27f560907dd4 Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Thu, 8 Feb 2024 16:36:06 +0000 Subject: [PATCH 01/11] Add new trigonometric functions directory --- src/trig_functions/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/trig_functions/.gitkeep diff --git a/src/trig_functions/.gitkeep b/src/trig_functions/.gitkeep new file mode 100644 index 0000000..e69de29 From 831001fef524b08f1ad1845546d098cfdb575c25 Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Thu, 8 Feb 2024 16:36:32 +0000 Subject: [PATCH 02/11] Add new trigonometric functions.c file --- src/trig_functions/trig_functions.c | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/trig_functions/trig_functions.c diff --git a/src/trig_functions/trig_functions.c b/src/trig_functions/trig_functions.c new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/trig_functions/trig_functions.c @@ -0,0 +1 @@ + From da1d688fa9d6546c2f59494250bab1f9056e2715 Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Thu, 8 Feb 2024 16:37:31 +0000 Subject: [PATCH 03/11] Update src/trig_functions/trig_functions.c --- src/trig_functions/trig_functions.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/trig_functions/trig_functions.c b/src/trig_functions/trig_functions.c index 8b13789..8eec384 100644 --- a/src/trig_functions/trig_functions.c +++ b/src/trig_functions/trig_functions.c @@ -1 +1,14 @@ +#include "trig_functions.h" +#include +double calculate_sin(double angle) { + return sin(angle); +} + +double calculate_cos(double angle) { + return cos(angle); +} + +double calculate_tan(double angle) { + return tan(angle); +} From 4ce736e53bdfc46f2bbfdc97be4b9b0517c53a42 Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Thu, 8 Feb 2024 16:38:16 +0000 Subject: [PATCH 04/11] Add new trig_functions.h file --- src/trig_functions/trig_functions.h | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/trig_functions/trig_functions.h diff --git a/src/trig_functions/trig_functions.h b/src/trig_functions/trig_functions.h new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/trig_functions/trig_functions.h @@ -0,0 +1 @@ + From b2abfdc72d138168e32a9181d6823d7244e555c5 Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Thu, 8 Feb 2024 16:41:18 +0000 Subject: [PATCH 05/11] Create the header for trig_functions --- src/trig_functions/trig_functions.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/trig_functions/trig_functions.h b/src/trig_functions/trig_functions.h index 8b13789..e15575b 100644 --- a/src/trig_functions/trig_functions.h +++ b/src/trig_functions/trig_functions.h @@ -1 +1,9 @@ +#ifndef trig_functions_H +#define trig_functions_H + +double calculate_sin(double angle); +double calculate_cos(double angle); +double calculate_tan(double angle); + +#endif From 81db444a7a520479eb441d8e21ae15b1bb46bf72 Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Thu, 8 Feb 2024 16:41:58 +0000 Subject: [PATCH 06/11] Add new directory --- test/trig_functions/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/trig_functions/.gitkeep diff --git a/test/trig_functions/.gitkeep b/test/trig_functions/.gitkeep new file mode 100644 index 0000000..e69de29 From 23555e622d7d6fedd6d98f1fed764c378f1b92ef Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Thu, 8 Feb 2024 16:42:30 +0000 Subject: [PATCH 07/11] Add new test file for trig_functions --- test/trig_functions/test_trig_functions.c | 1 + 1 file changed, 1 insertion(+) create mode 100644 test/trig_functions/test_trig_functions.c diff --git a/test/trig_functions/test_trig_functions.c b/test/trig_functions/test_trig_functions.c new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/test/trig_functions/test_trig_functions.c @@ -0,0 +1 @@ + From 00d252c60b31b2633401bb263b8b2c1e93e5b871 Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Thu, 8 Feb 2024 16:44:31 +0000 Subject: [PATCH 08/11] Update test/trig_functions/test_trig_functions.c --- test/trig_functions/test_trig_functions.c | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/trig_functions/test_trig_functions.c b/test/trig_functions/test_trig_functions.c index 8b13789..115d0c9 100644 --- a/test/trig_functions/test_trig_functions.c +++ b/test/trig_functions/test_trig_functions.c @@ -1 +1,31 @@ +#include "unity.h" +#include "trig_functions.h" +#define PI 3.14159265 +void setUp(void){} + +void tearDown(void){} + +void test_sin() { + TEST_ASSERT_EQUAL_DOUBLE(0.0, calculate_sin(0)); + TEST_ASSERT_EQUAL_DOUBLE(1.0, calculate_sin(PI/2)); + TEST_ASSERT_EQUAL_DOUBLE(0.0, calculate_sin(PI)); + TEST_ASSERT_EQUAL_DOUBLE(-1.0, calculate_sin(3*PI/2)); + TEST_ASSERT_EQUAL_DOUBLE(0.0, calculate_sin(2*PI)); +} + +void test_cos() { + TEST_ASSERT_EQUAL_DOUBLE(1.0, calculate_cos(0)); + TEST_ASSERT_EQUAL_DOUBLE(0.0, calculate_cos(PI/2)); + TEST_ASSERT_EQUAL_DOUBLE(-1.0, calculate_cos(PI)); + TEST_ASSERT_EQUAL_DOUBLE(0.0, calculate_cos(3*PI/2)); + TEST_ASSERT_EQUAL_DOUBLE(1.0, calculate_cos(2*PI)); +} + +void test_tan() { + TEST_ASSERT_EQUAL_DOUBLE(0.0, calculate_tan(0)); + TEST_ASSERT_EQUAL_DOUBLE(INFINITY, calculate_tan(PI/2)); // Tangens von 90 Grad ist unendlich + TEST_ASSERT_EQUAL_DOUBLE(0.0, calculate_tan(PI)); + TEST_ASSERT_EQUAL_DOUBLE(INFINITY, calculate_tan(3*PI/2)); // Tangens von 270 Grad ist unendlich + TEST_ASSERT_EQUAL_DOUBLE(0.0, calculate_tan(2*PI)); +} From 0d884ee53c566bac76d9153d1a6fafef2eabda7f Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Thu, 8 Feb 2024 16:50:18 +0000 Subject: [PATCH 09/11] refactoring: if angle is 0 return 0 for sin --- src/trig_functions/trig_functions.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/trig_functions/trig_functions.c b/src/trig_functions/trig_functions.c index 8eec384..ffae719 100644 --- a/src/trig_functions/trig_functions.c +++ b/src/trig_functions/trig_functions.c @@ -2,7 +2,8 @@ #include double calculate_sin(double angle) { - return sin(angle); + if (angle==0) return 0; + else return sin(angle); } double calculate_cos(double angle) { From 0c04b0fdbd475c663726c767cd4679518d42b160 Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Thu, 8 Feb 2024 16:51:13 +0000 Subject: [PATCH 10/11] refactoring: if angle is 0 return 1 for cosinus --- src/trig_functions/trig_functions.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/trig_functions/trig_functions.c b/src/trig_functions/trig_functions.c index ffae719..7f12327 100644 --- a/src/trig_functions/trig_functions.c +++ b/src/trig_functions/trig_functions.c @@ -7,7 +7,8 @@ double calculate_sin(double angle) { } double calculate_cos(double angle) { - return cos(angle); + if (angle==0) return 1; + else return cos(angle); } double calculate_tan(double angle) { From 98d95b8c49d7d75982d70213a12bbd07b007f7e6 Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Thu, 8 Feb 2024 16:56:26 +0000 Subject: [PATCH 11/11] refactoring: if angle is 0 return 0 for tangens --- src/trig_functions/trig_functions.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/trig_functions/trig_functions.c b/src/trig_functions/trig_functions.c index 7f12327..186a4fe 100644 --- a/src/trig_functions/trig_functions.c +++ b/src/trig_functions/trig_functions.c @@ -12,5 +12,6 @@ double calculate_cos(double angle) { } double calculate_tan(double angle) { - return tan(angle); + if (angle==0) return 0; + else return tan(angle); }