blob: 70ca4e88233854c3c7de3c569d53335cebd27120 [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2014. All Rights Reserved. */
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 <AnalogOutput.h>
9#include <AnalogPotentiometer.h>
10#include <Timer.h>
11#include <ControllerPower.h>
12#include "TestBench.h"
13#include "gtest/gtest.h"
14
15static const double kScale = 270.0;
16static const double kAngle = 180.0;
17
18class AnalogPotentiometerTest : public testing::Test {
19 protected:
20 AnalogOutput *m_fakePot;
21 AnalogPotentiometer *m_pot;
22
23 virtual void SetUp() override {
24 m_fakePot = new AnalogOutput(TestBench::kAnalogOutputChannel);
25 m_pot =
26 new AnalogPotentiometer(TestBench::kFakeAnalogOutputChannel, kScale);
27 }
28
29 virtual void TearDown() override {
30 delete m_fakePot;
31 delete m_pot;
32 }
33};
34
35TEST_F(AnalogPotentiometerTest, TestInitialSettings) {
36 m_fakePot->SetVoltage(0.0);
37 Wait(0.1);
38 EXPECT_NEAR(0.0, m_pot->Get(), 5.0)
39 << "The potentiometer did not initialize to 0.";
40}
41
42TEST_F(AnalogPotentiometerTest, TestRangeValues) {
43 m_fakePot->SetVoltage(kAngle / kScale * ControllerPower::GetVoltage5V());
44 Wait(0.1);
45 EXPECT_NEAR(kAngle, m_pot->Get(), 2.0)
46 << "The potentiometer did not measure the correct angle.";
47}