From ee62a56d1a58b273fce4c7e19c8862b30843dd1d Mon Sep 17 00:00:00 2001 From: Shivam Chaudhary Date: Tue, 7 Feb 2023 16:25:56 +0100 Subject: [PATCH] Add test for toUSD function --- tests/test_currencyExchange.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/test_currencyExchange.c diff --git a/tests/test_currencyExchange.c b/tests/test_currencyExchange.c new file mode 100644 index 0000000..168f0c2 --- /dev/null +++ b/tests/test_currencyExchange.c @@ -0,0 +1,35 @@ +#ifdef TEST + +#include "unity.h" +#include "currencyExchange.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_toUSD(void) { + int length = 5; + float euro[] = {34, 233, 400, 100, 45}; + float expectedUSD[length]; + float resultUSD[length]; + + for (int i = 0; i < length; i++) { + resultUSD[i] = toUSD(euro[i]); + } + + for (int i = 0; i < length; i++) { + expectedUSD[i] = euro[i] * CURRENT_USD_RATE_OF_ONE_EURO; + } + + for (int i = 0; i < length; i++) { + TEST_ASSERT_EQUAL_FLOAT(expectedUSD[i], resultUSD[i]); + } + +} + + +#endif // TEST