Browse Source

added logic to ConLiterToGallon and Unittest for the function

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

17
src/main/c/ConvertMode.c

@ -139,6 +139,21 @@ double getValue(int choice) {
printf("\nThe convertet result is %dlf %d", result, Fluid[endingUnit]); printf("\nThe convertet result is %dlf %d", result, Fluid[endingUnit]);
break; break;
case 9://'ml', 'l'
printf("\nEnter what the Unit is starting with (0 l, 1 gallon): ");
scanf("%d", &startingUnit);
printf("\nEnter what the value should it be changed to (0 l, 1 gallon): ");
scanf("%d", &endingUnit);
result = ConLiterToGallon(value, startingUnit, endingUnit);
printf("\nThe convertet result is %dlf %d", result, Fluid[endingUnit]);
break;
} }
} }
} }
@ -184,9 +199,7 @@ double ConSpeed(double speed, int startingUnit, int endingUnit) {
double ConLiterToGallon() {
}
double ConData() { double ConData() {

38
src/main/c/main_taschenrechner.c

@ -517,6 +517,44 @@ double ConLiter(double liter, int startingUnit, int endingUnit) {
} }
} }
double ConLiterToGallon(double fluid, int startingUnit, int endingUnit) {
switch (startingUnit)
{
case 0: //l to x
switch (endingUnit)
{
case 0: //l to l
return fluid;
break;
case 1: //l to gallon
return fluid * 0.264172;
break;
default:
break;
}
case 1: //gallon to x
switch (endingUnit)
{
case 0: //gallon to l
return fluid * 3.78541;
break;
case 1: //gallon to gallon
return fluid;
break;
default:
break;
}
default:
break;
}
}
//.. //..
// graphMode // graphMode
void graphMode() { void graphMode() {

4
src/main/c/taschenrechner.h

@ -71,6 +71,8 @@ double ConTemp(double temp, int startingUnit, int endingUnit);
double ConSpeed(double speed, int startingUnit, int endingUnit); double ConSpeed(double speed, int startingUnit, int endingUnit);
double ConLiter(double liter, int startingUnit, int endingUnit)
double ConLiter(double liter, int startingUnit, int endingUnit);
double ConLiterToGallon(double fluid, int startingUnit, int endingUnit);
#endif // TASCHENRECHNER_H #endif // TASCHENRECHNER_H

4
src/test/c/test_taschenrechner.c

@ -78,6 +78,10 @@ void test_ConLiter(void) {//5 l to ml
TEST_ASSERT_EQUAL(5000, result); TEST_ASSERT_EQUAL(5000, result);
} }
void test_ConLiterToGallon(void) {//5 l to gallon
double result = ConTemp(5, 0, 1);
TEST_ASSERT_EQUAL(1.32086, result);
}
#endif // TEST #endif // TEST
Loading…
Cancel
Save