Browse Source
Merge branch 'main' into 'testing'
Merge branch 'main' into 'testing'
Main in testing See merge request fdai7812/theadmirals!10remotes/origin/testing
66 changed files with 1386 additions and 1 deletions
-
35src/arithmeticAddition.c
-
12src/arithmeticAddition.h
-
48src/arithmeticDivision.c
-
12src/arithmeticDivision.h
-
12src/arithmeticMultiplication_Double.c
-
14src/arithmeticMultiplication_Double.h
-
12src/arithmeticMultiplication_Float.c
-
13src/arithmeticMultiplication_Float.h
-
13src/arithmeticMultiplication_Int.c
-
8src/arithmeticMultiplication_Int.h
-
24src/arithmeticSubtraction.c
-
9src/arithmeticSubtraction.h
-
23src/calculateFactorial.c
-
8src/calculateFactorial.h
-
7src/convert_CM_in_M.c
-
7src/convert_CM_in_M.h
-
19src/convert_C_to_F.c
-
7src/convert_C_to_F.h
-
6src/convert_M_in_KM.c
-
7src/convert_M_in_KM.h
-
7src/convert_cm_in_dm.c
-
7src/convert_cm_in_dm.h
-
6src/convert_g_to_mg.c
-
17src/convert_g_to_mg.h
-
6src/convert_kg_to_g.c
-
18src/convert_kg_to_g.h
-
6src/convert_kg_to_ton.c
-
7src/convert_kg_to_ton.h
-
11src/convert_kph_to_mps.c
-
7src/convert_kph_to_mps.h
-
23src/convert_m_to_ft.c
-
15src/convert_m_to_ft.h
-
49src/convert_time.c
-
13src/convert_time.h
-
7src/convert_ton_to_kg.c
-
17src/convert_ton_to_kg.h
-
7src/convert_ton_to_mt.c
-
13src/convert_ton_to_mt.h
-
9src/exponentials.c
-
6src/exponentials.h
-
58src/inputHandler.c
-
12src/inputHandler.h
-
18src/logarithmicFunctions.c
-
6src/logarithmicFunctions.h
-
34src/main.c
-
122src/operationHandler.c
-
23src/operationHandler.h
-
24src/trigonometricFunctions.c
-
9src/trigonometricFunctions.h
-
2team.md
-
45test/test_arithmeticAddition.c
-
40test/test_arithmeticDivision.c
-
21test/test_arithmeticMultiplication_Int.c
-
31test/test_arithmeticSubtraction.c
-
17test/test_calculateFactorial .c
-
32test/test_convert_CM_in_M.c
-
32test/test_convert_M_in_KM.c
-
32test/test_convert_cm_in_dm.c
-
25test/test_convert_kph_to_mps.c
-
28test/test_convert_m_to_ft.c
-
67test/test_convert_time.c
-
18test/test_exponentials.c
-
39test/test_inputHandler.c
-
18test/test_logarithmicFunctions.c
-
56test/test_operationHandler.c
-
29test/test_trigonometricFunctions.c
@ -0,0 +1,35 @@ |
|||||
|
#include "arithmeticAddition.h" |
||||
|
#include <stdio.h> |
||||
|
#include <limits.h> |
||||
|
#include <stdlib.h> |
||||
|
|
||||
|
// addition for two integer inputs (no decimal number) |
||||
|
int* addition_integer(int num1, int num2) { |
||||
|
if ((num2 > 0 && num1 > INT_MAX - num2) || (num2 < 0 && num1 < INT_MIN - num2)) { |
||||
|
return NULL; |
||||
|
} |
||||
|
int* result = malloc(sizeof(int)); |
||||
|
*result = num1 + num2; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
// addition for two double inputs (decimal number) |
||||
|
double* addition_double(double num1, double num2) { |
||||
|
double* result = malloc(sizeof(double)); |
||||
|
*result = num1+num2; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
// addition for two float inputs (decimal number) |
||||
|
float* addition_float(float num1, float num2) { |
||||
|
float* result = malloc(sizeof(float)); |
||||
|
*result = num1+num2; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
// addition for two long inputs (no decimal number) |
||||
|
long* addition_long(long num1, long num2) { |
||||
|
long* result = malloc(sizeof(long)); |
||||
|
*result = num1+num2; |
||||
|
return result; |
||||
|
} |
@ -0,0 +1,12 @@ |
|||||
|
#ifndef THEADMIRALS_ARITHMETICADDITION_H |
||||
|
#define THEADMIRALS_ARITHMETICADDITION_H |
||||
|
|
||||
|
int* addition_integer(int, int); |
||||
|
|
||||
|
double* addition_double(double, double); |
||||
|
|
||||
|
float* addition_float(float, float); |
||||
|
|
||||
|
long* addition_long(long, long); |
||||
|
|
||||
|
#endif //THEADMIRALS_ARITHMETICADDITION_H |
@ -0,0 +1,48 @@ |
|||||
|
#include "arithmeticDivision.h" |
||||
|
#include <stdio.h> |
||||
|
#include <limits.h> |
||||
|
#include <stdlib.h> |
||||
|
|
||||
|
int* division_integer(int dividend, int divisor) { |
||||
|
// division with 0 would cause errors |
||||
|
if(divisor == 0) { |
||||
|
return NULL; |
||||
|
} |
||||
|
// Overflow protection |
||||
|
if (dividend == INT_MIN && divisor == -1) { |
||||
|
return NULL; |
||||
|
} |
||||
|
int* result = malloc(sizeof(int)); |
||||
|
*result = dividend / divisor; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
long* division_long(long dividend, long divisor) { |
||||
|
// division with 0 would cause errors |
||||
|
if(divisor == 0) { |
||||
|
return NULL; |
||||
|
} |
||||
|
long* result = malloc(sizeof(long)); |
||||
|
*result = dividend / divisor; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
double* division_double(double dividend, double divisor) { |
||||
|
// division with 0 would cause errors |
||||
|
if(divisor == 0) { |
||||
|
return NULL; |
||||
|
} |
||||
|
double* result = malloc(sizeof(double )); |
||||
|
*result = dividend / divisor; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
float* division_float(float dividend, float divisor) { |
||||
|
// division with 0 would cause errors |
||||
|
if(divisor == 0) { |
||||
|
return NULL; |
||||
|
} |
||||
|
float* result = malloc(sizeof(float)); |
||||
|
*result = dividend / divisor; |
||||
|
return result; |
||||
|
} |
@ -0,0 +1,12 @@ |
|||||
|
#ifndef THEADMIRALS_ARITHMETICDIVISION_H |
||||
|
#define THEADMIRALS_ARITHMETICDIVISION_H |
||||
|
|
||||
|
int* division_integer(int, int); |
||||
|
|
||||
|
long* division_long(long, long); |
||||
|
|
||||
|
double* division_double(double, double); |
||||
|
|
||||
|
float* division_float(float, float); |
||||
|
|
||||
|
#endif //THEADMIRALS_ARITHMETICDIVISION_H |
@ -0,0 +1,12 @@ |
|||||
|
#include "stdlib.h" |
||||
|
#include "arithmeticMultiplication_Double.h" |
||||
|
|
||||
|
|
||||
|
double* multiplication_double(double a, double b) { |
||||
|
double* result = (double*)malloc(sizeof(double)); |
||||
|
if (result == NULL) { |
||||
|
return NULL; |
||||
|
} |
||||
|
*result = a * b; // we multiply a times b and the result gets saved in *result |
||||
|
return result; |
||||
|
} |
@ -0,0 +1,14 @@ |
|||||
|
|
||||
|
|
||||
|
#ifndef THEADMIRALS_ARITHMETICMULTIPLICATION_DOUBLE_H |
||||
|
#define THEADMIRALS_ARITHMETICMULTIPLICATION_DOUBLE_H |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
double* multiplication_double(double num1, double num2); |
||||
|
|
||||
|
|
||||
|
|
||||
|
#endif //THEADMIRALS_ARITHMETICMULTIPLICATION_DOUBLE_H |
@ -0,0 +1,12 @@ |
|||||
|
#include "arithmeticMultiplication_Float.h" |
||||
|
#include <stdlib.h> |
||||
|
|
||||
|
float* multiplication_float(float a, float b) { |
||||
|
float* result = (float*)malloc(sizeof(float)); |
||||
|
if (result == NULL) { |
||||
|
return NULL; |
||||
|
} |
||||
|
*result = a * b; |
||||
|
return result; |
||||
|
} |
||||
|
|
@ -0,0 +1,13 @@ |
|||||
|
|
||||
|
#ifndef THEADMIRALS_ARITHMETICMULTIPLICATION_FLOAT_H |
||||
|
#define THEADMIRALS_ARITHMETICMULTIPLICATION_FLOAT_H |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
float* multiplication_float(float num1, float num2); |
||||
|
|
||||
|
|
||||
|
#endif //THEADMIRALS_ARITHMETICMULTIPLICATION_FLOAT_H |
@ -0,0 +1,13 @@ |
|||||
|
#include "arithmeticMultiplication_Int.h" |
||||
|
#include <stdlib.h> |
||||
|
|
||||
|
int* multiplication_integer(int a, int b) { |
||||
|
int *result = (int*)malloc(sizeof(int)); |
||||
|
if (result == NULL) { |
||||
|
return NULL; |
||||
|
} |
||||
|
*result = a * b; |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
|
@ -0,0 +1,8 @@ |
|||||
|
|
||||
|
|
||||
|
#ifndef THEADMIRALS_ARITHMETICMULTIPLICATION_INT_H |
||||
|
#define THEADMIRALS_ARITHMETICMULTIPLICATION_INT_H |
||||
|
|
||||
|
int* multiplication_integer(int, int); |
||||
|
|
||||
|
#endif //THEADMIRALS_ARITHMETICMULTIPLICATION_INT_H |
@ -0,0 +1,24 @@ |
|||||
|
#include "arithmeticSubtraction.h" |
||||
|
|
||||
|
#include <stdlib.h> |
||||
|
|
||||
|
// arithmetic subtraction for integer |
||||
|
int* subtraction_integer(int a, int b) { |
||||
|
int* result= malloc(sizeof (int)); |
||||
|
*result=a - b; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
// arithmetic subtraction for float |
||||
|
float* subtraction_float(float a, float b) { |
||||
|
float* result= malloc(sizeof (float)); |
||||
|
*result=a - b; |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
// arithmetic subtraction for double |
||||
|
double* subtraction_double(double a, double b) { |
||||
|
double* result= malloc(sizeof (double)); |
||||
|
*result=a - b; |
||||
|
return result; |
||||
|
} |
@ -0,0 +1,9 @@ |
|||||
|
|
||||
|
#ifndef THEADMIRALS_ARITHMETICSUBTRACTION_H |
||||
|
#define THEADMIRALS_ARITHMETICSUBTRACTION_H |
||||
|
|
||||
|
int* subtraction_integer(int a, int b); |
||||
|
float* subtraction_float(float a, float b); |
||||
|
double* subtraction_double(double a, double b); |
||||
|
|
||||
|
#endif //THEADMIRALS_ARITHMETICSUBTRACTION_H |
@ -0,0 +1,23 @@ |
|||||
|
|
||||
|
|
||||
|
#include "calculateFactorial.h" |
||||
|
|
||||
|
// Function for Factorial with integer |
||||
|
int calculateFactorial_integer(int n) { |
||||
|
if (n < 0) { |
||||
|
|
||||
|
} else if (n == 0 || n == 1) { |
||||
|
|
||||
|
return 1; |
||||
|
} else { |
||||
|
|
||||
|
int result = 1; |
||||
|
for (int i = 2; i <= n; ++i) { |
||||
|
result *= i; |
||||
|
} |
||||
|
return result; |
||||
|
} |
||||
|
return 0; |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,8 @@ |
|||||
|
|
||||
|
|
||||
|
#ifndef THEADMIRALS_CALCULATEFACTORIAL_H |
||||
|
#define THEADMIRALS_CALCULATEFACTORIAL_H |
||||
|
|
||||
|
int calculateFactorial_integer(int n); |
||||
|
|
||||
|
#endif //THEADMIRALS_CALCULATEFACTORIAL_H |
@ -0,0 +1,7 @@ |
|||||
|
|
||||
|
#include "convert_CM_in_M.h" |
||||
|
#include <stdio.h> |
||||
|
//convert length for float cm into meter |
||||
|
float cm_to_meter(float cm) { |
||||
|
return cm / 100.0; |
||||
|
} |
@ -0,0 +1,7 @@ |
|||||
|
|
||||
|
#ifndef THEADMIRALS_CONVERT_CM_IN_M_H |
||||
|
#define THEADMIRALS_CONVERT_CM_IN_M_H |
||||
|
|
||||
|
float cm_to_meter(float cm); |
||||
|
|
||||
|
#endif //THEADMIRALS_CONVERT_CM_IN_M_H |
@ -0,0 +1,19 @@ |
|||||
|
#include "stdio.h" |
||||
|
#include "convert_C_to_F.h" |
||||
|
|
||||
|
float convert_temperature(float value, char from_unit, char to_unit) { |
||||
|
float result; |
||||
|
|
||||
|
if (from_unit == 'c' && to_unit == 'f') { |
||||
|
result = (value * 9 / 5) + 32; // Celsius to Fahrenheit |
||||
|
} else if (from_unit == 'f' && to_unit == 'c') { |
||||
|
result = (value - 32) * 5 / 9; // Fahrenheit to Celsius |
||||
|
} else { |
||||
|
printf("Invalid units or conversion not supported.\n"); |
||||
|
result = -1; // Error code |
||||
|
} |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
|
@ -0,0 +1,7 @@ |
|||||
|
|
||||
|
#ifndef THEADMIRALS_CONVERT_C_TO_F_H |
||||
|
#define THEADMIRALS_CONVERT_C_TO_F_H |
||||
|
|
||||
|
float convert_temperature(float value, char from_unit, char to_unit); |
||||
|
|
||||
|
#endif //THEADMIRALS_CONVERT_C_TO_F_H |
@ -0,0 +1,6 @@ |
|||||
|
#include "convert_M_in_KM.h" |
||||
|
|
||||
|
//convert length for double metre into kilometre |
||||
|
double meter_to_kilometer(double meter) { |
||||
|
return meter / 1000.0; |
||||
|
} |
@ -0,0 +1,7 @@ |
|||||
|
|
||||
|
#ifndef THEADMIRALS_CONVERT_M_IN_KM_H |
||||
|
#define THEADMIRALS_CONVERT_M_IN_KM_H |
||||
|
|
||||
|
double meter_to_kilometer(double meter); |
||||
|
|
||||
|
#endif //THEADMIRALS_CONVERT_M_IN_KM_H |
@ -0,0 +1,7 @@ |
|||||
|
|
||||
|
#include "convert_cm_in_dm.h" |
||||
|
#include <stdio.h> |
||||
|
//convert length for double cm into dm |
||||
|
double cm_to_dm(double cm) { |
||||
|
return cm / 10.0; |
||||
|
} |
@ -0,0 +1,7 @@ |
|||||
|
|
||||
|
#ifndef THEADMIRALS_CONVERT_CM_TO_DM_H |
||||
|
#define THEADMIRALS_CONVERT_CM_TO_DM_H |
||||
|
|
||||
|
double cm_to_dm(double cm); |
||||
|
|
||||
|
#endif //THEADMIRALS_CONVERT_CM_TO_DM_H |
@ -0,0 +1,6 @@ |
|||||
|
|
||||
|
#include "convert_g_to_mg.h" |
||||
|
|
||||
|
double g_to_mg(double grams) { |
||||
|
return grams * 1000.0; |
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
|
||||
|
#ifndef THEADMIRALS_CONVERT_G_TO_MG_H |
||||
|
#define THEADMIRALS_CONVERT_G_TO_MG_H |
||||
|
|
||||
|
|
||||
|
|
||||
|
// Convert grams to milligrams |
||||
|
// Parameters: |
||||
|
// grams: weight in grams |
||||
|
// Returns: |
||||
|
// The equivalent weight in milligrams |
||||
|
|
||||
|
double g_to_mg(double grams); |
||||
|
|
||||
|
|
||||
|
|
||||
|
#endif //THEADMIRALS_CONVERT_G_TO_MG_H |
@ -0,0 +1,6 @@ |
|||||
|
|
||||
|
#include "convert_kg_to_g.h" |
||||
|
|
||||
|
double kg_to_gram(double kilograms) { |
||||
|
return kilograms * 1000.0; |
||||
|
} |
@ -0,0 +1,18 @@ |
|||||
|
|
||||
|
|
||||
|
#ifndef THEADMIRALS_CONVERT_KG_TO_G_H |
||||
|
#define THEADMIRALS_CONVERT_KG_TO_G_H |
||||
|
|
||||
|
|
||||
|
|
||||
|
// Convert kilograms to grams |
||||
|
// Parameters: |
||||
|
// kilograms: weight in kilograms |
||||
|
// Returns: |
||||
|
// The equivalent weight in grams |
||||
|
|
||||
|
double kg_to_gram(double kilograms); |
||||
|
|
||||
|
|
||||
|
|
||||
|
#endif //THEADMIRALS_CONVERT_KG_TO_G_H |
@ -0,0 +1,6 @@ |
|||||
|
|
||||
|
#include "convert_kg_to_ton.h" |
||||
|
|
||||
|
double kg_to_tons(double kilograms) { |
||||
|
return kilograms / 1000.0; |
||||
|
} |
@ -0,0 +1,7 @@ |
|||||
|
#ifndef THEADMIRALS_CONVERT_KG_TO_TON_H |
||||
|
#define THEADMIRALS_CONVERT_KG_TO_TON_H |
||||
|
|
||||
|
// Convert kilograms to tons |
||||
|
double kg_to_tons(double kilograms); |
||||
|
|
||||
|
#endif //THEADMIRALS_CONVERT_KG_TO_TON_H |
@ -0,0 +1,11 @@ |
|||||
|
#include "convert_kph_to_mps.h" |
||||
|
|
||||
|
double converter_kph_to_mps(double kph){ |
||||
|
double speed = kph / 3.6; |
||||
|
return speed; |
||||
|
} |
||||
|
|
||||
|
double converter_mps_to_kph(double mps){ |
||||
|
double speed = mps * 3.6; |
||||
|
return speed; |
||||
|
} |
@ -0,0 +1,7 @@ |
|||||
|
#ifndef THEADMIRALS_CONVERT_KPH_TO_MPS_H |
||||
|
#define THEADMIRALS_CONVERT_KPH_TO_MPS_H |
||||
|
|
||||
|
double converter_kph_to_mps(double kph); |
||||
|
double converter_mps_to_kph(double mps); |
||||
|
|
||||
|
#endif //THEADMIRALS_CONVERT_KPH_TO_MPS_H |
@ -0,0 +1,23 @@ |
|||||
|
|
||||
|
#include "convert_m_to_ft.h" |
||||
|
#include <stdio.h> |
||||
|
|
||||
|
float convert_length(float value, char from_unit, char to_unit) { |
||||
|
float result; |
||||
|
|
||||
|
if (from_unit == 'm' && to_unit == 'f') { |
||||
|
result = value * 3.281; // Meters to feet |
||||
|
} else if (from_unit == 'f' && to_unit == 'm') { |
||||
|
result = value / 3.281; // Feet to meters |
||||
|
} else if (from_unit == 'i' && to_unit == 'c') { |
||||
|
result = value * 2.54; // Inches to centimeters |
||||
|
} else if (from_unit == 'c' && to_unit == 'i') { |
||||
|
result = value / 2.54; |
||||
|
} else { |
||||
|
printf("Invalid units or conversion not supported.\n"); |
||||
|
result = -1; // Error code |
||||
|
} |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
// function converts between cm to inches and vice versa, and between m to ft and vice versa |
@ -0,0 +1,15 @@ |
|||||
|
|
||||
|
#ifndef THEADMIRALS_CONVERT_M_TO_FT_H |
||||
|
#define THEADMIRALS_CONVERT_M_TO_FT_H |
||||
|
|
||||
|
// Convert length from one unit to another |
||||
|
// Parameters: |
||||
|
// value: the value to be converted |
||||
|
// from_unit: the unit to convert from ('m' for meters, 'c' for centimeters, 'i' for inches) |
||||
|
// to_unit: the unit to convert to ('m' for meters, 'c' for centimeters, 'i' for inches) |
||||
|
// Returns: |
||||
|
// The converted length value |
||||
|
|
||||
|
float convert_length(float value, char from_unit, char to_unit); |
||||
|
|
||||
|
#endif //THEADMIRALS_CONVERT_M_TO_FT_H |
@ -0,0 +1,49 @@ |
|||||
|
#include "convert_time.h" |
||||
|
|
||||
|
// Converts Seconds to Minutes |
||||
|
double converter_sec_to_min(double sec){ |
||||
|
double time = sec / 60; |
||||
|
return time; |
||||
|
} |
||||
|
|
||||
|
// Converts Minutes to Seconds |
||||
|
double converter_min_to_sec(double min){ |
||||
|
double time = min * 60; |
||||
|
return time; |
||||
|
} |
||||
|
|
||||
|
// Converts Hours to Minutes |
||||
|
double converter_hour_to_min(double hour){ |
||||
|
double min = hour * 60; |
||||
|
return min; |
||||
|
} |
||||
|
|
||||
|
// Converts Minutes To Hours |
||||
|
double converter_min_to_hour(double min){ |
||||
|
double hours = min / 60; |
||||
|
return hours; |
||||
|
} |
||||
|
|
||||
|
// Converts Hours in Seconds |
||||
|
double converter_hour_in_sec(double hour){ |
||||
|
double secs = hour * 60 * 60; |
||||
|
return secs; |
||||
|
} |
||||
|
|
||||
|
// Converts Seconds in Hours |
||||
|
double converter_sec_in_hour(double sec){ |
||||
|
double hours = sec / 60 / 60; |
||||
|
return hours; |
||||
|
} |
||||
|
|
||||
|
// Converts Days in Years |
||||
|
double converter_days_to_years(double days){ |
||||
|
double years = days / 365; |
||||
|
return years; |
||||
|
} |
||||
|
|
||||
|
// convert Years in days |
||||
|
double converter_years_to_days(double years){ |
||||
|
double amount = years * 365; |
||||
|
return amount; |
||||
|
} |
@ -0,0 +1,13 @@ |
|||||
|
#ifndef THEADMIRALS_CONVERT_TIME_H |
||||
|
#define THEADMIRALS_CONVERT_TIME_H |
||||
|
|
||||
|
double converter_sec_to_min(double sec); |
||||
|
double converter_min_to_sec(double min); |
||||
|
double converter_hour_to_min(double hour); |
||||
|
double converter_min_to_hour(double min); |
||||
|
double converter_hour_in_sec(double hour); |
||||
|
double converter_sec_in_hour(double sec); |
||||
|
double converter_days_to_years(double days); |
||||
|
double converter_years_to_days(double years); |
||||
|
|
||||
|
#endif //THEADMIRALS_CONVERT_TIME_H |
@ -0,0 +1,7 @@ |
|||||
|
|
||||
|
#include "convert_ton_to_kg.h" |
||||
|
|
||||
|
|
||||
|
double tons_to_kg(double tons) { |
||||
|
return tons * 1000.0; |
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
|
||||
|
|
||||
|
#ifndef THEADMIRALS_CONVERT_TON_TO_KG_H |
||||
|
#define THEADMIRALS_CONVERT_TON_TO_KG_H |
||||
|
|
||||
|
// Convert tons to kilograms |
||||
|
// Parameters: |
||||
|
// tons: weight in tons |
||||
|
// Returns: |
||||
|
// The equivalent weight in kilograms |
||||
|
|
||||
|
|
||||
|
double tons_to_kg(double tons); |
||||
|
|
||||
|
|
||||
|
|
||||
|
#endif //THEADMIRALS_CONVERT_TON_TO_KG_H |
@ -0,0 +1,7 @@ |
|||||
|
|
||||
|
#include "convert_ton_to_mt.h" |
||||
|
|
||||
|
|
||||
|
double tons_to_megatons(double tons) { |
||||
|
return tons / 1000000.0; |
||||
|
} |
@ -0,0 +1,13 @@ |
|||||
|
|
||||
|
#ifndef THEADMIRALS_CONVERT_TON_TO_MT_H |
||||
|
#define THEADMIRALS_CONVERT_TON_TO_MT_H |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
double tons_to_megatons(double tons); |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
#endif //THEADMIRALS_CONVERT_TON_TO_MT_H |
@ -0,0 +1,9 @@ |
|||||
|
#include "exponentials.h" |
||||
|
#include <stdlib.h> |
||||
|
#include <math.h> |
||||
|
|
||||
|
double* exponentials_double(int base, int exponent) { |
||||
|
double* result = malloc(sizeof(double)); |
||||
|
*result = pow(base, exponent); |
||||
|
return result; |
||||
|
} |
@ -0,0 +1,6 @@ |
|||||
|
#ifndef THEADMIRALS_EXPONENTIALS_H |
||||
|
#define THEADMIRALS_EXPONENTIALS_H |
||||
|
|
||||
|
double* exponentials_double(int, int); |
||||
|
|
||||
|
#endif //THEADMIRALS_EXPONENTIALS_H |
@ -0,0 +1,58 @@ |
|||||
|
#include "inputHandler.h" |
||||
|
#include <stdio.h> |
||||
|
|
||||
|
// return operation id for a specific symbol |
||||
|
int getOperationIdBySymbol(char symbol) { |
||||
|
int id = 0; |
||||
|
switch (symbol) { |
||||
|
case '+': |
||||
|
return 1; |
||||
|
case '-': |
||||
|
return 2; |
||||
|
case '/': |
||||
|
return 3; |
||||
|
case '*': |
||||
|
return 4; |
||||
|
case '^': |
||||
|
return 5; |
||||
|
case '%': |
||||
|
return 6; |
||||
|
case '!': |
||||
|
return 7; |
||||
|
} |
||||
|
return id; |
||||
|
} |
||||
|
|
||||
|
// returns operation symbol for a specific operation id |
||||
|
char getOperationSymbolById(int id) { |
||||
|
char symbol = ' '; |
||||
|
switch (id) { |
||||
|
case 1: |
||||
|
return '+'; |
||||
|
case 2: |
||||
|
return '-'; |
||||
|
case 3: |
||||
|
return '/'; |
||||
|
case 4: |
||||
|
return '*'; |
||||
|
case 5: |
||||
|
return '^'; |
||||
|
case 6: |
||||
|
return '%'; |
||||
|
case 7: |
||||
|
return '!'; |
||||
|
} |
||||
|
return symbol; |
||||
|
} |
||||
|
|
||||
|
// Checking if operation id is available |
||||
|
int isOperationIdValid(int id) { |
||||
|
if(id < 1 || id > 7) return 0; |
||||
|
return 1; |
||||
|
} |
||||
|
|
||||
|
int isNumberTooBig(int number) { |
||||
|
if(number < 200) return 0; |
||||
|
//printf("This number is too big. Please choose a smaller one...\n"); |
||||
|
return 1; |
||||
|
} |
@ -0,0 +1,12 @@ |
|||||
|
#ifndef THEADMIRALS_INPUTHANDLER_H |
||||
|
#define THEADMIRALS_INPUTHANDLER_H |
||||
|
|
||||
|
int getOperationIdBySymbol(char); |
||||
|
|
||||
|
char getOperationSymbolById(int); |
||||
|
|
||||
|
int isOperationIdValid(int); |
||||
|
|
||||
|
int isNumberTooBig(int); |
||||
|
|
||||
|
#endif //THEADMIRALS_INPUTHANDLER_H |
@ -0,0 +1,18 @@ |
|||||
|
#include "logarithmicFunctions.h" |
||||
|
#include <stdio.h> |
||||
|
#include <stdlib.h> |
||||
|
#include <math.h> |
||||
|
|
||||
|
double* logarithm_two_integer(int base, int num){ |
||||
|
if(base <= 1 || num <= 0){ |
||||
|
return NULL; |
||||
|
} |
||||
|
|
||||
|
double* result = (double*)malloc(sizeof(double)); |
||||
|
if (result == NULL) { |
||||
|
return NULL; |
||||
|
} |
||||
|
|
||||
|
*result = log(num) / log(base); |
||||
|
return result; |
||||
|
} |
@ -0,0 +1,6 @@ |
|||||
|
#ifndef THEADMIRALS_LOGARITHMICFUNCTIONS_H |
||||
|
#define THEADMIRALS_LOGARITHMICFUNCTIONS_H |
||||
|
|
||||
|
double* logarithm_two_integer(int base, int num); |
||||
|
|
||||
|
#endif //THEADMIRALS_LOGARITHMICFUNCTIONS_H |
@ -1,4 +1,38 @@ |
|||||
#include <stdio.h> |
#include <stdio.h> |
||||
|
#include <string.h> |
||||
|
#include "operationHandler.h" |
||||
|
|
||||
|
char buffer[100]; |
||||
|
|
||||
int main() { |
int main() { |
||||
|
printf("Please enter the id of a specific operation...\n1. addition\n2. subtraction\n3. multiplication\n4. division\n"); |
||||
|
|
||||
|
// input for math operation as integer |
||||
|
int input; |
||||
|
scanf("%d", &input); |
||||
|
|
||||
|
// check if operation input is valid |
||||
|
if(!checkOperationInput(input)) { |
||||
|
printf("Invalid operation id\n"); |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
printf("\nPlease enter the first and the second number separated by a space...\n"); |
||||
|
|
||||
|
// loop to enter numbers for calculation |
||||
|
while(fgets(buffer, 100, stdin)) { |
||||
|
buffer[strcspn(buffer, "\n")] = '\0'; |
||||
|
if (strlen(buffer) > 0) { |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// extracting numbers from input |
||||
|
int* result = evaluateInput(buffer, input); |
||||
|
|
||||
|
if(result == NULL) { |
||||
|
printf("\nInvalid formatting. Two numbers need to be separated by a space\n"); |
||||
|
return 0; |
||||
|
} |
||||
|
printf("\nResult: %d", *result); |
||||
} |
} |
@ -0,0 +1,122 @@ |
|||||
|
#include "operationHandler.h" |
||||
|
#include <stdbool.h> |
||||
|
#include <ctype.h> |
||||
|
#include <stdlib.h> |
||||
|
#include <string.h> |
||||
|
#include <stdio.h> |
||||
|
|
||||
|
// checking integer input as operation id |
||||
|
bool checkOperationInput(int input) { |
||||
|
switch (input) { |
||||
|
case 4: case 3: case 2: case 1: |
||||
|
return true; |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
// full input process |
||||
|
int* evaluateInput(char* input, int operation) { |
||||
|
// check if formatting is correct |
||||
|
if(!containsTwoNumbers(input)) return NULL; |
||||
|
int firstNumber = extractFirstNumber(input); |
||||
|
// origin string "input" has been edited |
||||
|
int secondNumber = atoi(input); |
||||
|
int* result = malloc(sizeof(int)); |
||||
|
switch (operation) { |
||||
|
case 1: |
||||
|
*result = firstNumber + secondNumber; |
||||
|
break; |
||||
|
case 2: |
||||
|
*result = firstNumber - secondNumber; |
||||
|
break; |
||||
|
case 3: |
||||
|
*result = firstNumber * secondNumber; |
||||
|
break; |
||||
|
case 4: |
||||
|
*result = firstNumber / secondNumber; |
||||
|
break; |
||||
|
} |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
// formatting check of string |
||||
|
bool containsTwoNumbers(const char* str) { |
||||
|
int numbersCount = 0; |
||||
|
bool hasSpace = false; |
||||
|
bool isInNumber = false; |
||||
|
|
||||
|
for (int i = 0; str[i] != '\0'; i++) { |
||||
|
if (isdigit(str[i])) { |
||||
|
if (!isInNumber) { |
||||
|
isInNumber = true; |
||||
|
numbersCount++; |
||||
|
} |
||||
|
} else if (str[i] == ' ' && isInNumber) { |
||||
|
hasSpace = true; |
||||
|
isInNumber = false; |
||||
|
} else if (str[i] == ' ' && !isInNumber) { |
||||
|
hasSpace = false; |
||||
|
} else { |
||||
|
hasSpace = false; |
||||
|
isInNumber = false; |
||||
|
} |
||||
|
} |
||||
|
return (numbersCount == 2 && hasSpace); |
||||
|
} |
||||
|
|
||||
|
// extracting of first number and removing from string |
||||
|
int extractFirstNumber(char* str) { |
||||
|
int number = 0; |
||||
|
bool isInNumber = false; |
||||
|
int endIndex = 0; |
||||
|
|
||||
|
for (int i = 0; str[i] != '\0'; i++) { |
||||
|
if (isdigit(str[i])) { |
||||
|
if (!isInNumber) { |
||||
|
isInNumber = true; |
||||
|
number = str[i] - '0'; |
||||
|
} else { |
||||
|
number = number * 10 + (str[i] - '0'); |
||||
|
} |
||||
|
} else if (str[i] == ' ' && isInNumber) { |
||||
|
endIndex = i; |
||||
|
break; |
||||
|
} else { |
||||
|
isInNumber = false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
int index = 0; |
||||
|
char temp[strlen(str)-endIndex+1]; |
||||
|
for(int i = endIndex+1; i < strlen(str); i++) { |
||||
|
temp[index++] = str[i]; |
||||
|
} |
||||
|
temp[index] = '\0'; |
||||
|
strcpy(str, temp); |
||||
|
|
||||
|
return number; |
||||
|
} |
||||
|
|
||||
|
void outputInteger(int output) { |
||||
|
outputTemplate(); |
||||
|
printf("Result: %d", output); |
||||
|
} |
||||
|
|
||||
|
void outputLong(long output) { |
||||
|
outputTemplate(); |
||||
|
printf("Result: %ld", output); |
||||
|
} |
||||
|
|
||||
|
void outputDouble(double output) { |
||||
|
outputTemplate(); |
||||
|
printf("Result: %lf", output); |
||||
|
} |
||||
|
|
||||
|
void outputFloat(float output) { |
||||
|
outputTemplate(); |
||||
|
printf("Result: %f", output); |
||||
|
} |
||||
|
|
||||
|
void outputTemplate() { |
||||
|
printf("###############################\n-> Calculator\n#################################"); |
||||
|
} |
@ -0,0 +1,23 @@ |
|||||
|
#ifndef THEADMIRALS_OPERATIONHANDLER_H |
||||
|
#define THEADMIRALS_OPERATIONHANDLER_H |
||||
|
#include <stdbool.h> |
||||
|
|
||||
|
bool checkOperationInput(int); |
||||
|
|
||||
|
int* evaluateInput(char*, int); |
||||
|
|
||||
|
bool containsTwoNumbers(const char*); |
||||
|
|
||||
|
int extractFirstNumber(char*); |
||||
|
|
||||
|
void outputInteger(int); |
||||
|
|
||||
|
void outputDouble(double); |
||||
|
|
||||
|
void outputFloat(float); |
||||
|
|
||||
|
void outputLong(long); |
||||
|
|
||||
|
void outputTemplate(); |
||||
|
|
||||
|
#endif //THEADMIRALS_OPERATIONHANDLER_H |
@ -0,0 +1,24 @@ |
|||||
|
|
||||
|
#include "trigonometricFunctions.h" |
||||
|
#include "math.h" |
||||
|
#include <stdio.h> |
||||
|
#include <stdlib.h> |
||||
|
//function for trigonometric |
||||
|
//Function 1 for double |
||||
|
double* calculate_sin_double(double angle) { |
||||
|
double* result= malloc(sizeof (double)); |
||||
|
*result=sin(angle); |
||||
|
return result; |
||||
|
} |
||||
|
//Function 2 for double |
||||
|
double* calculate_cos_double(double angle) { |
||||
|
double* result= malloc(sizeof (double)); |
||||
|
*result=cos(angle); |
||||
|
return result; |
||||
|
} |
||||
|
//Function 3 for double |
||||
|
double* calculate_tan_double(double angle) { |
||||
|
double* result= malloc(sizeof (double)); |
||||
|
*result=tan(angle); |
||||
|
return result; |
||||
|
} |
@ -0,0 +1,9 @@ |
|||||
|
|
||||
|
#ifndef THEADMIRALS_TRIGONOMETRICFUNCTIONS_H |
||||
|
#define THEADMIRALS_TRIGONOMETRICFUNCTIONS_H |
||||
|
|
||||
|
double* calculate_sin_double(double angle); |
||||
|
double* calculate_cos_double(double angle); |
||||
|
double* calculate_tan_double(double angle); |
||||
|
|
||||
|
#endif //THEADMIRALS_TRIGONOMETRICFUNCTIONS_H |
@ -1,3 +1,5 @@ |
|||||
- Eric Bagus, fdai7812 |
- Eric Bagus, fdai7812 |
||||
|
- fdai7812, fdai7812 |
||||
- Leon Wolf, fdai7845 |
- Leon Wolf, fdai7845 |
||||
- Sandro Welte, fdai7728 |
- Sandro Welte, fdai7728 |
||||
|
- Jonas Zitzmann, fdai7791 |
@ -0,0 +1,45 @@ |
|||||
|
#include "../src/arithmeticAddition.h" |
||||
|
#include "unity.h" |
||||
|
#include "limits.h" |
||||
|
|
||||
|
void setUp(void) { |
||||
|
// set stuff up here |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) { |
||||
|
// clean stuff up here |
||||
|
} |
||||
|
|
||||
|
void test_arithmeticAddition_numberplusnumberequalsnumber(void) { |
||||
|
int expectedResult = 8; |
||||
|
int* result; |
||||
|
result = addition_integer(5, 3); |
||||
|
TEST_ASSERT_EQUAL_INT(expectedResult, *result); |
||||
|
} |
||||
|
|
||||
|
void test_arithmeticAddition_numberplusmaxintegervalueequalsnull(void) { |
||||
|
int* result; |
||||
|
result = addition_integer(INT_MAX, 1); |
||||
|
TEST_ASSERT_NULL(result); |
||||
|
} |
||||
|
|
||||
|
void test_arithmeticAddition_doublenumbercalculationequalscorrectdoublenumber(void) { |
||||
|
double expectedResult = 5.500000; |
||||
|
double* result; |
||||
|
result = addition_double(3.5, 2.0); |
||||
|
TEST_ASSERT_EQUAL_DOUBLE(expectedResult, *result); |
||||
|
} |
||||
|
|
||||
|
void test_arithmeticAddition_longnumbercalculationequalscorrectlong(void) { |
||||
|
long expectedResult = 10; |
||||
|
long* result; |
||||
|
result = addition_long(5, 5); |
||||
|
TEST_ASSERT_EQUAL_INT(expectedResult, *result); |
||||
|
} |
||||
|
|
||||
|
void test_arithmeticAddition_floatnumbercalculationequalsfloat(void) { |
||||
|
float expectedResult = 5.5; |
||||
|
float* result; |
||||
|
result = addition_float(3.5, 2.0); |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expectedResult, *result); |
||||
|
} |
@ -0,0 +1,40 @@ |
|||||
|
#include "../src/arithmeticDivision.h" |
||||
|
#include "unity.h" |
||||
|
#include "limits.h" |
||||
|
|
||||
|
void setUp(void) { |
||||
|
// set stuff up here |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) { |
||||
|
// clean stuff up here |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void test_arithmeticDivision_numberdividedbynumberequalsnumber(void) { |
||||
|
int expectedResult = 2; |
||||
|
int* result; |
||||
|
result = division_integer(14, 7); |
||||
|
TEST_ASSERT_EQUAL_INT(expectedResult, *result); |
||||
|
} |
||||
|
|
||||
|
void test_arithmeticDivision_longdividedbylongequalscorrectlong(void) { |
||||
|
long expectedResult = 5; |
||||
|
long* result; |
||||
|
result = division_long(10, 2); |
||||
|
TEST_ASSERT_EQUAL_INT(expectedResult, *result); |
||||
|
} |
||||
|
|
||||
|
void test_arithmeticDivsion_floatdividedbyfloatequalscorrectfloat(void) { |
||||
|
float expectedResult = 5.0; |
||||
|
float* result; |
||||
|
result = division_float(10.0, 2.0); |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expectedResult, *result); |
||||
|
} |
||||
|
|
||||
|
void test_arithmeticDivision_doubledividedbydoublequalscorrectdouble(void) { |
||||
|
double expectedResult = 5.0; |
||||
|
double* result; |
||||
|
result = division_double(10.0, 2.0); |
||||
|
TEST_ASSERT_EQUAL_DOUBLE(expectedResult, *result); |
||||
|
} |
@ -0,0 +1,21 @@ |
|||||
|
#include "../src/arithmeticMultiplication_Int.h" |
||||
|
#include "unity.h" |
||||
|
#include "limits.h" |
||||
|
|
||||
|
void setUp(void) { |
||||
|
// set stuff up here |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) { |
||||
|
// clean stuff up here |
||||
|
} |
||||
|
|
||||
|
void test_arithmeticMultiplication_numbertimesnumberequalsnumber(void) { |
||||
|
int expectedResult = 10; |
||||
|
int* result; |
||||
|
result = multiplication_integer(2,5); |
||||
|
TEST_ASSERT_EQUAL_INT(expectedResult, *result); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
@ -0,0 +1,31 @@ |
|||||
|
#include "../src/arithmeticSubtraction.h" |
||||
|
#include "unity.h" |
||||
|
#include "limits.h" |
||||
|
|
||||
|
void setUp(void) { |
||||
|
// set stuff up here |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) { |
||||
|
// clean stuff up here |
||||
|
} |
||||
|
void test_arithmeticSubtraction_subractionoftwonumbers(void) { |
||||
|
int expectedResult = 7; |
||||
|
int* result; |
||||
|
result = subtraction_integer(14, 7); |
||||
|
TEST_ASSERT_EQUAL_INT(expectedResult, *result); |
||||
|
} |
||||
|
void test_arithmeticSubtraction_subractionoftwonumberswithfloat(void) { |
||||
|
float expectedResult = 7; |
||||
|
float* result; |
||||
|
result = subtraction_float(14, 7); |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expectedResult, *result); |
||||
|
} |
||||
|
void test_arithmeticSubtraction_subractionoftwonumberswithdouble(void) { |
||||
|
double expectedResult = 7; |
||||
|
double* result; |
||||
|
result = subtraction_double(14, 7); |
||||
|
TEST_ASSERT_EQUAL_DOUBLE (expectedResult, *result); |
||||
|
} |
||||
|
|
||||
|
|
@ -0,0 +1,17 @@ |
|||||
|
#include "../src/calculateFactorial.h" |
||||
|
#include "unity.h" |
||||
|
#include "limits.h" |
||||
|
|
||||
|
void setUp(void) { |
||||
|
// set stuff up here |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) { |
||||
|
// clean stuff up here |
||||
|
} |
||||
|
void test_calculateFactorial_calculateFactorialofanumber(void) { |
||||
|
int expectedResult = 120; |
||||
|
int result; |
||||
|
result = calculateFactorial_integer(5); |
||||
|
TEST_ASSERT_EQUAL_INT(expectedResult, result); |
||||
|
} |
@ -0,0 +1,32 @@ |
|||||
|
#include "../src/convert_CM_in_M.h" |
||||
|
#include "unity.h" |
||||
|
#include "limits.h" |
||||
|
|
||||
|
void setUp(void) { |
||||
|
// Set up resources here if needed |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) { |
||||
|
// Clean up resources here if needed |
||||
|
} |
||||
|
void test_cm_to_meter(void) { |
||||
|
// Testfall 1: 100 cm sollten 1 Meter sein |
||||
|
float value_1 = 100.0; |
||||
|
float expectedResult_1 = 1.0; |
||||
|
float result_1 = cm_to_meter(value_1); |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expectedResult_1, result_1); |
||||
|
} |
||||
|
void test_cm_to_meter2(void) { |
||||
|
// Testfall 2: 50 cm sollten 0.5 Meter sein |
||||
|
float value_2 = 50.0; |
||||
|
float expectedResult_2 = 0.5; |
||||
|
float result_2 = cm_to_meter(value_2); |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expectedResult_2, result_2); |
||||
|
} |
||||
|
void test_cm_to_meter3(void) { |
||||
|
// Testfall 3: 200 cm sollten 2 Meter sein |
||||
|
float value_3 = 200.0; |
||||
|
float expectedResult_3 = 2.0; |
||||
|
float result_3 = cm_to_meter(value_3); |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expectedResult_3, result_3); |
||||
|
} |
@ -0,0 +1,32 @@ |
|||||
|
#include "../src/convert_M_in_KM.h" |
||||
|
#include "unity.h" |
||||
|
#include "limits.h" |
||||
|
|
||||
|
void setUp(void) { |
||||
|
// Set up resources here if needed |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) { |
||||
|
// Clean up resources here if needed |
||||
|
} |
||||
|
void test_meter_to_kilometer(void) { |
||||
|
// Testfall 1: 1000 Meter sollten 1 Kilometer sein |
||||
|
double value_1 = 1000.0; |
||||
|
double expectedResult_1 = 1.0; |
||||
|
double result_1 = meter_to_kilometer(value_1); |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expectedResult_1, result_1); |
||||
|
} |
||||
|
void test_meter_to_kilometer2(void) { |
||||
|
// Testfall 2: 500 Meter sollten 0.5 Kilometer sein |
||||
|
double value_2 = 500.0; |
||||
|
double expectedResult_2 = 0.5; |
||||
|
double result_2 = meter_to_kilometer(value_2); |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expectedResult_2, result_2); |
||||
|
} |
||||
|
void test_meter_to_kilometer3(void) { |
||||
|
// Testfall 3: 1500 Meter sollten 1.5 Kilometer sein |
||||
|
double value_3 = 1500.0; |
||||
|
double expectedResult_3 = 1.5; |
||||
|
double result_3 = meter_to_kilometer(value_3); |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expectedResult_3, result_3); |
||||
|
} |
@ -0,0 +1,32 @@ |
|||||
|
#include "../src/convert_cm_in_dm.h" |
||||
|
#include "unity.h" |
||||
|
#include "limits.h" |
||||
|
|
||||
|
void setUp(void) { |
||||
|
// Set up resources here if needed |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) { |
||||
|
// Clean up resources here if needed |
||||
|
} |
||||
|
void test_cm_to_dm(void) { |
||||
|
// Testfall 1: 100 cm sollten 10 Dezimeter sein |
||||
|
double value_1 = 100.0; |
||||
|
double expectedResult_1 = 10.0; |
||||
|
double result_1 = cm_to_dm(value_1); |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expectedResult_1, result_1); |
||||
|
} |
||||
|
void test_cm_to_dm2(void) { |
||||
|
// Testfall 2: 50 cm sollten 5 Dezimeter sein |
||||
|
double value_2 = 50.0; |
||||
|
double expectedResult_2 = 5.0; |
||||
|
double result_2 = cm_to_dm(value_2); |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expectedResult_2, result_2); |
||||
|
} |
||||
|
void test_cm_to_dm3(void) { |
||||
|
// Testfall 3: 200 cm sollten 20 Dezimeter sein |
||||
|
double value_3 = 200.0; |
||||
|
double expectedResult_3 = 20.0; |
||||
|
double result_3 = cm_to_dm(value_3); |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expectedResult_3, result_3); |
||||
|
} |
@ -0,0 +1,25 @@ |
|||||
|
#include "../src/convert_kph_to_mps.h" |
||||
|
#include "unity.h" |
||||
|
#include "limits.h" |
||||
|
|
||||
|
void setUp(void) { |
||||
|
// set stuff up here |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) { |
||||
|
// clean stuff up here |
||||
|
} |
||||
|
|
||||
|
void test_convert_kph_to_mps_kpstomps(void){ |
||||
|
double expectedResult = 1.0; |
||||
|
double result; |
||||
|
result = converter_kph_to_mps(3.6); |
||||
|
TEST_ASSERT_EQUAL_DOUBLE(expectedResult, result); |
||||
|
} |
||||
|
|
||||
|
void test_convert_kph_to_mps_mpstokps(void){ |
||||
|
double expectedResult = 3.6; |
||||
|
double result; |
||||
|
result = converter_mps_to_kph(1.0); |
||||
|
TEST_ASSERT_EQUAL_DOUBLE(expectedResult, result); |
||||
|
} |
@ -0,0 +1,28 @@ |
|||||
|
|
||||
|
#include "../src/convert_m_to_ft.h" |
||||
|
#include "unity.h" |
||||
|
#include "limits.h" |
||||
|
|
||||
|
void setUp(void) { |
||||
|
// Set up resources here if needed |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) { |
||||
|
// Clean up resources here if needed |
||||
|
} |
||||
|
|
||||
|
void test_convert_length(void) { |
||||
|
float value = 10.0; |
||||
|
char from_unit = 'm'; |
||||
|
char to_unit = 'f'; |
||||
|
|
||||
|
// Perform the conversion |
||||
|
float result = convert_length(value, from_unit, to_unit); |
||||
|
|
||||
|
// Define the expected result (10 meters to feet is approximately 32.81 feet) |
||||
|
float expectedResult = 32.81; |
||||
|
|
||||
|
// Assert the result |
||||
|
TEST_ASSERT_EQUAL_FLOAT(expectedResult, result); |
||||
|
} |
||||
|
|
@ -0,0 +1,67 @@ |
|||||
|
#include "../src/convert_time.h" |
||||
|
#include "unity.h" |
||||
|
#include "limits.h" |
||||
|
|
||||
|
void setUp(void) { |
||||
|
// set stuff up here |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) { |
||||
|
// clean stuff up here |
||||
|
} |
||||
|
|
||||
|
void test_convert_time_sectomin(void){ |
||||
|
double expectedResult = 1.0; |
||||
|
double result; |
||||
|
result = converter_sec_to_min(60.0); |
||||
|
TEST_ASSERT_EQUAL_DOUBLE(expectedResult, result); |
||||
|
} |
||||
|
|
||||
|
void test_convert_time_mintosec(void){ |
||||
|
double expectedResult = 60.0; |
||||
|
double result; |
||||
|
result = converter_min_to_sec(1.0); |
||||
|
TEST_ASSERT_EQUAL_DOUBLE(expectedResult, result); |
||||
|
} |
||||
|
|
||||
|
void test_convert_time_hourtomin(void){ |
||||
|
double expectedResult = 60.0; |
||||
|
double result; |
||||
|
result = converter_hour_to_min(1.0); |
||||
|
TEST_ASSERT_EQUAL_DOUBLE(expectedResult, result); |
||||
|
} |
||||
|
|
||||
|
void test_convert_time_mintohour(void){ |
||||
|
double expectedResult = 1.0; |
||||
|
double result; |
||||
|
result = converter_min_to_hour(60.0); |
||||
|
TEST_ASSERT_EQUAL_DOUBLE(expectedResult, result); |
||||
|
} |
||||
|
|
||||
|
void test_convert_time_hourinsec(void){ |
||||
|
double expectedResult = 3600.0; |
||||
|
double result; |
||||
|
result = converter_hour_in_sec(1.0); |
||||
|
TEST_ASSERT_EQUAL_DOUBLE(expectedResult, result); |
||||
|
} |
||||
|
|
||||
|
void test_convert_time_sectohour(void){ |
||||
|
double expectedResult = 1.0; |
||||
|
double result; |
||||
|
result = converter_sec_in_hour(3600.0); |
||||
|
TEST_ASSERT_EQUAL_DOUBLE(expectedResult, result); |
||||
|
} |
||||
|
|
||||
|
void test_convert_time_daysinyears(void){ |
||||
|
double expectedResult = 1.0; |
||||
|
double result; |
||||
|
result = converter_days_to_years(365.0); |
||||
|
TEST_ASSERT_EQUAL_DOUBLE(expectedResult, result); |
||||
|
} |
||||
|
|
||||
|
void test_convert_time_yearsindays(void){ |
||||
|
double expectedResult = 365.0; |
||||
|
double result; |
||||
|
result = converter_years_to_days(1.0); |
||||
|
TEST_ASSERT_EQUAL_DOUBLE(expectedResult, result); |
||||
|
} |
@ -0,0 +1,18 @@ |
|||||
|
#include "../src/exponentials.h" |
||||
|
#include "unity.h" |
||||
|
#include "limits.h" |
||||
|
|
||||
|
void setUp(void) { |
||||
|
// set stuff up here |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) { |
||||
|
// clean stuff up here |
||||
|
} |
||||
|
|
||||
|
void test_exponentials_calculatenumfrombaseandexponent(void) { |
||||
|
double expectedResult = 32.000000; |
||||
|
double* result; |
||||
|
result = exponentials_double(2, 5); |
||||
|
TEST_ASSERT_EQUAL_DOUBLE(expectedResult, *result); |
||||
|
} |
@ -0,0 +1,39 @@ |
|||||
|
#include "../src/inputHandler.h" |
||||
|
#include "unity.h" |
||||
|
|
||||
|
void setUp(void) { |
||||
|
// set stuff up here |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) { |
||||
|
// clean stuff up here |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void test_inputHandler_returntwoforinputminus(void) { |
||||
|
int expectedResult = 2; |
||||
|
int result; |
||||
|
result = getOperationIdBySymbol('-'); |
||||
|
TEST_ASSERT_EQUAL_INT(expectedResult, result); |
||||
|
} |
||||
|
|
||||
|
void test_inputHandler_returnoneforinputplus(void) { |
||||
|
int expectedResult = 1; |
||||
|
int result; |
||||
|
result = getOperationIdBySymbol('+'); |
||||
|
TEST_ASSERT_EQUAL_INT(expectedResult, result); |
||||
|
} |
||||
|
|
||||
|
void test_inputHandler_returnzeroforinvalidinput(void) { |
||||
|
int expectedResult = 0; |
||||
|
int result; |
||||
|
result = isOperationIdValid(0); |
||||
|
TEST_ASSERT_EQUAL_INT(expectedResult, result); |
||||
|
} |
||||
|
|
||||
|
void test_inputHandler_returnoneifinputtoobig(void) { |
||||
|
int expectedResult = 1; |
||||
|
int result; |
||||
|
result = isNumberTooBig(300); |
||||
|
TEST_ASSERT_EQUAL_INT(expectedResult, result); |
||||
|
} |
@ -0,0 +1,18 @@ |
|||||
|
#include "../src/logarithmicFunctions.h" |
||||
|
#include "unity.h" |
||||
|
#include "limits.h" |
||||
|
|
||||
|
void setUp(void) { |
||||
|
// set stuff up here |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) { |
||||
|
// clean stuff up here |
||||
|
} |
||||
|
|
||||
|
void test_logarithmicFunctions_logarithmiccalculation(void){ |
||||
|
double expectedResult = 3.000000; |
||||
|
double* result; |
||||
|
result = logarithm_two_integer(2,8); |
||||
|
TEST_ASSERT_EQUAL_DOUBLE(expectedResult, *result); |
||||
|
} |
@ -0,0 +1,56 @@ |
|||||
|
#include "../src/operationHandler.h" |
||||
|
#include "unity.h" |
||||
|
|
||||
|
void setUp(void) { |
||||
|
// set stuff up here |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) { |
||||
|
// clean stuff up here |
||||
|
} |
||||
|
|
||||
|
void test_operationHandler_truereturnvaluewithvalidinput(void) { |
||||
|
int expectedResult = 1; |
||||
|
int result1 = checkOperationInput(1); |
||||
|
int result2 = checkOperationInput(2); |
||||
|
int result3 = checkOperationInput(3); |
||||
|
int result4 = checkOperationInput(4); |
||||
|
TEST_ASSERT_EQUAL_INT(expectedResult, result1); |
||||
|
TEST_ASSERT_EQUAL_INT(expectedResult, result2); |
||||
|
TEST_ASSERT_EQUAL_INT(expectedResult, result3); |
||||
|
TEST_ASSERT_EQUAL_INT(expectedResult, result4); |
||||
|
} |
||||
|
|
||||
|
void test_operationHandler_falsereturnvaluewithinvalidinput(void) { |
||||
|
int expectedResult = 0; |
||||
|
int result = checkOperationInput(8); |
||||
|
TEST_ASSERT_EQUAL_INT(expectedResult, result); |
||||
|
} |
||||
|
|
||||
|
void test_operationHandler_truereturnvaluewithformattedinput(void) { |
||||
|
int expectedResult = 1; |
||||
|
const char str[] = {'1', '4', ' ', '5', '6', '\0'}; |
||||
|
int result = containsTwoNumbers(str); |
||||
|
TEST_ASSERT_EQUAL_INT(expectedResult, result); |
||||
|
} |
||||
|
|
||||
|
void test_operationHandler_falsereturnvaluewithwronginput(void) { |
||||
|
int expectedResult = 0; |
||||
|
const char str[] = {'5', '6', '\0'}; |
||||
|
int result = containsTwoNumbers(str); |
||||
|
TEST_ASSERT_EQUAL_INT(expectedResult, result); |
||||
|
} |
||||
|
|
||||
|
void test_operationHandler_extractingFirstNumber(void) { |
||||
|
int expectedResult = 48; |
||||
|
char str[] = {'4', '8', ' ', '5', '\0'}; |
||||
|
int result = extractFirstNumber(str); |
||||
|
TEST_ASSERT_EQUAL_INT(expectedResult, result); |
||||
|
} |
||||
|
|
||||
|
void test_operationHandler_removefirstnumberfromoriginalstring(void) { |
||||
|
char expected[] = {'5', '\0'}; |
||||
|
char str[] = {'4', '8', ' ', '5', '\0'}; |
||||
|
extractFirstNumber(str); |
||||
|
TEST_ASSERT_EQUAL_STRING(expected, str); |
||||
|
} |
@ -0,0 +1,29 @@ |
|||||
|
#include "../src/trigonometricFunctions.h" |
||||
|
#include "unity.h" |
||||
|
#include "limits.h" |
||||
|
|
||||
|
void setUp(void) { |
||||
|
// set stuff up here |
||||
|
} |
||||
|
|
||||
|
void tearDown(void) { |
||||
|
// clean stuff up here |
||||
|
} |
||||
|
void test_trigonometricFunctions_trigonometricFunctionsofsin(void) { |
||||
|
double expectedResult = 0.850903525 ; |
||||
|
double *result; |
||||
|
result = calculate_sin_double(45); |
||||
|
TEST_ASSERT_DOUBLE_WITHIN(0.1, expectedResult, *result); |
||||
|
} |
||||
|
void test_trigonometricFunctions_trigonometricFunctionsofcos(void) { |
||||
|
double expectedResult = 0.525321989 ; |
||||
|
double *result; |
||||
|
result = calculate_cos_double(45); |
||||
|
TEST_ASSERT_DOUBLE_WITHIN(0.1, expectedResult, *result); |
||||
|
} |
||||
|
void test_trigonometricFunctions_trigonometricFunctionsoftan(void) { |
||||
|
double expectedResult = 1.61977519 ; |
||||
|
double *result; |
||||
|
result = calculate_tan_double(45); |
||||
|
TEST_ASSERT_DOUBLE_WITHIN(0.1, expectedResult, *result); |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue