From 670f4c019df37c698c4c96413e446080a71a67f1 Mon Sep 17 00:00:00 2001 From: Enrico Schellenberger Date: Tue, 6 Feb 2024 12:34:45 +0100 Subject: [PATCH] added logic to ConSpeed and Unittest for the function --- src/main/c/ConvertMode.c | 17 +++++++++++--- src/main/c/main_taschenrechner.c | 38 ++++++++++++++++++++++++++++++++ src/main/c/taschenrechner.h | 2 ++ src/test/c/test_taschenrechner.c | 5 +++++ 4 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/main/c/ConvertMode.c b/src/main/c/ConvertMode.c index 351a973..5a79e46 100644 --- a/src/main/c/ConvertMode.c +++ b/src/main/c/ConvertMode.c @@ -13,7 +13,8 @@ double value, result; char Distance[] = { 'mm', 'cm', 'm', 'km', 'feet/inch', 'miles'}; char Weight[] = { 'mg', 'g', 'kg', 't', 'pounds'}; char Fluid[] = { 'ml', 'l' }; -char Temp[] = {'celsius', 'fahrenheit'} +char Temp[] = { 'celsius', 'fahrenheit' }; +char Speed[] = { 'km/h','mp/h' }; char Data[] = { 'B', 'KB', 'MB', 'GB', 'TB', 'PT' }; char Time[] = { 'ms', 's', 'min', 'h', 'd', 'w', 'mon', 'y' }; char currency[] = { 'E', 'D', 'R' }; @@ -114,6 +115,18 @@ double getValue(int choice) { printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]); break; + + case 6://'km/h','mp/h' + printf("\nEnter what the Unit is starting with (0 km/h, 1 mp/h): "); + scanf("%d", &startingUnit); + + printf("\nEnter what the value should it be changed to (0 km/h, 1 mp/h): "); + scanf("%d", &endingUnit); + + result = ConSpeed(value, startingUnit, endingUnit); + + printf("\nThe convertet result is %dlf %d", result, Distance[endingUnit]); + break; } } @@ -121,9 +134,7 @@ double getValue(int choice) { -double ConSpeed() { -} double ConLiter() { diff --git a/src/main/c/main_taschenrechner.c b/src/main/c/main_taschenrechner.c index 1a3c5f2..cd9d0fe 100644 --- a/src/main/c/main_taschenrechner.c +++ b/src/main/c/main_taschenrechner.c @@ -441,6 +441,44 @@ double ConTemp(double temp, int startingUnit, int endingUnit) { } } +double ConSpeed(double speed, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //kmh to x + switch (endingUnit) + { + case 0: //kmh to kmh + return distance; + break; + + case 1: //kmh to mph + return distance * 0.621371; + break; + + default: + break; + } + + case 1: //mph to x + switch (endingUnit) + { + case 0: //mph to kmh + return distance * 1.60934; + break; + + case 1: //mph to mph + return distance; + break; + + default: + break; + } + + default: + break; + } +} + //.. // graphMode void graphMode() { diff --git a/src/main/c/taschenrechner.h b/src/main/c/taschenrechner.h index 69dd7ed..94164ab 100644 --- a/src/main/c/taschenrechner.h +++ b/src/main/c/taschenrechner.h @@ -69,4 +69,6 @@ double ConGramToPounds(double weight, int startingUnit, int endingUnit); double ConTemp(double temp, int startingUnit, int endingUnit); +double ConSpeed(double speed, int startingUnit, int endingUnit); + #endif // TASCHENRECHNER_H diff --git a/src/test/c/test_taschenrechner.c b/src/test/c/test_taschenrechner.c index 5e16459..17fcd4e 100644 --- a/src/test/c/test_taschenrechner.c +++ b/src/test/c/test_taschenrechner.c @@ -68,5 +68,10 @@ void test_ConTemp(void) {//5 celsius to fahrenheit TEST_ASSERT_EQUAL(41, result); } +void test_ConSpeed(void) {//5 kmh to mph + double result = ConTemp(5, 0, 1); + TEST_ASSERT_EQUAL(3.10686, result); +} + #endif // TEST