Browse Source

added logic to ConClock and Unittest for the function

remotes/origin/feature
Enrico Schellenberger 11 months ago
parent
commit
8e83e65b2c
  1. 56
      src/main/c/ConvertMode.c
  2. 319
      src/main/c/main_taschenrechner.c
  3. 3
      src/main/c/taschenrechner.h
  4. 7
      src/test/c/test_taschenrechner.c

56
src/main/c/ConvertMode.c

@ -189,67 +189,33 @@ double getValue(int choice) {
printf("\nThe convertet result is %dlf %d³", result, Distance[endingUnit]);
break;
case 13:
printf("\nEnter what the Unit is starting with (0 (24h), 1 (12h)): ");
case 13://char Time[] = { 'ms', 's', 'min', 'h', 'd', 'w', 'mon', 'y' };
printf("\nEnter what the Unit is starting with (0 ms, 1 s, 2 min, 3 h, 4 d, 5 w, 6 mon, 7 y): ");
scanf("%d", &startingUnit);
printf("\nEnter what the value should it be changed to (0 (24h), 1 (12h)): ");
printf("\nEnter what the value should it be changed to (0 ms, 1 s, 2 min, 3 h, 4 d, 5 w, 6 mon, 7 y): ");
scanf("%d", &endingUnit);
result = ConArea(value, startingUnit, endingUnit);
result = ConTime(value, startingUnit, endingUnit);
printf("\nThe convertet result is %dlf %d", result, Distance[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;
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 14:
printf("\nEnter what the Unit is starting with (0 (24h), 1 (12h)): ");
scanf("%d", &startingUnit);
case 1: //mph to mph
return speed;
break;
printf("\nEnter what the value should it be changed to (0 (24h), 1 (12h)): ");
scanf("%d", &endingUnit);
default:
break;
}
result = ConClock(value, startingUnit, endingUnit);
default:
printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]);
break;
}
}
*/
double ConClock() {
}
void unitConverterMode() {
printf("Unit Converter Mode:\n");

319
src/main/c/main_taschenrechner.c

@ -948,7 +948,7 @@ double ConVolume(double volum, int startingUnit, int endingUnit) {
break;
}
}
double ConTime(double time, int startingUnit, int endingUnit) {
double ConClock(double time, int startingUnit, int endingUnit) {
switch (startingUnit)
{
case 0: //24 to x
@ -992,6 +992,323 @@ double ConTime(double time, int startingUnit, int endingUnit) {
}
}
double ConTime(double time, int startingUnit, int endingUnit) {
switch (startingUnit)
{//'ms', 's', 'min', 'h', 'd', 'w', 'mon', 'y'
case 0: //ms to x
switch (endingUnit)
{
case 0: //ms
return time;
break;
case 1: //s
return time / 1000;
break;
case 2: //min
return time / (1000 * 60);
break;
case 3: //h
return time / (1000 * 60 * 60);
break;
case 4: //d
return time / (1000 * 60 * 60 * 24);
break;
case 5: //w
return time / (1000 * 60 * 60 * 24 * 7);
break;
case 6: //mon
return time / (1000 * 60 * 60 * 24 * 7 * 30);
break;
case 7: //y
return time / (1000 * 60 * 60 * 24 * 7 * 30 * 12);
break;
default:
break;
}
case 1: //s to x
switch (endingUnit)
{
case 0: //ms
return time * 1000;
break;
case 1: //s
return time;
break;
case 2: //min
return time / 60;
break;
case 3: //h
return time / (60 * 60);
break;
case 4: //d
return time / (60 * 60 * 24);
break;
case 5: //w
return time / (60 * 60 * 24 * 7);
break;
case 6: //mon
return time / (60 * 60 * 24 * 7 * 30);
break;
case 7: //y
return time / (60 * 60 * 24 * 7 * 30 * 12);
break;
default:
break;
}
case 2: //min to x
switch (endingUnit)
{
case 0: //ms
return time * 1000;
break;
case 1: //s
return time * 1000 * 60;
break;
case 2: //min
return time;
break;
case 3: //h
return time / 60;
break;
case 4: //d
return time / (60 * 24);
break;
case 5: //w
return time / (60 * 24 * 7);
break;
case 6: //mon
return time / (60 * 24 * 7 * 4);
break;
case 7: //y
return time / 60 * 24 * 7 * 4 * 12);
break;
default:
break;
}
case 3: //h to x
switch (endingUnit)
{
case 0: //ms
return time * 1000 * 60 * 60;
break;
case 1: //s
return time * 60 * 60;
break;
case 2: //min
return time * 60;
break;
case 3: //h
return time;
break;
case 4: //d
return time / 24;
break;
case 5: //w
return time / (24 * 7);
break;
case 6: //mon
return time / (24 * 7 * 4);
break;
case 7: //y
return time / (24 * 7 * 4 * 12);
break;
default:
break;
}
case 4: //d to x
switch (endingUnit)
{
case 0: //ms
return time * 1000 * 60 * 60 * 24;
break;
case 1: //s
return time * 60 * 60 * 24;
break;
case 2: //min
return time * 60 * 24;
break;
case 3: //h
return time * 24;
break;
case 4: //d
return time;
break;
case 5: //w
return time / 7;
break;
case 6: //mon
return time / (7 * 4);
break;
case 7: //y
return time / (7 * 4 * 12);
break;
default:
break;
}
case 5: //w to x
switch (endingUnit)
{
case 0: //ms
return time * 1000 * 60 * 60 * 24 * 7;
break;
case 1: //s
return time * 60 * 60 * 24 * 7;
break;
case 2: //min
return time * 60 * 24 * 7;
break;
case 3: //h
return time * 24 * 7;
break;
case 4: //d
return time * 7;
break;
case 5: //w
return time;
break;
case 6: //mon
return time / 4;
break;
case 7: //y
return time / (4 * 12);
break;
default:
break;
}
case 6: //mon to x
switch (endingUnit)
{
case 0: //ms
return time * 1000 * 60 * 60 * 24 * 7 * 4;
break;
case 1: //s
return time * 60 * 60 * 24 * 7 * 4;
break;
case 2: //min
return time * 60 * 24 * 7 * 4;
break;
case 3: //h
return time * 24 * 7 * 4;
break;
case 4: //d
return time * 7 * 4;
break;
case 5: //w
return time * 4;
break;
case 6: //mon
return time;
break;
case 7: //y
return time / 12;
break;
default:
break;
}
case 7: //y to x
switch (endingUnit)
{
case 0: //ms
return time * 1000 * 60 * 60 * 24 * 7 * 4 * 12;
break;
case 1: //s
return time * 60 * 60 * 24 * 7 * 4 * 12;
break;
case 2: //min
return time * 60 * 24 * 7 * 4 * 12;
break;
case 3: //h
return time * 24 * 7 * 4 * 12;
break;
case 4: //d
return time * 7 * 4 * 12;
break;
case 5: //w
return time * 4 * 12;
break;
case 6: //mon
return time * 12);
break;
case 7: //y
return time;
break;
//(1000 * 60 * 60 * 24 * 7 * 4 * 12)
default:
break;
}
}
}
//..
// graphMode

3
src/main/c/taschenrechner.h

@ -81,6 +81,9 @@ double ConArea(double area, int startingUnit, int endingUnit);
double ConVolume(double volum, int startingUnit, int endingUnit);
double ConClock(double time, int startingUnit, int endingUnit);
double ConTime(double time, int startingUnit, int endingUnit);
#endif // TASCHENRECHNER_H

7
src/test/c/test_taschenrechner.c

@ -98,11 +98,16 @@ void test_ConVolume(void) {//5 mm to cm
TEST_ASSERT_EQUAL(0.005), result);
}
void test_ConTime(void) {//5:00 to 5AM
void test_ConClock(void) {//5:00 to 5AM
double result = ConData(5, 0, 1);
TEST_ASSERT_EQUAL(5), result);
}
void test_ConTime(void) {//5 ms to s
double result = ConData(5, 0, 1);
TEST_ASSERT_EQUAL(0.005), result);
}
#endif // TEST
Loading…
Cancel
Save