-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.c
70 lines (57 loc) · 1.85 KB
/
tests.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "vendor/unity.h"
#include <stdlib.h>
extern int fib(int n);
extern int index(int *matrix, int rows, int cols, int rindex, int cindex);
extern void transpose(int *in, int *out, int rows, int cols);
extern float volume(float radius, float height);
void setUp(void) {
}
void tearDown(void) {
}
void test_fib_0(void) { TEST_ASSERT_EQUAL(0, fib(0)); }
void test_fib_1(void) { TEST_ASSERT_EQUAL(1, fib(1)); }
void test_fib_2(void) { TEST_ASSERT_EQUAL(1, fib(2)); }
void test_fib_3(void) { TEST_ASSERT_EQUAL(2, fib(3)); }
void test_fib_10(void) { TEST_ASSERT_EQUAL(55, fib(10)); }
void test_fib_12(void) { TEST_ASSERT_EQUAL(144, fib(12)); }
void test_index_row(void) {
int matrix[1][4] = {{1, 2, 3, 4}};
TEST_ASSERT_EQUAL(3, index((int *)matrix, 1, 4, 0, 2));
}
void test_index_col(void) {
int matrix[4][1] = {{1}, {2}, {3}, {4}};
TEST_ASSERT_EQUAL(2, index((int *)matrix, 4, 1, 1, 0));
}
void test_index_rect(void) {
int matrix[2][3] = {{1, 2, 3}, {4, 5, 6}};
TEST_ASSERT_EQUAL(6, index((int *)matrix, 2, 3, 1, 2));
}
void test_cone_volume_0_0(void) {
TEST_ASSERT_FLOAT_WITHIN(0.01, 0.0, volume(0.0, 0.0));
}
void test_cone_volume_1_2(void) {
TEST_ASSERT_FLOAT_WITHIN(0.01, 2.09, volume(1.0, 2.0));
}
void test_cone_volume_55_55(void) {
TEST_ASSERT_FLOAT_WITHIN(0.01, 174.23, volume(5.5, 5.5));
}
void test_cone_volume_1234_5678(void) {
TEST_ASSERT_FLOAT_WITHIN(0.01, 9.05, volume(1.234, 5.678));
}
int main(void) {
UNITY_BEGIN();
RUN_TEST(test_fib_0);
RUN_TEST(test_fib_1);
RUN_TEST(test_fib_2);
RUN_TEST(test_fib_3);
RUN_TEST(test_fib_10);
RUN_TEST(test_fib_12);
RUN_TEST(test_index_row);
RUN_TEST(test_index_col);
RUN_TEST(test_index_rect);
RUN_TEST(test_cone_volume_0_0);
RUN_TEST(test_cone_volume_1_2);
RUN_TEST(test_cone_volume_55_55);
RUN_TEST(test_cone_volume_1234_5678);
return UNITY_END();
}