-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_vector.c
66 lines (58 loc) · 1.61 KB
/
test_vector.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
#include "vector/vector.h"
#include <stdio.h>
#include <string.h>
void print_vector(vector_t src);
int main(int argc, char *argv[])
{
// Initialization using existing array of size VECTOR_SIZE
vector_t first, second, result;
int els1[] = {1, 2, 3};
int els2[] = {4, 5, 6};
int e1[] = {1, 0, 0};
int e2[] = {0, 1, 0};
first = vector_init(els1);
second = vector_init(els2);
printf("Testing Vector operations over %d Dimension\n\n", VECTOR_SIZE);
// Testing addition
printf("\nTesting Addition\n");
result = vector_add(first, second);
print_vector(first);
printf("+\n");
print_vector(second);
print_vector(result);
// Testing substraction
printf("\nTesting Substraction\n");
result = vector_sub(first, second);
print_vector(first);
printf("-\n");
print_vector(second);
print_vector(result);
// Testing dot product
printf("\nTesting Dot product\n");
vector_el result_el = vector_dot(first, second);
print_vector(first);
printf(".\n");
print_vector(second);
printf("= %d\n", result_el);
// Testing cross product
printf("\nTesting cross product\n");
first = vector_init(e1);
second = vector_init(e2);
result = vector_cross(first, second);
print_vector(first);
printf("x\n");
print_vector(second);
print_vector(result);
}
void print_vector(vector_t src)
{
int i;
char msg[256], num[16];
sprintf(msg, "Vector[%d] = ", VECTOR_SIZE);
for(i = 0; i < VECTOR_SIZE; i++)
{
sprintf(num, "%d ", src.elements[i]);
strcat(msg, num);
}
printf("%s\n", msg);
}