Browse Source

unit tests added and adjusted calculations with double

remotes/origin/feature
Enrico Schellenberger 11 months ago
parent
commit
944e3a1544
  1. 11
      src/main/c/main_taschenrechner.c
  2. 8
      src/main/c/taschenrechner.h
  3. 27
      src/test/c/test_taschenrechner.c

11
src/main/c/main_taschenrechner.c

@ -6,19 +6,22 @@
#include "taschenrechner.h"
int add(int a, int b) {
doulbe add(doulbe a, doulbe b) {
return a + b;
}
int minus (int a, int b){
doulbe minus (doulbe a, doulbe b){
return a - b;
}
int multiply(int a, int b) {
doulbe multiply(doulbe a, doulbe b) {
return a * b;
}
int divide(int a, int b) {
doulbe divide(doulbe a, doulbe b) {
if (b == 0) {
return 0;
}
return a / b;
}

8
src/main/c/taschenrechner.h

@ -1,13 +1,13 @@
#ifndef TASCHENRECHNER_H
#define TASCHENRECHNER_H
int add(int a, int b);
doulbe add(doulbe a, doulbe b);
int minus(int a, int b);
doulbe minus(doulbe a, doulbe b);
int multiply(int a, int b);
doulbe multiply(doulbe a, doulbe b);
int divide(int a, int b);
doulbe divide(doulbe a, doulbe b);
// Square root function
double squareRootFunction(double x);

27
src/test/c/test_taschenrechner.c

@ -14,14 +14,29 @@ void tearDown(void)
void test_addition(void)
{
/* arrange */
char* result;
char expected[] = "2\n";
doulbe result = add(1, 2);
TEST_ASSERT_EQUAL(3, result);
}
void test_minus(void)
{
doulbe result = minus(3, 1);
TEST_ASSERT_EQUAL(2, result);
}
/* act */
result = convert(2);
void test_multiply(void)
{
doulbe result = multiply(1, 2);
TEST_ASSERT_EQUAL(2, result);
}
void test_divide(void)
{
doulbe result = divide(4, 2);
TEST_ASSERT_EQUAL(2, result);
/* assert */
doulbe result1 = divide(4, 0);
TEST_ASSERT_EQUAL(0, result1);
}
#endif // TEST
Loading…
Cancel
Save