Browse Source

Merge branch 'develop' into 'main'

develop in main

See merge request fdai7812/theadmirals!3
main
fdai7812 11 months ago
parent
commit
77959826cc
  1. 4
      src/arithmeticAddition.c
  2. 6
      src/arithmeticSubtraction.c
  3. 2
      src/convert_M_in_KM.c
  4. 12
      src/convert_kg_to_ton.h
  5. 20
      src/convert_time.c
  6. 8
      src/trigonometricFunctions.c
  7. 23
      test/test_arithmeticAddition.c
  8. 21
      test/test_arithmeticDivision.c
  9. 39
      test/test_inputHandler.c

4
src/arithmeticAddition.c

@ -3,6 +3,7 @@
#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;
@ -12,18 +13,21 @@ int* addition_integer(int num1, int 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;

6
src/arithmeticSubtraction.c

@ -2,21 +2,21 @@
#include <stdlib.h>
// arithmetic subtraction integer
// arithmetic subtraction for integer
int* subtraction_integer(int a, int b) {
int* result= malloc(sizeof (int));
*result=a - b;
return result;
}
// arithmetic subtraction float
// arithmetic subtraction for float
float* subtraction_float(float a, float b) {
float* result= malloc(sizeof (float));
*result=a - b;
return result;
}
// arithmetic subtraction double
// arithmetic subtraction for double
double* subtraction_double(double a, double b) {
double* result= malloc(sizeof (double));
*result=a - b;

2
src/convert_M_in_KM.c

@ -1,6 +1,6 @@
#include "convert_M_in_KM.h"
// convert length for double metre into kilometre
//convert length for double metre into kilometre
double meter_to_kilometer(double meter) {
return meter / 1000.0;
}

12
src/convert_kg_to_ton.h

@ -1,19 +1,7 @@
#ifndef THEADMIRALS_CONVERT_KG_TO_TON_H
#define THEADMIRALS_CONVERT_KG_TO_TON_H
// Convert kilograms to tons
// Parameters:
// kilograms: weight in kilograms
// Returns:
// The equivalent weight in tons
double kg_to_tons(double kilograms);
#endif //THEADMIRALS_CONVERT_KG_TO_TON_H

20
src/convert_time.c

@ -14,32 +14,32 @@ double converter_min_to_sec(double min){
// Converts Hours to Minutes
double converter_hour_to_min(double hour){
double time = hour * 60;
return time;
double min = hour * 60;
return min;
}
// Converts Minutes To Hours
double converter_min_to_hour(double min){
double time = min / 60;
return time;
double hours = min / 60;
return hours;
}
// Converts Hours in Seconds
double converter_hour_in_sec(double hour){
double time = hour * 60 * 60;
return time;
double secs = hour * 60 * 60;
return secs;
}
// Converts Seconds in Hours
double converter_sec_in_hour(double sec){
double time = sec / 60 / 60;
return time;
double hours = sec / 60 / 60;
return hours;
}
// Converts Days in Years
double converter_days_to_years(double days){
double time = days / 365;
return time;
double years = days / 365;
return years;
}
// convert Years in days

8
src/trigonometricFunctions.c

@ -4,21 +4,19 @@
#include <stdio.h>
#include <stdlib.h>
//function for trigonometric
//Function 1 double
//Function 1 for double
double* calculate_sin_double(double angle) {
double* result= malloc(sizeof (double));
*result=sin(angle);
return result;
}
//Function 2 double
//Function 2 for double
double* calculate_cos_double(double angle) {
double* result= malloc(sizeof (double));
*result=cos(angle);
return result;
}
//Function 3 double
//Function 3 for double
double* calculate_tan_double(double angle) {
double* result= malloc(sizeof (double));
*result=tan(angle);

23
test/test_arithmeticAddition.c

@ -21,4 +21,25 @@ 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);
}

21
test/test_arithmeticDivision.c

@ -17,3 +17,24 @@ void test_arithmeticDivision_numberdividedbynumberequalsnumber(void) {
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);
}

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