Browse Source

added logic to ConVolume and Unittest for the function and fixed wrong test results

remotes/origin/feature
Enrico Schellenberger 11 months ago
parent
commit
95af781723
  1. 14
      src/main/c/ConvertMode.c
  2. 100
      src/main/c/main_taschenrechner.c
  3. 2
      src/main/c/taschenrechner.h
  4. 9
      src/test/c/test_taschenrechner.c

14
src/main/c/ConvertMode.c

@ -176,6 +176,18 @@ double getValue(int choice) {
printf("\nThe convertet result is %dlf %d²", result, Distance[endingUnit]); printf("\nThe convertet result is %dlf %d²", result, Distance[endingUnit]);
break; break;
case 12://char Distance[] = { 'mm', 'cm', 'm', 'km', 'feet/inch', 'miles'};
printf("\nEnter what the Unit is starting with (0 mm, 1 cm, 2 m , 3 km,): ");
scanf("%d", &startingUnit);
printf("\nEnter what the value should it be changed to (0 mm, 1 cm, 2 m , 3 km,): ");
scanf("%d", &endingUnit);
result = ConArea(value, startingUnit, endingUnit);
printf("\nThe convertet result is %dlf %d³", result, Distance[endingUnit]);
break;
} }
} }
} }
@ -220,9 +232,7 @@ double ConSpeed(double speed, int startingUnit, int endingUnit) {
*/ */
double ConVolume() {
}
double ConTime() { double ConTime() {

100
src/main/c/main_taschenrechner.c

@ -849,6 +849,106 @@ double ConData(double data, int startingUnit, int endingUnit) {
} }
} }
double ConVolume(double volum, int startingUnit, int endingUnit) {
switch (startingUnit)
{
case 0: //mm to x
switch (endingUnit)
{
case 0: //1mm
return volum;
break;
case 1: //0.001cm
return volum / 1000;
break;
case 2: //0.000000001m
return volum / 1000000000;
break;
case 3: //0.000000000000001km
return volum / 1000000000000000000;
break;
default:
break;
}
case 1: //cm to x
switch (endingUnit)
{
case 0: //1000
return volum * 1000;
break;
case 1: //1
return volum;
break;
case 2: //0.000001
return volum / 1000000;
break;
case 3: //0.0000000000001
return volum / 1000000000000000;
break;
default:
break;
}
case 2: //m to x
switch (endingUnit)
{
case 0: //100000000
return volum * 1000000000;
break;
case 1: //1000000
return volum * 1000000;
break;
case 2: //1
return volum;
break;
case 3: //0.000000001
return volum / 1000000000;
break;
default:
break;
}
case 3:// km to x
switch (endingUnit)
{
case 0: // 1000000000000000000
return volum * 1000000000000000000;
break;
case 1: // 1000000000000000
return volum * 1000000000000000;
break;
case 2: // 1000000000 m
return volum * 1000000000;
break;
case 3: //1 km
return volum;
break;
default:
break;
}
default:
break;
}
}
//.. //..
// graphMode // graphMode

2
src/main/c/taschenrechner.h

@ -79,4 +79,6 @@ double ConData(double data, int startingUnit, int endingUnit);
double ConArea(double area, int startingUnit, int endingUnit); double ConArea(double area, int startingUnit, int endingUnit);
double ConVolume(double volum, int startingUnit, int endingUnit);
#endif // TASCHENRECHNER_H #endif // TASCHENRECHNER_H

9
src/test/c/test_taschenrechner.c

@ -90,8 +90,15 @@ void test_ConData(void) {//5 b to kb
void test_ConArea(void) {//5 mm to cm void test_ConArea(void) {//5 mm to cm
double result = ConData(5, 0, 1); double result = ConData(5, 0, 1);
TEST_ASSERT_EQUAL(0.0005), result);
TEST_ASSERT_EQUAL(0.05), result);
} }
void test_ConVolume(void) {//5 mm to cm
double result = ConData(5, 0, 1);
TEST_ASSERT_EQUAL(0.005), result);
}
#endif // TEST #endif // TEST
Loading…
Cancel
Save