Browse Source

added unittest to check wether the performOperation works when dividing by zero

remotes/origin/kabrel
fdai7782 11 months ago
parent
commit
a4d4537ae0
  1. 6
      .vscode/c_cpp_properties.json
  2. 24
      .vscode/launch.json
  3. 3
      .vscode/settings.json
  4. 1
      src/main/c/programmingMode.c
  5. 7
      src/test/c/test_calculator.c
  6. 18
      target/test/cache/test_calculator.c
  7. BIN
      target/test/out/c/programmingMode.o
  8. BIN
      target/test/out/c/test_calculator.o
  9. BIN
      target/test/out/c/test_calculator_runner.o
  10. BIN
      target/test/out/test_calculator.out
  11. 18
      target/test/preprocess/files/test_calculator.c
  12. 10
      target/test/results/test_calculator.pass
  13. 2
      target/test/runners/test_calculator_runner.c

6
.vscode/c_cpp_properties.json

@ -1,14 +1,14 @@
{ {
"configurations": [ "configurations": [
{ {
"name": "Linux",
"name": "linux-gcc-x64",
"includePath": [ "includePath": [
"${workspaceFolder}/**" "${workspaceFolder}/**"
], ],
"defines": [], "defines": [],
"compilerPath": "/usr/bin/gcc", "compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "c++98",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64" "intelliSenseMode": "linux-gcc-x64"
} }
], ],

24
.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
}
]
}
]
}

3
.vscode/settings.json

@ -4,5 +4,6 @@
"testforoperator.h": "c", "testforoperator.h": "c",
"testfornumber.h": "c", "testfornumber.h": "c",
"programmingmode.h": "c" "programmingmode.h": "c"
}
},
"C_Cpp_Runner.msvcBatchPath": ""
} }

1
src/main/c/programmingMode.c

@ -38,7 +38,6 @@ int performOperation(int num1, char operatorType, int num2) {
if (num2 != 0) { if (num2 != 0) {
return num1 / num2; return num1 / num2;
} else { } else {
printf("Error: Division by zero\n");
return 0; return 0;
} }
default: default:

7
src/test/c/test_calculator.c

@ -192,3 +192,10 @@ void test_performOperation_Division(void) {
// Assert // Assert
TEST_ASSERT_EQUAL_INT(4, result); 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));
}

18
target/test/cache/test_calculator.c

@ -500,3 +500,21 @@ void test_performOperation_Division(void) {
), (UNITY_UINT)(193), UNITY_DISPLAY_STYLE_INT); ), (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);
}

BIN
target/test/out/c/programmingMode.o

BIN
target/test/out/c/test_calculator.o

BIN
target/test/out/c/test_calculator_runner.o

BIN
target/test/out/test_calculator.out

18
target/test/preprocess/files/test_calculator.c

@ -500,3 +500,21 @@ void test_performOperation_Division(void) {
), (UNITY_UINT)(193), UNITY_DISPLAY_STYLE_INT); ), (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);
}

10
target/test/results/test_calculator.pass

@ -119,12 +119,16 @@
:line: 185 :line: 185
:message: '' :message: ''
:unity_test_time: 0 :unity_test_time: 0
- :test: test_performOperation_division_by_zero
:line: 197
:message: ''
:unity_test_time: 0
:failures: [] :failures: []
:ignores: [] :ignores: []
:counts: :counts:
:total: 29
:passed: 29
:total: 30
:passed: 30
:failed: 0 :failed: 0
:ignored: 0 :ignored: 0
:stdout: [] :stdout: []
:time: 0.001314320999881602
:time: 0.0015222660003928468

2
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_Subtraction(void);
extern void test_performOperation_Multiplication(void); extern void test_performOperation_Multiplication(void);
extern void test_performOperation_Division(void); extern void test_performOperation_Division(void);
extern void test_performOperation_division_by_zero(void);
/*=======Mock Management=====*/ /*=======Mock Management=====*/
@ -132,6 +133,7 @@ int main(void)
run_test(test_performOperation_Subtraction, "test_performOperation_Subtraction", 161); run_test(test_performOperation_Subtraction, "test_performOperation_Subtraction", 161);
run_test(test_performOperation_Multiplication, "test_performOperation_Multiplication", 173); run_test(test_performOperation_Multiplication, "test_performOperation_Multiplication", 173);
run_test(test_performOperation_Division, "test_performOperation_Division", 185); run_test(test_performOperation_Division, "test_performOperation_Division", 185);
run_test(test_performOperation_division_by_zero, "test_performOperation_division_by_zero", 197);
return UnityEnd(); return UnityEnd();
} }
Loading…
Cancel
Save