-
Notifications
You must be signed in to change notification settings - Fork 44
/
test_calculator.c
43 lines (37 loc) · 987 Bytes
/
test_calculator.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <assert.h>
#include "calculator.h"
void test_add() {
assert(add(1, 2) == 3.0);
assert(add(1.0, 2.0) == 3.0);
assert(add(0, 2.0) == 2.0);
assert(add(2.0, 0) == 2.0);
assert(add(-4, 2.0) == -2.0);
}
void test_subtract() {
assert(subtract(1, 2) == -1.0);
assert(subtract(2, 1) == 1.0);
assert(subtract(1.0, 2.0) == -1.0);
assert(subtract(0, 2.0) == -2.0);
assert(subtract(2.0, 0) == 2.0);
assert(subtract(-4, 2.0) == -6.0);
}
void test_multiply() {
assert(multiply(1, 2) == 2.0);
assert(multiply(1.0, 2.0) == 2.0);
assert(multiply(0, 2.0) == 0.0);
assert(multiply(2.0, 0) == 0.0);
assert(multiply(-4, 2.0) == -8.0);
}
void test_divide() {
assert(divide(1, 2) == 0.5);
assert(divide(1.0, 2.0) == 0.5);
assert(divide(0, 2.0) == 0);
assert(divide(-4, 2.0) == -2.0);
// assert(divide(2.0, 0) == 0.0);
}
int main() {
test_add();
test_subtract();
test_multiply();
test_divide();
}