From f93c3821359acbda96145f6494c547b5c9be9420 Mon Sep 17 00:00:00 2001 From: Kajetan Date: Sun, 28 Sep 2025 02:00:40 +0000 Subject: [PATCH 1/6] Cover ShouldReturnInvalidData test --- homework/calculate/calculate.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 7a933a25..59bd077a 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -2,6 +2,6 @@ #include std::string calculate(const std::string& command, int first, int second) { - // TODO: Implement your solution here and return proper value - return ""; + std::string result{"Invalid data"}; + return result; } From 6afec5db13170e116442cc2d183b6397a2bae3ac Mon Sep 17 00:00:00 2001 From: Kajetan Date: Sun, 28 Sep 2025 02:06:34 +0000 Subject: [PATCH 2/6] Cover ShouldAdd test --- homework/calculate/calculate.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 59bd077a..042a2437 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -3,5 +3,8 @@ std::string calculate(const std::string& command, int first, int second) { std::string result{"Invalid data"}; + if(command == "add") { + result = std::to_string(first + second); + } return result; } From 4bab74118d7ad1d2c6ca5f961197bf20c80f16f1 Mon Sep 17 00:00:00 2001 From: Kajetan Date: Sun, 28 Sep 2025 02:10:20 +0000 Subject: [PATCH 3/6] Cover ShouldSubtract test --- homework/calculate/calculate.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 042a2437..00f666e1 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -6,5 +6,8 @@ std::string calculate(const std::string& command, int first, int second) { if(command == "add") { result = std::to_string(first + second); } + if(command == "subtract") { + result = std::to_string(first - second); + } return result; } From 02cac1aa3dc901ce1d61a322955c95b0933f8fa5 Mon Sep 17 00:00:00 2001 From: Kajetan Date: Sun, 28 Sep 2025 02:13:04 +0000 Subject: [PATCH 4/6] Cover ShouldMultiply test --- homework/calculate/calculate.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 00f666e1..395fce49 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -9,5 +9,8 @@ std::string calculate(const std::string& command, int first, int second) { if(command == "subtract") { result = std::to_string(first - second); } + if(command == "multiply") { + result = std::to_string(first * second); + } return result; } From 0fd352b62efa15197b51a7a1a405c34303699c92 Mon Sep 17 00:00:00 2001 From: Kajetan Date: Sun, 28 Sep 2025 02:16:36 +0000 Subject: [PATCH 5/6] Cover ShouldDivide test --- homework/calculate/calculate.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 395fce49..7bade6b0 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -12,5 +12,13 @@ std::string calculate(const std::string& command, int first, int second) { if(command == "multiply") { result = std::to_string(first * second); } + if(command == "divide") { + if(second == 0) { + result = "Division by 0"; + } + else { + result = std::to_string(first / second); + } + } return result; } From c47e14722bb58e3b7b86e782ae2e8e056c19acf4 Mon Sep 17 00:00:00 2001 From: Kajetan Date: Sun, 28 Sep 2025 14:07:26 +0000 Subject: [PATCH 6/6] Fix code style to clang-format --- homework/calculate/calculate.hpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 7bade6b0..e740a462 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -3,20 +3,19 @@ std::string calculate(const std::string& command, int first, int second) { std::string result{"Invalid data"}; - if(command == "add") { + if (command == "add") { result = std::to_string(first + second); } - if(command == "subtract") { + if (command == "subtract") { result = std::to_string(first - second); } - if(command == "multiply") { + if (command == "multiply") { result = std::to_string(first * second); } - if(command == "divide") { - if(second == 0) { + if (command == "divide") { + if (second == 0) { result = "Division by 0"; - } - else { + } else { result = std::to_string(first / second); } }