Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/ |
Brian Silverman | 1a67511 | 2016-02-20 20:42:49 -0500 | [diff] [blame^] | 2 | /* Copyright (c) FIRST 2014-2016. All Rights Reserved. */ |
Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
| 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ |
| 5 | /* the project. */ |
| 6 | /*----------------------------------------------------------------------------*/ |
| 7 | |
| 8 | #include <BuiltInAccelerometer.h> |
| 9 | #include <Timer.h> |
| 10 | #include "gtest/gtest.h" |
| 11 | |
| 12 | static constexpr double kAccelerationTolerance = 0.1; |
| 13 | /** |
| 14 | * There's not much we can automatically test with the on-board accelerometer, |
| 15 | * but checking for gravity is probably good enough to tell that it's working. |
| 16 | */ |
| 17 | TEST(BuiltInAccelerometerTest, Accelerometer) { |
| 18 | BuiltInAccelerometer accelerometer; |
| 19 | |
| 20 | /* The testbench sometimes shakes a little from a previous test. Give it |
| 21 | some time. */ |
| 22 | Wait(1.0); |
| 23 | |
| 24 | ASSERT_NEAR(0.0, accelerometer.GetX(), kAccelerationTolerance); |
| 25 | ASSERT_NEAR(1.0, accelerometer.GetY(), kAccelerationTolerance); |
| 26 | ASSERT_NEAR(0.0, accelerometer.GetZ(), kAccelerationTolerance); |
| 27 | } |