From 72f01d58ad1bab3f8a7b89d2b4db6244c0f003ed Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Mon, 5 Feb 2024 19:20:30 +0000 Subject: [PATCH 01/10] Add new subtraction directory --- src/subtraction/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/subtraction/.gitkeep diff --git a/src/subtraction/.gitkeep b/src/subtraction/.gitkeep new file mode 100644 index 0000000..e69de29 From 4c2b7fd6dabccf9ab81b2d9f667a2cf325592fb8 Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Mon, 5 Feb 2024 19:23:56 +0000 Subject: [PATCH 02/10] Add new subtraction.c --- src/subtraction/subtraction.c | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/subtraction/subtraction.c diff --git a/src/subtraction/subtraction.c b/src/subtraction/subtraction.c new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/subtraction/subtraction.c @@ -0,0 +1 @@ + From a5f0319427c8ed75c35ba74a1779d95ae4de0f7f Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Mon, 5 Feb 2024 19:30:34 +0000 Subject: [PATCH 03/10] Update src/subtraction/subtraction.c --- src/subtraction/subtraction.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/subtraction/subtraction.c b/src/subtraction/subtraction.c index 8b13789..31d373d 100644 --- a/src/subtraction/subtraction.c +++ b/src/subtraction/subtraction.c @@ -1 +1,3 @@ - +int subtract(int a, int b) { + return a - b; +} From 033277c37e1104049939c655edf02462b2fa37cb Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Mon, 5 Feb 2024 19:31:17 +0000 Subject: [PATCH 04/10] Add new subtraction.h file --- src/subtraction/subtraction.h | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/subtraction/subtraction.h diff --git a/src/subtraction/subtraction.h b/src/subtraction/subtraction.h new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/subtraction/subtraction.h @@ -0,0 +1 @@ + From 0c728d8355957a4cc86ffc8ce5ec7e631e578d97 Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Mon, 5 Feb 2024 19:32:22 +0000 Subject: [PATCH 05/10] Update src/subtraction/subtraction.h --- src/subtraction/subtraction.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/subtraction/subtraction.h b/src/subtraction/subtraction.h index 8b13789..0ae67d9 100644 --- a/src/subtraction/subtraction.h +++ b/src/subtraction/subtraction.h @@ -1 +1,8 @@ +#ifndef subtraction_H +#define subtraction_H + +int subtract(int a, int b); + +#endif + From 338743838898f7f32ee31074e7217bf4032d234b Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Mon, 5 Feb 2024 19:44:03 +0000 Subject: [PATCH 06/10] refactoring: if one a or b is zero just return the other --- src/subtraction/subtraction.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/subtraction/subtraction.c b/src/subtraction/subtraction.c index 31d373d..f853998 100644 --- a/src/subtraction/subtraction.c +++ b/src/subtraction/subtraction.c @@ -1,3 +1,6 @@ +#include "subtraction.h" int subtract(int a, int b) { - return a - b; + if (a==0) return b; + if(b==0) return a; + else return a - b; } From e920dbd5a7dc1925e38d9b8fd2896fbd09f789b0 Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Mon, 5 Feb 2024 19:44:44 +0000 Subject: [PATCH 07/10] Add new subtraction directory --- test/subtraction/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/subtraction/.gitkeep diff --git a/test/subtraction/.gitkeep b/test/subtraction/.gitkeep new file mode 100644 index 0000000..e69de29 From e86eaac135304580e79d19b28d0d2ded6df59432 Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Mon, 5 Feb 2024 19:45:42 +0000 Subject: [PATCH 08/10] Add new subtraction file for tests --- test/subtraction/subtraction | 1 + 1 file changed, 1 insertion(+) create mode 100644 test/subtraction/subtraction diff --git a/test/subtraction/subtraction b/test/subtraction/subtraction new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/test/subtraction/subtraction @@ -0,0 +1 @@ + From a6704ce16bbdb5ad09ca59545aedca9bf47ebfde Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Mon, 5 Feb 2024 20:14:19 +0000 Subject: [PATCH 09/10] Update test/subtraction/subtraction.c --- test/subtraction/subtraction | 1 - test/subtraction/subtraction.c | 8 ++++++++ 2 files changed, 8 insertions(+), 1 deletion(-) delete mode 100644 test/subtraction/subtraction create mode 100644 test/subtraction/subtraction.c diff --git a/test/subtraction/subtraction b/test/subtraction/subtraction deleted file mode 100644 index 8b13789..0000000 --- a/test/subtraction/subtraction +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/subtraction/subtraction.c b/test/subtraction/subtraction.c new file mode 100644 index 0000000..8894e75 --- /dev/null +++ b/test/subtraction/subtraction.c @@ -0,0 +1,8 @@ +#include "unity.h" +#include "subtraction.h" + +void test_subtraction() { + TEST_ASSERT_EQUAL_INT(1, subtract(3, 2)); + TEST_ASSERT_EQUAL_INT(5, subtract(2, -3)); + TEST_ASSERT_EQUAL_INT(0, subtract(0, 0)); +} From f23b7ddc2b4ff5e0db5475fca7ca9af191390f40 Mon Sep 17 00:00:00 2001 From: fdai7968 Date: Mon, 5 Feb 2024 20:26:27 +0000 Subject: [PATCH 10/10] added forgotten setup and teardown --- test/subtraction/subtraction.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/subtraction/subtraction.c b/test/subtraction/subtraction.c index 8894e75..d49be5c 100644 --- a/test/subtraction/subtraction.c +++ b/test/subtraction/subtraction.c @@ -1,5 +1,8 @@ #include "unity.h" #include "subtraction.h" +void setUp(){} + +void tearDown(){} void test_subtraction() { TEST_ASSERT_EQUAL_INT(1, subtract(3, 2));