-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_simple.c
59 lines (49 loc) · 1.54 KB
/
test_simple.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
#include <stdio.h>
#include <stdlib.h>
// Include test suite
#include "unity.h"
// Include the header from the c implementation
#include "simple.h"
// Include the header file that the ispc compiler generates
#include "simple_ispc.h"
#ifndef N
#define N 16
#endif
// every test file requires this function
// setUp() is called before each test case function
void setUp(void) {
printf("\nSetting up stuff before test\n");
}
// every test file requires this function
// tearDown() is called after each test case function
void tearDown(void) {
printf("\nCleaning up stuff after test\n");
}
//test deterministic stuff
void test_simple(void) {
float vin[N], vout[N], vout_ispc[N], vexpected[N];
// Initialize input buffer and expected results
for (int i = 0; i < N; ++i){
vin[i] = (float)i;
vexpected[i] = simple_op((float)i);
}
// Call simple() function from simple.c file
simple(vin, vout, N);
// Call simple_ispc() function from simple.ispc file
simple_ispc(vin, vout_ispc, N);
// Print results
printf("i: expected[i], vin[i], simple(vin)[i], simple_ispc(vin)[i]\n");
for (int i = 0; i < N; ++i)
printf("%d: %f, %f, %f, %f\n",
i, vexpected[i], vin[i], vout[i], vout_ispc[i]);
// Verify simple result
TEST_ASSERT_EQUAL_FLOAT_ARRAY(vexpected, vout, N);
// Verify simple_ispc result
TEST_ASSERT_EQUAL_FLOAT_ARRAY(vexpected, vout_ispc, N);
}
int main(void) {
UNITY_BEGIN();
// We should list all tests here
RUN_TEST(test_simple);
return UNITY_END();
}