1#include "test.h"
2#include <gtest/gtest.h>
3
4#include <base/bezier.h>
5
6// Due to the implementation, derivatives must be divisible by 3 to be exactly
7// represented.
8
9TEST(Bezier, Constant)
10{
11 CCubicBezier Zero = CCubicBezier::With(Start: 0.0f, StartDerivative: 0.0f, EndDerivative: 0.0f, End: 0.0f);
12 ASSERT_EQ(Zero.Evaluate(0.0f), 0.0f);
13 ASSERT_EQ(Zero.Evaluate(0.3f), 0.0f);
14 ASSERT_EQ(Zero.Evaluate(1.0f), 0.0f);
15 ASSERT_EQ(Zero.Derivative(0.0f), 0.0f);
16 ASSERT_EQ(Zero.Derivative(0.3f), 0.0f);
17 ASSERT_EQ(Zero.Derivative(1.0f), 0.0f);
18
19 CCubicBezier Five = CCubicBezier::With(Start: 5.0f, StartDerivative: 0.0f, EndDerivative: 0.0f, End: 5.0f);
20 ASSERT_EQ(Five.Evaluate(0.0f), 5.0f);
21 ASSERT_EQ(Five.Evaluate(0.3f), 5.0f);
22 ASSERT_EQ(Five.Evaluate(1.0f), 5.0f);
23 ASSERT_EQ(Five.Derivative(0.0f), 0.0f);
24 ASSERT_EQ(Five.Derivative(0.3f), 0.0f);
25 ASSERT_EQ(Five.Derivative(1.0f), 0.0f);
26}
27
28TEST(Bezier, Linear)
29{
30 CCubicBezier TripleSlope = CCubicBezier::With(Start: 4.0f, StartDerivative: 3.0f, EndDerivative: 3.0f, End: 7.0f);
31 ASSERT_EQ(TripleSlope.Evaluate(0.0f), 4.0f);
32 ASSERT_EQ(TripleSlope.Evaluate(0.3f), 4.9f);
33 ASSERT_EQ(TripleSlope.Evaluate(1.0f), 7.0f);
34 ASSERT_EQ(TripleSlope.Derivative(0.0f), 3.0f);
35 ASSERT_EQ(TripleSlope.Derivative(0.3f), 3.0f);
36 ASSERT_EQ(TripleSlope.Derivative(1.0f), 3.0f);
37}
38
39TEST(Bezier, Arbitrary)
40{
41 CCubicBezier Something = CCubicBezier::With(Start: 4.9f, StartDerivative: 1.5f, EndDerivative: -4.5f, End: 1.0f);
42 ASSERT_EQ(Something.Evaluate(0.0f), 4.9f);
43 ASSERT_EQ(Something.Evaluate(1.0f), 1.0f);
44 ASSERT_EQ(Something.Derivative(0.0f), 1.5f);
45 ASSERT_EQ(Something.Derivative(1.0f), -4.5f);
46}
47