forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
double_overloads_test.cc
74 lines (65 loc) · 2 KB
/
double_overloads_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "drake/common/double_overloads.h"
#include <gtest/gtest.h>
#include "drake/common/cond.h"
namespace drake {
namespace common {
namespace {
GTEST_TEST(Cond, DoubleIfThenElse) {
const double x = 10.0;
const double y = 5.0;
EXPECT_DOUBLE_EQ(if_then_else(x > y, x, y), x);
EXPECT_DOUBLE_EQ(if_then_else(x < y, x, y), y);
}
GTEST_TEST(Cond, Cond0) {
const double x = 10.0;
// clang-format off
const double cond_result{cond(true, x + 20.0,
false, x + 5.0,
true, x + 3.0,
0.0)};
// clang-format on
EXPECT_DOUBLE_EQ(cond_result, x + 20.0);
}
GTEST_TEST(Cond, Cond1) {
const double x = 10.0;
// clang-format off
const double cond_result{cond(x >= 10.0, x + 20.0,
x >= 5.0, x + 5.0,
x >= 3.0, x + 3.0,
0.0)};
// clang-format on
EXPECT_DOUBLE_EQ(cond_result, x + 20.0);
}
GTEST_TEST(Cond, Cond2) {
const double x = 8.0;
// clang-format off
const double cond_result{cond(x >= 10.0, x + 20.0,
x >= 5.0, x + 5.0,
x >= 3.0, x + 3.0,
0.0)};
// clang-format on
EXPECT_DOUBLE_EQ(cond_result, x + 5.0);
}
GTEST_TEST(Cond, Cond3) {
const double x = 3.0;
// clang-format off
const double cond_result{cond(x >= 10.0, x + 20.0,
x >= 5.0, x + 5.0,
x >= 3.0, x + 3.0,
0.0)};
// clang-format on
EXPECT_DOUBLE_EQ(cond_result, x + 3.0);
}
GTEST_TEST(Cond, Cond4) {
const double x = -10.0;
// clang-format off
const double cond_result{cond(x >= 10.0, x + 20.0,
x >= 5.0, x + 5.0,
x >= 3.0, x + 3.0,
0.0)};
// clang-format on
EXPECT_DOUBLE_EQ(cond_result, 0.0);
}
} // namespace
} // namespace common
} // namespace drake