blob: 07934ae367b569a4f675df508c1f5cb19b5b41ef [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
Brian Silverman1a675112016-02-20 20:42:49 -05002/* Copyright (c) FIRST 2014-2016. All Rights Reserved. */
Brian Silverman26e4e522015-12-17 01:56:40 -05003/* 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}