#include <stdlib.h>
#include <stdio.h>
#include "tests.h"
#ifndef M_SQRT3_4
#define M_SQRT3_4 (0.866025403784438646764)
#endif
#define NUM_TESTS (1000)
static void generate_rand_angle(
static void check_angle_sum_sub(
double ref_sum, double ref_sub);
static void check_compare_angles(double dble_angle_a, double dble_angle_b,
srand(1337);
double angle;
double angles[] = {0.0, 0.24, 0.26, 0.5, 0.8, 1.0, 1.1, 1.5, 1.6, 1.9};
for (size_t i = 0; i < sizeof(angles) / sizeof(angles[0]); ++i)
angles[i] *= M_PI;
};
{
for (size_t i = 0; i < sizeof(angles) / sizeof(angles[0]); ++i)
if (fabs(
compute_angle(compute_sin_cos_angle(angles[i])) - angles[i]) >
PUT_ERR("error in compute_angle");
for (size_t i = 0; i < NUM_TESTS; ++i) {
double temp_angle;
PUT_ERR("error in compute_angle");
}
}
{
for (size_t i = 0; i < sizeof(angles)/sizeof(angles[0]); ++i) {
for (size_t j = 0; j < sizeof(angles)/sizeof(angles[0]); ++j) {
{compute_sin_cos_angle(angles[i]), compute_sin_cos_angle(angles[j])};
check_compare_angles(
angles[i], angles[j], temp_sin_cos_angles[0], temp_sin_cos_angles[1]);
}
}
for (size_t i = 0; i < NUM_TESTS; ++i) {
double temp_angles[2];
for (size_t j = 0; j < 2; ++j)
generate_rand_angle(&(temp_angles[j]), &(temp_sin_cos_angles[j]));
for (size_t j = 0; j < 2; ++j)
for (size_t k = 0; k < 2; ++k)
check_compare_angles(temp_angles[j], temp_angles[k],
temp_sin_cos_angles[j], temp_sin_cos_angles[k]);
}
for (size_t i = 0; i < sizeof(sin_cos_angles)/sizeof(sin_cos_angles[0]); ++i) {
for (size_t j = 0; j < sizeof(sin_cos_angles)/sizeof(sin_cos_angles[0]); ++j) {
if ((compare_ij !=
compare_angles(sin_cos_angles[i], sin_cos_angles[j])) ||
PUT_ERR("error in compare_angles");
}
}
}
{
for (size_t i = 0; i < sizeof(angles)/sizeof(angles[0]); ++i) {
for (size_t j = 0; j < sizeof(angles)/sizeof(angles[0]); ++j) {
{compute_sin_cos_angle(angles[i]), compute_sin_cos_angle(angles[j])};
check_angle_sum_sub(temp_sin_cos_angles[0], temp_sin_cos_angles[1],
angles[i] + angles[j], angles[i] - angles[j]);
}
}
for (size_t i = 0; i < NUM_TESTS; ++i) {
double temp_angles[2];
for (size_t j = 0; j < 2; ++j)
generate_rand_angle(&(temp_angles[j]), &(temp_sin_cos_angles[j]));
for (size_t j = 0; j < 2; ++j)
for (size_t k = 0; k < 2; ++k)
check_angle_sum_sub(
temp_sin_cos_angles[j], temp_sin_cos_angles[k],
temp_angles[j] + temp_angles[k], temp_angles[j] - temp_angles[k]);
}
}
{
for (size_t i = 0; i < sizeof(angles)/sizeof(angles[0]); ++i)
if (fabs(angles[i] * 0.5 -
PUT_ERR("error in half_angle");
for (size_t i = 0; i < NUM_TESTS; ++i) {
if (fabs(angle * 0.5 -
PUT_ERR("error in half_angle");
}
}
{
for (size_t i = 0; i < sizeof(angles)/sizeof(angles[0]); ++i)
if (fabs(angles[i] * 0.25 -
PUT_ERR("error in quarter_angle");
for (size_t i = 0; i < NUM_TESTS; ++i) {
if (fabs(angle * 0.25 -
PUT_ERR("error in quarter_angle");
}
}
return TEST_EXIT_CODE;
}
static void generate_rand_angle(
*angle = (2.0 * M_PI) * ((double)rand() / (double)RAND_MAX);
}
static struct sin_cos_angle compute_sin_cos_angle(double angle) {
double sin_angle =
sin(angle);
double cos_angle =
cos(angle);
}
return (a > b) - (a < b);
}
return (a > b) - (a < b);
}
static void check_angle_sum_sub(
double ref_sum, double ref_sub) {
double angle_sum =
compute_angle(sum) + ((big_sum)?(2.0*M_PI):0.0);
if (fabs(angle_sum - ref_sum) >
yac_angle_tol) PUT_ERR(
"error sum_angles");
if (fabs(angle_sub - ref_sub) >
yac_angle_tol) PUT_ERR(
"error sub_angles");
}
static void check_compare_angles(double dble_angle_a, double dble_angle_b,
PUT_ERR("error in compare_angles");
PUT_ERR("error in sin_cos_angle_to_dble");
}
int main(int argc, char **argv)
static int compare_size_t(const void *a, const void *b)
static const struct sin_cos_angle SIN_COS_M_PI
static double sin_cos_angle_to_dble(struct sin_cos_angle angle)
static struct sin_cos_angle quarter_angle(struct sin_cos_angle angle)
static int compare_angles(struct sin_cos_angle a, struct sin_cos_angle b)
static int sub_angles(struct sin_cos_angle a, struct sin_cos_angle b, struct sin_cos_angle *restrict sub)
static double compute_angle(struct sin_cos_angle angle)
return angles in the range of [0;2PI[
static int sum_angles(struct sin_cos_angle a, struct sin_cos_angle b, struct sin_cos_angle *restrict sum)
static struct sin_cos_angle sin_cos_angle_new(double sin, double cos)
static struct sin_cos_angle half_angle(struct sin_cos_angle angle)
static int compare_double(void const *a, void const *b)