From 0822b9d60bc647abdba64f08df898556d8f7f659 Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Mon, 5 Feb 2024 16:40:33 +0000 Subject: [PATCH 1/7] Add multiplication --- src/multiplication/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/multiplication/.gitkeep diff --git a/src/multiplication/.gitkeep b/src/multiplication/.gitkeep new file mode 100644 index 0000000..e69de29 From 8472e257487b69dad65217caad5b34f6128ae504 Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Mon, 5 Feb 2024 16:43:44 +0000 Subject: [PATCH 2/7] Add multiplication.c --- src/multiplication/multiplication.c | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/multiplication/multiplication.c diff --git a/src/multiplication/multiplication.c b/src/multiplication/multiplication.c new file mode 100644 index 0000000..ca9e804 --- /dev/null +++ b/src/multiplication/multiplication.c @@ -0,0 +1,3 @@ +int multiply(int a, int b) { + return a * b; +} From f0608d5029e2880a4e05e396ff36e6a122923e18 Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Mon, 5 Feb 2024 16:46:17 +0000 Subject: [PATCH 3/7] Add multiplication.h --- src/multiplication/multiplication.h | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/multiplication/multiplication.h diff --git a/src/multiplication/multiplication.h b/src/multiplication/multiplication.h new file mode 100644 index 0000000..697e80f --- /dev/null +++ b/src/multiplication/multiplication.h @@ -0,0 +1,7 @@ +#ifndef multiplication_H +#define multiplication_H + +int multiplication(int a, int b); + +#endif + From 9e55db740eefe48bb99bb02c41e8314b3beecc5f Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Mon, 5 Feb 2024 16:47:58 +0000 Subject: [PATCH 4/7] create new directory multiplication --- test/multiplication/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/multiplication/.gitkeep diff --git a/test/multiplication/.gitkeep b/test/multiplication/.gitkeep new file mode 100644 index 0000000..e69de29 From 364401a11c09034e830cd99554625c9e16307dc8 Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Mon, 5 Feb 2024 16:50:17 +0000 Subject: [PATCH 5/7] Add test_calculator.c --- test/multiplication/test_calculator.c | 1 + 1 file changed, 1 insertion(+) create mode 100644 test/multiplication/test_calculator.c diff --git a/test/multiplication/test_calculator.c b/test/multiplication/test_calculator.c new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/test/multiplication/test_calculator.c @@ -0,0 +1 @@ + From e037d3237a99f8beff050b1a80af8f9e81f0d41a Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Mon, 5 Feb 2024 17:03:55 +0000 Subject: [PATCH 6/7] refactoring case one or two zeros always return 0 --- src/multiplication/multiplication.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/multiplication/multiplication.c b/src/multiplication/multiplication.c index ca9e804..aee181c 100644 --- a/src/multiplication/multiplication.c +++ b/src/multiplication/multiplication.c @@ -1,3 +1,4 @@ int multiply(int a, int b) { - return a * b; + if (a==0||b==0) return 0; + else return a * b; } From 951389500c53ceb1bd6d37d24bff63ee003f1461 Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Mon, 5 Feb 2024 17:11:43 +0000 Subject: [PATCH 7/7] Corrected naming mistake --- src/multiplication/multiplication.h | 2 +- test/multiplication/test_calculator.c | 1 - test/multiplication/test_multiplication.c | 12 ++++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) delete mode 100644 test/multiplication/test_calculator.c create mode 100644 test/multiplication/test_multiplication.c diff --git a/src/multiplication/multiplication.h b/src/multiplication/multiplication.h index 697e80f..295da10 100644 --- a/src/multiplication/multiplication.h +++ b/src/multiplication/multiplication.h @@ -1,7 +1,7 @@ #ifndef multiplication_H #define multiplication_H -int multiplication(int a, int b); +int multiply(int a, int b); #endif diff --git a/test/multiplication/test_calculator.c b/test/multiplication/test_calculator.c deleted file mode 100644 index 8b13789..0000000 --- a/test/multiplication/test_calculator.c +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/multiplication/test_multiplication.c b/test/multiplication/test_multiplication.c new file mode 100644 index 0000000..e02bb41 --- /dev/null +++ b/test/multiplication/test_multiplication.c @@ -0,0 +1,12 @@ +#include "unity.h" +#include "multiplication.h" + +void setUp(void){} +void tearDown(void){} + +void test_multiplication() { + TEST_ASSERT_EQUAL_INT(6, multiply(2, 3)); + TEST_ASSERT_EQUAL_INT(-6, multiply(2, -3)); + TEST_ASSERT_EQUAL_INT(0, multiply(0, 0)); +} +