#include "vector.h" #include "derived.h" vector *v[NUM_VECTORS]; void initialize_all() { v[0] = make_vector(3.3, 5.5); v[1] = make_vector(5.5, -3.3); v[2] = make_vector(8.2343, 6.34); v[3] = make_vector(4.2, 7.4); v[4] = make_vector(0, 0); v[5] = make_vector(3.3, 5.5); v[6] = make_vector(5.5, -3.3); v[7] = make_vector(8.2343, 6.34); v[8] = make_vector(4.2, 7.4); } void print_coordinates(int index) { float x = x_coordinate(v[index]); float y = y_coordinate(v[index]); printf("\tv[%d] = ( %f , %f )\n", index, x, y); } void test_mul(int index, float r) { mul(v[index], r); printf("\tv[%d] = v[%d] * %f \n", index, index, r); print_coordinates(index); } void test_sum(int index, float a, float b) { sum(v[index], a, b); printf("\tv[%d] = v[%d] + (%f, %f)\n", index, index, a, b); print_coordinates(5); } void test_magnitude(int index) { printf("\tmag(v[%d]) = %f\n", index, magnitude(v[index])); } void test_angle(int index) { printf("\tangle(v[%d]) = %f\n", index, angle(v[index])); } void test_orthogonal(int index1, int index2) { printf("\tv[%d] and v[%d] orthogonal? ", index1, index2); if (orthogonal(v[index1], x_coordinate(v[index2]), y_coordinate(v[index2]))) printf("YES\n"); else printf("NO\n"); } main() { int counter; initialize_all(); printf("================\n"); printf("Testing vector.c\n"); printf("================\n\n"); printf("Testing \"make_vector\", \"x_coordinate\" and \"y_coordinate\"\n"); for(counter=0; counter < NUM_VECTORS; counter++) print_coordinates(counter); printf("\n\n"); printf("Testing \"mul\"\n"); test_mul(2, 3.5); test_mul(3, 3.6); test_mul(4, -4.21); printf("\n\n"); printf("Testing \"sum\"\n"); test_sum(5, 5.3, 2.7); test_sum(6, -7.4, 9.2); test_sum(7, 2.7, 1.1); printf("\n\n"); printf("=================\n"); printf("Testing derived.c\n"); printf("=================\n\n"); printf("Testing \"magnitude\"\n"); test_magnitude(0); test_magnitude(1); test_magnitude(2); test_magnitude(3); printf("\n\n"); printf("Testing \"angle\"\n"); test_angle(4); test_angle(5); test_angle(6); test_angle(7); printf("\n\n"); printf("Testing \"orthogonal\"\n"); test_orthogonal(0,1); test_orthogonal(1,2); test_orthogonal(2,3); test_orthogonal(3,2); test_orthogonal(3,4); }