Browse Source

Konflikt gelöst

remotes/origin/siamak
Habib 11 months ago
parent
commit
e1685f3466
  1. 212
      src/c/funktionen.c
  2. 95
      src/c/funktionen.h
  3. 173
      src/test/test_funktionen.c

212
src/c/funktionen.c

@ -1,6 +1,10 @@
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#include "funktionen.h"
void welcome() {
char x[15];
printf("Hallo! Wie heisst du?\n");
@ -90,3 +94,211 @@ int i(int v, int r) {
int p(int f, int a) {
return f / a;
}
// Function to calculate the sine of an angle in radians
float sine(float x) {
return sin(x);
}
// Function to calculate the cosine of an angle in radians
float cosine(float x) {
return cos(x);
}
// Function to calculate the tangent of an angle in radians
float tangent(float x) {
return tan(x);
}
// Function to calculate the arc sine of a value and return the result in radians
float arcSine(float x) {
if (x >= -1 && x <= 1) {
return asin(x);
}
else {
printf("Error: Invalid input for arc sine!\n");
return 0;
}
}
// Function to calculate the arc cosine of a value and return the result in radians
float arcCosine(float x) {
if (x >= -1 && x <= 1) {
return acos(x);
}
else {
printf("Error: Invalid input for arc cosine!\n");
return 0;
}
}
// Function to calculate the arc tangent of a value and return the result in radians
float arcTangent(float x) {
return atan(x);
}
// Function to convert degrees to radians
float degreesToRadians(float x) {
return x * (M_PI / 180);
}
// Function to convert radians to degrees
float radiansToDegrees(float x) {
return x * (180 / M_PI);
}
// Function to calculate the base 10 logarithm of a number and add 1
float logarithmPlusOne(float x) {
if (x > 0) {
return log10(x) + 1;
}
else {
printf("Error: Invalid input for logarithm + 1!\n");
return 0;
}
}
// Function to calculate the natural logarithm (base e) of a number and add 1
float naturalLogarithmPlusOne(float x) {
if (x > 0) {
return log(x) + 1;
}
else {
printf("Error: Invalid input for natural logarithm + 1!\n");
return 0;
}
}
// Function to calculate the square root of a number and add 1
float squareRootPlusOne(float x) {
if (x >= 0) {
return sqrt(x) + 1;
}
else {
printf("Error: Invalid input for square root + 1!\n");
return 0;
}
}
// Function to calculate the cube root of a number and add 1
float cubeRootPlusOne(float x) {
return cbrt(x) + 1;
}
// Function to calculate the sine of an angle in degrees
float sineDegrees(float x) {
return sin(degreesToRadians(x));
}
// Function to calculate the cosine of an angle in degrees
float cosineDegrees(float x) {
return cos(degreesToRadians(x));
}
// Function to calculate the tangent of an angle in degrees
float tangentDegrees(float x) {
return tan(degreesToRadians(x));
}
// Function to calculate the square of a number
float square(float x) {
return x * x;
}
float squareRoot(float x) {
if (x >= 0) {
return sqrt(x);
} else {
printf("Error: Invalid input for square root!\n");
return 0;
}
}
// Function to calculate the cube of a number
float cube(float x) {
return x * x * x;
}
// Function to calculate the cube root of a number
float cubeRoot(float x) {
return cbrt(x);
}
// Function to calculate the absolute value of a number
float absolute(float x) {
return fabs(x);
}
// Function to calculate the logarithm (base 10) of a number
float logarithm(float x) {
if (x > 0) {
return log10(x);
} else {
printf("Error: Invalid input for logarithm!\n");
return 0;
}
}
// Function to calculate the natural logarithm (base e) of a number
float naturalLogarithm(float x) {
if (x > 0) {
return log(x);
} else {
printf("Error: Invalid input for natural logarithm!\n");
return 0;
}
}
// Function to calculate the exponentiation of a number to the power of another number
float power(float x, float y) {
return pow(x, y);
}
// Function to calculate the factorial of a number
int factorial(int x) {
if (x >= 0) {
int result = 1;
for (int i = 1; i <= x; i++) {
result *= i;
}
return result;
} else {
printf("Error: Invalid input for factorial!\n");
return 0;
}
}
// Function to calculate the floor value of a number
float floorValue(float x) {
return floor(x);
}
// Function to calculate the ceiling value of a number
float ceilingValue(float x) {
return ceil(x);
}
// Function to calculate the absolute difference between two numbers
float absoluteDifference(float x, float y) {
return fabs(x - y);
}
// Function to calculate the maximum of two numbers
float maximum(float x, float y) {
return fmax(x, y);
}
// Function to calculate the minimum of two numbers
float minimum(float x, float y) {
return fmin(x, y);
}
// Function to calculate the average of two numbers
float average(float x, float y) {
return (x + y) / 2;
}
// Function to calculate the remainder of division between two numbers
float remainderValue(float x, float y) {
return fmod(x, y);
}

95
src/c/funktionen.h

@ -1,6 +1,7 @@
#ifndef FUNKTIONEN_H
#define FUNKTIONEN_H
void welcome();
// Die welcome() Funktion fragt den Namen des Benutzers ab und gibt einen entsprechenden Text aus.
@ -43,4 +44,98 @@ int i(int v, int r);
int p(int f, int a);
// berechnet den Druck
// Function to calculate the sine of an angle in radians
float sine(float x);
// Function to calculate the cosine of an angle in radians
float cosine(float x);
// Function to calculate the tangent of an angle in radians
float tangent(float x);
// Function to calculate the arc sine of a value and return the result in radians
float arcSine(float x);
// Function to calculate the arc cosine of a value and return the result in radians
float arcCosine(float x);
// Function to calculate the arc tangent of a value and return the result in radians
float arcTangent(float x);
// Function to convert degrees to radians
float degreesToRadians(float x);
// Function to convert radians to degrees
float radiansToDegrees(float x);
// Function to calculate the base 10 logarithm of a number and add 1
float logarithmPlusOne(float x);
// Function to calculate the natural logarithm (base e) of a number and add 1
float naturalLogarithmPlusOne(float x);
// Function to calculate the square root of a number and add 1
float squareRootPlusOne(float x);
// Function to calculate the cube root of a number and add 1
float cubeRootPlusOne(float x);
// Function to calculate the sine of an angle in degrees
float sineDegrees(float x);
// Function to calculate the cosine of an angle in degrees
float cosineDegrees(float x);
// Function to calculate the tangent of an angle in degrees
float tangentDegrees(float x);
// Function to calculate the square of a number
float square(float x);
// Function to calculate the square root of a number
float squareRoot(float x);
// Function to calculate the cube of a number
float cube(float x);
// Function to calculate the cube root of a number
float cubeRoot(float x);
// Function to calculate the absolute value of a number
float absolute(float x);
// Function to calculate the logarithm (base 10) of a number
float logarithm(float x);
// Function to calculate the natural logarithm (base e) of a number
float naturalLogarithm(float x);
// Function to calculate the exponentiation of a number to the power of another number
float power(float x, float y);
// Function to calculate the factorial of a number
int factorial(int x);
// Function to calculate the floor value of a number
float floorValue(float x);
// Function to calculate the ceiling value of a number
float ceilingValue(float x);
// Function to calculate the absolute difference between two numbers
float absoluteDifference(float x, float y);
// Function to calculate the maximum of two numbers
float maximum(float x, float y);
// Function to calculate the minimum of two numbers
float minimum(float x, float y);
// Function to calculate the average of two numbers
float average(float x, float y);
// Function to calculate the remainder of division between two numbers
float remainderValue(float x, float y);
#endif

173
src/test/test_funktionen.c

@ -11,7 +11,88 @@ void tearDown(void)
{
}
void test_1000_plus_1(void)
void test_square(void) {
float result = square(2.5);
TEST_ASSERT_EQUAL_FLOAT(6.25, result);
}
void test_squareRoot(void) {
float result = squareRoot(9.0);
TEST_ASSERT_EQUAL_FLOAT(3.0, result);
}
void test_cube(void) {
float result = cube(2.0);
TEST_ASSERT_EQUAL_FLOAT(8.0, result);
}
void test_cubeRoot(void) {
float result = cubeRoot(27.0);
TEST_ASSERT_EQUAL_FLOAT(3.0, result);
}
void test_absolute(void) {
float result = absolute(-5.0);
TEST_ASSERT_EQUAL_FLOAT(5.0, result);
}
void test_logarithm(void) {
float result = logarithm(100.0);
TEST_ASSERT_FLOAT_WITHIN(0.000001, 2.0, result);
}
void test_naturalLogarithm(void) {
float result = naturalLogarithm(100.0);
TEST_ASSERT_FLOAT_WITHIN(0.000001, 4.60517, result);
}
void test_power(void) {
float result = power(2.0, 3.0);
TEST_ASSERT_FLOAT_WITHIN(0.000001, 8.0, result);
}
void test_factorial(void) {
int result = factorial(5);
TEST_ASSERT_EQUAL_INT(120, result);
}
void test_floorValue(void) {
float result = floorValue(5.7);
TEST_ASSERT_EQUAL_FLOAT(5.0, result);
}
void test_ceilingValue(void) {
float result = ceilingValue(5.2);
TEST_ASSERT_EQUAL_FLOAT(6.0, result);
}
void test_absoluteDifference(void) {
float result = absoluteDifference(8.0, 4.5);
TEST_ASSERT_FLOAT_WITHIN(0.000001, 3.5, result);
}
void test_maximum(void) {
float result = maximum(5.0, 9.0);
TEST_ASSERT_FLOAT_WITHIN(0.000001, 9.0, result);
}
void test_minimum(void) {
float result = minimum(5.0, 9.0);
TEST_ASSERT_FLOAT_WITHIN(0.000001, 5.0, result);
}
void test_average(void) {
float result = average(5.0, 9.0);
TEST_ASSERT_FLOAT_WITHIN(0.000001, 7.0, result);
}
void test_remainderValue(void) {
float result = remainderValue(10.5, 3.0);
TEST_ASSERT_FLOAT_WITHIN(0.000001, 1.5, result);
}
void test_500_plus_249_plus_251(void)
{
/* arrange */
int actual;
@ -182,4 +263,94 @@ void test_pressure_at_force360_area12(void)
TEST_ASSERT_EQUAL_INT(expected, actual);
}
void test_sine(void) {
float result = sine(0.5);
TEST_ASSERT_EQUAL_FLOAT(0.479426, result);
}
void test_cosine(void) {
float result = cosine(1.0);
TEST_ASSERT_EQUAL_FLOAT(0.540302, result);
// Add more test cases for different inputs and expected outputs
}
void test_tangent(void) {
float result = tangent(1.5);
TEST_ASSERT_EQUAL_FLOAT(14.101419, result);
// Add more test cases for different inputs and expected outputs
}
void test_arcSine(void) {
float result = arcSine(0.5);
TEST_ASSERT_EQUAL_FLOAT(0.523599, result);
// Add more test cases for different inputs and expected outputs
}
void test_arcCosine(void) {
float result = arcCosine(0.5);
TEST_ASSERT_EQUAL_FLOAT(1.047198, result);
// Add more test cases for different inputs and expected outputs
}
void test_arcTangent(void) {
float result = arcTangent(1.0);
TEST_ASSERT_EQUAL_FLOAT(0.785398, result);
// Add more test cases for different inputs and expected outputs
}
void test_degreesToRadians(void) {
float result = degreesToRadians(90.0);
TEST_ASSERT_EQUAL_FLOAT(1.570796, result);
// Add more test cases for different inputs and expected outputs
}
void test_radiansToDegrees(void) {
float result = radiansToDegrees(1.570796);
TEST_ASSERT_EQUAL_FLOAT(90.0, result);
// Add more test cases for different inputs and expected outputs
}
void test_logarithmPlusOne(void) {
float result = logarithmPlusOne(10.0);
TEST_ASSERT_EQUAL_FLOAT(2.0, result);
// Add more test cases for different inputs and expected outputs
}
void test_naturalLogarithmPlusOne(void) {
float result = naturalLogarithmPlusOne(10.0);
TEST_ASSERT_EQUAL_FLOAT(3.302585, result);
// Add more test cases for different inputs and expected outputs
}
void test_squareRootPlusOne(void) {
float result = squareRootPlusOne(9.0);
TEST_ASSERT_EQUAL_FLOAT(4.0, result);
// Add more test cases for different inputs and expected outputs
}
void test_cubeRootPlusOne(void) {
float result = cubeRootPlusOne(8.0);
TEST_ASSERT_FLOAT_WITHIN(0.000001, 3.0, result);
// Add more test cases for different inputs and expected outputs
}
void test_sineDegrees(void) {
float result = sineDegrees(45.0);
TEST_ASSERT_FLOAT_WITHIN(0.000001, 0.7071068, result);
// Add more test cases for different inputs and expected outputs
}
void test_cosineDegrees(void) {
float result = cosineDegrees(60.0);
TEST_ASSERT_FLOAT_WITHIN(0.000001, 0.5, result);
// Add more test cases for different inputs and expected outputs
}
void test_tangentDegrees(void) {
float result = tangentDegrees(30.0);
TEST_ASSERT_FLOAT_WITHIN(0.000001, 0.5773503, result);
// Add more test cases for different inputs and expected outputs
}
#endif
Loading…
Cancel
Save