etrobocon2018 feat.KatLab  770af34cce41ae9c30c41303275e1add2daae0c3 (with uncommitted changes)
 全て クラス 名前空間 ファイル 関数 変数 列挙型 列挙値 フレンド マクロ定義 ページ
SelfLocalizationTest.cpp
[詳解]
1 
5 /* コンパイル(平木場)
6 $ g++-7 SelfLocalizationTest.cpp ../src/SelfLocalization.cpp gtest_main.o gtest-all.o -I../include
7 -I../../googletest/googletest/include
8 */
9 
10 #include "SelfLocalization.h" // このヘッダファイルのcppファイルをテスト
11 #include <gtest/gtest.h>
12 
13 namespace etrobocon2018_test {
14 
15  void straight(SelfLocalization& sl, int kyori, int& l, int& r)
16  {
17  for(int i = 0; i < kyori; i++) {
18  l += 10;
19  r += 10;
20  sl.update(l, r);
21  }
22  }
23 
24  void curve(SelfLocalization& sl, float sub_degree, int& l, int& r)
25  {
26  int angle_one = -3;
27  if(sub_degree < 0) angle_one = 3;
28  sub_degree = sub_degree / 90;
29  for(int i = 0; i < 120 * std::abs(sub_degree); i++) {
30  l += angle_one;
31  sl.update(l, r);
32  }
33  }
34 
35  TEST(SelfLocalizationTest, CalculateTest1)
36  {
37  SelfLocalization sl(0, 0, false);
38 
39  sl.update(100, 200);
40 
41  ASSERT_GE(sl.getPointX(), 10.0);
42  ASSERT_GE(sl.getPointY(), 2.0);
43  }
44 
45  TEST(SelfLocalizationTest, calculateBetweenEv3AndBorder1)
46  {
47  SelfLocalization sl(0, 0, true);
48  float distance = sl.calculate_between_ev3_and_border(0.0, 0.0, 10.0, 10.0, 0.0, 0.0);
49  ASSERT_FLOAT_EQ(distance, 0.0);
50  }
51 
52  TEST(SelfLocalizationTest, calculateBetweenEv3AndBorder2)
53  {
54  SelfLocalization sl(0, 0, true);
55  float distance = sl.calculate_between_ev3_and_border(-50.0, 80.0, 127.0, 91.0, -85.0, 70.0);
56  ASSERT_NEAR(distance, 7.809, 0.001);
57  }
58 
59  TEST(SelfLocalizationTest, calculateBetweenEv3AndBorder3)
60  {
61  SelfLocalization sl(0, 0, true);
62  float distance = sl.calculate_between_ev3_and_border(2.0, 1.0, 6.0, 7.0, 3.0, 4.0);
63  ASSERT_NEAR(distance, -0.83205, 0.001);
64  }
65 
66  TEST(SelfLocalizationTest, calculateBetweenEv3AndBorder4)
67  {
68  SelfLocalization sl(0, 0, true);
69  float distance = sl.calculate_between_ev3_and_border(0.0, 0.0, 10.0, 0.0, 3.0, 0.0);
70  ASSERT_NEAR(distance, 0.0, 0.001);
71  }
72 
73  TEST(SelfLocalizationTest, calculateBetweenEv3AndBorder5)
74  {
75  SelfLocalization sl(0, 0, true);
76  float distance = sl.calculate_between_ev3_and_border(0.0, 0.0, 0.0, 10.0, 0.0, 3.0);
77  ASSERT_NEAR(distance, 0.0, 0.001);
78  }
79 
80  TEST(SelfLocalizationTest, calculateCurrentAngleTest1)
81  {
82  SelfLocalization sl(0, 0, false);
83  int l, r;
84  l = r = 0;
85 
86  straight(sl, 20, l, r);
87  curve(sl, 45, l, r);
88 
90 
91  ASSERT_EQ(sl.current_angle_degree, 69);
92  }
93 
94  TEST(SelfLocalizationTest, calculateCurrentAngleTest2)
95  {
96  SelfLocalization sl(0, 0, false);
97  int l, r;
98  l = r = 0;
99 
100  straight(sl, 20, l, r);
101  curve(sl, -45, l, r);
102 
104 
105  ASSERT_EQ(sl.current_angle_degree, -69);
106  }
107 
108  TEST(SelfLocalizationTest, calculateCurrentAngleTest3)
109  {
110  SelfLocalization sl(0, 0, false);
111  int l, r;
112  l = r = 0;
113 
114  straight(sl, 20, l, r);
115  curve(sl, 90, l, r);
116  straight(sl, 20, l, r);
117  curve(sl, -90, l, r);
118 
120 
121  ASSERT_EQ(sl.current_angle_degree, 0);
122  }
123 
124  TEST(SelfLocalizationTest, isOverNormalVectorTest1)
125  {
126  SelfLocalization sl(0, 0, false);
127  sl.init_normal_vector(0.0, 0.0, 100.0, 100.0, 0.0, 0.0);
128  ASSERT_EQ(sl.is_over_normal_vector(10.0, 10.0), false);
129  }
130 
131  TEST(SelfLocalizationTest, isOverNormalVectorTest2)
132  {
133  SelfLocalization sl(0, 0, false);
134  sl.init_normal_vector(0.0, 0.0, 100.0, 100.0, 0.0, 0.0);
135  ASSERT_EQ(sl.is_over_normal_vector(101.0, 101.0), true);
136  }
137 
138  TEST(SelfLocalizationTest, isOverNormalVectorTest3)
139  {
140  SelfLocalization sl(0, 0, false);
141  sl.init_normal_vector(0.0, 0.0, 100.0, 100.0, 0.0, 0.0);
142  ASSERT_EQ(sl.is_over_normal_vector(99.0, 101.0), true);
143  }
144 
145  TEST(SelfLocalizationTest, isOverNormalVectorTest4)
146  {
147  SelfLocalization sl(0, 0, false);
148  sl.init_normal_vector(0.0, 0.0, 100.0, 100.0, 0.0, 0.0);
149  ASSERT_EQ(sl.is_over_normal_vector(101.0, 99.0), true);
150  }
151 } // namespace etrobocon2018_test
void straight(SelfLocalization &sl, int kyori, int &l, int &r)
void init_normal_vector(float _start_x, float _start_y, float _goal_x, float _goal_y, float _current_x, float _current_y)
void curve(SelfLocalization &sl, float sub_degree, int &l, int &r)
TEST(AIAnswerArrayTest, construct)
void update(std::int32_t left_motor_sl, std::int32_t right_motor_sl)
float calculate_between_ev3_and_border(float _start_x, float _start_y, float _goal_x, float _goal_y, float _current_x, float _current_y)
bool is_over_normal_vector(float _current_x, float _current_y)