Browse Source

Merge branch 'develop' into 'main'

develop to main

See merge request fdai7812/theadmirals!1
main
fdai7812 11 months ago
parent
commit
12806e1a0e
  1. 31
      src/arithmeticAddition.c
  2. 12
      src/arithmeticAddition.h
  3. 17
      src/arithmeticDivision.c
  4. 6
      src/arithmeticDivision.h
  5. 12
      src/arithmeticMultiplication_Double.c
  6. 14
      src/arithmeticMultiplication_Double.h
  7. 12
      src/arithmeticMultiplication_Float.c
  8. 13
      src/arithmeticMultiplication_Float.h
  9. 17
      src/arithmeticMultiplication_Int.c
  10. 8
      src/arithmeticMultiplication_Int.h
  11. 22
      src/arithmeticSubtraction.c
  12. 9
      src/arithmeticSubtraction.h
  13. 20
      src/calculateFactorial.c
  14. 8
      src/calculateFactorial.h
  15. 7
      src/convert_CM_in_M.c
  16. 7
      src/convert_CM_in_M.h
  17. 19
      src/convert_C_to_F.c
  18. 7
      src/convert_C_to_F.h
  19. 7
      src/convert_M_in_KM.c
  20. 7
      src/convert_M_in_KM.h
  21. 6
      src/convert_kg_to_ton.c
  22. 13
      src/convert_kg_to_ton.h
  23. 11
      src/convert_kph_to_mps.c
  24. 7
      src/convert_kph_to_mps.h
  25. 23
      src/convert_m_to_ft.c
  26. 8
      src/convert_m_to_ft.h
  27. 47
      src/convert_time.c
  28. 13
      src/convert_time.h
  29. 7
      src/convert_ton_to_kg.c
  30. 11
      src/convert_ton_to_kg.h
  31. 9
      src/exponentials.c
  32. 6
      src/exponentials.h
  33. 18
      src/logarithmicFunctions.c
  34. 6
      src/logarithmicFunctions.h
  35. 26
      src/main.c
  36. 97
      src/operationHandler.c
  37. 13
      src/operationHandler.h
  38. 25
      src/trigonometricFunctions.c
  39. 9
      src/trigonometricFunctions.h
  40. 1
      team.md
  41. 24
      test/test_arithmeticAddition.c
  42. 19
      test/test_arithmeticDivision.c
  43. 21
      test/test_arithmeticMultiplication_Int.c
  44. 31
      test/test_arithmeticSubtraction.c
  45. 28
      test/test_convert_m_to_ft.c
  46. 18
      test/test_exponentials.c
  47. 18
      test/test_logarithmicFunctions.c
  48. 49
      test/test_operationHandler.c

31
src/arithmeticAddition.c

@ -0,0 +1,31 @@
#include "arithmeticAddition.h"
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
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;
}
double* addition_double(double number1, double number2) {
double* result = malloc(sizeof(double));
*result = number1+number2;
return result;
}
float* addition_float(float number1, float number2) {
float* result = malloc(sizeof(float));
*result = number1+number2;
return result;
}
long* addition_long(long number1, long number2) {
long* result = malloc(sizeof(long));
*result = number1+number2;
return result;
}

12
src/arithmeticAddition.h

@ -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

17
src/arithmeticDivision.c

@ -0,0 +1,17 @@
#include "arithmeticDivision.h"
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
int* division_integer(int dividend, int divisor) {
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;
}

6
src/arithmeticDivision.h

@ -0,0 +1,6 @@
#ifndef THEADMIRALS_ARITHMETICDIVISION_H
#define THEADMIRALS_ARITHMETICDIVISION_H
int* division_integer(int, int);
#endif //THEADMIRALS_ARITHMETICDIVISION_H

12
src/arithmeticMultiplication_Double.c

@ -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; // Handle memory allocation failure
}
*result = a * b; // we multiply a times b and the result gets saved in *result
return result;
}

14
src/arithmeticMultiplication_Double.h

@ -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

12
src/arithmeticMultiplication_Float.c

@ -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; // Handle memory allocation failure
}
*result = a * b;
return result;
}

13
src/arithmeticMultiplication_Float.h

@ -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

17
src/arithmeticMultiplication_Int.c

@ -0,0 +1,17 @@
#include "arithmeticMultiplication_Int.h"
#include <stdlib.h>
int* multiplication_integer(int a, int b) {
int *result = (int*)malloc(sizeof(int));
if (result == NULL) {
// Handle memory allocation failure
return NULL;
}
*result = a * b;
return result;
}

8
src/arithmeticMultiplication_Int.h

@ -0,0 +1,8 @@
#ifndef THEADMIRALS_ARITHMETICMULTIPLICATION_INT_H
#define THEADMIRALS_ARITHMETICMULTIPLICATION_INT_H
int* multiplication_integer(int, int);
#endif //THEADMIRALS_ARITHMETICMULTIPLICATION_INT_H

22
src/arithmeticSubtraction.c

@ -0,0 +1,22 @@
#include "arithmeticSubtraction.h"
#include <stdlib.h>
//arithmetic Subtraction specification integer
int* subtraction_integer(int a, int b) {
int* result= malloc(sizeof (int));
*result=a - b;
return result;
}
//arithmetic Subtraction specification float
float* subtraction_float(float a, float b) {
float* result= malloc(sizeof (float));
*result=a - b;
return result;
}
//arithmetic Subtraction specification double
double* subtraction_double(double a, double b) {
double* result= malloc(sizeof (double));
*result=a - b;
return result;
}

9
src/arithmeticSubtraction.h

@ -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

20
src/calculateFactorial.c

@ -0,0 +1,20 @@
#include "calculateFactorial.h"
//Factorial
// Function for Factorial
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;
}
}

8
src/calculateFactorial.h

@ -0,0 +1,8 @@
#ifndef THEADMIRALS_CALCULATEFACTORIAL_H
#define THEADMIRALS_CALCULATEFACTORIAL_H
int calculateFactorial_integer(int n);
#endif //THEADMIRALS_CALCULATEFACTORIAL_H

7
src/convert_CM_in_M.c

@ -0,0 +1,7 @@
#include "convert_CM_in_M.h"
#include <stdio.h>
//convert length
float cm_to_meter(float cm) {
return cm / 100.0;
}

7
src/convert_CM_in_M.h

@ -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

19
src/convert_C_to_F.c

@ -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;
}

7
src/convert_C_to_F.h

@ -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

7
src/convert_M_in_KM.c

@ -0,0 +1,7 @@
#include "convert_M_in_KM.h"
#include <stdio.h>
//convert length
double meter_to_kilometer(double meter) {
return meter / 1000.0;
}

7
src/convert_M_in_KM.h

@ -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

6
src/convert_kg_to_ton.c

@ -0,0 +1,6 @@
#include "convert_kg_to_ton.h"
double kg_to_tons(double kilograms) {
return kilograms / 1000.0; // 1 ton = 1000 kilograms
}

13
src/convert_kg_to_ton.h

@ -0,0 +1,13 @@
#ifndef THEADMIRALS_CONVERT_KG_TO_TON_H
#define THEADMIRALS_CONVERT_KG_TO_TON_H
double kg_to_tons(double kilograms);
#endif //THEADMIRALS_CONVERT_KG_TO_TON_H

11
src/convert_kph_to_mps.c

@ -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;
}

7
src/convert_kph_to_mps.h

@ -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

23
src/convert_m_to_ft.c

@ -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; // Centimeters to inches
} else {
printf("Invalid units or conversion not supported.\n");
result = -1; // Error code
}
return result;
}

8
src/convert_m_to_ft.h

@ -0,0 +1,8 @@
#ifndef THEADMIRALS_CONVERT_M_TO_FT_H
#define THEADMIRALS_CONVERT_M_TO_FT_H
float convert_length(float value, char from_unit, char to_unit);
#endif //THEADMIRALS_CONVERT_M_TO_FT_H

47
src/convert_time.c

@ -0,0 +1,47 @@
#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 time = hour * 60;
return time;
}
// Converts Minutes To Hours
double converter_min_to_hour(double min){
double time = min / 60;
return time;
}
// Converts Hours in Seconds
double converter_hour_in_sec(double hour){
double time = hour * 60 * 60;
return time;
}
// Converts Seconds in Hours
double converter_sec_in_hour(double sec){
double time = sec / 60 / 60;
return time;
}
double converter_days_to_years(double days){
double time = days / 365;
return time;
}
double converter_years_to_days(double years){
double amount = years * 365;
return amount;
}

13
src/convert_time.h

@ -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

7
src/convert_ton_to_kg.c

@ -0,0 +1,7 @@
#include "convert_ton_to_kg.h"
double tons_to_kg(double tons) {
return tons * 1000.0; // 1 ton = 1000 kilograms
}

11
src/convert_ton_to_kg.h

@ -0,0 +1,11 @@
#ifndef THEADMIRALS_CONVERT_TON_TO_KG_H
#define THEADMIRALS_CONVERT_TON_TO_KG_H
double tons_to_kg(double tons);
#endif //THEADMIRALS_CONVERT_TON_TO_KG_H

9
src/exponentials.c

@ -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;
}

6
src/exponentials.h

@ -0,0 +1,6 @@
#ifndef THEADMIRALS_EXPONENTIALS_H
#define THEADMIRALS_EXPONENTIALS_H
double* exponentials_double(int, int);
#endif //THEADMIRALS_EXPONENTIALS_H

18
src/logarithmicFunctions.c

@ -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;
}

6
src/logarithmicFunctions.h

@ -0,0 +1,6 @@
#ifndef THEADMIRALS_LOGARITHMICFUNCTIONS_H
#define THEADMIRALS_LOGARITHMICFUNCTIONS_H
double* logarithm_two_integer(int base, int num);
#endif //THEADMIRALS_LOGARITHMICFUNCTIONS_H

26
src/main.c

@ -1,4 +1,30 @@
#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");
int input;
scanf("%d", &input);
if(!checkOperationInput(input)) {
printf("Invalid operation id\n");
return 0;
}
printf("\nPlease enter the first and the second number separated by a space...\n");
while(fgets(buffer, 100, stdin)) {
buffer[strcspn(buffer, "\n")] = '\0';
if (strlen(buffer) > 0) {
break;
}
}
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);
} }

97
src/operationHandler.c

@ -0,0 +1,97 @@
#include "operationHandler.h"
#include <stdbool.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.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;
}

13
src/operationHandler.h

@ -0,0 +1,13 @@
#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*);
#endif //THEADMIRALS_OPERATIONHANDLER_H

25
src/trigonometricFunctions.c

@ -0,0 +1,25 @@
#include "trigonometricFunctions.h"
#include "math.h"
#include <stdio.h>
#include <stdlib.h>
double* calculate_sin_double(double angle) {
double* result= malloc(sizeof (double));
*result=sin(angle);
return result;
}
double* calculate_cos_double(double angle) {
double* result= malloc(sizeof (double));
*result=cos(angle);
return result;
}
double* calculate_tan_double(double angle) {
double* result= malloc(sizeof (double));
*result=tan(angle);
return result;
}

9
src/trigonometricFunctions.h

@ -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
team.md

@ -1,3 +1,4 @@
- Eric Bagus, fdai7812 - Eric Bagus, fdai7812
- Leon Wolf, fdai7845 - Leon Wolf, fdai7845
- Sandro Welte, fdai7728 - Sandro Welte, fdai7728
- Jonas Zitzmann, fdai7791

24
test/test_arithmeticAddition.c

@ -0,0 +1,24 @@
#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);
}

19
test/test_arithmeticDivision.c

@ -0,0 +1,19 @@
#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);
}

21
test/test_arithmeticMultiplication_Int.c

@ -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);
}

31
test/test_arithmeticSubtraction.c

@ -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);
}

28
test/test_convert_m_to_ft.c

@ -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);
}

18
test/test_exponentials.c

@ -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);
}

18
test/test_logarithmicFunctions.c

@ -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);
}

49
test/test_operationHandler.c

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