From bce3b53bb80e58ff37563f36929fc84e0af840a7 Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Wed, 8 Feb 2023 23:46:24 +0100 Subject: [PATCH 01/32] implement function calculatorAdd() --- project.yml | 101 +++++++++++++++++++++++++++++++++++++ src/calculatorAdd.c | 5 ++ src/calculatorAdd.h | 6 +++ src/main.c | 20 ++++++-- tests/support/.gitkeep | 0 tests/test_calculatorAdd.c | 20 ++++++++ 6 files changed, 149 insertions(+), 3 deletions(-) create mode 100644 project.yml create mode 100644 src/calculatorAdd.c create mode 100644 src/calculatorAdd.h create mode 100644 tests/support/.gitkeep create mode 100644 tests/test_calculatorAdd.c diff --git a/project.yml b/project.yml new file mode 100644 index 0000000..640cb8f --- /dev/null +++ b/project.yml @@ -0,0 +1,101 @@ +--- + +# Notes: +# Sample project C code is not presently written to produce a release artifact. +# As such, release build options are disabled. +# This sample, therefore, only demonstrates running a collection of unit tests. + +:project: + :use_exceptions: FALSE + :use_test_preprocessor: TRUE + :use_auxiliary_dependencies: TRUE + :build_root: build +# :release_build: TRUE + :test_file_prefix: test_ + :which_ceedling: gem + :ceedling_version: 0.31.1 + :default_tasks: + - test:all + +#:test_build: +# :use_assembly: TRUE + +#:release_build: +# :output: MyApp.out +# :use_assembly: FALSE + +:environment: + +:extension: + :executable: .out + +:paths: + :test: + - +:tests/** + - -:tests/support + :source: + - src/** + :support: + - tests/support + :libraries: [] + +:defines: + # in order to add common defines: + # 1) remove the trailing [] from the :common: section + # 2) add entries to the :common: section (e.g. :test: has TEST defined) + :common: &common_defines [] + :test: + - *common_defines + - TEST + :test_preprocess: + - *common_defines + - TEST + +:cmock: + :mock_prefix: mock_ + :when_no_prototypes: :warn + :enforce_strict_ordering: TRUE + :plugins: + - :ignore + - :callback + :treat_as: + uint8: HEX8 + uint16: HEX16 + uint32: UINT32 + int8: INT8 + bool: UINT8 + +# Add -gcov to the plugins list to make sure of the gcov plugin +# You will need to have gcov and gcovr both installed to make it work. +# For more information on these options, see docs in plugins/gcov +:gcov: + :reports: + - HtmlDetailed + :gcovr: + :html_medium_threshold: 75 + :html_high_threshold: 90 + +#:tools: +# Ceedling defaults to using gcc for compiling, linking, etc. +# As [:tools] is blank, gcc will be used (so long as it's in your system path) +# See documentation to configure a given toolchain for use + +# LIBRARIES +# These libraries are automatically injected into the build process. Those specified as +# common will be used in all types of builds. Otherwise, libraries can be injected in just +# tests or releases. These options are MERGED with the options in supplemental yaml files. +:libraries: + :placement: :end + :flag: "-l${1}" + :path_flag: "-L ${1}" + :system: [] # for example, you might list 'm' to grab the math library + :test: [] + :release: [] + +:plugins: + :load_paths: + - "#{Ceedling.load_path}" + :enabled: + - stdout_pretty_tests_report + - module_generator +... diff --git a/src/calculatorAdd.c b/src/calculatorAdd.c new file mode 100644 index 0000000..781e507 --- /dev/null +++ b/src/calculatorAdd.c @@ -0,0 +1,5 @@ +#include "calculatorAdd.h" + +float calculatorAdd(float x,float y) +{return x+y;} + diff --git a/src/calculatorAdd.h b/src/calculatorAdd.h new file mode 100644 index 0000000..443a906 --- /dev/null +++ b/src/calculatorAdd.h @@ -0,0 +1,6 @@ +#ifndef CALCULATORADD_H +#define CALCULATORADD_H +#include +#include +float calculatorAdd(float x,float y); +#endif // CALCULATORADD_H diff --git a/src/main.c b/src/main.c index a3a8e04..cec361d 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,18 @@ -#include -int main(){ -return 0; +#include "calculatorAdd.c" + + +int main() +{ + float num1, num2, sum; + + printf("number1: "); + scanf("%f", &num1); + + printf("number2: "); + scanf("%f", &num2); + + sum = calculatorAdd(num1, num2); + + printf("answer: %f", sum); + return 0; } diff --git a/tests/support/.gitkeep b/tests/support/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_calculatorAdd.c b/tests/test_calculatorAdd.c new file mode 100644 index 0000000..5dd554b --- /dev/null +++ b/tests/test_calculatorAdd.c @@ -0,0 +1,20 @@ +#ifdef TEST + +#include "unity.h" + +#include "calculatorAdd.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_calculatorAdd_NeedToImplement(void) +{ + TEST_IGNORE_MESSAGE("Need to Implement calculatorAdd"); +} + +#endif // TEST From 22c4f866369fba6741cab8c08affbb177a626e7c Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Wed, 8 Feb 2023 23:49:26 +0100 Subject: [PATCH 02/32] implement unittest for calculatorAdd.c --- build-project.sh | 1 + tests/test_calculatorAdd.c | 101 +++++++++++++++++++++++++++++++++++-- 2 files changed, 99 insertions(+), 3 deletions(-) diff --git a/build-project.sh b/build-project.sh index 43a0588..51cf723 100755 --- a/build-project.sh +++ b/build-project.sh @@ -1,4 +1,5 @@ clear +ceedling test:all cd src/ gcc main.c -o main ./main diff --git a/tests/test_calculatorAdd.c b/tests/test_calculatorAdd.c index 5dd554b..0c55e52 100644 --- a/tests/test_calculatorAdd.c +++ b/tests/test_calculatorAdd.c @@ -2,7 +2,7 @@ #include "unity.h" -#include "calculatorAdd.h" +#include "calculatorAdd.c" void setUp(void) { @@ -12,9 +12,104 @@ void tearDown(void) { } -void test_calculatorAdd_NeedToImplement(void) +void test1_calculatorAdd(void) { - TEST_IGNORE_MESSAGE("Need to Implement calculatorAdd"); + float x, y, a ,e; + x = 26.24; + y = 23.22; + a = calculatorAdd(x, y); + e = x + y; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test2_calculatorAdd(void) +{ + float x, y, a ,e; + x = 56.24; + y = 233.22; + a = calculatorAdd(x, y); + e = x + y; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test3_calculatorAdd(void) +{ + float x, y, a ,e; + x = 1226.24; + y = 323.22; + a = calculatorAdd(x, y); + e = x + y; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test4_calculatorAdd(void) +{ + float x, y, a ,e; + x = 2623.24; + y = 2323.22; + a = calculatorAdd(x, y); + e = x + y; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test5_calculatorAdd(void) +{ + float x, y, a ,e; + x = 2435.24; + y = 23423.22; + a = calculatorAdd(x, y); + e = x + y; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test6_calculatorAdd(void) +{ + float x, y, a ,e; + x = 4534.24; + y = 2221.22; + a = calculatorAdd(x, y); + e = x + y; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test7_calculatorAdd(void) +{ + float x, y, a ,e; + x = 26322.24; + y = 2332.222; + a = calculatorAdd(x, y); + e = x + y; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test8_calculatorAdd(void) +{ + float x, y, a ,e; + x = 26132.24; + y = 2331122.222; + a = calculatorAdd(x, y); + e = x + y; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test9_calculatorAdd(void) +{ + float x, y, a ,e; + x = 6322.24; + y = 21232.2322; + a = calculatorAdd(x, y); + e = x + y; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test10_calculatorAdd(void) +{ + float x, y, a ,e; + x = 1234.456; + y = 654.4321; + a = calculatorAdd(x, y); + e = x + y; + TEST_ASSERT_EQUAL_FLOAT(e, a); } #endif // TEST From 9a8bfb585e4b7f3d0fae180f1ffc4eff1a23e140 Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Sun, 5 Feb 2023 00:01:00 +0100 Subject: [PATCH 03/32] refactoring: change variable names calculatorAdd.c and calculatorAdd.h --- src/calculatorAdd.c | 11 +++++++++-- src/calculatorAdd.h | 4 +++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/calculatorAdd.c b/src/calculatorAdd.c index 781e507..99c892a 100644 --- a/src/calculatorAdd.c +++ b/src/calculatorAdd.c @@ -1,5 +1,12 @@ #include "calculatorAdd.h" -float calculatorAdd(float x,float y) -{return x+y;} + +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + +float calculatorAdd(float num1,float num2) +{ + return num1+num2; +} diff --git a/src/calculatorAdd.h b/src/calculatorAdd.h index 443a906..412a599 100644 --- a/src/calculatorAdd.h +++ b/src/calculatorAdd.h @@ -1,6 +1,8 @@ #ifndef CALCULATORADD_H #define CALCULATORADD_H + #include #include -float calculatorAdd(float x,float y); +float calculatorAdd(float num1,float num2); + #endif // CALCULATORADD_H From ef307cac167198a4efcf5272df7b8df056807015 Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Sun, 5 Feb 2023 00:13:48 +0100 Subject: [PATCH 04/32] refactoring: change variable names in test_calculatorAdd.c --- tests/test_calculatorAdd.c | 127 +++++++++++++++++++------------------ 1 file changed, 67 insertions(+), 60 deletions(-) diff --git a/tests/test_calculatorAdd.c b/tests/test_calculatorAdd.c index 0c55e52..3e22349 100644 --- a/tests/test_calculatorAdd.c +++ b/tests/test_calculatorAdd.c @@ -4,6 +4,13 @@ #include "calculatorAdd.c" + + +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + + void setUp(void) { } @@ -14,102 +21,102 @@ void tearDown(void) void test1_calculatorAdd(void) { - float x, y, a ,e; - x = 26.24; - y = 23.22; - a = calculatorAdd(x, y); - e = x + y; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual ,expected; //Arrange + num1 = 26.24; + num2 = 23.22; + actual = calculatorAdd(num1, num2); //Act + expected = num1 + num2; + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test2_calculatorAdd(void) { - float x, y, a ,e; - x = 56.24; - y = 233.22; - a = calculatorAdd(x, y); - e = x + y; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual ,expected; //Arrange + num1 = 56.24; + num2 = 233.22; + actual = calculatorAdd(num1, num2); //Act + expected = num1 + num2; + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test3_calculatorAdd(void) { - float x, y, a ,e; - x = 1226.24; - y = 323.22; - a = calculatorAdd(x, y); - e = x + y; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual ,expected; //Arrange + num1 = 1226.24; + num2 = 323.22; + actual = calculatorAdd(num1, num2); //Act + expected = num1 + num2; + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test4_calculatorAdd(void) { - float x, y, a ,e; - x = 2623.24; - y = 2323.22; - a = calculatorAdd(x, y); - e = x + y; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual ,expected; //Arrange + num1 = 2623.24; + num2 = 2323.22; + actual = calculatorAdd(num1, num2); //Act + expected = num1 + num2; + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test5_calculatorAdd(void) { - float x, y, a ,e; - x = 2435.24; - y = 23423.22; - a = calculatorAdd(x, y); - e = x + y; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual ,expected; //Arrange + num1 = 2435.24; + num2 = 23423.22; + actual = calculatorAdd(num1, num2); //Act + expected = num1 + num2; + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test6_calculatorAdd(void) { - float x, y, a ,e; - x = 4534.24; - y = 2221.22; - a = calculatorAdd(x, y); - e = x + y; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual ,expected; //Arrange + num1 = 4534.24; + num2 = 2221.22; + actual = calculatorAdd(num1, num2); //Act + expected = num1 + num2; + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test7_calculatorAdd(void) { - float x, y, a ,e; - x = 26322.24; - y = 2332.222; - a = calculatorAdd(x, y); - e = x + y; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual ,expected; //Arrange + num1 = 26322.24; + num2 = 2332.222; + actual = calculatorAdd(num1, num2); //Act + expected = num1 + num2; + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test8_calculatorAdd(void) { - float x, y, a ,e; - x = 26132.24; - y = 2331122.222; - a = calculatorAdd(x, y); - e = x + y; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual ,expected; //Arrange + num1 = 26132.24; + num2 = 2331122.222; + actual = calculatorAdd(num1, num2); //Act + expected = num1 + num2; + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test9_calculatorAdd(void) { - float x, y, a ,e; - x = 6322.24; - y = 21232.2322; - a = calculatorAdd(x, y); - e = x + y; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual ,expected; //Arrange + num1 = 6322.24; + num2 = 21232.2322; + actual = calculatorAdd(num1, num2); //Act + expected = num1 + num2; + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test10_calculatorAdd(void) { - float x, y, a ,e; - x = 1234.456; - y = 654.4321; - a = calculatorAdd(x, y); - e = x + y; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual ,expected; //Arrange + num1 = 1234.456; + num2 = 654.4321; + actual = calculatorAdd(num1, num2); //Act + expected = num1 + num2; + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } #endif // TEST From 92f74b3f37c05fdb80e84084fb85736c8e79e567 Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Thu, 9 Feb 2023 00:12:49 +0100 Subject: [PATCH 05/32] implement function calculatorSubtract() --- project.yml | 101 ++++++++++++++++++++++++++++++++ src/calculatorSubtract.c | 5 ++ src/calculatorSubtract.h | 11 ++++ src/main.c | 22 ++++++- tests/support/.gitkeep | 0 tests/test_calculatorSubtract.c | 20 +++++++ 6 files changed, 156 insertions(+), 3 deletions(-) create mode 100644 project.yml create mode 100644 src/calculatorSubtract.c create mode 100644 src/calculatorSubtract.h create mode 100644 tests/support/.gitkeep create mode 100644 tests/test_calculatorSubtract.c diff --git a/project.yml b/project.yml new file mode 100644 index 0000000..640cb8f --- /dev/null +++ b/project.yml @@ -0,0 +1,101 @@ +--- + +# Notes: +# Sample project C code is not presently written to produce a release artifact. +# As such, release build options are disabled. +# This sample, therefore, only demonstrates running a collection of unit tests. + +:project: + :use_exceptions: FALSE + :use_test_preprocessor: TRUE + :use_auxiliary_dependencies: TRUE + :build_root: build +# :release_build: TRUE + :test_file_prefix: test_ + :which_ceedling: gem + :ceedling_version: 0.31.1 + :default_tasks: + - test:all + +#:test_build: +# :use_assembly: TRUE + +#:release_build: +# :output: MyApp.out +# :use_assembly: FALSE + +:environment: + +:extension: + :executable: .out + +:paths: + :test: + - +:tests/** + - -:tests/support + :source: + - src/** + :support: + - tests/support + :libraries: [] + +:defines: + # in order to add common defines: + # 1) remove the trailing [] from the :common: section + # 2) add entries to the :common: section (e.g. :test: has TEST defined) + :common: &common_defines [] + :test: + - *common_defines + - TEST + :test_preprocess: + - *common_defines + - TEST + +:cmock: + :mock_prefix: mock_ + :when_no_prototypes: :warn + :enforce_strict_ordering: TRUE + :plugins: + - :ignore + - :callback + :treat_as: + uint8: HEX8 + uint16: HEX16 + uint32: UINT32 + int8: INT8 + bool: UINT8 + +# Add -gcov to the plugins list to make sure of the gcov plugin +# You will need to have gcov and gcovr both installed to make it work. +# For more information on these options, see docs in plugins/gcov +:gcov: + :reports: + - HtmlDetailed + :gcovr: + :html_medium_threshold: 75 + :html_high_threshold: 90 + +#:tools: +# Ceedling defaults to using gcc for compiling, linking, etc. +# As [:tools] is blank, gcc will be used (so long as it's in your system path) +# See documentation to configure a given toolchain for use + +# LIBRARIES +# These libraries are automatically injected into the build process. Those specified as +# common will be used in all types of builds. Otherwise, libraries can be injected in just +# tests or releases. These options are MERGED with the options in supplemental yaml files. +:libraries: + :placement: :end + :flag: "-l${1}" + :path_flag: "-L ${1}" + :system: [] # for example, you might list 'm' to grab the math library + :test: [] + :release: [] + +:plugins: + :load_paths: + - "#{Ceedling.load_path}" + :enabled: + - stdout_pretty_tests_report + - module_generator +... diff --git a/src/calculatorSubtract.c b/src/calculatorSubtract.c new file mode 100644 index 0000000..a2a54f6 --- /dev/null +++ b/src/calculatorSubtract.c @@ -0,0 +1,5 @@ +#include "calculatorSubtract.h" + +float calculatorSubtract(float x, float y){return x-y;} + + diff --git a/src/calculatorSubtract.h b/src/calculatorSubtract.h new file mode 100644 index 0000000..120b8b2 --- /dev/null +++ b/src/calculatorSubtract.h @@ -0,0 +1,11 @@ +#ifndef CALCULATORSUBTRACT_H +#define CALCULATORSUBTRACT_H + +#include +#include + +float calculatorSubtract(float x, float y); + + + +#endif // CALCULATORSUBTRACT_H diff --git a/src/main.c b/src/main.c index a3a8e04..f6b4482 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,20 @@ -#include -int main(){ -return 0; +#include "calculatorSubtract.c" + + +int main() +{ + float num1, num2, difference; + + printf("number1: "); + scanf("%f", &num1); + + printf("number2: "); + scanf("%f", &num2); + + difference = calculatorSubtract(num1, num2); + + printf("answer: %f", difference); + return 0; } + + diff --git a/tests/support/.gitkeep b/tests/support/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_calculatorSubtract.c b/tests/test_calculatorSubtract.c new file mode 100644 index 0000000..498d037 --- /dev/null +++ b/tests/test_calculatorSubtract.c @@ -0,0 +1,20 @@ +#ifdef TEST + +#include "unity.h" + +#include "calculatorSubtract.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_calculatorSubtract_NeedToImplement(void) +{ + TEST_IGNORE_MESSAGE("Need to Implement calculatorSubtract"); +} + +#endif // TEST From c19f56958b4b737cd0164a425ce1d39299c45b30 Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Thu, 9 Feb 2023 00:16:29 +0100 Subject: [PATCH 06/32] implement unittest for calculatorSubtract.c --- build-project.sh | 1 + tests/test_calculatorSubtract.c | 100 +++++++++++++++++++++++++++++++- 2 files changed, 99 insertions(+), 2 deletions(-) diff --git a/build-project.sh b/build-project.sh index 43a0588..51cf723 100755 --- a/build-project.sh +++ b/build-project.sh @@ -1,4 +1,5 @@ clear +ceedling test:all cd src/ gcc main.c -o main ./main diff --git a/tests/test_calculatorSubtract.c b/tests/test_calculatorSubtract.c index 498d037..abf9859 100644 --- a/tests/test_calculatorSubtract.c +++ b/tests/test_calculatorSubtract.c @@ -12,9 +12,105 @@ void tearDown(void) { } -void test_calculatorSubtract_NeedToImplement(void) + +void test1_calculatorSubtract(void) +{ + float p, q, a, e; + p = 123.211; + q = 112.21; + e = p - q; + a = calculatorSubtract(p, q); + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test2_calculatorSubtract(void) +{ + float p, q, a, e; + p = 13.21; + q = 112.21; + e = p - q; + a = calculatorSubtract(p, q); + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test3_calculatorSubtract(void) +{ + float p, q, a, e; + p = 12231.211; + q = 1122.21; + e = p - q; + a = calculatorSubtract(p, q); + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test4_calculatorSubtract(void) +{ + float p, q, a, e; + p = 113453.211; + q = 11254.21; + e = p - q; + a = calculatorSubtract(p, q); + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test5_calculatorSubtract(void) +{ + float p, q, a, e; + p = 12133.211; + q = 112.231; + e = p - q; + a = calculatorSubtract(p, q); + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test6_calculatorSubtract(void) +{ + float p, q, a, e; + p = 1133.201; + q = 11221.21; + e = p - q; + a = calculatorSubtract(p, q); + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test7_calculatorSubtract(void) +{ + float p, q, a, e; + p = 12213.2211; + q = 111.21; + e = p - q; + a = calculatorSubtract(p, q); + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test8_calculatorSubtract(void) +{ + float p, q, a, e; + p = 16213.711; + q = 1214.2251; + e = p - q; + a = calculatorSubtract(p, q); + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test9_calculatorSubtract(void) +{ + float p, q, a, e; + p = 1933.611; + q = 1432.21; + e = p - q; + a = calculatorSubtract(p, q); + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test10_calculatorSubtract(void) { - TEST_IGNORE_MESSAGE("Need to Implement calculatorSubtract"); + float p, q, a, e; + p = 1233.811; + q = 1121.131; + e = p - q; + a = calculatorSubtract(p, q); + TEST_ASSERT_EQUAL_FLOAT(e, a); } #endif // TEST From 9e0d1cece91a28d2a780381d9b472c1283a04264 Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Sun, 5 Feb 2023 23:23:02 +0100 Subject: [PATCH 07/32] refactoring: change variable names and format code in calculatorSubtract.c and calculatorSubtract.h --- src/calculatorSubtract.c | 9 ++++++++- src/calculatorSubtract.h | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/calculatorSubtract.c b/src/calculatorSubtract.c index a2a54f6..d460458 100644 --- a/src/calculatorSubtract.c +++ b/src/calculatorSubtract.c @@ -1,5 +1,12 @@ #include "calculatorSubtract.h" -float calculatorSubtract(float x, float y){return x-y;} +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + +float calculatorSubtract (float num1, float num2) +{ + return num1 - num2; +} diff --git a/src/calculatorSubtract.h b/src/calculatorSubtract.h index 120b8b2..156eaa9 100644 --- a/src/calculatorSubtract.h +++ b/src/calculatorSubtract.h @@ -4,7 +4,7 @@ #include #include -float calculatorSubtract(float x, float y); +float calculatorSubtract(float num1, float num2); From 6be626e2352b07d9d8068508772c0ce18c47e026 Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Sun, 5 Feb 2023 23:40:03 +0100 Subject: [PATCH 08/32] refactoring: change variable names in test_calculatorSubtract.c --- tests/test_calculatorSubtract.c | 125 +++++++++++++++++--------------- 1 file changed, 65 insertions(+), 60 deletions(-) diff --git a/tests/test_calculatorSubtract.c b/tests/test_calculatorSubtract.c index abf9859..e898b7b 100644 --- a/tests/test_calculatorSubtract.c +++ b/tests/test_calculatorSubtract.c @@ -4,6 +4,11 @@ #include "calculatorSubtract.h" +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + + void setUp(void) { } @@ -15,102 +20,102 @@ void tearDown(void) void test1_calculatorSubtract(void) { - float p, q, a, e; - p = 123.211; - q = 112.21; - e = p - q; - a = calculatorSubtract(p, q); - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual, expected; //Arrange + num1 = 123.211; + num2 = 112.21; + expected = num1 - num2; + actual = calculatorSubtract(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test2_calculatorSubtract(void) { - float p, q, a, e; - p = 13.21; - q = 112.21; - e = p - q; - a = calculatorSubtract(p, q); - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual, expected; //Arrange + num1 = 13.21; + num2 = 112.21; + expected = num1 - num2; + actual = calculatorSubtract(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test3_calculatorSubtract(void) { - float p, q, a, e; - p = 12231.211; - q = 1122.21; - e = p - q; - a = calculatorSubtract(p, q); - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual, expected; //Arrange + num1 = 12231.211; + num2 = 1122.21; + expected = num1 - num2; + actual = calculatorSubtract(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test4_calculatorSubtract(void) { - float p, q, a, e; - p = 113453.211; - q = 11254.21; - e = p - q; - a = calculatorSubtract(p, q); - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual, expected; //Arrange + num1 = 113453.211; + num2 = 11254.21; + expected = num1 - num2; + actual = calculatorSubtract(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test5_calculatorSubtract(void) { - float p, q, a, e; - p = 12133.211; - q = 112.231; - e = p - q; - a = calculatorSubtract(p, q); - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual, expected; //Arrange + num1 = 12133.211; + num2 = 112.231; + expected = num1 - num2; + actual = calculatorSubtract(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test6_calculatorSubtract(void) { - float p, q, a, e; - p = 1133.201; - q = 11221.21; - e = p - q; - a = calculatorSubtract(p, q); - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual, expected; //Arrange + num1 = 1133.201; + num2 = 11221.21; + expected = num1 - num2; + actual = calculatorSubtract(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test7_calculatorSubtract(void) { - float p, q, a, e; - p = 12213.2211; - q = 111.21; - e = p - q; - a = calculatorSubtract(p, q); - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual, expected; //Arrange + num1 = 12213.2211; + num2 = 111.21; + expected = num1 - num2; + actual = calculatorSubtract(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test8_calculatorSubtract(void) { - float p, q, a, e; - p = 16213.711; - q = 1214.2251; - e = p - q; - a = calculatorSubtract(p, q); - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual, expected; //Arrange + num1 = 16213.711; + num2 = 1214.2251; + expected = num1 - num2; + actual = calculatorSubtract(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test9_calculatorSubtract(void) { - float p, q, a, e; - p = 1933.611; - q = 1432.21; - e = p - q; - a = calculatorSubtract(p, q); - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual, expected; //Arrange + num1 = 1933.611; + num2 = 1432.21; + expected = num1 - num2; + actual = calculatorSubtract(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test10_calculatorSubtract(void) { - float p, q, a, e; - p = 1233.811; - q = 1121.131; - e = p - q; - a = calculatorSubtract(p, q); - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual, expected; //Arrange + num1 = 1233.811; + num2 = 1121.131; + expected = num1 - num2; + actual = calculatorSubtract(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } #endif // TEST From 5416031d06c2fc272be6fbbcc3f7184f456052d2 Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Thu, 9 Feb 2023 00:27:13 +0100 Subject: [PATCH 09/32] implement function calculatorMultiply() --- project.yml | 101 ++++++++++++++++++++++++++++++++ src/calculatorMultiply.c | 2 + src/calculatorMultiply.h | 9 +++ src/main.c | 21 ++++++- tests/support/.gitkeep | 0 tests/test_calculatorMultiply.c | 20 +++++++ 6 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 project.yml create mode 100644 src/calculatorMultiply.c create mode 100644 src/calculatorMultiply.h create mode 100644 tests/support/.gitkeep create mode 100644 tests/test_calculatorMultiply.c diff --git a/project.yml b/project.yml new file mode 100644 index 0000000..640cb8f --- /dev/null +++ b/project.yml @@ -0,0 +1,101 @@ +--- + +# Notes: +# Sample project C code is not presently written to produce a release artifact. +# As such, release build options are disabled. +# This sample, therefore, only demonstrates running a collection of unit tests. + +:project: + :use_exceptions: FALSE + :use_test_preprocessor: TRUE + :use_auxiliary_dependencies: TRUE + :build_root: build +# :release_build: TRUE + :test_file_prefix: test_ + :which_ceedling: gem + :ceedling_version: 0.31.1 + :default_tasks: + - test:all + +#:test_build: +# :use_assembly: TRUE + +#:release_build: +# :output: MyApp.out +# :use_assembly: FALSE + +:environment: + +:extension: + :executable: .out + +:paths: + :test: + - +:tests/** + - -:tests/support + :source: + - src/** + :support: + - tests/support + :libraries: [] + +:defines: + # in order to add common defines: + # 1) remove the trailing [] from the :common: section + # 2) add entries to the :common: section (e.g. :test: has TEST defined) + :common: &common_defines [] + :test: + - *common_defines + - TEST + :test_preprocess: + - *common_defines + - TEST + +:cmock: + :mock_prefix: mock_ + :when_no_prototypes: :warn + :enforce_strict_ordering: TRUE + :plugins: + - :ignore + - :callback + :treat_as: + uint8: HEX8 + uint16: HEX16 + uint32: UINT32 + int8: INT8 + bool: UINT8 + +# Add -gcov to the plugins list to make sure of the gcov plugin +# You will need to have gcov and gcovr both installed to make it work. +# For more information on these options, see docs in plugins/gcov +:gcov: + :reports: + - HtmlDetailed + :gcovr: + :html_medium_threshold: 75 + :html_high_threshold: 90 + +#:tools: +# Ceedling defaults to using gcc for compiling, linking, etc. +# As [:tools] is blank, gcc will be used (so long as it's in your system path) +# See documentation to configure a given toolchain for use + +# LIBRARIES +# These libraries are automatically injected into the build process. Those specified as +# common will be used in all types of builds. Otherwise, libraries can be injected in just +# tests or releases. These options are MERGED with the options in supplemental yaml files. +:libraries: + :placement: :end + :flag: "-l${1}" + :path_flag: "-L ${1}" + :system: [] # for example, you might list 'm' to grab the math library + :test: [] + :release: [] + +:plugins: + :load_paths: + - "#{Ceedling.load_path}" + :enabled: + - stdout_pretty_tests_report + - module_generator +... diff --git a/src/calculatorMultiply.c b/src/calculatorMultiply.c new file mode 100644 index 0000000..df3f401 --- /dev/null +++ b/src/calculatorMultiply.c @@ -0,0 +1,2 @@ +#include "calculatorMultiply.h" +float calculatorMultiply(float x, float y){return x*y;} diff --git a/src/calculatorMultiply.h b/src/calculatorMultiply.h new file mode 100644 index 0000000..8641b05 --- /dev/null +++ b/src/calculatorMultiply.h @@ -0,0 +1,9 @@ +#ifndef CALCULATORMULTIPLY_H +#define CALCULATORMULTIPLY_H +#include +#include +float calculatorMultiply(float x, float y); + + + +#endif // CALCULATORMULTIPLY_H diff --git a/src/main.c b/src/main.c index a3a8e04..01a278f 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,19 @@ -#include -int main(){ -return 0; +#include "calculatorMultiply.c" + + +int main() +{ + float num1, num2, produkt; + + printf("number1: "); + scanf("%f", &num1); + + printf("number2: "); + scanf("%f", &num2); + + produkt = calculatorMultiply(num1, num2); + + printf("answer: %f", produkt); + return 0; } + diff --git a/tests/support/.gitkeep b/tests/support/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_calculatorMultiply.c b/tests/test_calculatorMultiply.c new file mode 100644 index 0000000..5768561 --- /dev/null +++ b/tests/test_calculatorMultiply.c @@ -0,0 +1,20 @@ +#ifdef TEST + +#include "unity.h" + +#include "calculatorMultiply.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_calculatorMultiply_NeedToImplement(void) +{ + TEST_IGNORE_MESSAGE("Need to Implement calculatorMultiply"); +} + +#endif // TEST From da0dd52871db84df0b44b429affcaa39308a8b07 Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Thu, 9 Feb 2023 00:29:25 +0100 Subject: [PATCH 10/32] implement unittest for calculatorMultiply.c --- build-project.sh | 1 + tests/test_calculatorMultiply.c | 99 ++++++++++++++++++++++++++++++++- 2 files changed, 98 insertions(+), 2 deletions(-) diff --git a/build-project.sh b/build-project.sh index 43a0588..51cf723 100755 --- a/build-project.sh +++ b/build-project.sh @@ -1,4 +1,5 @@ clear +ceedling test:all cd src/ gcc main.c -o main ./main diff --git a/tests/test_calculatorMultiply.c b/tests/test_calculatorMultiply.c index 5768561..359fe6b 100644 --- a/tests/test_calculatorMultiply.c +++ b/tests/test_calculatorMultiply.c @@ -12,9 +12,104 @@ void tearDown(void) { } -void test_calculatorMultiply_NeedToImplement(void) +void test1_calculatorMultiply(void) { - TEST_IGNORE_MESSAGE("Need to Implement calculatorMultiply"); + float p, q, a, e; + p = 26.24; + q = 23.22; + a = calculatorMultiply(p, q); + e = p * q; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test2_calculatorMultiply(void) +{ + float p, q, a, e; + p = 56.24; + q = 233.22; + a = calculatorMultiply(p, q); + e = p * q; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test3_calculatorMultiply(void) +{ + float p, q, a, e; + p = 1226.24; + q = 323.22; + a = calculatorMultiply(p, q); + e = p * q; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test4_calculatorMultiply(void) +{ + float p, q, a, e; + p = 2623.24; + q = 2323.22; + a = calculatorMultiply(p, q); + e = p * q; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test5_calculatorMultiply(void) +{ + float p, q, a, e; + p = 2435.24; + q = 23423.22; + a = calculatorMultiply(p, q); + e = p * q; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test6_calculatorMultiply(void) +{ + float p, q, a, e; + p = 4534.24; + q = 2221.22; + a = calculatorMultiply(p, q); + e = p * q; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test7_calculatorMultiply(void) +{ + float p, q, a, e; + p = 26322.24; + q = 2332.222; + a = calculatorMultiply(p, q); + e = p * q; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test8_calculatorMultiply(void) +{ + float p, q, a, e; + p = 26132.24; + q = 2331122.222; + a = calculatorMultiply(p, q); + e = p * q; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test9_calculatorMultiply(void) +{ + float p, q, a, e; + p = 6322.24; + q = 21232.2322; + a = calculatorMultiply(p, q); + e = p * q; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test10_calculatorMultiply(void) +{ + float p, q, a, e; + p = 1234.456; + q = 654.4321; + a = calculatorMultiply(p, q); + e = p * q; + TEST_ASSERT_EQUAL_FLOAT(e, a); } #endif // TEST From c14d061ac40d5ba6e059062bd428c56e9250ae5a Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Mon, 6 Feb 2023 19:51:32 +0100 Subject: [PATCH 11/32] refactoring: change variable names and format code in calculatorMultiply.c --- src/calculatorMultiply.c | 10 +++++++++- src/calculatorMultiply.h | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/calculatorMultiply.c b/src/calculatorMultiply.c index df3f401..42e1763 100644 --- a/src/calculatorMultiply.c +++ b/src/calculatorMultiply.c @@ -1,2 +1,10 @@ #include "calculatorMultiply.h" -float calculatorMultiply(float x, float y){return x*y;} +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + +float calculatorMultiply(float num1, float num2) +{ + return num1 * num2; +} + diff --git a/src/calculatorMultiply.h b/src/calculatorMultiply.h index 8641b05..569b389 100644 --- a/src/calculatorMultiply.h +++ b/src/calculatorMultiply.h @@ -2,7 +2,7 @@ #define CALCULATORMULTIPLY_H #include #include -float calculatorMultiply(float x, float y); +float calculatorMultiply(float num1, float num2); From 8192d8e234f90984b8ab7ce48a664cd12adc5e4b Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Mon, 6 Feb 2023 19:57:42 +0100 Subject: [PATCH 12/32] refactoring: change variable names in test_calculatorMultiply.c --- tests/test_calculatorMultiply.c | 125 +++++++++++++++++--------------- 1 file changed, 65 insertions(+), 60 deletions(-) diff --git a/tests/test_calculatorMultiply.c b/tests/test_calculatorMultiply.c index 359fe6b..64f1b78 100644 --- a/tests/test_calculatorMultiply.c +++ b/tests/test_calculatorMultiply.c @@ -4,6 +4,11 @@ #include "calculatorMultiply.h" +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + + void setUp(void) { } @@ -14,102 +19,102 @@ void tearDown(void) void test1_calculatorMultiply(void) { - float p, q, a, e; - p = 26.24; - q = 23.22; - a = calculatorMultiply(p, q); - e = p * q; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual ,expected; //Arrange + num1 = 26.24; + num2 = 23.22; + expected = num1 * num2; + actual = calculatorMultiply(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test2_calculatorMultiply(void) { - float p, q, a, e; - p = 56.24; - q = 233.22; - a = calculatorMultiply(p, q); - e = p * q; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual ,expected; //Arrange + num1 = 56.24; + num2 = 233.22; + expected = num1 * num2; + actual = calculatorMultiply(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test3_calculatorMultiply(void) { - float p, q, a, e; - p = 1226.24; - q = 323.22; - a = calculatorMultiply(p, q); - e = p * q; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual ,expected; //Arrange + num1 = 1226.24; + num2 = 323.22; + expected = num1 * num2; + actual = calculatorMultiply(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test4_calculatorMultiply(void) { - float p, q, a, e; - p = 2623.24; - q = 2323.22; - a = calculatorMultiply(p, q); - e = p * q; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual ,expected; //Arrange + num1 = 2623.24; + num2 = 2323.22; + expected = num1 * num2; + actual = calculatorMultiply(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test5_calculatorMultiply(void) { - float p, q, a, e; - p = 2435.24; - q = 23423.22; - a = calculatorMultiply(p, q); - e = p * q; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual ,expected; //Arrange + num1 = 2435.24; + num2 = 23423.22; + expected = num1 * num2; + actual = calculatorMultiply(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test6_calculatorMultiply(void) { - float p, q, a, e; - p = 4534.24; - q = 2221.22; - a = calculatorMultiply(p, q); - e = p * q; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual ,expected; //Arrange + num1 = 4534.24; + num2 = 2221.22; + expected = num1 * num2; + actual = calculatorMultiply(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test7_calculatorMultiply(void) { - float p, q, a, e; - p = 26322.24; - q = 2332.222; - a = calculatorMultiply(p, q); - e = p * q; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual ,expected; //Arrange + num1 = 26322.24; + num2 = 2332.222; + expected = num1 * num2; + actual = calculatorMultiply(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test8_calculatorMultiply(void) { - float p, q, a, e; - p = 26132.24; - q = 2331122.222; - a = calculatorMultiply(p, q); - e = p * q; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual ,expected; //Arrange + num1 = 26132.24; + num2 = 2331122.222; + expected = num1 * num2; + actual = calculatorMultiply(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test9_calculatorMultiply(void) { - float p, q, a, e; - p = 6322.24; - q = 21232.2322; - a = calculatorMultiply(p, q); - e = p * q; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual ,expected; //Arrange + num1 = 6322.24; + num2 = 21232.2322; + expected = num1 * num2; + actual = calculatorMultiply(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test10_calculatorMultiply(void) { - float p, q, a, e; - p = 1234.456; - q = 654.4321; - a = calculatorMultiply(p, q); - e = p * q; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual ,expected; //Arrange + num1 = 1234.456; + num2 = 654.4321; + expected = num1 * num2; + actual = calculatorMultiply(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } #endif // TEST From 70bccf002ca53a83cbe6a1e741c709d8eec84d26 Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Thu, 9 Feb 2023 00:50:02 +0100 Subject: [PATCH 13/32] implement function calculatorDivide() --- project.yml | 101 ++++++++++++++++++++++++++++++++++ src/calculatorDivide.c | 2 + src/calculatorDivide.h | 8 +++ src/main.c | 19 ++++++- tests/support/.gitkeep | 0 tests/test_calculatorDivide.c | 20 +++++++ 6 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 project.yml create mode 100644 src/calculatorDivide.c create mode 100644 src/calculatorDivide.h create mode 100644 tests/support/.gitkeep create mode 100644 tests/test_calculatorDivide.c diff --git a/project.yml b/project.yml new file mode 100644 index 0000000..640cb8f --- /dev/null +++ b/project.yml @@ -0,0 +1,101 @@ +--- + +# Notes: +# Sample project C code is not presently written to produce a release artifact. +# As such, release build options are disabled. +# This sample, therefore, only demonstrates running a collection of unit tests. + +:project: + :use_exceptions: FALSE + :use_test_preprocessor: TRUE + :use_auxiliary_dependencies: TRUE + :build_root: build +# :release_build: TRUE + :test_file_prefix: test_ + :which_ceedling: gem + :ceedling_version: 0.31.1 + :default_tasks: + - test:all + +#:test_build: +# :use_assembly: TRUE + +#:release_build: +# :output: MyApp.out +# :use_assembly: FALSE + +:environment: + +:extension: + :executable: .out + +:paths: + :test: + - +:tests/** + - -:tests/support + :source: + - src/** + :support: + - tests/support + :libraries: [] + +:defines: + # in order to add common defines: + # 1) remove the trailing [] from the :common: section + # 2) add entries to the :common: section (e.g. :test: has TEST defined) + :common: &common_defines [] + :test: + - *common_defines + - TEST + :test_preprocess: + - *common_defines + - TEST + +:cmock: + :mock_prefix: mock_ + :when_no_prototypes: :warn + :enforce_strict_ordering: TRUE + :plugins: + - :ignore + - :callback + :treat_as: + uint8: HEX8 + uint16: HEX16 + uint32: UINT32 + int8: INT8 + bool: UINT8 + +# Add -gcov to the plugins list to make sure of the gcov plugin +# You will need to have gcov and gcovr both installed to make it work. +# For more information on these options, see docs in plugins/gcov +:gcov: + :reports: + - HtmlDetailed + :gcovr: + :html_medium_threshold: 75 + :html_high_threshold: 90 + +#:tools: +# Ceedling defaults to using gcc for compiling, linking, etc. +# As [:tools] is blank, gcc will be used (so long as it's in your system path) +# See documentation to configure a given toolchain for use + +# LIBRARIES +# These libraries are automatically injected into the build process. Those specified as +# common will be used in all types of builds. Otherwise, libraries can be injected in just +# tests or releases. These options are MERGED with the options in supplemental yaml files. +:libraries: + :placement: :end + :flag: "-l${1}" + :path_flag: "-L ${1}" + :system: [] # for example, you might list 'm' to grab the math library + :test: [] + :release: [] + +:plugins: + :load_paths: + - "#{Ceedling.load_path}" + :enabled: + - stdout_pretty_tests_report + - module_generator +... diff --git a/src/calculatorDivide.c b/src/calculatorDivide.c new file mode 100644 index 0000000..c6abdcf --- /dev/null +++ b/src/calculatorDivide.c @@ -0,0 +1,2 @@ +#include "calculatorDivide.h" +float calculatorDivide(float x, float y){return x/y;} diff --git a/src/calculatorDivide.h b/src/calculatorDivide.h new file mode 100644 index 0000000..e33d7ef --- /dev/null +++ b/src/calculatorDivide.h @@ -0,0 +1,8 @@ +#ifndef CALCULATORDIVIDE_H +#define CALCULATORDIVIDE_H +#include +#include +float calculatorDivide(float x, float y); + + +#endif // CALCULATORDIVIDE_H diff --git a/src/main.c b/src/main.c index a3a8e04..72023c8 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,17 @@ -#include -int main(){ -return 0; +#include "calculatorDivide.c" +int main() +{ + float num1, num2, quotient; + + printf("number1: "); + scanf("%f", &num1); + + printf("number2: "); + scanf("%f", &num2); + + quotient = calculatorDivide(num1, num2); + + printf("answer: %f", quotient); + return 0; } + diff --git a/tests/support/.gitkeep b/tests/support/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_calculatorDivide.c b/tests/test_calculatorDivide.c new file mode 100644 index 0000000..d18118f --- /dev/null +++ b/tests/test_calculatorDivide.c @@ -0,0 +1,20 @@ +#ifdef TEST + +#include "unity.h" + +#include "calculatorDivide.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_calculatorDivide_NeedToImplement(void) +{ + TEST_IGNORE_MESSAGE("Need to Implement calculatorDivide"); +} + +#endif // TEST From b0acd83da21a082c4ca8fdab32f497dec77deac7 Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Thu, 9 Feb 2023 00:51:50 +0100 Subject: [PATCH 14/32] implement unittest for calculatorDivide.c --- build-project.sh | 1 + tests/test_calculatorDivide.c | 100 +++++++++++++++++++++++++++++++++- 2 files changed, 99 insertions(+), 2 deletions(-) diff --git a/build-project.sh b/build-project.sh index 43a0588..51cf723 100755 --- a/build-project.sh +++ b/build-project.sh @@ -1,4 +1,5 @@ clear +ceedling test:all cd src/ gcc main.c -o main ./main diff --git a/tests/test_calculatorDivide.c b/tests/test_calculatorDivide.c index d18118f..1894d0b 100644 --- a/tests/test_calculatorDivide.c +++ b/tests/test_calculatorDivide.c @@ -12,9 +12,105 @@ void tearDown(void) { } -void test_calculatorDivide_NeedToImplement(void) +void test1_calculatorDivide(void) { - TEST_IGNORE_MESSAGE("Need to Implement calculatorDivide"); + float p, q, a, e; + p = 26.24; + q = 23.22; + a = calculatorDivide(p, q); + e = p/q; + TEST_ASSERT_EQUAL_FLOAT(e, a); } +void test2_calculatorDivide(void) +{ + float p, q, a, e; + p = 2236.24; + q = 2123.22; + a = calculatorDivide(p, q); + e = p/q; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test3_calculatorDivide(void) +{ + float p, q, a, e; + p = 623.2; + q = 23.22; + a = calculatorDivide(p, q); + e = p/q; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test4_calculatorDivide(void) +{ + float p, q, a, e; + p = 234.7; + q = 124.2; + a = calculatorDivide(p, q); + e = p/q; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test5_calculatorDivide(void) +{ + float p, q, a, e; + p = 26207.2; + q = 278.23; + a = calculatorDivide(p, q); + e = p/q; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test6_calculatorDivide(void) +{ + float p, q, a, e; + p = 111; + q = 21; + a = calculatorDivide(p, q); + e = p/q; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test7_calculatorDivide(void) +{ + float p, q, a, e; + p = 167; + q = 23.22; + a = calculatorDivide(p, q); + e = p/q; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test8_calculatorDivide(void) +{ + float p, q, a, e; + p = 26124; + q = 23022; + a = calculatorDivide(p, q); + e = p/q; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test9_calculatorDivide(void) +{ + float p, q, a, e; + p = 1234; + q = 4321; + a = calculatorDivide(p, q); + e = p/q; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + +void test10_calculatorDivide(void) +{ + float p, q, a, e; + p = 2345; + q = 123.7; + a = calculatorDivide(p, q); + e = p/q; + TEST_ASSERT_EQUAL_FLOAT(e, a); +} + + #endif // TEST From a9cda3ff44d238c88e7705b561407e590855b304 Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Mon, 6 Feb 2023 20:15:10 +0100 Subject: [PATCH 15/32] refactoring: change variable names and format code in calculatorDivide.c --- src/calculatorDivide.c | 11 ++++++++++- src/calculatorDivide.h | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/calculatorDivide.c b/src/calculatorDivide.c index c6abdcf..86e0a5c 100644 --- a/src/calculatorDivide.c +++ b/src/calculatorDivide.c @@ -1,2 +1,11 @@ #include "calculatorDivide.h" -float calculatorDivide(float x, float y){return x/y;} +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + + +float calculatorDivide(float num1, float num2) +{ + return num1 / num2; +} + diff --git a/src/calculatorDivide.h b/src/calculatorDivide.h index e33d7ef..18c242e 100644 --- a/src/calculatorDivide.h +++ b/src/calculatorDivide.h @@ -2,7 +2,7 @@ #define CALCULATORDIVIDE_H #include #include -float calculatorDivide(float x, float y); +float calculatorDivide(float num1, float num2); #endif // CALCULATORDIVIDE_H From a975931afbf773dfa4bf66fdf9bb9dbf8e16f992 Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Mon, 6 Feb 2023 20:22:00 +0100 Subject: [PATCH 16/32] refactoring: change variable names in test_calculatorDivide.c --- tests/test_calculatorDivide.c | 126 ++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 60 deletions(-) diff --git a/tests/test_calculatorDivide.c b/tests/test_calculatorDivide.c index 1894d0b..dca5c49 100644 --- a/tests/test_calculatorDivide.c +++ b/tests/test_calculatorDivide.c @@ -4,6 +4,11 @@ #include "calculatorDivide.h" +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + + void setUp(void) { } @@ -14,103 +19,104 @@ void tearDown(void) void test1_calculatorDivide(void) { - float p, q, a, e; - p = 26.24; - q = 23.22; - a = calculatorDivide(p, q); - e = p/q; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual, expected; //Arrange + num1 = 26.24; + num2 = 23.22; + expected = num1 / num2; + actual = calculatorDivide(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test2_calculatorDivide(void) { - float p, q, a, e; - p = 2236.24; - q = 2123.22; - a = calculatorDivide(p, q); - e = p/q; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual, expected; //Arrange + num1 = 2236.24; + num2 = 2123.22; + expected = num1 / num2; + actual = calculatorDivide(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test3_calculatorDivide(void) { - float p, q, a, e; - p = 623.2; - q = 23.22; - a = calculatorDivide(p, q); - e = p/q; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual, expected; //Arrange + num1 = 623.2; + num2 = 23.22; + expected = num1 / num2; + actual = calculatorDivide(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test4_calculatorDivide(void) { - float p, q, a, e; - p = 234.7; - q = 124.2; - a = calculatorDivide(p, q); - e = p/q; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual, expected; //Arrange + num1 = 234.7; + num2 = 124.2; + expected = num1 / num2; + actual = calculatorDivide(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test5_calculatorDivide(void) { - float p, q, a, e; - p = 26207.2; - q = 278.23; - a = calculatorDivide(p, q); - e = p/q; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual, expected; //Arrange + num1 = 26207.2; + num2 = 278.23; + expected = num1 / num2; + actual = calculatorDivide(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test6_calculatorDivide(void) { - float p, q, a, e; - p = 111; - q = 21; - a = calculatorDivide(p, q); - e = p/q; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual, expected; //Arrange + num1 = 111; + num2 = 21; + expected = num1 / num2; + actual = calculatorDivide(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test7_calculatorDivide(void) { - float p, q, a, e; - p = 167; - q = 23.22; - a = calculatorDivide(p, q); - e = p/q; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual, expected; //Arrange + num1 = 167; + num2 = 23.22; + expected = num1 / num2; + actual = calculatorDivide(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test8_calculatorDivide(void) { - float p, q, a, e; - p = 26124; - q = 23022; - a = calculatorDivide(p, q); - e = p/q; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual, expected; //Arrange + num1 = 26124; + num2 = 23022; + expected = num1 / num2; + actual = calculatorDivide(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test9_calculatorDivide(void) { - float p, q, a, e; - p = 1234; - q = 4321; - a = calculatorDivide(p, q); - e = p/q; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual, expected; //Arrange + num1 = 1234; + num2 = 4321; + expected = num1 / num2; + actual = calculatorDivide(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } void test10_calculatorDivide(void) { - float p, q, a, e; - p = 2345; - q = 123.7; - a = calculatorDivide(p, q); - e = p/q; - TEST_ASSERT_EQUAL_FLOAT(e, a); + float num1, num2, actual, expected; //Arrange + num1 = 2345; + num2 = 123.7; + expected = num1 / num2; + actual = calculatorDivide(num1, num2); //Act + TEST_ASSERT_EQUAL_FLOAT(expected, actual); //Assert } + #endif // TEST From e13793bb20caeab7e29eb4b42ae21bd59d06a1e7 Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Thu, 9 Feb 2023 01:08:20 +0100 Subject: [PATCH 17/32] implement function calculatorFactorial() --- project.yml | 101 +++++++++++++++++++++++++++++++ src/calculatorFactorial.c | 6 ++ src/calculatorFactorial.h | 8 +++ src/main.c | 16 ++++- tests/support/.gitkeep | 0 tests/test_calculatorFactorial.c | 20 ++++++ 6 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 project.yml create mode 100644 src/calculatorFactorial.c create mode 100644 src/calculatorFactorial.h create mode 100644 tests/support/.gitkeep create mode 100644 tests/test_calculatorFactorial.c diff --git a/project.yml b/project.yml new file mode 100644 index 0000000..640cb8f --- /dev/null +++ b/project.yml @@ -0,0 +1,101 @@ +--- + +# Notes: +# Sample project C code is not presently written to produce a release artifact. +# As such, release build options are disabled. +# This sample, therefore, only demonstrates running a collection of unit tests. + +:project: + :use_exceptions: FALSE + :use_test_preprocessor: TRUE + :use_auxiliary_dependencies: TRUE + :build_root: build +# :release_build: TRUE + :test_file_prefix: test_ + :which_ceedling: gem + :ceedling_version: 0.31.1 + :default_tasks: + - test:all + +#:test_build: +# :use_assembly: TRUE + +#:release_build: +# :output: MyApp.out +# :use_assembly: FALSE + +:environment: + +:extension: + :executable: .out + +:paths: + :test: + - +:tests/** + - -:tests/support + :source: + - src/** + :support: + - tests/support + :libraries: [] + +:defines: + # in order to add common defines: + # 1) remove the trailing [] from the :common: section + # 2) add entries to the :common: section (e.g. :test: has TEST defined) + :common: &common_defines [] + :test: + - *common_defines + - TEST + :test_preprocess: + - *common_defines + - TEST + +:cmock: + :mock_prefix: mock_ + :when_no_prototypes: :warn + :enforce_strict_ordering: TRUE + :plugins: + - :ignore + - :callback + :treat_as: + uint8: HEX8 + uint16: HEX16 + uint32: UINT32 + int8: INT8 + bool: UINT8 + +# Add -gcov to the plugins list to make sure of the gcov plugin +# You will need to have gcov and gcovr both installed to make it work. +# For more information on these options, see docs in plugins/gcov +:gcov: + :reports: + - HtmlDetailed + :gcovr: + :html_medium_threshold: 75 + :html_high_threshold: 90 + +#:tools: +# Ceedling defaults to using gcc for compiling, linking, etc. +# As [:tools] is blank, gcc will be used (so long as it's in your system path) +# See documentation to configure a given toolchain for use + +# LIBRARIES +# These libraries are automatically injected into the build process. Those specified as +# common will be used in all types of builds. Otherwise, libraries can be injected in just +# tests or releases. These options are MERGED with the options in supplemental yaml files. +:libraries: + :placement: :end + :flag: "-l${1}" + :path_flag: "-L ${1}" + :system: [] # for example, you might list 'm' to grab the math library + :test: [] + :release: [] + +:plugins: + :load_paths: + - "#{Ceedling.load_path}" + :enabled: + - stdout_pretty_tests_report + - module_generator +... diff --git a/src/calculatorFactorial.c b/src/calculatorFactorial.c new file mode 100644 index 0000000..a86dcea --- /dev/null +++ b/src/calculatorFactorial.c @@ -0,0 +1,6 @@ +#include "calculatorFactorial.h" +int calculatorFactorial(int x) +{ + if (x==0)return 1; + else return x*calculatorFactorial(x-1); +} diff --git a/src/calculatorFactorial.h b/src/calculatorFactorial.h new file mode 100644 index 0000000..d6f0383 --- /dev/null +++ b/src/calculatorFactorial.h @@ -0,0 +1,8 @@ +#ifndef CALCULATORFACTORIAL_H +#define CALCULATORFACTORIAL_H + +#include +#include +int calculatorFactorial(int x); + +#endif // CALCULATORFACTORIAL_H diff --git a/src/main.c b/src/main.c index a3a8e04..5ec1b5b 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,14 @@ -#include -int main(){ -return 0; +#include "calculatorFactorial.c" +int main() +{ + int num, result; + + printf("number: "); + scanf("%d", &num); + + result = calculatorFactorial(num); + + printf("answer: %d", result); + return 0; } + diff --git a/tests/support/.gitkeep b/tests/support/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_calculatorFactorial.c b/tests/test_calculatorFactorial.c new file mode 100644 index 0000000..e2a176a --- /dev/null +++ b/tests/test_calculatorFactorial.c @@ -0,0 +1,20 @@ +#ifdef TEST + +#include "unity.h" + +#include "calculatorFactorial.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_calculatorFactorial_NeedToImplement(void) +{ + TEST_IGNORE_MESSAGE("Need to Implement calculatorFactorial"); +} + +#endif // TEST From 23472c84f49ac147a99de0b754f627490b22dc6e Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Thu, 9 Feb 2023 01:11:01 +0100 Subject: [PATCH 18/32] implement unittest for calculatorFactorial.c --- build-project.sh | 1 + tests/test_calculatorFactorial.c | 63 +++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/build-project.sh b/build-project.sh index 43a0588..51cf723 100755 --- a/build-project.sh +++ b/build-project.sh @@ -1,4 +1,5 @@ clear +ceedling test:all cd src/ gcc main.c -o main ./main diff --git a/tests/test_calculatorFactorial.c b/tests/test_calculatorFactorial.c index e2a176a..42af4ec 100644 --- a/tests/test_calculatorFactorial.c +++ b/tests/test_calculatorFactorial.c @@ -12,9 +12,68 @@ void tearDown(void) { } -void test_calculatorFactorial_NeedToImplement(void) +void test1_calculatorFactorial(void) { - TEST_IGNORE_MESSAGE("Need to Implement calculatorFactorial"); + int p, a, e; + p = 1; + e = 1; + a = calculatorFactorial(p); + TEST_ASSERT_EQUAL_INT(e, a); } +void test2_calculatorFactorial(void) +{ + int p, a, e; + p = 0; + e = 1; + a = calculatorFactorial(p); + TEST_ASSERT_EQUAL_INT(e, a); +} + +void test3_calculatorFactorial(void) +{ + int p, a, e; + p = 3; + e = 6; + a = calculatorFactorial(p); + TEST_ASSERT_EQUAL_INT(e, a); +} + +void test4_calculatorFactorial(void) +{ + int p, a, e; + p = 5; + e = 120; + a = calculatorFactorial(p); + TEST_ASSERT_EQUAL_INT(e, a); +} + +void test5_calculatorFactorial(void) +{ + int p, a, e; + p = 8; + e = 40320; + a = calculatorFactorial(p); + TEST_ASSERT_EQUAL_INT(e, a); +} + +void test6_calculatorFactorial(void) +{ + int p, a, e; + p = 11; + e = 39916800; + a = calculatorFactorial(p); + TEST_ASSERT_EQUAL_INT(e, a); +} + +void test7_calculatorFactorial(void) +{ + int p, a, e; + p = 10; + e = 3628800; + a = calculatorFactorial(p); + TEST_ASSERT_EQUAL_INT(e, a); +} + + #endif // TEST From 0c34fa9c5b5d972cf942fe26b8a36e58bc1de367 Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Mon, 6 Feb 2023 20:53:58 +0100 Subject: [PATCH 19/32] refactoring: change variable names, format code and attach some descriptive comments in calculatorFactorial.c --- src/calculatorFactorial.c | 13 ++++++++++--- src/calculatorFactorial.h | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/calculatorFactorial.c b/src/calculatorFactorial.c index a86dcea..fb1a228 100644 --- a/src/calculatorFactorial.c +++ b/src/calculatorFactorial.c @@ -1,6 +1,13 @@ #include "calculatorFactorial.h" -int calculatorFactorial(int x) +int calculatorFactorial(int num) //implement recursion. The function calls itself so many times, till the breaking condition is fulfilled. { - if (x==0)return 1; - else return x*calculatorFactorial(x-1); + if (num == 0) //breaking condition + { + return 1; + } + else + { + return num * calculatorFactorial(num - 1); //If its not breaking condition, then multiply the number with the same function implemented on the previous number. Eventually it will reach breaking condition. + } } + diff --git a/src/calculatorFactorial.h b/src/calculatorFactorial.h index d6f0383..5dbd323 100644 --- a/src/calculatorFactorial.h +++ b/src/calculatorFactorial.h @@ -3,6 +3,6 @@ #include #include -int calculatorFactorial(int x); +int calculatorFactorial(int num); #endif // CALCULATORFACTORIAL_H From 38cfd6baf1991d6bd2bde7d5b75c0b11b8d1e03f Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Mon, 6 Feb 2023 20:59:46 +0100 Subject: [PATCH 20/32] refactoring: change variable names in test_calculatorFactorial.c --- src/calculatorFactorial.c | 5 +++ tests/test_calculatorFactorial.c | 75 +++++++++++++++++--------------- 2 files changed, 45 insertions(+), 35 deletions(-) diff --git a/src/calculatorFactorial.c b/src/calculatorFactorial.c index fb1a228..e95fd11 100644 --- a/src/calculatorFactorial.c +++ b/src/calculatorFactorial.c @@ -1,4 +1,9 @@ #include "calculatorFactorial.h" +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + + int calculatorFactorial(int num) //implement recursion. The function calls itself so many times, till the breaking condition is fulfilled. { if (num == 0) //breaking condition diff --git a/tests/test_calculatorFactorial.c b/tests/test_calculatorFactorial.c index 42af4ec..624f9fe 100644 --- a/tests/test_calculatorFactorial.c +++ b/tests/test_calculatorFactorial.c @@ -4,6 +4,11 @@ #include "calculatorFactorial.h" +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + + void setUp(void) { } @@ -14,65 +19,65 @@ void tearDown(void) void test1_calculatorFactorial(void) { - int p, a, e; - p = 1; - e = 1; - a = calculatorFactorial(p); - TEST_ASSERT_EQUAL_INT(e, a); + int num, actual, expected; //Arrange + num = 1; + expected = 1; + actual = calculatorFactorial(num); //Act + TEST_ASSERT_EQUAL_INT(expected, actual); //Assert } void test2_calculatorFactorial(void) { - int p, a, e; - p = 0; - e = 1; - a = calculatorFactorial(p); - TEST_ASSERT_EQUAL_INT(e, a); + int num, actual, expected; //Arrange + num = 0; + expected = 1; + actual = calculatorFactorial(num); //Act + TEST_ASSERT_EQUAL_INT(expected, actual); //Assert } void test3_calculatorFactorial(void) { - int p, a, e; - p = 3; - e = 6; - a = calculatorFactorial(p); - TEST_ASSERT_EQUAL_INT(e, a); + int num, actual, expected; //Arrange + num = 3; + expected = 6; + actual = calculatorFactorial(num); //Act + TEST_ASSERT_EQUAL_INT(expected, actual); //Assert } void test4_calculatorFactorial(void) { - int p, a, e; - p = 5; - e = 120; - a = calculatorFactorial(p); - TEST_ASSERT_EQUAL_INT(e, a); + int num, actual, expected; //Arrange + num = 5; + expected = 120; + actual = calculatorFactorial(num); //Act + TEST_ASSERT_EQUAL_INT(expected, actual); //Assert } void test5_calculatorFactorial(void) { - int p, a, e; - p = 8; - e = 40320; - a = calculatorFactorial(p); - TEST_ASSERT_EQUAL_INT(e, a); + int num, actual, expected; //Arrange + num = 8; + expected = 40320; + actual = calculatorFactorial(num); //Act + TEST_ASSERT_EQUAL_INT(expected, actual); //Assert } void test6_calculatorFactorial(void) { - int p, a, e; - p = 11; - e = 39916800; - a = calculatorFactorial(p); - TEST_ASSERT_EQUAL_INT(e, a); + int num, actual, expected; //Arrange + num = 11; + expected = 39916800; + actual = calculatorFactorial(num); //Act + TEST_ASSERT_EQUAL_INT(expected, actual); //Assert } void test7_calculatorFactorial(void) { - int p, a, e; - p = 10; - e = 3628800; - a = calculatorFactorial(p); - TEST_ASSERT_EQUAL_INT(e, a); + int num, actual, expected; //Arrange + num = 10; + expected = 3628800; + actual = calculatorFactorial(num); //Act + TEST_ASSERT_EQUAL_INT(expected, actual); //Assert } From f80b84380dfc365f93112e03f48536693eda55ce Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Thu, 9 Feb 2023 01:22:39 +0100 Subject: [PATCH 21/32] implement function displayMenuCalculator() --- project.yml | 101 +++++++++++++++++++++++++++++ src/displayMenuCalculator.c | 24 +++++++ src/displayMenuCalculator.h | 10 +++ src/main.c | 7 +- tests/support/.gitkeep | 0 tests/test_displayMenuCalculator.c | 20 ++++++ 6 files changed, 159 insertions(+), 3 deletions(-) create mode 100644 project.yml create mode 100644 src/displayMenuCalculator.c create mode 100644 src/displayMenuCalculator.h create mode 100644 tests/support/.gitkeep create mode 100644 tests/test_displayMenuCalculator.c diff --git a/project.yml b/project.yml new file mode 100644 index 0000000..640cb8f --- /dev/null +++ b/project.yml @@ -0,0 +1,101 @@ +--- + +# Notes: +# Sample project C code is not presently written to produce a release artifact. +# As such, release build options are disabled. +# This sample, therefore, only demonstrates running a collection of unit tests. + +:project: + :use_exceptions: FALSE + :use_test_preprocessor: TRUE + :use_auxiliary_dependencies: TRUE + :build_root: build +# :release_build: TRUE + :test_file_prefix: test_ + :which_ceedling: gem + :ceedling_version: 0.31.1 + :default_tasks: + - test:all + +#:test_build: +# :use_assembly: TRUE + +#:release_build: +# :output: MyApp.out +# :use_assembly: FALSE + +:environment: + +:extension: + :executable: .out + +:paths: + :test: + - +:tests/** + - -:tests/support + :source: + - src/** + :support: + - tests/support + :libraries: [] + +:defines: + # in order to add common defines: + # 1) remove the trailing [] from the :common: section + # 2) add entries to the :common: section (e.g. :test: has TEST defined) + :common: &common_defines [] + :test: + - *common_defines + - TEST + :test_preprocess: + - *common_defines + - TEST + +:cmock: + :mock_prefix: mock_ + :when_no_prototypes: :warn + :enforce_strict_ordering: TRUE + :plugins: + - :ignore + - :callback + :treat_as: + uint8: HEX8 + uint16: HEX16 + uint32: UINT32 + int8: INT8 + bool: UINT8 + +# Add -gcov to the plugins list to make sure of the gcov plugin +# You will need to have gcov and gcovr both installed to make it work. +# For more information on these options, see docs in plugins/gcov +:gcov: + :reports: + - HtmlDetailed + :gcovr: + :html_medium_threshold: 75 + :html_high_threshold: 90 + +#:tools: +# Ceedling defaults to using gcc for compiling, linking, etc. +# As [:tools] is blank, gcc will be used (so long as it's in your system path) +# See documentation to configure a given toolchain for use + +# LIBRARIES +# These libraries are automatically injected into the build process. Those specified as +# common will be used in all types of builds. Otherwise, libraries can be injected in just +# tests or releases. These options are MERGED with the options in supplemental yaml files. +:libraries: + :placement: :end + :flag: "-l${1}" + :path_flag: "-L ${1}" + :system: [] # for example, you might list 'm' to grab the math library + :test: [] + :release: [] + +:plugins: + :load_paths: + - "#{Ceedling.load_path}" + :enabled: + - stdout_pretty_tests_report + - module_generator +... diff --git a/src/displayMenuCalculator.c b/src/displayMenuCalculator.c new file mode 100644 index 0000000..de2ad01 --- /dev/null +++ b/src/displayMenuCalculator.c @@ -0,0 +1,24 @@ +#include "displayMenuCalculator.h" +int check() +{ +if(a == 1) +{ +return 1; +} +} + +void displayMenuCalculator(char x) +{ +if(x == 'c') +{ +if(check() == 1) +{ +printf(" 1. Add\n"); +printf(" 2. Subtract\n"); +printf(" 3. Multiply\n"); +printf(" 4. Divide\n"); +printf(" 5. Factorial\n"); +} +} +} + diff --git a/src/displayMenuCalculator.h b/src/displayMenuCalculator.h new file mode 100644 index 0000000..6b13c2b --- /dev/null +++ b/src/displayMenuCalculator.h @@ -0,0 +1,10 @@ +#ifndef DISPLAYMENUCALCULATOR_H +#define DISPLAYMENUCALCULATOR_H + +#include +#include +int check(); +const int a = 1; +void displayMenuCalculator(char x); + +#endif // DISPLAYMENUCALCULATOR_H diff --git a/src/main.c b/src/main.c index a3a8e04..9a2a175 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,5 @@ -#include -int main(){ -return 0; +#include "displayMenuCalculator.c" +int main() +{ + displayMenuCalculator('c'); //Calculator Function activated with 'c' } diff --git a/tests/support/.gitkeep b/tests/support/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_displayMenuCalculator.c b/tests/test_displayMenuCalculator.c new file mode 100644 index 0000000..d6a51be --- /dev/null +++ b/tests/test_displayMenuCalculator.c @@ -0,0 +1,20 @@ +#ifdef TEST + +#include "unity.h" + +#include "displayMenuCalculator.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_displayMenuCalculator_NeedToImplement(void) +{ + TEST_IGNORE_MESSAGE("Need to Implement displayMenuCalculator"); +} + +#endif // TEST From de05d331e03171b9c8f82da1b6a82738078d3482 Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Thu, 9 Feb 2023 01:24:41 +0100 Subject: [PATCH 22/32] implement unittest for displayMenuCalculator.c --- build-project.sh | 1 + tests/test_displayMenuCalculator.c | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/build-project.sh b/build-project.sh index 43a0588..51cf723 100755 --- a/build-project.sh +++ b/build-project.sh @@ -1,4 +1,5 @@ clear +ceedling test:all cd src/ gcc main.c -o main ./main diff --git a/tests/test_displayMenuCalculator.c b/tests/test_displayMenuCalculator.c index d6a51be..66c2499 100644 --- a/tests/test_displayMenuCalculator.c +++ b/tests/test_displayMenuCalculator.c @@ -2,7 +2,7 @@ #include "unity.h" -#include "displayMenuCalculator.h" +#include "displayMenuCalculator.c" void setUp(void) { @@ -12,9 +12,13 @@ void tearDown(void) { } -void test_displayMenuCalculator_NeedToImplement(void) +void test_displayMenuCalculator(void) { - TEST_IGNORE_MESSAGE("Need to Implement displayMenuCalculator"); + int e, a; + e = 1; + a = check(); + TEST_ASSERT_EQUAL_INT(e, a); } + #endif // TEST From c4280af27cbe6b40f799168fc18b94409c7b6b5f Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Mon, 6 Feb 2023 22:27:23 +0100 Subject: [PATCH 23/32] refactoring: format the code by implementing new variables and important comments in displayMenuCalculator.c and displayMenuCalculator.h --- src/displayMenuCalculator.c | 37 ++++++++++++++++++++++--------------- src/displayMenuCalculator.h | 10 ++++++++-- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/displayMenuCalculator.c b/src/displayMenuCalculator.c index de2ad01..872c724 100644 --- a/src/displayMenuCalculator.c +++ b/src/displayMenuCalculator.c @@ -1,24 +1,31 @@ #include "displayMenuCalculator.h" + +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + int check() { -if(a == 1) -{ -return 1; -} + if(a == 1) + { + return 1; + } } + void displayMenuCalculator(char x) { -if(x == 'c') -{ -if(check() == 1) -{ -printf(" 1. Add\n"); -printf(" 2. Subtract\n"); -printf(" 3. Multiply\n"); -printf(" 4. Divide\n"); -printf(" 5. Factorial\n"); -} -} + if(x == 'c') + { + if(check() == 1) + { + printf(" %d. Add\n", operation1); + printf(" %d. Subtract\n", operation2); + printf(" %d. Multiply\n", operation3); + printf(" %d. Divide\n", operation4); + printf(" %d. Factorial\n", operation5); + } + } } + diff --git a/src/displayMenuCalculator.h b/src/displayMenuCalculator.h index 6b13c2b..1afbc55 100644 --- a/src/displayMenuCalculator.h +++ b/src/displayMenuCalculator.h @@ -3,8 +3,14 @@ #include #include -int check(); -const int a = 1; +int check(); //int check() is helpful for indirectly testing void displayMenuCalculator() +const int a = 1; // Variable for indirectly testing void displayMenuCalculator() void displayMenuCalculator(char x); +int operation1 = 1; +int operation2 = 2; +int operation3 = 3; +int operation4 = 4; +int operation5 = 5; + #endif // DISPLAYMENUCALCULATOR_H From 6f2fe2b994f6ff4e7c404849c55d289577214e5d Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Mon, 6 Feb 2023 22:30:36 +0100 Subject: [PATCH 24/32] refactoring: change variable names in test_displayMenuCalculator --- tests/test_displayMenuCalculator.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_displayMenuCalculator.c b/tests/test_displayMenuCalculator.c index 66c2499..665be20 100644 --- a/tests/test_displayMenuCalculator.c +++ b/tests/test_displayMenuCalculator.c @@ -14,10 +14,10 @@ void tearDown(void) void test_displayMenuCalculator(void) { - int e, a; - e = 1; - a = check(); - TEST_ASSERT_EQUAL_INT(e, a); + int expected, actual; //Arrange + expected = 1; + actual = check(); //Act + TEST_ASSERT_EQUAL_INT(expected, actual);//Assert } From 4c58ea605681d12cda339b2e88e398ae41b81ff1 Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Thu, 9 Feb 2023 01:38:17 +0100 Subject: [PATCH 25/32] implement function calculatorGetUserInput() --- project.yml | 101 ++++++++++++++++++++++++++++ src/calculatorGetUserInput.c | 20 ++++++ src/calculatorGetUserInput.h | 8 +++ src/main.c | 10 ++- tests/support/.gitkeep | 0 tests/test_calculatorGetUserInput.c | 20 ++++++ 6 files changed, 156 insertions(+), 3 deletions(-) create mode 100644 project.yml create mode 100644 src/calculatorGetUserInput.c create mode 100644 src/calculatorGetUserInput.h create mode 100644 tests/support/.gitkeep create mode 100644 tests/test_calculatorGetUserInput.c diff --git a/project.yml b/project.yml new file mode 100644 index 0000000..640cb8f --- /dev/null +++ b/project.yml @@ -0,0 +1,101 @@ +--- + +# Notes: +# Sample project C code is not presently written to produce a release artifact. +# As such, release build options are disabled. +# This sample, therefore, only demonstrates running a collection of unit tests. + +:project: + :use_exceptions: FALSE + :use_test_preprocessor: TRUE + :use_auxiliary_dependencies: TRUE + :build_root: build +# :release_build: TRUE + :test_file_prefix: test_ + :which_ceedling: gem + :ceedling_version: 0.31.1 + :default_tasks: + - test:all + +#:test_build: +# :use_assembly: TRUE + +#:release_build: +# :output: MyApp.out +# :use_assembly: FALSE + +:environment: + +:extension: + :executable: .out + +:paths: + :test: + - +:tests/** + - -:tests/support + :source: + - src/** + :support: + - tests/support + :libraries: [] + +:defines: + # in order to add common defines: + # 1) remove the trailing [] from the :common: section + # 2) add entries to the :common: section (e.g. :test: has TEST defined) + :common: &common_defines [] + :test: + - *common_defines + - TEST + :test_preprocess: + - *common_defines + - TEST + +:cmock: + :mock_prefix: mock_ + :when_no_prototypes: :warn + :enforce_strict_ordering: TRUE + :plugins: + - :ignore + - :callback + :treat_as: + uint8: HEX8 + uint16: HEX16 + uint32: UINT32 + int8: INT8 + bool: UINT8 + +# Add -gcov to the plugins list to make sure of the gcov plugin +# You will need to have gcov and gcovr both installed to make it work. +# For more information on these options, see docs in plugins/gcov +:gcov: + :reports: + - HtmlDetailed + :gcovr: + :html_medium_threshold: 75 + :html_high_threshold: 90 + +#:tools: +# Ceedling defaults to using gcc for compiling, linking, etc. +# As [:tools] is blank, gcc will be used (so long as it's in your system path) +# See documentation to configure a given toolchain for use + +# LIBRARIES +# These libraries are automatically injected into the build process. Those specified as +# common will be used in all types of builds. Otherwise, libraries can be injected in just +# tests or releases. These options are MERGED with the options in supplemental yaml files. +:libraries: + :placement: :end + :flag: "-l${1}" + :path_flag: "-L ${1}" + :system: [] # for example, you might list 'm' to grab the math library + :test: [] + :release: [] + +:plugins: + :load_paths: + - "#{Ceedling.load_path}" + :enabled: + - stdout_pretty_tests_report + - module_generator +... diff --git a/src/calculatorGetUserInput.c b/src/calculatorGetUserInput.c new file mode 100644 index 0000000..d38d0bb --- /dev/null +++ b/src/calculatorGetUserInput.c @@ -0,0 +1,20 @@ +#include "calculatorGetUserInput.h" + +int allowOnly() +{ + if( a == 1) + { + return 1; + } +} + +void calculatorGetUserInput(float *x, float *y) +{ + if (allowOnly() == 1) + { + printf("number1: "); + scanf("%f", x); + printf("number2: "); + scanf("%f", y); + } +} diff --git a/src/calculatorGetUserInput.h b/src/calculatorGetUserInput.h new file mode 100644 index 0000000..49e0b8c --- /dev/null +++ b/src/calculatorGetUserInput.h @@ -0,0 +1,8 @@ +#ifndef CALCULATORGETUSERINPUT_H +#define CALCULATORGETUSERINPUT_H +#include +#include +void calculatorGetUserInput(float *x, float *y); +const int a = 1; + +#endif // CALCULATORGETUSERINPUT_H diff --git a/src/main.c b/src/main.c index a3a8e04..ca9e127 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,8 @@ -#include -int main(){ -return 0; +#include "calculatorGetUserInput.c" +int main() +{ + float userInput1, userInput2; + calculatorGetUserInput(&userInput1, &userInput2); + printf("Your inputs are %f and %f", userInput1, userInput2); + return 0; } diff --git a/tests/support/.gitkeep b/tests/support/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_calculatorGetUserInput.c b/tests/test_calculatorGetUserInput.c new file mode 100644 index 0000000..3fabe3d --- /dev/null +++ b/tests/test_calculatorGetUserInput.c @@ -0,0 +1,20 @@ +#ifdef TEST + +#include "unity.h" + +#include "calculatorGetUserInput.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_calculatorGetUserInput_NeedToImplement(void) +{ + TEST_IGNORE_MESSAGE("Need to Implement calculatorGetUserInput"); +} + +#endif // TEST From fd006a95acad36d15c3874530bf288f932f2a43e Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Thu, 9 Feb 2023 01:40:06 +0100 Subject: [PATCH 26/32] implement unittest for calculatorGetUserInput.c --- build-project.sh | 1 + tests/test_calculatorGetUserInput.c | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/build-project.sh b/build-project.sh index 43a0588..51cf723 100755 --- a/build-project.sh +++ b/build-project.sh @@ -1,4 +1,5 @@ clear +ceedling test:all cd src/ gcc main.c -o main ./main diff --git a/tests/test_calculatorGetUserInput.c b/tests/test_calculatorGetUserInput.c index 3fabe3d..ff01ef4 100644 --- a/tests/test_calculatorGetUserInput.c +++ b/tests/test_calculatorGetUserInput.c @@ -2,7 +2,7 @@ #include "unity.h" -#include "calculatorGetUserInput.h" +#include "calculatorGetUserInput.c" void setUp(void) { @@ -14,7 +14,10 @@ void tearDown(void) void test_calculatorGetUserInput_NeedToImplement(void) { - TEST_IGNORE_MESSAGE("Need to Implement calculatorGetUserInput"); + int a, e; + e = 1; + a = allowOnly(); + TEST_ASSERT_EQUAL_INT(e, a); } #endif // TEST From 1d6a732010d07e90b6f7da8fbee5c1659e16497a Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Tue, 7 Feb 2023 12:23:18 +0100 Subject: [PATCH 27/32] refactoring: change variable names and attach descriptive comments in calculatorGetUserInput.c --- src/calculatorGetUserInput.c | 23 ++++++++++++++--------- src/calculatorGetUserInput.h | 5 +++-- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/calculatorGetUserInput.c b/src/calculatorGetUserInput.c index d38d0bb..2eed445 100644 --- a/src/calculatorGetUserInput.c +++ b/src/calculatorGetUserInput.c @@ -1,20 +1,25 @@ #include "calculatorGetUserInput.h" +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ -int allowOnly() +int allowOnly() //int allowOnly() is helpful for indirectly testing void calculatorGetUserInput(). { - if( a == 1) + if(a == 1) { - return 1; + return 1; } } -void calculatorGetUserInput(float *x, float *y) +void calculatorGetUserInput(float *num1, float *num2) { - if (allowOnly() == 1) + if (allowOnly() == 1) //only if int allowOnly() returns 1, void calculatorGetUserInput will display the desired output. { - printf("number1: "); - scanf("%f", x); - printf("number2: "); - scanf("%f", y); + printf("number1: "); + scanf("%f", num1); + printf("number2: "); + scanf("%f", num2); } } + + diff --git a/src/calculatorGetUserInput.h b/src/calculatorGetUserInput.h index 49e0b8c..9ec1d32 100644 --- a/src/calculatorGetUserInput.h +++ b/src/calculatorGetUserInput.h @@ -2,7 +2,8 @@ #define CALCULATORGETUSERINPUT_H #include #include -void calculatorGetUserInput(float *x, float *y); -const int a = 1; +void calculatorGetUserInput(float *num1, float *num2); +int allowOnly(); +const int a = 1; //Just a random constant which has a role in testing #endif // CALCULATORGETUSERINPUT_H From 1ead3924d88bba039f305d1bbce213b88f372b70 Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Tue, 7 Feb 2023 12:26:29 +0100 Subject: [PATCH 28/32] refactoring: change variable names in test_calculatorGetUserInput.c --- tests/test_calculatorGetUserInput.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/test_calculatorGetUserInput.c b/tests/test_calculatorGetUserInput.c index ff01ef4..57b4e71 100644 --- a/tests/test_calculatorGetUserInput.c +++ b/tests/test_calculatorGetUserInput.c @@ -4,6 +4,10 @@ #include "calculatorGetUserInput.c" +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + void setUp(void) { } @@ -14,10 +18,10 @@ void tearDown(void) void test_calculatorGetUserInput_NeedToImplement(void) { - int a, e; - e = 1; - a = allowOnly(); - TEST_ASSERT_EQUAL_INT(e, a); + int actual, expected; //Arrange + expected = 1; + actual = allowOnly(); //Act + TEST_ASSERT_EQUAL_INT(expected, actual);//Assert } #endif // TEST From acdfb400b329b06c740f3fc599f8054c1852bf38 Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Thu, 9 Feb 2023 02:10:47 +0100 Subject: [PATCH 29/32] implement function calculatorGetUserInputFactorial() --- project.yml | 101 +++++++++++++++++++ src/calculatorGetUserInputFactorial.c | 16 +++ src/calculatorGetUserInputFactorial.h | 10 ++ src/main.c | 10 +- tests/support/.gitkeep | 0 tests/test_calculatorGetUserInputFactorial.c | 20 ++++ 6 files changed, 154 insertions(+), 3 deletions(-) create mode 100644 project.yml create mode 100644 src/calculatorGetUserInputFactorial.c create mode 100644 src/calculatorGetUserInputFactorial.h create mode 100644 tests/support/.gitkeep create mode 100644 tests/test_calculatorGetUserInputFactorial.c diff --git a/project.yml b/project.yml new file mode 100644 index 0000000..640cb8f --- /dev/null +++ b/project.yml @@ -0,0 +1,101 @@ +--- + +# Notes: +# Sample project C code is not presently written to produce a release artifact. +# As such, release build options are disabled. +# This sample, therefore, only demonstrates running a collection of unit tests. + +:project: + :use_exceptions: FALSE + :use_test_preprocessor: TRUE + :use_auxiliary_dependencies: TRUE + :build_root: build +# :release_build: TRUE + :test_file_prefix: test_ + :which_ceedling: gem + :ceedling_version: 0.31.1 + :default_tasks: + - test:all + +#:test_build: +# :use_assembly: TRUE + +#:release_build: +# :output: MyApp.out +# :use_assembly: FALSE + +:environment: + +:extension: + :executable: .out + +:paths: + :test: + - +:tests/** + - -:tests/support + :source: + - src/** + :support: + - tests/support + :libraries: [] + +:defines: + # in order to add common defines: + # 1) remove the trailing [] from the :common: section + # 2) add entries to the :common: section (e.g. :test: has TEST defined) + :common: &common_defines [] + :test: + - *common_defines + - TEST + :test_preprocess: + - *common_defines + - TEST + +:cmock: + :mock_prefix: mock_ + :when_no_prototypes: :warn + :enforce_strict_ordering: TRUE + :plugins: + - :ignore + - :callback + :treat_as: + uint8: HEX8 + uint16: HEX16 + uint32: UINT32 + int8: INT8 + bool: UINT8 + +# Add -gcov to the plugins list to make sure of the gcov plugin +# You will need to have gcov and gcovr both installed to make it work. +# For more information on these options, see docs in plugins/gcov +:gcov: + :reports: + - HtmlDetailed + :gcovr: + :html_medium_threshold: 75 + :html_high_threshold: 90 + +#:tools: +# Ceedling defaults to using gcc for compiling, linking, etc. +# As [:tools] is blank, gcc will be used (so long as it's in your system path) +# See documentation to configure a given toolchain for use + +# LIBRARIES +# These libraries are automatically injected into the build process. Those specified as +# common will be used in all types of builds. Otherwise, libraries can be injected in just +# tests or releases. These options are MERGED with the options in supplemental yaml files. +:libraries: + :placement: :end + :flag: "-l${1}" + :path_flag: "-L ${1}" + :system: [] # for example, you might list 'm' to grab the math library + :test: [] + :release: [] + +:plugins: + :load_paths: + - "#{Ceedling.load_path}" + :enabled: + - stdout_pretty_tests_report + - module_generator +... diff --git a/src/calculatorGetUserInputFactorial.c b/src/calculatorGetUserInputFactorial.c new file mode 100644 index 0000000..661e1ec --- /dev/null +++ b/src/calculatorGetUserInputFactorial.c @@ -0,0 +1,16 @@ +#include "calculatorGetUserInputFactorial.h" +int allowWhen() +{ + if(q == 1) + return 1; +} + +void calculatorGetUserInputFactorial(int *z) +{ + if(allowWhen() == 1) + { + printf("num: "); + scanf("%d", z); + } +} + diff --git a/src/calculatorGetUserInputFactorial.h b/src/calculatorGetUserInputFactorial.h new file mode 100644 index 0000000..272bb52 --- /dev/null +++ b/src/calculatorGetUserInputFactorial.h @@ -0,0 +1,10 @@ +#ifndef CALCULATORGETUSERINPUTFACTORIAL_H +#define CALCULATORGETUSERINPUTFACTORIAL_H +#include +#include +int allowWhen(); +const int q = 1; +void calculatorGetUserInputFactorial(int *z); + + +#endif // CALCULATORGETUSERINPUTFACTORIAL_H diff --git a/src/main.c b/src/main.c index a3a8e04..2180373 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,8 @@ -#include -int main(){ -return 0; +#include "calculatorGetUserInputFactorial.c" +int main() +{ + int userInput; + calculatorGetUserInputFactorial(&userInput); + printf("Your Input is %d", userInput); + return 0; } diff --git a/tests/support/.gitkeep b/tests/support/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_calculatorGetUserInputFactorial.c b/tests/test_calculatorGetUserInputFactorial.c new file mode 100644 index 0000000..2e0ff2c --- /dev/null +++ b/tests/test_calculatorGetUserInputFactorial.c @@ -0,0 +1,20 @@ +#ifdef TEST + +#include "unity.h" + +#include "calculatorGetUserInputFactorial.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_calculatorGetUserInputFactorial_NeedToImplement(void) +{ + TEST_IGNORE_MESSAGE("Need to Implement calculatorGetUserInputFactorial"); +} + +#endif // TEST From 0e355995fcdad00462b1c8940c627b192adb7958 Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Thu, 9 Feb 2023 02:12:43 +0100 Subject: [PATCH 30/32] implement unittest for calculatorGetUserInputFactorial.c --- build-project.sh | 1 + tests/test_calculatorGetUserInputFactorial.c | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/build-project.sh b/build-project.sh index 43a0588..51cf723 100755 --- a/build-project.sh +++ b/build-project.sh @@ -1,4 +1,5 @@ clear +ceedling test:all cd src/ gcc main.c -o main ./main diff --git a/tests/test_calculatorGetUserInputFactorial.c b/tests/test_calculatorGetUserInputFactorial.c index 2e0ff2c..5a42adb 100644 --- a/tests/test_calculatorGetUserInputFactorial.c +++ b/tests/test_calculatorGetUserInputFactorial.c @@ -2,7 +2,7 @@ #include "unity.h" -#include "calculatorGetUserInputFactorial.h" +#include "calculatorGetUserInputFactorial.c" void setUp(void) { @@ -12,9 +12,12 @@ void tearDown(void) { } -void test_calculatorGetUserInputFactorial_NeedToImplement(void) +void test_calculatorGetUserInputFactorial(void) { - TEST_IGNORE_MESSAGE("Need to Implement calculatorGetUserInputFactorial"); + int a, e; + e = 1; + a = allowWhen(); + TEST_ASSERT_EQUAL_INT(e, a); } #endif // TEST From b796599129a05667e4436601ecd4e23a017e39f1 Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Tue, 7 Feb 2023 16:47:02 +0100 Subject: [PATCH 31/32] refactoring: change variable names and attach descriptive comments in calculatorGetUserInputFactorial.c --- src/calculatorGetUserInputFactorial.c | 14 +++++++++----- src/calculatorGetUserInputFactorial.h | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/calculatorGetUserInputFactorial.c b/src/calculatorGetUserInputFactorial.c index 661e1ec..0f556e8 100644 --- a/src/calculatorGetUserInputFactorial.c +++ b/src/calculatorGetUserInputFactorial.c @@ -1,16 +1,20 @@ #include "calculatorGetUserInputFactorial.h" -int allowWhen() +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + +int allowWhen()// int allowWhen() is helpful for indirectly unittesting void calculatorGetUserInputFactorial() { - if(q == 1) + if(utc == 1) return 1; } -void calculatorGetUserInputFactorial(int *z) +void calculatorGetUserInputFactorial(int *num) { - if(allowWhen() == 1) + if(allowWhen() == 1)//Only when int allowWhen() returns 1, void calculatorGetUserInputFactorial() will display desired Output { printf("num: "); - scanf("%d", z); + scanf("%d", num); } } diff --git a/src/calculatorGetUserInputFactorial.h b/src/calculatorGetUserInputFactorial.h index 272bb52..d8da77c 100644 --- a/src/calculatorGetUserInputFactorial.h +++ b/src/calculatorGetUserInputFactorial.h @@ -3,8 +3,8 @@ #include #include int allowWhen(); -const int q = 1; -void calculatorGetUserInputFactorial(int *z); +const int utc = 1; //ufc is unitTestConstant, which has a role in unittesting void calculatorGetUserInputFactorial() +void calculatorGetUserInputFactorial(int *num); #endif // CALCULATORGETUSERINPUTFACTORIAL_H From 7fd2d0e3aa950e130732752611d02b9994d04b19 Mon Sep 17 00:00:00 2001 From: fdai7514 Date: Tue, 7 Feb 2023 16:50:14 +0100 Subject: [PATCH 32/32] refactoring: change variable names in test_calculatorGetUserInputFactorial.c --- tests/test_calculatorGetUserInputFactorial.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/test_calculatorGetUserInputFactorial.c b/tests/test_calculatorGetUserInputFactorial.c index 5a42adb..b9a2e91 100644 --- a/tests/test_calculatorGetUserInputFactorial.c +++ b/tests/test_calculatorGetUserInputFactorial.c @@ -4,6 +4,10 @@ #include "calculatorGetUserInputFactorial.c" +// Note: +/* This Function may or may not be implemented in actual program, even if it is merged to the main branch. + If it is temporarily not included in the main Program, then this has a role in future Development of the Project */ + void setUp(void) { } @@ -14,10 +18,10 @@ void tearDown(void) void test_calculatorGetUserInputFactorial(void) { - int a, e; - e = 1; - a = allowWhen(); - TEST_ASSERT_EQUAL_INT(e, a); + int actual, expected; //Arrange + expected = 1; + actual = allowWhen(); //Act + TEST_ASSERT_EQUAL_INT(expected, actual); //Assert } #endif // TEST