Skip to content

Commit

Permalink
fix: expectedの値を手計算で算出した値に修正
Browse files Browse the repository at this point in the history
  • Loading branch information
YKhm20020 committed Jun 8, 2024
1 parent 057b76b commit 5d080e8
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions test/MileageTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,26 @@ namespace etrobocon2024_test {
double leftAngle = 40.0;
double rightWheelMileage = 2.0 * rightAngle * radius * M_PI / 360.0;
double leftWheelMileage = 2.0 * leftAngle * radius * M_PI / 360.0;
double expected = (rightWheelMileage + leftWheelMileage) / 2.0;
// 計算過程
// 1.右車輪の累計走行距離を算出
// M_PI = 3.14: rightWheelMileage = 2.0 * 30.0 * 50.0 * 3.14 / 360.0 = 26.1666...
// M_PI = 3.15: rightWheelMileage = 2.0 * 30.0 * 50.0 * 3.15 / 360.0 = 26.25
// 2.左車輪の累計走行距離を算出
// M_PI = 3.14: leftWheelMileage = 2.0 * 40.0 * 50.0 * 3.14 / 360.0 = 32.1111...
// M_PI = 3.15: leftWheelMileage = 2.0 * 40.0 * 50.0 * 3.15 / 360.0 = 35
// 3.両車輪の累計走行距離の平均を算出
// double expected = (rightWheelMileage + leftWheelMileage) / 2.0;
// M_PI = 3.14: (26.1666... + 32.1111...) / 2 = 29.13888...
// M_PI = 3.15: (26.25 + 35) / 2 = 30.625
double expected_min = 29.13888;
double expected_max = 30.625;

// actual: 30.543261909900767
double actual = Mileage::calculateMileage(rightAngle, leftAngle);
EXPECT_DOUBLE_EQ(expected, actual);

// M_PIが3.14で計算した値よりも大きいアサーションと、3.15で計算した値よりも小さいアサーションを両方満たすか
EXPECT_LT(expected_min, actual);
EXPECT_GT(expected_max, actual);
}

TEST(MileageTest, calculateMileageMinus)
Expand All @@ -28,9 +45,11 @@ namespace etrobocon2024_test {
double leftAngle = -40.0;
double rightWheelMileage = 2.0 * rightAngle * radius * M_PI / 360.0;
double leftWheelMileage = 2.0 * leftAngle * radius * M_PI / 360.0;
double expected = (rightWheelMileage + leftWheelMileage) / 2.0;
double expected_min = -30.625;
double expected_max = -29.13888;
double actual = Mileage::calculateMileage(rightAngle, leftAngle);
EXPECT_DOUBLE_EQ(expected, actual);
EXPECT_LT(expected_min, actual);
EXPECT_GT(expected_max, actual);
}

TEST(MileageTest, calculateMileageZero)
Expand All @@ -40,7 +59,7 @@ namespace etrobocon2024_test {
double leftAngle = 0.0;
double rightWheelMileage = 2.0 * rightAngle * radius * M_PI / 360.0;
double leftWheelMileage = 2.0 * leftAngle * radius * M_PI / 360.0;
double expected = (rightWheelMileage + leftWheelMileage) / 2.0;
double expected = 0.0;
double actual = Mileage::calculateMileage(rightAngle, leftAngle);
EXPECT_DOUBLE_EQ(expected, actual);
}
Expand Down

0 comments on commit 5d080e8

Please sign in to comment.