From 95af78172314795040e43467acc3f0af44b71cb7 Mon Sep 17 00:00:00 2001 From: Enrico Schellenberger Date: Tue, 6 Feb 2024 14:57:41 +0100 Subject: [PATCH] added logic to ConVolume and Unittest for the function and fixed wrong test results --- src/main/c/ConvertMode.c | 14 ++++- src/main/c/main_taschenrechner.c | 100 +++++++++++++++++++++++++++++++ src/main/c/taschenrechner.h | 2 + src/test/c/test_taschenrechner.c | 9 ++- 4 files changed, 122 insertions(+), 3 deletions(-) diff --git a/src/main/c/ConvertMode.c b/src/main/c/ConvertMode.c index 990c78c..080f0aa 100644 --- a/src/main/c/ConvertMode.c +++ b/src/main/c/ConvertMode.c @@ -176,6 +176,18 @@ double getValue(int choice) { printf("\nThe convertet result is %dlf %d²", result, Distance[endingUnit]); break; + + case 12://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; } } } @@ -220,9 +232,7 @@ double ConSpeed(double speed, int startingUnit, int endingUnit) { */ -double ConVolume() { -} double ConTime() { diff --git a/src/main/c/main_taschenrechner.c b/src/main/c/main_taschenrechner.c index fa4d493..e0b225b 100644 --- a/src/main/c/main_taschenrechner.c +++ b/src/main/c/main_taschenrechner.c @@ -849,6 +849,106 @@ double ConData(double data, int startingUnit, int endingUnit) { } } +double ConVolume(double volum, int startingUnit, int endingUnit) { + switch (startingUnit) + { + case 0: //mm to x + switch (endingUnit) + { + case 0: //1mm + return volum; + break; + + case 1: //0.001cm + return volum / 1000; + break; + + case 2: //0.000000001m + return volum / 1000000000; + break; + + case 3: //0.000000000000001km + return volum / 1000000000000000000; + break; + + default: + break; + } + + case 1: //cm to x + switch (endingUnit) + { + case 0: //1000 + return volum * 1000; + break; + + case 1: //1 + return volum; + break; + + case 2: //0.000001 + return volum / 1000000; + break; + + case 3: //0.0000000000001 + return volum / 1000000000000000; + break; + + default: + break; + } + + case 2: //m to x + switch (endingUnit) + { + case 0: //100000000 + return volum * 1000000000; + break; + + case 1: //1000000 + return volum * 1000000; + break; + + case 2: //1 + return volum; + break; + + case 3: //0.000000001 + return volum / 1000000000; + break; + + default: + break; + } + + case 3:// km to x + switch (endingUnit) + { + case 0: // 1000000000000000000 + return volum * 1000000000000000000; + break; + + case 1: // 1000000000000000 + return volum * 1000000000000000; + break; + + case 2: // 1000000000 m + return volum * 1000000000; + break; + + case 3: //1 km + return volum; + break; + + default: + break; + } + + default: + break; + } +} + //.. // graphMode diff --git a/src/main/c/taschenrechner.h b/src/main/c/taschenrechner.h index c24090b..c575997 100644 --- a/src/main/c/taschenrechner.h +++ b/src/main/c/taschenrechner.h @@ -79,4 +79,6 @@ double ConData(double data, int startingUnit, int endingUnit); double ConArea(double area, int startingUnit, int endingUnit); +double ConVolume(double volum, int startingUnit, int endingUnit); + #endif // TASCHENRECHNER_H diff --git a/src/test/c/test_taschenrechner.c b/src/test/c/test_taschenrechner.c index 6adeb59..283f097 100644 --- a/src/test/c/test_taschenrechner.c +++ b/src/test/c/test_taschenrechner.c @@ -90,8 +90,15 @@ void test_ConData(void) {//5 b to kb void test_ConArea(void) {//5 mm to cm double result = ConData(5, 0, 1); - TEST_ASSERT_EQUAL(0.0005), result); + TEST_ASSERT_EQUAL(0.05), result); } +void test_ConVolume(void) {//5 mm to cm + double result = ConData(5, 0, 1); + TEST_ASSERT_EQUAL(0.005), result); +} + + + #endif // TEST