From ad6c04ec8543958fe3504fb4967fe46641e076ae Mon Sep 17 00:00:00 2001 From: Kevin Ludwig Date: Wed, 7 Feb 2024 19:20:44 +0100 Subject: [PATCH 01/22] testbranch mit temperatur angelegt --- src/temperatur.c | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/temperatur.c diff --git a/src/temperatur.c b/src/temperatur.c new file mode 100644 index 0000000..2a43378 --- /dev/null +++ b/src/temperatur.c @@ -0,0 +1,8 @@ +#include + +int run_TemperaturRechner(){ + printf("\nTemperaturkonverter (Celsius, Fahrenheit, Kelvin)\nAchten Sie darauf, Kommazahlen mit einem Punkt anzugeben!\n\n"); + + + return 0; +} From 2b858f65490c0444be1f7b0fbe56c71ddcfa7849 Mon Sep 17 00:00:00 2001 From: Kevin Ludwig Date: Wed, 7 Feb 2024 19:32:22 +0100 Subject: [PATCH 02/22] celsius zu fahrenheit ein und ausgeben --- src/temperatur.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/temperatur.c b/src/temperatur.c index 2a43378..c5de411 100644 --- a/src/temperatur.c +++ b/src/temperatur.c @@ -1,8 +1,19 @@ #include int run_TemperaturRechner(){ + float var1; + int var3; + printf("\nTemperaturkonverter (Celsius, Fahrenheit, Kelvin)\nAchten Sie darauf, Kommazahlen mit einem Punkt anzugeben!\n\n"); + printf("Waehlen Sie: \n<1> Celsius zu Fahrenheit\n"); + scanf("%d", &var3); + + printf("\nGeben Sie die Temperatur ein: "); + scanf("%f", &var1); + + printf("\nErgebnis: %.2f\n", (var1 * 9/5) +32); + return 0; } From 35f27710a3a95253a74df823a212612780ff9dee Mon Sep 17 00:00:00 2001 From: Kevin Ludwig Date: Wed, 7 Feb 2024 19:38:49 +0100 Subject: [PATCH 03/22] =?UTF-8?q?Celsius=20zu=20Fahrenheit=20funktion=20f?= =?UTF-8?q?=C3=BCr=20berechnung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/temperatur.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/temperatur.c b/src/temperatur.c index c5de411..7a18e9e 100644 --- a/src/temperatur.c +++ b/src/temperatur.c @@ -1,5 +1,9 @@ #include +float CzuF(float tempC){ + return (tempC * 9/5) + 32; +} + int run_TemperaturRechner(){ float var1; int var3; @@ -12,8 +16,8 @@ int run_TemperaturRechner(){ printf("\nGeben Sie die Temperatur ein: "); scanf("%f", &var1); - printf("\nErgebnis: %.2f\n", (var1 * 9/5) +32); + printf("\nErgebnis: %.2f\n", CzuF(var1)); return 0; -} +} \ No newline at end of file From 9928f5be38145a8ce61e46d40f100935ee9ce5d4 Mon Sep 17 00:00:00 2001 From: Kevin Ludwig Date: Wed, 7 Feb 2024 19:50:20 +0100 Subject: [PATCH 04/22] Unittest: CzuF --- src/temperatur.c | 3 ++- src/temperatur.h | 6 ++++++ test/test_temperatur.c | 22 ++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/temperatur.h create mode 100644 test/test_temperatur.c diff --git a/src/temperatur.c b/src/temperatur.c index 7a18e9e..3568a8f 100644 --- a/src/temperatur.c +++ b/src/temperatur.c @@ -1,4 +1,5 @@ #include +#include "temperatur.h" float CzuF(float tempC){ return (tempC * 9/5) + 32; @@ -20,4 +21,4 @@ int run_TemperaturRechner(){ return 0; -} \ No newline at end of file +} diff --git a/src/temperatur.h b/src/temperatur.h new file mode 100644 index 0000000..30e1a0f --- /dev/null +++ b/src/temperatur.h @@ -0,0 +1,6 @@ +#ifndef TEMPERATUR_H +#define TEMPERATUR_H + +float CzuF(float tempC); + +#endif //TEMPERATUR_H diff --git a/test/test_temperatur.c b/test/test_temperatur.c new file mode 100644 index 0000000..e46691b --- /dev/null +++ b/test/test_temperatur.c @@ -0,0 +1,22 @@ +#ifdef TEST + +#include "unity.h" + +#include "temperatur.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_temperaturRechner_CzuF(void) +{ +float result = CzuF(25); +float expected = 77; +TEST_ASSERT_EQUAL(expected, result); +} + +#endif From f197feccf477de4a99317842bcef19666f7c5e44 Mon Sep 17 00:00:00 2001 From: Kevin Ludwig Date: Wed, 7 Feb 2024 20:47:58 +0100 Subject: [PATCH 05/22] =?UTF-8?q?Celsius=20zu=20Kelvin=20funktion=20f?= =?UTF-8?q?=C3=BCr=20berechnung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/temperatur.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/temperatur.c b/src/temperatur.c index 3568a8f..29c7db3 100644 --- a/src/temperatur.c +++ b/src/temperatur.c @@ -4,6 +4,9 @@ float CzuF(float tempC){ return (tempC * 9/5) + 32; } +float CzuK(float tempC){ + return tempC + 273.15; +} int run_TemperaturRechner(){ float var1; @@ -11,13 +14,16 @@ int run_TemperaturRechner(){ printf("\nTemperaturkonverter (Celsius, Fahrenheit, Kelvin)\nAchten Sie darauf, Kommazahlen mit einem Punkt anzugeben!\n\n"); - printf("Waehlen Sie: \n<1> Celsius zu Fahrenheit\n"); + printf("Waehlen Sie: \n<1> Celsius zu Fahrenheit\n<2> Celsius zu Kelvin\n"); scanf("%d", &var3); printf("\nGeben Sie die Temperatur ein: "); scanf("%f", &var1); - printf("\nErgebnis: %.2f\n", CzuF(var1)); + if(var3 == 1) + printf("\nErgebnis: %.2f\n", CzuF(var1)); + if(var3 == 2) + printf("\nErgebnis: %.2f\n", CzuK(var1)); return 0; From 73f35bacf6e95afcd1210ad8141b58ff4b53f207 Mon Sep 17 00:00:00 2001 From: Kevin Ludwig Date: Wed, 7 Feb 2024 20:50:17 +0100 Subject: [PATCH 06/22] Unittest: CzuK --- src/temperatur.h | 1 + test/test_temperatur.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/src/temperatur.h b/src/temperatur.h index 30e1a0f..9cb94b5 100644 --- a/src/temperatur.h +++ b/src/temperatur.h @@ -2,5 +2,6 @@ #define TEMPERATUR_H float CzuF(float tempC); +float CzuK(float tempC); #endif //TEMPERATUR_H diff --git a/test/test_temperatur.c b/test/test_temperatur.c index e46691b..584ce47 100644 --- a/test/test_temperatur.c +++ b/test/test_temperatur.c @@ -19,4 +19,11 @@ float expected = 77; TEST_ASSERT_EQUAL(expected, result); } +void test_temperaturRechner_CzuK(void) +{ +float result = CzuK(25); +float expected = 298.15; +TEST_ASSERT_EQUAL(expected, result); +} + #endif From ce396b43024ffc12ddae78a206d14d8a6ef62c7e Mon Sep 17 00:00:00 2001 From: Kevin Ludwig Date: Wed, 7 Feb 2024 20:54:51 +0100 Subject: [PATCH 07/22] refactoring: switch statt if --- src/temperatur.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/temperatur.c b/src/temperatur.c index 29c7db3..d7926d5 100644 --- a/src/temperatur.c +++ b/src/temperatur.c @@ -9,7 +9,7 @@ float CzuK(float tempC){ } int run_TemperaturRechner(){ - float var1; + float var1, var2; int var3; printf("\nTemperaturkonverter (Celsius, Fahrenheit, Kelvin)\nAchten Sie darauf, Kommazahlen mit einem Punkt anzugeben!\n\n"); @@ -20,10 +20,17 @@ int run_TemperaturRechner(){ printf("\nGeben Sie die Temperatur ein: "); scanf("%f", &var1); - if(var3 == 1) - printf("\nErgebnis: %.2f\n", CzuF(var1)); - if(var3 == 2) - printf("\nErgebnis: %.2f\n", CzuK(var1)); + + switch(var3){ + case 1: + var2 = CzuF(var1); + break; + case 2: + var2 = CzuK(var1); + break; + } + + printf("\nErgebnis: %.2f\n", var2); return 0; From c4365ac496237dd588a61f2650cc5fc373f7d099 Mon Sep 17 00:00:00 2001 From: Kevin Ludwig Date: Wed, 7 Feb 2024 20:59:27 +0100 Subject: [PATCH 08/22] =?UTF-8?q?Fahrenheit=20zu=20Celsius=20funktion=20f?= =?UTF-8?q?=C3=BCr=20berechnung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/temperatur.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/temperatur.c b/src/temperatur.c index d7926d5..388e32f 100644 --- a/src/temperatur.c +++ b/src/temperatur.c @@ -8,13 +8,17 @@ float CzuK(float tempC){ return tempC + 273.15; } +float FzuC(float tempF){ + return (tempF - 32) * 5/9; +} + int run_TemperaturRechner(){ float var1, var2; int var3; printf("\nTemperaturkonverter (Celsius, Fahrenheit, Kelvin)\nAchten Sie darauf, Kommazahlen mit einem Punkt anzugeben!\n\n"); - printf("Waehlen Sie: \n<1> Celsius zu Fahrenheit\n<2> Celsius zu Kelvin\n"); + printf("Waehlen Sie: \n<1> Celsius zu Fahrenheit\n<2> Celsius zu Kelvin\n<3> Fahrenheit zu Celsius\n"); scanf("%d", &var3); printf("\nGeben Sie die Temperatur ein: "); @@ -28,6 +32,9 @@ int run_TemperaturRechner(){ case 2: var2 = CzuK(var1); break; + case 3: + var2 = FzuC(var1); + break; } printf("\nErgebnis: %.2f\n", var2); From df1ed97ad1687b1d01dfa766fdc4248b02838c56 Mon Sep 17 00:00:00 2001 From: Kevin Ludwig Date: Wed, 7 Feb 2024 21:00:59 +0100 Subject: [PATCH 09/22] Unittest: KzuC --- src/temperatur.h | 1 + test/test_temperatur.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/src/temperatur.h b/src/temperatur.h index 9cb94b5..226e114 100644 --- a/src/temperatur.h +++ b/src/temperatur.h @@ -3,5 +3,6 @@ float CzuF(float tempC); float CzuK(float tempC); +float FzuC(float tempF); #endif //TEMPERATUR_H diff --git a/test/test_temperatur.c b/test/test_temperatur.c index 584ce47..9751fc2 100644 --- a/test/test_temperatur.c +++ b/test/test_temperatur.c @@ -26,4 +26,11 @@ float expected = 298.15; TEST_ASSERT_EQUAL(expected, result); } + +void test_temperaturRechner_FzuC(void) +{ +float result = FzuC(77); +float expected = 25; +TEST_ASSERT_EQUAL(expected, result); +} #endif From 071516eeccd6474cdbf400d75d3d9223fcb51917 Mon Sep 17 00:00:00 2001 From: Kevin Ludwig Date: Wed, 7 Feb 2024 21:06:19 +0100 Subject: [PATCH 10/22] =?UTF-8?q?Fahrenheit=20zu=20Kelvin=20funktion=20f?= =?UTF-8?q?=C3=BCr=20berechnung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/temperatur.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/temperatur.c b/src/temperatur.c index 388e32f..33b5e1d 100644 --- a/src/temperatur.c +++ b/src/temperatur.c @@ -11,14 +11,17 @@ float CzuK(float tempC){ float FzuC(float tempF){ return (tempF - 32) * 5/9; } +float FzuK(float tempF){ + return (tempF - 32) * 5/9 + 273.15; +} -int run_TemperaturRechner(){ +int main(){ float var1, var2; int var3; printf("\nTemperaturkonverter (Celsius, Fahrenheit, Kelvin)\nAchten Sie darauf, Kommazahlen mit einem Punkt anzugeben!\n\n"); - printf("Waehlen Sie: \n<1> Celsius zu Fahrenheit\n<2> Celsius zu Kelvin\n<3> Fahrenheit zu Celsius\n"); + printf("Waehlen Sie: \n<1> Celsius zu Fahrenheit\n<2> Celsius zu Kelvin\n<3> Fahrenheit zu Celsius\n<4> Fahrenheit zu Kelvin\n"); scanf("%d", &var3); printf("\nGeben Sie die Temperatur ein: "); @@ -35,6 +38,9 @@ int run_TemperaturRechner(){ case 3: var2 = FzuC(var1); break; + case 4: + var2 = FzuK(var1); + break; } printf("\nErgebnis: %.2f\n", var2); From d1809e68b7c5fa2cb80f552c16ca472f9b8f15ad Mon Sep 17 00:00:00 2001 From: Kevin Ludwig Date: Wed, 7 Feb 2024 21:09:23 +0100 Subject: [PATCH 11/22] Unittest FzuK --- src/temperatur.c | 2 +- src/temperatur.h | 2 ++ test/test_temperatur.c | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/temperatur.c b/src/temperatur.c index 33b5e1d..1fbeaf0 100644 --- a/src/temperatur.c +++ b/src/temperatur.c @@ -15,7 +15,7 @@ float FzuK(float tempF){ return (tempF - 32) * 5/9 + 273.15; } -int main(){ +int run_TemperaturRechner(){ float var1, var2; int var3; diff --git a/src/temperatur.h b/src/temperatur.h index 226e114..1409e5d 100644 --- a/src/temperatur.h +++ b/src/temperatur.h @@ -3,6 +3,8 @@ float CzuF(float tempC); float CzuK(float tempC); + float FzuC(float tempF); +float FzuK(float tempF); #endif //TEMPERATUR_H diff --git a/test/test_temperatur.c b/test/test_temperatur.c index 9751fc2..f237aaf 100644 --- a/test/test_temperatur.c +++ b/test/test_temperatur.c @@ -33,4 +33,10 @@ float result = FzuC(77); float expected = 25; TEST_ASSERT_EQUAL(expected, result); } +void test_temperaturRechner_FzuK(void) +{ +float result = FzuK(77); +float expected = 298.15; +TEST_ASSERT_EQUAL(expected, result); +} #endif From 078cc3cc9646b2acc51688d27c4f822adc40d64f Mon Sep 17 00:00:00 2001 From: Kevin Ludwig Date: Wed, 7 Feb 2024 21:12:27 +0100 Subject: [PATCH 12/22] =?UTF-8?q?Kelvin=20zu=20Celsius=20funktion=20f?= =?UTF-8?q?=C3=BCr=20berechnung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/temperatur.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/temperatur.c b/src/temperatur.c index 1fbeaf0..842c13d 100644 --- a/src/temperatur.c +++ b/src/temperatur.c @@ -14,6 +14,11 @@ float FzuC(float tempF){ float FzuK(float tempF){ return (tempF - 32) * 5/9 + 273.15; } +float KzuC(float tempK){ + float tmp = tempK - 273.15; + //Variable auf 2 Nachkommastellen begrenzen + return ((int)(tmp * 100 + 0.5) / 100.0); +} int run_TemperaturRechner(){ float var1, var2; @@ -21,7 +26,7 @@ int run_TemperaturRechner(){ printf("\nTemperaturkonverter (Celsius, Fahrenheit, Kelvin)\nAchten Sie darauf, Kommazahlen mit einem Punkt anzugeben!\n\n"); - printf("Waehlen Sie: \n<1> Celsius zu Fahrenheit\n<2> Celsius zu Kelvin\n<3> Fahrenheit zu Celsius\n<4> Fahrenheit zu Kelvin\n"); + printf("Waehlen Sie: \n<1> Celsius zu Fahrenheit\n<2> Celsius zu Kelvin\n<3> Fahrenheit zu Celsius\n<4> Fahrenheit zu Kelvin\n<5> Kelvin zu Celsius\n"); scanf("%d", &var3); printf("\nGeben Sie die Temperatur ein: "); @@ -41,6 +46,9 @@ int run_TemperaturRechner(){ case 4: var2 = FzuK(var1); break; + case 5: + var2 = KzuC(var1); + break; } printf("\nErgebnis: %.2f\n", var2); From e7b548dcb5aaa8c41f272fac40a155051f888031 Mon Sep 17 00:00:00 2001 From: Kevin Ludwig Date: Wed, 7 Feb 2024 21:14:25 +0100 Subject: [PATCH 13/22] Unittest: KzuC --- src/temperatur.h | 2 ++ test/test_temperatur.c | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/src/temperatur.h b/src/temperatur.h index 1409e5d..ebdea50 100644 --- a/src/temperatur.h +++ b/src/temperatur.h @@ -7,4 +7,6 @@ float CzuK(float tempC); float FzuC(float tempF); float FzuK(float tempF); +float KzuC(float tempK); + #endif //TEMPERATUR_H diff --git a/test/test_temperatur.c b/test/test_temperatur.c index f237aaf..e27c7da 100644 --- a/test/test_temperatur.c +++ b/test/test_temperatur.c @@ -39,4 +39,11 @@ float result = FzuK(77); float expected = 298.15; TEST_ASSERT_EQUAL(expected, result); } + +void test_temperaturRechner_KzuC(void) +{ +float result = KzuC(298.15); +float expected = 25; +TEST_ASSERT_EQUAL(expected, result); +} #endif From b40341c7dbb7e4b6c2d7a865297b6052c94c9db1 Mon Sep 17 00:00:00 2001 From: Kevin Ludwig Date: Wed, 7 Feb 2024 21:18:45 +0100 Subject: [PATCH 14/22] =?UTF-8?q?Kelvin=20zu=20Fahrenheit=20funktion=20f?= =?UTF-8?q?=C3=BCr=20berechnung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/temperatur.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/temperatur.c b/src/temperatur.c index 842c13d..e3c7abe 100644 --- a/src/temperatur.c +++ b/src/temperatur.c @@ -14,11 +14,17 @@ float FzuC(float tempF){ float FzuK(float tempF){ return (tempF - 32) * 5/9 + 273.15; } + float KzuC(float tempK){ float tmp = tempK - 273.15; //Variable auf 2 Nachkommastellen begrenzen return ((int)(tmp * 100 + 0.5) / 100.0); } +float KzuF(float tempK){ + float tmp = (tempK - 273.15) * 9/5 + 32; + //Variable auf 2 Nachkommastellen begrenzen + return ((int)(tmp * 100 + .5) / 100.0); +} int run_TemperaturRechner(){ float var1, var2; @@ -26,7 +32,7 @@ int run_TemperaturRechner(){ printf("\nTemperaturkonverter (Celsius, Fahrenheit, Kelvin)\nAchten Sie darauf, Kommazahlen mit einem Punkt anzugeben!\n\n"); - printf("Waehlen Sie: \n<1> Celsius zu Fahrenheit\n<2> Celsius zu Kelvin\n<3> Fahrenheit zu Celsius\n<4> Fahrenheit zu Kelvin\n<5> Kelvin zu Celsius\n"); + printf("Waehlen Sie: \n<1> Celsius zu Fahrenheit\n<2> Celsius zu Kelvin\n<3> Fahrenheit zu Celsius\n<4> Fahrenheit zu Kelvin\n<5> Kelvin zu Celsius\n<6> Kelvin zu Fahrenheit\n"); scanf("%d", &var3); printf("\nGeben Sie die Temperatur ein: "); @@ -49,6 +55,9 @@ int run_TemperaturRechner(){ case 5: var2 = KzuC(var1); break; + case 6: + var2 = KzuF(var1); + break; } printf("\nErgebnis: %.2f\n", var2); From ae207c82298f025e3793d90f41a0c87124d3d53e Mon Sep 17 00:00:00 2001 From: Kevin Ludwig Date: Wed, 7 Feb 2024 21:21:07 +0100 Subject: [PATCH 15/22] Unittest: KzuF --- src/temperatur.h | 1 + test/test_temperatur.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/src/temperatur.h b/src/temperatur.h index ebdea50..d4f13bf 100644 --- a/src/temperatur.h +++ b/src/temperatur.h @@ -8,5 +8,6 @@ float FzuC(float tempF); float FzuK(float tempF); float KzuC(float tempK); +float KzuF(float tempK); #endif //TEMPERATUR_H diff --git a/test/test_temperatur.c b/test/test_temperatur.c index e27c7da..e22c8e1 100644 --- a/test/test_temperatur.c +++ b/test/test_temperatur.c @@ -46,4 +46,11 @@ float result = KzuC(298.15); float expected = 25; TEST_ASSERT_EQUAL(expected, result); } +void test_temperaturRechner_KzuF(void) +{ +float result = KzuF(298.15); +float expected = 77; +TEST_ASSERT_EQUAL(expected, result); +} + #endif From f8fb5b8cde507f62d65deff53e5110d506e5d2c1 Mon Sep 17 00:00:00 2001 From: Kevin Ludwig Date: Wed, 7 Feb 2024 21:29:03 +0100 Subject: [PATCH 16/22] auswahlspezifische eingabeaufforderung --- src/temperatur.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/temperatur.c b/src/temperatur.c index e3c7abe..6fd2f5b 100644 --- a/src/temperatur.c +++ b/src/temperatur.c @@ -1,4 +1,5 @@ #include +#include #include "temperatur.h" float CzuF(float tempC){ @@ -26,6 +27,16 @@ float KzuF(float tempK){ return ((int)(tmp * 100 + .5) / 100.0); } +const char* getFirstUnit(int input){ + if(input < 3) + return "Celsius"; + else if(input < 5) + return "Fahrenheit"; + else if(input < 7) + return "Kelvin"; + return ""; +} + int run_TemperaturRechner(){ float var1, var2; int var3; @@ -35,7 +46,7 @@ int run_TemperaturRechner(){ printf("Waehlen Sie: \n<1> Celsius zu Fahrenheit\n<2> Celsius zu Kelvin\n<3> Fahrenheit zu Celsius\n<4> Fahrenheit zu Kelvin\n<5> Kelvin zu Celsius\n<6> Kelvin zu Fahrenheit\n"); scanf("%d", &var3); - printf("\nGeben Sie die Temperatur ein: "); + printf("\nGeben Sie die Temperatur in %s ein: ", getFirstUnit(var3)); scanf("%f", &var1); From b3b97bb7838c0873e48660b7cd41340260ed86b8 Mon Sep 17 00:00:00 2001 From: Kevin Ludwig Date: Wed, 7 Feb 2024 21:31:06 +0100 Subject: [PATCH 17/22] Unittest: getFirstUnit --- src/temperatur.h | 1 + test/test_temperatur.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/temperatur.h b/src/temperatur.h index d4f13bf..6063d96 100644 --- a/src/temperatur.h +++ b/src/temperatur.h @@ -10,4 +10,5 @@ float FzuK(float tempF); float KzuC(float tempK); float KzuF(float tempK); +const char* getFirstUnit(int input); #endif //TEMPERATUR_H diff --git a/test/test_temperatur.c b/test/test_temperatur.c index e22c8e1..c1a14fb 100644 --- a/test/test_temperatur.c +++ b/test/test_temperatur.c @@ -53,4 +53,10 @@ float expected = 77; TEST_ASSERT_EQUAL(expected, result); } +void test_returnUnit_first(void) +{ +const char *result = getFirstUnit(1); +char expected[] = "Celsius"; +TEST_ASSERT_EQUAL_STRING(expected, result); +} #endif From 5ea71dbc5e5f65f9af165df941df207f1652cd3c Mon Sep 17 00:00:00 2001 From: Kevin Ludwig Date: Wed, 7 Feb 2024 21:39:15 +0100 Subject: [PATCH 18/22] auswahlspezifische ausgabe --- src/temperatur.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/temperatur.c b/src/temperatur.c index 6fd2f5b..0ccf6fc 100644 --- a/src/temperatur.c +++ b/src/temperatur.c @@ -36,6 +36,17 @@ const char* getFirstUnit(int input){ return "Kelvin"; return ""; } +const char* getSecondUnit(int input){ + if(input == 1 || input == 6) + return "° Fahrenheit"; + else if(input == 2 || input == 4) + return " Kelvin"; + else if(input == 3 || input == 5) + return "° Celsius"; + + + return ""; +} int run_TemperaturRechner(){ float var1, var2; @@ -71,7 +82,7 @@ int run_TemperaturRechner(){ break; } - printf("\nErgebnis: %.2f\n", var2); + printf(" = %.2f%s\n\n", var2, getSecondUnit(var3)); return 0; From 2876af69eb72ce76f0b3ae54c12c4ab8e984a64e Mon Sep 17 00:00:00 2001 From: Kevin Ludwig Date: Wed, 7 Feb 2024 21:42:29 +0100 Subject: [PATCH 19/22] Unittest: getSecondUnit --- src/temperatur.h | 1 + test/test_temperatur.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/temperatur.h b/src/temperatur.h index 6063d96..010365b 100644 --- a/src/temperatur.h +++ b/src/temperatur.h @@ -11,4 +11,5 @@ float KzuC(float tempK); float KzuF(float tempK); const char* getFirstUnit(int input); +const char* getSecondUnit(int input); #endif //TEMPERATUR_H diff --git a/test/test_temperatur.c b/test/test_temperatur.c index c1a14fb..04485a8 100644 --- a/test/test_temperatur.c +++ b/test/test_temperatur.c @@ -59,4 +59,10 @@ const char *result = getFirstUnit(1); char expected[] = "Celsius"; TEST_ASSERT_EQUAL_STRING(expected, result); } +void test_returnUnit_second(void) +{ +const char *result = getSecondUnit(2); +char expected[] = " Kelvin"; +TEST_ASSERT_EQUAL_STRING(expected, result); +} #endif From 1d31fd31acb575a78bc508b0acaa2eb3cb395aa9 Mon Sep 17 00:00:00 2001 From: Kevin Ludwig Date: Wed, 7 Feb 2024 21:49:07 +0100 Subject: [PATCH 20/22] =?UTF-8?q?abbruch=20bei=20zu=20kleiner/gro=C3=9Fer?= =?UTF-8?q?=20eingabe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/temperatur.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/temperatur.c b/src/temperatur.c index 0ccf6fc..4d9e11a 100644 --- a/src/temperatur.c +++ b/src/temperatur.c @@ -57,6 +57,11 @@ int run_TemperaturRechner(){ printf("Waehlen Sie: \n<1> Celsius zu Fahrenheit\n<2> Celsius zu Kelvin\n<3> Fahrenheit zu Celsius\n<4> Fahrenheit zu Kelvin\n<5> Kelvin zu Celsius\n<6> Kelvin zu Fahrenheit\n"); scanf("%d", &var3); + if(var3 < 1 || var3 > 6){ + printf("Eingabe nicht zulaessig!"); + return 0; + } + printf("\nGeben Sie die Temperatur in %s ein: ", getFirstUnit(var3)); scanf("%f", &var1); From e5248b9cb57b32331640db991bb2beb54c65e52e Mon Sep 17 00:00:00 2001 From: Kevin Ludwig Date: Wed, 7 Feb 2024 21:53:53 +0100 Subject: [PATCH 21/22] auswahlpunkt zum beenden --- src/temperatur.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/temperatur.c b/src/temperatur.c index 4d9e11a..e18b4d9 100644 --- a/src/temperatur.c +++ b/src/temperatur.c @@ -54,13 +54,15 @@ int run_TemperaturRechner(){ printf("\nTemperaturkonverter (Celsius, Fahrenheit, Kelvin)\nAchten Sie darauf, Kommazahlen mit einem Punkt anzugeben!\n\n"); - printf("Waehlen Sie: \n<1> Celsius zu Fahrenheit\n<2> Celsius zu Kelvin\n<3> Fahrenheit zu Celsius\n<4> Fahrenheit zu Kelvin\n<5> Kelvin zu Celsius\n<6> Kelvin zu Fahrenheit\n"); + printf("Waehlen Sie: \n<1> Celsius zu Fahrenheit\n<2> Celsius zu Kelvin\n<3> Fahrenheit zu Celsius\n<4> Fahrenheit zu Kelvin\n<5> Kelvin zu Celsius\n<6> Kelvin zu Fahrenheit\n<7> Zum beenden\nAuswahl: "); scanf("%d", &var3); - if(var3 < 1 || var3 > 6){ + if(var3 < 1 || var3 > 7){ printf("Eingabe nicht zulaessig!"); return 0; } + else if(var3 == 7) + return 0; printf("\nGeben Sie die Temperatur in %s ein: ", getFirstUnit(var3)); scanf("%f", &var1); From 435670e1d2986bea34a1d62ab49ea59ef621e6cd Mon Sep 17 00:00:00 2001 From: Kevin Ludwig Date: Wed, 7 Feb 2024 21:56:44 +0100 Subject: [PATCH 22/22] =?UTF-8?q?temperatur=20schleife=20f=C3=BCr=20mehrer?= =?UTF-8?q?e=20durchl=C3=A4ufe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/temperatur.c | 72 +++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/src/temperatur.c b/src/temperatur.c index e18b4d9..7c6929e 100644 --- a/src/temperatur.c +++ b/src/temperatur.c @@ -53,44 +53,46 @@ int run_TemperaturRechner(){ int var3; printf("\nTemperaturkonverter (Celsius, Fahrenheit, Kelvin)\nAchten Sie darauf, Kommazahlen mit einem Punkt anzugeben!\n\n"); - - printf("Waehlen Sie: \n<1> Celsius zu Fahrenheit\n<2> Celsius zu Kelvin\n<3> Fahrenheit zu Celsius\n<4> Fahrenheit zu Kelvin\n<5> Kelvin zu Celsius\n<6> Kelvin zu Fahrenheit\n<7> Zum beenden\nAuswahl: "); - scanf("%d", &var3); - - if(var3 < 1 || var3 > 7){ - printf("Eingabe nicht zulaessig!"); - return 0; - } - else if(var3 == 7) - return 0; - - printf("\nGeben Sie die Temperatur in %s ein: ", getFirstUnit(var3)); - scanf("%f", &var1); - - - switch(var3){ - case 1: - var2 = CzuF(var1); - break; - case 2: - var2 = CzuK(var1); - break; - case 3: - var2 = FzuC(var1); - break; - case 4: - var2 = FzuK(var1); - break; - case 5: - var2 = KzuC(var1); + + while(1){ + printf("Waehlen Sie: \n<1> Celsius zu Fahrenheit\n<2> Celsius zu Kelvin\n<3> Fahrenheit zu Celsius\n<4> Fahrenheit zu Kelvin\n<5> Kelvin zu Celsius\n<6> Kelvin zu Fahrenheit\n<7> Zum beenden\nAuswahl: "); + scanf("%d", &var3); + + if(var3 < 1 || var3 > 7){ + printf("Eingabe nicht zulaessig!"); break; - case 6: - var2 = KzuF(var1); + } + else if(var3 == 7) break; + + printf("\nGeben Sie die Temperatur in %s ein: ", getFirstUnit(var3)); + scanf("%f", &var1); + + + switch(var3){ + case 1: + var2 = CzuF(var1); + break; + case 2: + var2 = CzuK(var1); + break; + case 3: + var2 = FzuC(var1); + break; + case 4: + var2 = FzuK(var1); + break; + case 5: + var2 = KzuC(var1); + break; + case 6: + var2 = KzuF(var1); + break; + } + + printf(" = %.2f%s\n\n", var2, getSecondUnit(var3)); + } - - printf(" = %.2f%s\n\n", var2, getSecondUnit(var3)); - return 0; }