Browse Source

added logic to ConSpeed and Unittest for the function

remotes/origin/feature
Enrico Schellenberger 11 months ago
parent
commit
670f4c019d
  1. 17
      src/main/c/ConvertMode.c
  2. 38
      src/main/c/main_taschenrechner.c
  3. 2
      src/main/c/taschenrechner.h
  4. 5
      src/test/c/test_taschenrechner.c

17
src/main/c/ConvertMode.c

@ -13,7 +13,8 @@ double value, result;
char Distance[] = { 'mm', 'cm', 'm', 'km', 'feet/inch', 'miles'};
char Weight[] = { 'mg', 'g', 'kg', 't', 'pounds'};
char Fluid[] = { 'ml', 'l' };
char Temp[] = {'celsius', 'fahrenheit'}
char Temp[] = { 'celsius', 'fahrenheit' };
char Speed[] = { 'km/h','mp/h' };
char Data[] = { 'B', 'KB', 'MB', 'GB', 'TB', 'PT' };
char Time[] = { 'ms', 's', 'min', 'h', 'd', 'w', 'mon', 'y' };
char currency[] = { 'E', 'D', 'R' };
@ -114,6 +115,18 @@ double getValue(int choice) {
printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]);
break;
case 6://'km/h','mp/h'
printf("\nEnter what the Unit is starting with (0 km/h, 1 mp/h): ");
scanf("%d", &startingUnit);
printf("\nEnter what the value should it be changed to (0 km/h, 1 mp/h): ");
scanf("%d", &endingUnit);
result = ConSpeed(value, startingUnit, endingUnit);
printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]);
break;
}
}
@ -121,9 +134,7 @@ double getValue(int choice) {
double ConSpeed() {
}
double ConLiter() {

38
src/main/c/main_taschenrechner.c

@ -441,6 +441,44 @@ double ConTemp(double temp, int startingUnit, int endingUnit) {
}
}
double ConSpeed(double speed, int startingUnit, int endingUnit) {
switch (startingUnit)
{
case 0: //kmh to x
switch (endingUnit)
{
case 0: //kmh to kmh
return distance;
break;
case 1: //kmh to mph
return distance * 0.621371;
break;
default:
break;
}
case 1: //mph to x
switch (endingUnit)
{
case 0: //mph to kmh
return distance * 1.60934;
break;
case 1: //mph to mph
return distance;
break;
default:
break;
}
default:
break;
}
}
//..
// graphMode
void graphMode() {

2
src/main/c/taschenrechner.h

@ -69,4 +69,6 @@ double ConGramToPounds(double weight, int startingUnit, int endingUnit);
double ConTemp(double temp, int startingUnit, int endingUnit);
double ConSpeed(double speed, int startingUnit, int endingUnit);
#endif // TASCHENRECHNER_H

5
src/test/c/test_taschenrechner.c

@ -68,5 +68,10 @@ void test_ConTemp(void) {//5 celsius to fahrenheit
TEST_ASSERT_EQUAL(41, result);
}
void test_ConSpeed(void) {//5 kmh to mph
double result = ConTemp(5, 0, 1);
TEST_ASSERT_EQUAL(3.10686, result);
}
#endif // TEST
Loading…
Cancel
Save