Browse Source

added logic to ConLiter and Unittest for the function

remotes/origin/feature
Enrico Schellenberger 11 months ago
parent
commit
273c6cc34e
  1. 52
      src/main/c/ConvertMode.c
  2. 38
      src/main/c/main_taschenrechner.c
  3. 2
      src/main/c/taschenrechner.h
  4. 6
      src/test/c/test_taschenrechner.c

52
src/main/c/ConvertMode.c

@ -12,7 +12,7 @@ double value, result;
char Distance[] = { 'mm', 'cm', 'm', 'km', 'feet/inch', 'miles'}; char Distance[] = { 'mm', 'cm', 'm', 'km', 'feet/inch', 'miles'};
char Weight[] = { 'mg', 'g', 'kg', 't', 'pounds'}; char Weight[] = { 'mg', 'g', 'kg', 't', 'pounds'};
char Fluid[] = { 'ml', 'l' };
char Fluid[] = { 'ml', 'l' , 'gallon'};
char Temp[] = { 'celsius', 'fahrenheit' }; char Temp[] = { 'celsius', 'fahrenheit' };
char Speed[] = { 'km/h','mp/h' }; char Speed[] = { 'km/h','mp/h' };
char Data[] = { 'B', 'KB', 'MB', 'GB', 'TB', 'PT' }; char Data[] = { 'B', 'KB', 'MB', 'GB', 'TB', 'PT' };
@ -128,14 +128,62 @@ double getValue(int choice) {
printf("\nThe convertet result is %dlf %d", result, Speed[endingUnit]); printf("\nThe convertet result is %dlf %d", result, Speed[endingUnit]);
break; break;
case 8://'ml', 'l'
printf("\nEnter what the Unit is starting with (0 ml, 1 l): ");
scanf("%d", &startingUnit);
printf("\nEnter what the value should it be changed to (0 ml, 1 l): ");
scanf("%d", &endingUnit);
result = ConLiter(value, startingUnit, endingUnit);
printf("\nThe convertet result is %dlf %d", result, Fluid[endingUnit]);
break;
} }
} }
} }
/*
double ConSpeed(double speed, int startingUnit, int endingUnit) {
switch (startingUnit)
{
case 0: //kmh to x
switch (endingUnit)
{
case 0: //kmh to kmh
return speed;
break;
double ConLiter() {
case 1: //kmh to mph
return speed * 0.621371;
break;
default:
break;
} }
case 1: //mph to x
switch (endingUnit)
{
case 0: //mph to kmh
return speed * 1.60934;
break;
case 1: //mph to mph
return speed;
break;
default:
break;
}
default:
break;
}
}
*/
double ConLiterToGallon() { double ConLiterToGallon() {
} }

38
src/main/c/main_taschenrechner.c

@ -479,6 +479,44 @@ double ConSpeed(double speed, int startingUnit, int endingUnit) {
} }
} }
double ConLiter(double liter, int startingUnit, int endingUnit) {
switch (startingUnit)
{
case 0: //ml to x
switch (endingUnit)
{
case 0: //ml to ml
return liter;
break;
case 1: //ml to l
return liter / 1000;
break;
default:
break;
}
case 1: //l to x
switch (endingUnit)
{
case 0: //l to ml
return liter * 1000;
break;
case 1: //l to l
return liter;
break;
default:
break;
}
default:
break;
}
}
//.. //..
// graphMode // graphMode
void graphMode() { void graphMode() {

2
src/main/c/taschenrechner.h

@ -71,4 +71,6 @@ 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)
#endif // TASCHENRECHNER_H #endif // TASCHENRECHNER_H

6
src/test/c/test_taschenrechner.c

@ -73,5 +73,11 @@ void test_ConSpeed(void) {//5 kmh to mph
TEST_ASSERT_EQUAL(3.10686, result); TEST_ASSERT_EQUAL(3.10686, result);
} }
void test_ConLiter(void) {//5 l to ml
double result = ConTemp(5, 1, 0);
TEST_ASSERT_EQUAL(5000, result);
}
#endif // TEST #endif // TEST
Loading…
Cancel
Save