etrobocon2018 feat.KatLab  770af34cce41ae9c30c41303275e1add2daae0c3 (with uncommitted changes)
 全て クラス 名前空間 ファイル 関数 変数 列挙型 列挙値 フレンド マクロ定義 ページ
SpeedControlTest.cpp
[詳解]
1 
5 /* コンパイル(平木場)
6 $ g++-7 -w ../src/Pid.cpp ../src/SpeedControl.cpp SpeedControlTest.cpp gtest_main.o gtest-all.o
7 -I../include -I../../googletest/googletest/include $ ./a.out
8 */
9 
10 #include "SpeedControl.h" // このヘッダファイルのcppファイルをテスト
11 #include <gtest/gtest.h>
12 
13 namespace etrobocon2018_test {
14 
15  // SpeedControl.calculateSpeedForPid()で100を超えない
16  TEST(SpeedControlTest, calculateSpeedForPidTest1)
17  {
18  SpeedControl sp;
19  int value;
20 
21  sp.setPid(2.0, 4.8, 0.024, 150.0);
22  value = sp.calculateSpeedForPid(0, 0);
23 
24  ASSERT_LE(value, 100);
25  }
26 
27  // SpeedControl.calculateSpeedForPid()で-100より下回らない
28  TEST(SpeedControlTest, calculateSpeedForPidTest2)
29  {
30  SpeedControl sp;
31  int value, r, l;
32  r = l = 0;
33  sp.setPid(2.0, 4.8, 0.024, 150.0);
34  for(int i = 0; i < 25; i++) {
35  if(i == 24) {
36  r = l += 10000;
37  }
38  value = sp.calculateSpeedForPid(r, l);
39  l = r += i * 10;
40  }
41 
42  ASSERT_GE(value, -100);
43  }
44 
46  public:
48  int calcDistance4ms(int curAngleL, int curAngleR)
49  {
50  return SpeedControl::calcDistance4ms(curAngleL, curAngleR);
51  }
52  };
53 
54  // SpeedControl.calcDistance4msで4msで360度進んだとき、
55  // 円周分進んだことになる。
56  TEST(SpeedControlTest, calcDistance4msTest1)
57  {
59  int value;
60  float circle;
61 
62  circle = 2 * 3.14 * 81;
63  value = sp.calcDistance4ms(0, 0);
64  value += sp.calcDistance4ms(90, 90);
65  value += sp.calcDistance4ms(180, 180);
66  value += sp.calcDistance4ms(270, 270);
67  value += sp.calcDistance4ms(360, 360);
68 
69  ASSERT_EQ(value, (int)circle);
70  }
71 } // namespace etrobocon2018_test
std::int8_t calcDistance4ms(std::int32_t curAngleL, std::int32_t curAngleR)
std::int32_t calculateSpeedForPid(std::int32_t curAngleL, std::int32_t curAngleR)
void setPid(double p_gain_, double i_gain_, double d_gain_, double target_)
Definition: Pid.cpp:40
TEST(AIAnswerArrayTest, construct)
int calcDistance4ms(int curAngleL, int curAngleR)
PID制御による速度制御クラス
Definition: SpeedControl.h:18
PID制御による速度制御クラス