Browse Source

added logic to ConArea and Unittest for the function

remotes/origin/feature
Enrico Schellenberger 11 months ago
parent
commit
63d2a57f93
  1. 20
      src/main/c/ConvertMode.c
  2. 100
      src/main/c/main_taschenrechner.c
  3. 2
      src/main/c/taschenrechner.h
  4. 5
      src/test/c/test_taschenrechner.c

20
src/main/c/ConvertMode.c

@ -164,6 +164,18 @@ double getValue(int choice) {
printf("\nThe convertet result is %dlf %d", result, Data[endingUnit]); printf("\nThe convertet result is %dlf %d", result, Data[endingUnit]);
break; break;
case 11://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;
} }
} }
} }
@ -208,14 +220,6 @@ double ConSpeed(double speed, int startingUnit, int endingUnit) {
*/ */
double ConArea() {
}
double ConVolume() { double ConVolume() {
} }

100
src/main/c/main_taschenrechner.c

@ -189,6 +189,106 @@ double ConMeter(double meter, int startingUnit, int endingUnit) {
} }
} }
double ConArea(double area, int startingUnit, int endingUnit) {
switch (startingUnit)
{
case 0: //mm to x
switch (endingUnit)
{
case 0: //1mm
return area;
break;
case 1: //0.01cm
return area / 100;
break;
case 2: //0.000001m
return area / 1000000;
break;
case 3: //0.000000000001km
return area / 1000000000000;
break;
default:
break;
}
case 1: //cm to x
switch (endingUnit)
{
case 0: //100
return area * 100;
break;
case 1: //1
return area;
break;
case 2: //0.0001
return area / 10000;
break;
case 3: //0.0000000001
return area / 10000000000;
break;
default:
break;
}
case 2: //m to x
switch (endingUnit)
{
case 0: //1000000
return area * 1000000;
break;
case 1: //10000
return area * 10000;
break;
case 2: //1
return area;
break;
case 3: //0.000001
return area / 1000000;
break;
default:
break;
}
case 3:// km to x
switch (endingUnit)
{
case 0: // 1000000000000
return area * 1000000000000;
break;
case 1: // 10000000000
return area * 10000000000;
break;
case 2: // 1000000 m
return area * 1000000;
break;
case 3: //1 km
return area;
break;
default:
break;
}
default:
break;
}
}
double ConMeterToFoot(double distance, int startingUnit, int endingUnit) { double ConMeterToFoot(double distance, int startingUnit, int endingUnit) {
switch (startingUnit) switch (startingUnit)
{ {

2
src/main/c/taschenrechner.h

@ -77,4 +77,6 @@ double ConLiterToGallon(double fluid, int startingUnit, int endingUnit);
double ConData(double data, int startingUnit, int endingUnit); double ConData(double data, int startingUnit, int endingUnit);
double ConArea(double area, int startingUnit, int endingUnit);
#endif // TASCHENRECHNER_H #endif // TASCHENRECHNER_H

5
src/test/c/test_taschenrechner.c

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