Browse Source

Merge branch 'main' into 'feature'

main to feature

See merge request fdai7812/theadmirals!7
remotes/origin/feature
fdai7812 11 months ago
parent
commit
98bc177329
  1. 35
      src/arithmeticAddition.c
  2. 12
      src/arithmeticAddition.h
  3. 48
      src/arithmeticDivision.c
  4. 12
      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. 13
      src/arithmeticMultiplication_Int.c
  10. 8
      src/arithmeticMultiplication_Int.h
  11. 24
      src/arithmeticSubtraction.c
  12. 9
      src/arithmeticSubtraction.h
  13. 23
      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. 6
      src/convert_M_in_KM.c
  20. 7
      src/convert_M_in_KM.h
  21. 7
      src/convert_cm_in_dm.c
  22. 7
      src/convert_cm_in_dm.h
  23. 6
      src/convert_g_to_mg.c
  24. 17
      src/convert_g_to_mg.h
  25. 6
      src/convert_kg_to_g.c
  26. 18
      src/convert_kg_to_g.h
  27. 6
      src/convert_kg_to_ton.c
  28. 7
      src/convert_kg_to_ton.h
  29. 11
      src/convert_kph_to_mps.c
  30. 7
      src/convert_kph_to_mps.h
  31. 23
      src/convert_m_to_ft.c
  32. 15
      src/convert_m_to_ft.h
  33. 49
      src/convert_time.c
  34. 13
      src/convert_time.h
  35. 7
      src/convert_ton_to_kg.c
  36. 17
      src/convert_ton_to_kg.h
  37. 7
      src/convert_ton_to_mt.c
  38. 13
      src/convert_ton_to_mt.h
  39. 9
      src/exponentials.c
  40. 6
      src/exponentials.h
  41. 58
      src/inputHandler.c
  42. 12
      src/inputHandler.h
  43. 18
      src/logarithmicFunctions.c
  44. 6
      src/logarithmicFunctions.h
  45. 34
      src/main.c
  46. 122
      src/operationHandler.c
  47. 23
      src/operationHandler.h
  48. 24
      src/trigonometricFunctions.c
  49. 9
      src/trigonometricFunctions.h
  50. 4
      team.md
  51. 45
      test/test_arithmeticAddition.c
  52. 40
      test/test_arithmeticDivision.c
  53. 21
      test/test_arithmeticMultiplication_Int.c
  54. 31
      test/test_arithmeticSubtraction.c
  55. 25
      test/test_convert_kph_to_mps.c
  56. 28
      test/test_convert_m_to_ft.c
  57. 67
      test/test_convert_time.c
  58. 18
      test/test_exponentials.c
  59. 39
      test/test_inputHandler.c
  60. 18
      test/test_logarithmicFunctions.c
  61. 56
      test/test_operationHandler.c

35
src/arithmeticAddition.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;
}

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

48
src/arithmeticDivision.c

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

12
src/arithmeticDivision.h

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

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

13
src/arithmeticMultiplication_Int.c

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

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

24
src/arithmeticSubtraction.c

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

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

23
src/calculateFactorial.c

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

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 for float cm into meter
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

6
src/convert_M_in_KM.c

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

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

7
src/convert_cm_in_dm.c

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

7
src/convert_cm_in_dm.h

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

6
src/convert_g_to_mg.c

@ -0,0 +1,6 @@
#include "convert_g_to_mg.h"
double g_to_mg(double grams) {
return grams * 1000.0;
}

17
src/convert_g_to_mg.h

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

6
src/convert_kg_to_g.c

@ -0,0 +1,6 @@
#include "convert_kg_to_g.h"
double kg_to_gram(double kilograms) {
return kilograms * 1000.0;
}

18
src/convert_kg_to_g.h

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

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

7
src/convert_kg_to_ton.h

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

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

15
src/convert_m_to_ft.h

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

49
src/convert_time.c

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

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

17
src/convert_ton_to_kg.h

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

7
src/convert_ton_to_mt.c

@ -0,0 +1,7 @@
#include "convert_ton_to_mt.h"
double tons_to_megatons(double tons) {
return tons / 1000000.0;
}

13
src/convert_ton_to_mt.h

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

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

58
src/inputHandler.c

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

12
src/inputHandler.h

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

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

34
src/main.c

@ -1,4 +1,38 @@
#include <stdio.h>
#include <string.h>
#include "operationHandler.h"
char buffer[100];
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);
}

122
src/operationHandler.c

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

23
src/operationHandler.h

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

24
src/trigonometricFunctions.c

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

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

4
team.md

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

45
test/test_arithmeticAddition.c

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

40
test/test_arithmeticDivision.c

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

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

25
test/test_convert_kph_to_mps.c

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

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

67
test/test_convert_time.c

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

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

39
test/test_inputHandler.c

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

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

56
test/test_operationHandler.c

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