Skip to content
Snippets Groups Projects
Commit ca37e73a authored by JM's avatar JM
Browse files

Test unitaure compute_e

parent af2b1331
Branches
No related tags found
No related merge requests found
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
#include "field.h"
int main() {
printf("Field_tests\n");
return EXIT_SUCCESS;
typedef struct _test_result
{
bool passed;
const char *name;
} test_result;
typedef test_result (*unit_test_t)(void);
void print_in_color(char *color, char *text)
{
printf("\033%s", color);
printf("%s", text);
printf("\033[0m");
}
void print_in_red(char *text)
{
print_in_color("[0;31m", text);
}
void print_in_green(char *text)
{
print_in_color("[0;32m", text);
}
bool dbl_eq(double a, double b)
{
return fabs(a - b) < 1e-6;
}
test_result t_compute_e_0()
{
double test_charge_q[] = {0.25, -0.25, -0.75, 0.9, 0.5};
vec2 test_position[] = {
vec2_create(0.25, 0.6),
vec2_create(0.01, 0.01),
vec2_create(0.9, 0.9),
vec2_create(0.5, 0.5),
vec2_create(0.25, 0.25)
};
vec2 awaited_result[] = {
vec2_create(0, 224700000000.000122),
vec2_create(3320060992.530107, 6778457859.748968),
vec2_create(-9855843283.957649, -6065134328.589322),
vec2_create(129427200000, 0),
vec2_create(0, -71904000000)
};
uint32_t nb_tests = sizeof(test_charge_q) / sizeof(double);
bool passed = true;
for (uint32_t i = 0; i < nb_tests; i++)
{
charge_t c = charge_create(test_charge_q[i], vec2_create(0.25, 0.5));
vec2 res = vec2_create_zero();
compute_e(c, test_position[i], 0.01, &res);
if (!vec2_is_approx_equal(res, awaited_result[i], 0.0001))
{
passed = false;
break;
}
}
return (test_result){.passed = passed, .name = "Test compute_e 0"};
}
test_result t_compute_total_normalized_e_0()
{
bool passed = true;
return (test_result){.passed = passed, .name = "Test compute_total_normalized 0"};
}
test_result t_compute_delta_x_0()
{
bool passed = true;
return (test_result){.passed = passed, .name = "Test compute_delta_x 0"};
}
test_result t_is_in_screen_0()
{
bool passed = true;
return (test_result){.passed = passed, .name = "Test is_in_screen 0"};
}
// Add or remove your test function name here
const unit_test_t tests[] = {t_compute_e_0, t_compute_total_normalized_e_0, t_compute_delta_x_0, t_is_in_screen_0};
int main()
{
uint32_t nb_tests = sizeof(tests) / sizeof(unit_test_t);
char message[256];
bool all_passed = true;
for (uint32_t i = 0; i < nb_tests; i++)
{
printf("Running test n°%d: ...\n", i);
test_result r = tests[i]();
if (r.passed)
{
sprintf(message, "\t- %s : OK", r.name);
print_in_green(message);
}
else
{
all_passed = false;
sprintf(message, "\t- %s : FAILED", r.name);
print_in_red(message);
}
printf("\n");
}
if (all_passed)
print_in_green("\nTests suite result : OK\n");
else
print_in_red("\nTests suite result : FAILED\n");
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment