-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathck_vector.c
More file actions
90 lines (77 loc) · 1.49 KB
/
Copy pathck_vector.c
File metadata and controls
90 lines (77 loc) · 1.49 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <check.h>
#include "vector.h"
#include "ck_helper.h"
START_TEST(test_v_zero)
{
ck_assert_vec_eq(v_zero, 0, 0);
}
END_TEST
START_TEST(test_v_axpy)
{
double x[2] = {1, 2};
double y[2] = {3, 4};
v_axpy(2, x, y);
ck_assert_vec_eq(y, 5, 8);
}
END_TEST
START_TEST(test_v_scal)
{
double x[2] = {1, 2};
v_scal(2, x);
ck_assert_vec_eq(x, 2, 4);
}
END_TEST
START_TEST(test_v_dot)
{
double x[2] = {1, 2};
double y[2] = {3, 4};
ck_assert_double_eq_tol(v_dot(x, y), 11, EPSILON);
}
END_TEST
START_TEST(test_v_nrm2)
{
double x[2] = {3, 4};
ck_assert_double_eq_tol(v_nrm2(x), 5, EPSILON);
}
END_TEST
START_TEST(test_v_normalize)
{
double x[2] = {4, 4};
double l = v_normalize(x);
ck_assert_double_eq_tol(l, 4*sqrt(2), EPSILON);
ck_assert_vec_eq(x, sqrt(2)/2, sqrt(2)/2);
}
END_TEST
START_TEST(test_v_mul)
{
double x[2] = {2, 3};
double y[2] = {4, 9};
v_mul(x, y);
ck_assert_vec_eq(y, 8, 27);
}
END_TEST
START_TEST(test_v_div)
{
double x[2] = {4, 9};
double y[2] = {8, 27};
v_div(x, y);
ck_assert_vec_eq(y, 2, 3);
}
END_TEST
Suite* ck_vector_suite()
{
Suite* s;
TCase* tc_core;
s = suite_create("Vector");
tc_core = tcase_create("Core");
tcase_add_test(tc_core, test_v_zero);
tcase_add_test(tc_core, test_v_axpy);
tcase_add_test(tc_core, test_v_scal);
tcase_add_test(tc_core, test_v_dot);
tcase_add_test(tc_core, test_v_nrm2);
tcase_add_test(tc_core, test_v_normalize);
tcase_add_test(tc_core, test_v_mul);
tcase_add_test(tc_core, test_v_div);
suite_add_tcase(s, tc_core);
return s;
}