~dheinemann/Replicalc

ee7b54ccaf3b89eff582e364f468f89279c864e3 — David Heinemann 7 months ago a625aee
Add unit tests
4 files changed, 42 insertions(+), 0 deletions(-)

M .gitignore
A .gitmodules
A Unity
A tests/tests.c
M .gitignore => .gitignore +2 -0
@@ 1,2 1,4 @@
src/build/
tests/build/
tests/buildandrun.sh
.vscode/
\ No newline at end of file

A .gitmodules => .gitmodules +3 -0
@@ 0,0 1,3 @@
[submodule "Unity"]
	path = Unity
	url = https://github.com/ThrowTheSwitch/Unity.git

A Unity => Unity +1 -0
@@ 0,0 1,1 @@
Subproject commit 61f4428435881ad8888c33e92304f4f0b436c21c

A tests/tests.c => tests/tests.c +36 -0
@@ 0,0 1,36 @@
#include "../src/calc.h"
#include "../Unity/src/unity.h"

void setUp(void) {}
void tearDown(void) {}

void calculate_onePlusOne_Returns2() {
    TEST_ASSERT_EQUAL(2, calculate("1 + 1", NULL));
}

void calculate_unbalancedOpenParen_ReturnsError() {
    int errorCode = 0;
    calculate("3 * (1/4", &errorCode);
    TEST_ASSERT_EQUAL(Error_UnbalParens, errorCode);
}

void calculate_unbalancedCloseParen_ReturnsError() {
    int errorCode = 0;
    calculate("3 * 1/4)", &errorCode);
    TEST_ASSERT_EQUAL(Error_UnbalParens, errorCode);
}

void calculate_divideByZero_ReturnsError() {
    int errorCode = 0;
    calculate("1 / 0", &errorCode);
    TEST_ASSERT_EQUAL(Error_DivideByZero, errorCode);
}

int main(void) {
    UNITY_BEGIN();
    RUN_TEST(calculate_onePlusOne_Returns2);
    RUN_TEST(calculate_unbalancedOpenParen_ReturnsError);
    RUN_TEST(calculate_unbalancedCloseParen_ReturnsError);
    RUN_TEST(calculate_divideByZero_ReturnsError);
    return UNITY_END();
}
\ No newline at end of file