Browse Source

added logic to ConData and Unittest for the function

remotes/origin/feature
Enrico Schellenberger 11 months ago
parent
commit
4abedaa525
  1. 13
      src/main/c/ConvertMode.c
  2. 195
      src/main/c/main_taschenrechner.c
  3. 2
      src/main/c/taschenrechner.h
  4. 5
      src/test/c/test_taschenrechner.c

13
src/main/c/ConvertMode.c

@ -153,7 +153,17 @@ 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 10://char Data[] = { 'B', 'KB', 'MB', 'GB', 'TB', 'PT' };
printf("\nEnter what the Unit is starting with (0 B, 1 KB, 2 MB , 3 GB, 4 TB, 5 PT): ");
scanf("%d", &startingUnit);
printf("\nEnter what the value should it be changed to (0 B, 1 KB, 2 MB , 3 GB, 4 TB, 5 PT): ");
scanf("%d", &endingUnit);
result = ConData(value, startingUnit, endingUnit);
printf("\nThe convertet result is %dlf %d", result, Data[endingUnit]);
break;
} }
} }
} }
@ -201,9 +211,6 @@ double ConSpeed(double speed, int startingUnit, int endingUnit) {
double ConData() {
}
double ConArea() { double ConArea() {

195
src/main/c/main_taschenrechner.c

@ -555,6 +555,201 @@ double ConLiterToGallon(double fluid, int startingUnit, int endingUnit) {
} }
} }
double ConData(double data, int startingUnit, int endingUnit) {
switch (startingUnit)
{//'B', 'KB', 'MB', 'GB', 'TB', 'PT'
case 0: //B to x
switch (endingUnit)
{
case 0: //1
return data;
break;
case 1: //0.001
return data / 1000;
break;
case 2: //0.000001
return data / 1000000;
break;
case 3: //0.000000001
return data / 1000000000;
break;
case 4: //0.000000000001
return data / 1000000000000;
break;
case 5: //0.000000000000001
return data / 1000000000000000;
break;
default:
break;
}
case 1: //KB to x
switch (endingUnit)
{
case 0: //1000
return data * 1000;
break;
case 1: //1
return data;
break;
case 2: //0.001
return data / 1000;
break;
case 3: //0.000001
return data / 1000000;
break;
case 4: //0.000000001
return data / 1000000000;
break;
case 5: //0.000000000001
return data / 1000000000000;
break;
default:
break;
}
case 2: //MB to x
switch (endingUnit)
{
case 0: //0.000001
return data * 1000000;
break;
case 1: //0.001
return data * 1000;
break;
case 2: //1
return data;
break;
case 3: //0.001
return data / 1000;
break;
case 4: //0.000001
return data / 1000000;
break;
case 5: //0.000000001
return data / 1000000000;
break;
default:
break;
}
case 3: //GB to x
switch (endingUnit)
{
case 0: //0.000000001
return data * 1000000000;
break;
case 1: //0.000001
return data * 1000000;
break;
case 2: //1000
return data * 1000;;
break;
case 3: //1
return data;
break;
case 4: //0.001
return data / 1000;
break;
case 5: //0.000001
return data / 1000000;
break;
default:
break;
}
case 4: //TB to x
switch (endingUnit)
{
case 0: //0.000000000001
return data * 1000000000000;
break;
case 1: //0.000000001
return data * 1000000000;
break;
case 2: //1000000
return data * 1000000;;
break;
case 3: //1000
return data * 1000;
break;
case 4: //1
return;
break;
case 5: //0.001
return data / 1000;
break;
default:
break;
}
case 5: //PB to x
switch (endingUnit)
{
case 0: //0.000000000000001
return data * 1000000000000000;
break;
case 1: //0.000000000001
return data * 1000000000000;
break;
case 2: //1000000000
return data * 1000000000;;
break;
case 3: //1000000
return data * 1000000;
break;
case 4: //1000
return data * 1000;
break;
case 5: //1
return data;
break;
default:
break;
}
}
}
//.. //..
// graphMode // graphMode
void graphMode() { void graphMode() {

2
src/main/c/taschenrechner.h

@ -75,4 +75,6 @@ double ConLiter(double liter, int startingUnit, int endingUnit);
double ConLiterToGallon(double fluid, int startingUnit, int endingUnit); double ConLiterToGallon(double fluid, int startingUnit, int endingUnit);
double ConData(double data, int startingUnit, int endingUnit);
#endif // TASCHENRECHNER_H #endif // TASCHENRECHNER_H

5
src/test/c/test_taschenrechner.c

@ -83,5 +83,10 @@ void test_ConLiterToGallon(void) {//5 l to gallon
TEST_ASSERT_EQUAL(1.32086, result); TEST_ASSERT_EQUAL(1.32086, result);
} }
void test_ConData(void) {//5 b to kb
double result = ConData(5, 0, 1);
TEST_ASSERT_EQUAL(0.005, result);
}
#endif // TEST #endif // TEST
Loading…
Cancel
Save