Skip to content
Snippets Groups Projects
Commit 99046854 authored by orestis.malaspin's avatar orestis.malaspin
Browse files

updated vec2 lib and tests

parent 2e5ff2f3
No related branches found
No related tags found
No related merge requests found
Pipeline #12137 passed
#include <stdlib.h>
#include <stdio.h>
#include "vec2.h"
int main() {
vec2 v1 = vec2_create(1.0, -1.0);
// vec2_print(v1);
vec2 v2 = vec2_create(4.0, -2.0);
vec2 v2 = vec2_create(4.0, 2.0);
// vec2_print(v2);
vec2 v3 = vec2_sub(v1, v2);
vec2_print(v3);
printf("%f\n", vec2_dot(v2, vec2_create(1.0, 0.0)));
return EXIT_SUCCESS;
}
\ No newline at end of file
#include "minunit.h"
#include "../vec2.h"
#include <math.h>
static vec2 four_two;
static vec2 minus_three_nine;
......@@ -84,18 +85,43 @@ MU_TEST(test_vec2_mul) {
);
}
MU_TEST(test_vec2_scalar_product) {
MU_TEST(test_vec2_dot) {
mu_assert_double_eq(
vec2_scalar_product(four_two, minus_three_nine),
vec2_dot(four_two, minus_three_nine),
6.0
);
mu_assert_double_eq(
vec2_scalar_product(e_x, e_y),
vec2_dot(e_x, e_y),
0.0
);
mu_assert_double_eq(
vec2_dot(four_two, e_x),
4.0
);
mu_assert_double_eq(
vec2_dot(four_two, e_y),
2.0
);
}
MU_TEST(test_vec2_norm) {
mu_assert_double_eq(
vec2_norm(e_x),
1.0
);
mu_assert_double_eq(
vec2_norm(e_y),
1.0
);
mu_assert_double_eq(
vec2_norm(four_two),
sqrt(20.0)
);
}
MU_TEST_SUITE(test_suite) {
......@@ -106,7 +132,8 @@ MU_TEST_SUITE(test_suite) {
MU_RUN_TEST(test_vec2_add);
MU_RUN_TEST(test_vec2_sub);
MU_RUN_TEST(test_vec2_mul);
MU_RUN_TEST(test_vec2_scalar_product);
MU_RUN_TEST(test_vec2_dot);
MU_RUN_TEST(test_vec2_norm);
}
int main() {
......
......@@ -28,12 +28,12 @@ vec2 vec2_mul(double scalar, vec2 lhs) {
);
}
double vec2_scalar_product(vec2 lhs, vec2 rhs) {
double vec2_dot(vec2 lhs, vec2 rhs) {
return lhs.x * rhs.x + lhs.y * rhs.y;
}
double vec2_norm_sqr(vec2 v) {
return vec2_scalar_product(v, v);
return vec2_dot(v, v);
}
double vec2_norm(vec2 v) {
......
......@@ -15,7 +15,7 @@ vec2 vec2_sub(vec2 lhs, vec2 rhs);
vec2 vec2_mul(double scalar, vec2 lhs);
double vec2_scalar_product(vec2 lhs, vec2 rhs);
double vec2_dot(vec2 lhs, vec2 rhs);
double vec2_norm_sqr(vec2 v);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment