Browse Source

Merge branch 'trigonometrische_funktionen' into 'master'

Add new trigonometric functions

See merge request fdai8031/cstools101!10
master
fdai7968 11 months ago
parent
commit
c0cd67158a
  1. 0
      src/trig_functions/.gitkeep
  2. 17
      src/trig_functions/trig_functions.c
  3. 9
      src/trig_functions/trig_functions.h
  4. 0
      test/trig_functions/.gitkeep
  5. 31
      test/trig_functions/test_trig_functions.c

0
src/trig_functions/.gitkeep

17
src/trig_functions/trig_functions.c

@ -0,0 +1,17 @@
#include "trig_functions.h"
#include <math.h>
double calculate_sin(double angle) {
if (angle==0) return 0;
else return sin(angle);
}
double calculate_cos(double angle) {
if (angle==0) return 1;
else return cos(angle);
}
double calculate_tan(double angle) {
if (angle==0) return 0;
else return tan(angle);
}

9
src/trig_functions/trig_functions.h

@ -0,0 +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

0
test/trig_functions/.gitkeep

31
test/trig_functions/test_trig_functions.c

@ -0,0 +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));
}
Loading…
Cancel
Save