From 163034d1962bd7eb8bc272872ea15f5faa11c0c7 Mon Sep 17 00:00:00 2001 From: Enrico Schellenberger Date: Tue, 6 Feb 2024 13:05:52 +0100 Subject: [PATCH] added logic to ConLiterToGallon and Unittest for the function --- src/main/c/ConvertMode.c | 17 ++++++++++++-- src/main/c/main_taschenrechner.c | 38 ++++++++++++++++++++++++++++++++ src/main/c/taschenrechner.h | 4 +++- src/test/c/test_taschenrechner.c | 4 ++++ 4 files changed, 60 insertions(+), 3 deletions(-) diff --git a/src/main/c/ConvertMode.c b/src/main/c/ConvertMode.c index a98dda8..1481d29 100644 --- a/src/main/c/ConvertMode.c +++ b/src/main/c/ConvertMode.c @@ -139,6 +139,21 @@ double getValue(int choice) { printf("\nThe convertet result is %dlf %d", result, Fluid[endingUnit]); break; + + + case 9://'ml', 'l' + printf("\nEnter what the Unit is starting with (0 l, 1 gallon): "); + scanf("%d", &startingUnit); + + printf("\nEnter what the value should it be changed to (0 l, 1 gallon): "); + scanf("%d", &endingUnit); + + result = ConLiterToGallon(value, startingUnit, endingUnit); + + printf("\nThe convertet result is %dlf %d", result, Fluid[endingUnit]); + break; + + } } } @@ -184,9 +199,7 @@ double ConSpeed(double speed, int startingUnit, int endingUnit) { -double ConLiterToGallon() { -} double ConData() { diff --git a/src/main/c/main_taschenrechner.c b/src/main/c/main_taschenrechner.c index bed82fa..1bdf9cd 100644 --- a/src/main/c/main_taschenrechner.c +++ b/src/main/c/main_taschenrechner.c @@ -517,6 +517,44 @@ double ConLiter(double liter, int startingUnit, int endingUnit) { } } +double ConLiterToGallon(double fluid, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //l to x + switch (endingUnit) + { + case 0: //l to l + return fluid; + break; + + case 1: //l to gallon + return fluid * 0.264172; + break; + + default: + break; + } + + case 1: //gallon to x + switch (endingUnit) + { + case 0: //gallon to l + return fluid * 3.78541; + break; + + case 1: //gallon to gallon + return fluid; + break; + + default: + break; + } + + default: + break; + } +} + //.. // graphMode void graphMode() { diff --git a/src/main/c/taschenrechner.h b/src/main/c/taschenrechner.h index f6ebca0..97846a5 100644 --- a/src/main/c/taschenrechner.h +++ b/src/main/c/taschenrechner.h @@ -71,6 +71,8 @@ double ConTemp(double temp, int startingUnit, int endingUnit); double ConSpeed(double speed, int startingUnit, int endingUnit); -double ConLiter(double liter, int startingUnit, int endingUnit) +double ConLiter(double liter, int startingUnit, int endingUnit); + +double ConLiterToGallon(double fluid, int startingUnit, int endingUnit); #endif // TASCHENRECHNER_H diff --git a/src/test/c/test_taschenrechner.c b/src/test/c/test_taschenrechner.c index 002e23c..c1008b2 100644 --- a/src/test/c/test_taschenrechner.c +++ b/src/test/c/test_taschenrechner.c @@ -78,6 +78,10 @@ void test_ConLiter(void) {//5 l to ml TEST_ASSERT_EQUAL(5000, result); } +void test_ConLiterToGallon(void) {//5 l to gallon + double result = ConTemp(5, 0, 1); + TEST_ASSERT_EQUAL(1.32086, result); +} #endif // TEST