diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index c11401d..a50e8e7 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -1,16 +1,16 @@ { - "configurations": [ - { - "name": "Linux", - "includePath": [ - "${workspaceFolder}/**" - ], - "defines": [], - "compilerPath": "/usr/bin/gcc", - "cStandard": "c17", - "cppStandard": "c++98", - "intelliSenseMode": "linux-gcc-x64" - } - ], - "version": 4 + "configurations": [ + { + "name": "linux-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [], + "compilerPath": "/usr/bin/gcc", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "linux-gcc-x64" + } + ], + "version": 4 } \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..4a9efca --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": false, + "cwd": "/home/js/Desktop/caschenrechner/src/test/c", + "program": "/home/js/Desktop/caschenrechner/src/test/c/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 355d4a1..f168e7d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,8 +1,9 @@ { - "C_Cpp.errorSquiggles": "disabled", - "files.associations": { - "testforoperator.h": "c", - "testfornumber.h": "c", - "programmingmode.h": "c" - } + "C_Cpp.errorSquiggles": "disabled", + "files.associations": { + "testforoperator.h": "c", + "testfornumber.h": "c", + "programmingmode.h": "c" + }, + "C_Cpp_Runner.msvcBatchPath": "" } \ No newline at end of file diff --git a/src/main/c/programmingMode.c b/src/main/c/programmingMode.c index b96b77c..7457a95 100644 --- a/src/main/c/programmingMode.c +++ b/src/main/c/programmingMode.c @@ -38,7 +38,6 @@ int performOperation(int num1, char operatorType, int num2) { if (num2 != 0) { return num1 / num2; } else { - printf("Error: Division by zero\n"); return 0; } default: diff --git a/src/test/c/test_calculator.c b/src/test/c/test_calculator.c index dde64f2..641fceb 100644 --- a/src/test/c/test_calculator.c +++ b/src/test/c/test_calculator.c @@ -192,3 +192,10 @@ void test_performOperation_Division(void) { // Assert TEST_ASSERT_EQUAL_INT(4, result); } + +// Test case for dividing by zero +void test_performOperation_division_by_zero(void) { + + TEST_ASSERT_EQUAL_INT(0, performOperation(10, '/', 0)); + +} diff --git a/target/test/cache/test_calculator.c b/target/test/cache/test_calculator.c index b5bac52..3289aba 100644 --- a/target/test/cache/test_calculator.c +++ b/target/test/cache/test_calculator.c @@ -500,3 +500,21 @@ void test_performOperation_Division(void) { ), (UNITY_UINT)(193), UNITY_DISPLAY_STYLE_INT); } + + + + + +void test_performOperation_division_by_zero(void) { + + + + UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((performOperation(10, '/', 0))), ( + + ((void *)0) + + ), (UNITY_UINT)(199), UNITY_DISPLAY_STYLE_INT); + + + +} diff --git a/target/test/out/c/programmingMode.o b/target/test/out/c/programmingMode.o index 8217c85..55810a2 100644 Binary files a/target/test/out/c/programmingMode.o and b/target/test/out/c/programmingMode.o differ diff --git a/target/test/out/c/test_calculator.o b/target/test/out/c/test_calculator.o index 4ed0c13..1761a8b 100644 Binary files a/target/test/out/c/test_calculator.o and b/target/test/out/c/test_calculator.o differ diff --git a/target/test/out/c/test_calculator_runner.o b/target/test/out/c/test_calculator_runner.o index 8086889..53d8bb4 100644 Binary files a/target/test/out/c/test_calculator_runner.o and b/target/test/out/c/test_calculator_runner.o differ diff --git a/target/test/out/test_calculator.out b/target/test/out/test_calculator.out index 5c3f8d4..eb060c8 100755 Binary files a/target/test/out/test_calculator.out and b/target/test/out/test_calculator.out differ diff --git a/target/test/preprocess/files/test_calculator.c b/target/test/preprocess/files/test_calculator.c index b5bac52..3289aba 100644 --- a/target/test/preprocess/files/test_calculator.c +++ b/target/test/preprocess/files/test_calculator.c @@ -500,3 +500,21 @@ void test_performOperation_Division(void) { ), (UNITY_UINT)(193), UNITY_DISPLAY_STYLE_INT); } + + + + + +void test_performOperation_division_by_zero(void) { + + + + UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((performOperation(10, '/', 0))), ( + + ((void *)0) + + ), (UNITY_UINT)(199), UNITY_DISPLAY_STYLE_INT); + + + +} diff --git a/target/test/results/test_calculator.pass b/target/test/results/test_calculator.pass index 8999b26..7b87122 100644 --- a/target/test/results/test_calculator.pass +++ b/target/test/results/test_calculator.pass @@ -119,12 +119,16 @@ :line: 185 :message: '' :unity_test_time: 0 +- :test: test_performOperation_division_by_zero + :line: 197 + :message: '' + :unity_test_time: 0 :failures: [] :ignores: [] :counts: - :total: 29 - :passed: 29 + :total: 30 + :passed: 30 :failed: 0 :ignored: 0 :stdout: [] -:time: 0.001314320999881602 +:time: 0.0015222660003928468 diff --git a/target/test/runners/test_calculator_runner.c b/target/test/runners/test_calculator_runner.c index c2033f8..9459746 100644 --- a/target/test/runners/test_calculator_runner.c +++ b/target/test/runners/test_calculator_runner.c @@ -39,6 +39,7 @@ extern void test_exponentialFunction(void); extern void test_performOperation_Subtraction(void); extern void test_performOperation_Multiplication(void); extern void test_performOperation_Division(void); +extern void test_performOperation_division_by_zero(void); /*=======Mock Management=====*/ @@ -132,6 +133,7 @@ int main(void) run_test(test_performOperation_Subtraction, "test_performOperation_Subtraction", 161); run_test(test_performOperation_Multiplication, "test_performOperation_Multiplication", 173); run_test(test_performOperation_Division, "test_performOperation_Division", 185); + run_test(test_performOperation_division_by_zero, "test_performOperation_division_by_zero", 197); return UnityEnd(); }