1 #include "gtest/gtest.h"
3 #include <stdio.h> /* printf */
4 #include <stdlib.h> /* abort */
5 #include <string.h> /* memset */
11 #define epsilon 0.00001f
13 #define IS_REAL(f) (!isnan(f) && !isinf(f))
14 #define length(points_array) (sizeof(points_array) / sizeof(points_array[0]))
16 // To use a test fixture, derive a class from testing::Test.
17 class MathTestRaw
: public testing::Test
{};
19 TEST_F(MathTestRaw
, y_on_line0
) {
25 EXPECT_NEAR(-0.60f
, y_on_line(-0.25f
, &points
[0], &points
[1]), epsilon
);
26 EXPECT_NEAR(-0.30f
, y_on_line(0.00f
, &points
[0], &points
[1]), epsilon
);
27 EXPECT_NEAR(0.00f
, y_on_line(0.25f
, &points
[0], &points
[1]), epsilon
);
28 EXPECT_NEAR(0.30f
, y_on_line(0.50f
, &points
[0], &points
[1]), epsilon
);
29 EXPECT_NEAR(0.60f
, y_on_line(0.75f
, &points
[0], &points
[1]), epsilon
);
32 TEST_F(MathTestRaw
, y_on_line1
) {
38 EXPECT_NEAR(-1.50f
, y_on_line(-0.25f
, &points
[0], &points
[1]), epsilon
);
39 EXPECT_NEAR(-0.90f
, y_on_line(0.00f
, &points
[0], &points
[1]), epsilon
);
40 EXPECT_NEAR(-0.30f
, y_on_line(0.25f
, &points
[0], &points
[1]), epsilon
);
41 EXPECT_NEAR(0.30f
, y_on_line(0.50f
, &points
[0], &points
[1]), epsilon
);
42 EXPECT_NEAR(0.90f
, y_on_line(0.75f
, &points
[0], &points
[1]), epsilon
);
45 TEST_F(MathTestRaw
, y_on_line2
) {
51 EXPECT_NEAR(-0.30f
, y_on_line(-0.25f
, &points
[0], &points
[1]), epsilon
);
52 EXPECT_NEAR(-0.10f
, y_on_line(0.00f
, &points
[0], &points
[1]), epsilon
);
53 EXPECT_NEAR(0.10f
, y_on_line(0.25f
, &points
[0], &points
[1]), epsilon
);
54 EXPECT_NEAR(0.30f
, y_on_line(0.50f
, &points
[0], &points
[1]), epsilon
);
55 EXPECT_NEAR(0.50f
, y_on_line(0.75f
, &points
[0], &points
[1]), epsilon
);
58 TEST_F(MathTestRaw
, y_on_line3
) {
65 EXPECT_FALSE(IS_REAL(y_on_line(-0.25f
, &points
[0], &points
[1])));
68 TEST_F(MathTestRaw
, y_on_curve0
) {
77 EXPECT_NEAR(-0.50f
, y_on_curve(-0.125f
, points
, length(points
)), epsilon
);
78 EXPECT_NEAR(-0.40f
, y_on_curve(0.000f
, points
, length(points
)), epsilon
);
79 EXPECT_NEAR(-0.30f
, y_on_curve(0.125f
, points
, length(points
)), epsilon
);
80 EXPECT_NEAR(-0.20f
, y_on_curve(0.250f
, points
, length(points
)), epsilon
);
81 EXPECT_NEAR(-0.10f
, y_on_curve(0.375f
, points
, length(points
)), epsilon
);
82 EXPECT_NEAR(0.00f
, y_on_curve(0.500f
, points
, length(points
)), epsilon
);
83 EXPECT_NEAR(0.10f
, y_on_curve(0.625f
, points
, length(points
)), epsilon
);
84 EXPECT_NEAR(0.20f
, y_on_curve(0.750f
, points
, length(points
)), epsilon
);
85 EXPECT_NEAR(0.30f
, y_on_curve(0.875f
, points
, length(points
)), epsilon
);
86 EXPECT_NEAR(0.40f
, y_on_curve(1.000f
, points
, length(points
)), epsilon
);
87 EXPECT_NEAR(0.50f
, y_on_curve(1.125f
, points
, length(points
)), epsilon
);
91 TEST_F(MathTestRaw
, y_on_curve1
) {
100 EXPECT_NEAR(0.00f
, y_on_curve(-0.500f
, points
, length(points
)), epsilon
);
101 EXPECT_NEAR(0.10f
, y_on_curve(-0.250f
, points
, length(points
)), epsilon
);
102 EXPECT_NEAR(0.15f
, y_on_curve(-0.125f
, points
, length(points
)), epsilon
);
103 EXPECT_NEAR(0.20f
, y_on_curve(0.000f
, points
, length(points
)), epsilon
);
104 EXPECT_NEAR(0.22f
, y_on_curve(0.100f
, points
, length(points
)), epsilon
);
105 EXPECT_NEAR(0.30f
, y_on_curve(0.500f
, points
, length(points
)), epsilon
);
106 EXPECT_NEAR(0.00f
, y_on_curve(0.750f
, points
, length(points
)), epsilon
);
107 EXPECT_NEAR(-0.30f
, y_on_curve(1.000f
, points
, length(points
)), epsilon
);
108 EXPECT_NEAR(-0.35f
, y_on_curve(1.250f
, points
, length(points
)), epsilon
);
109 EXPECT_NEAR(-0.50f
, y_on_curve(2.000f
, points
, length(points
)), epsilon
);