blob: b8f859c1457ad34ec6b686e67199660bf09ff8a4 [file] [log] [blame]
Brian Silverman41cdd3e2019-01-19 19:48:58 -08001/*----------------------------------------------------------------------------*/
2/* Copyright (c) 2014-2018 FIRST. 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 "frc/Timer.h" // NOLINT(build/include_order)
9
10#include "TestBench.h"
11#include "gtest/gtest.h"
12
13using namespace frc;
14
15static const double kWaitTime = 0.5;
16
17class TimerTest : public testing::Test {
18 protected:
19 Timer* m_timer;
20
21 void SetUp() override { m_timer = new Timer; }
22
23 void TearDown() override { delete m_timer; }
24
25 void Reset() { m_timer->Reset(); }
26};
27
28/**
29 * Test if the Wait function works
30 */
31TEST_F(TimerTest, Wait) {
32 Reset();
33
34 double initialTime = m_timer->GetFPGATimestamp();
35
36 Wait(kWaitTime);
37
38 double finalTime = m_timer->GetFPGATimestamp();
39
40 EXPECT_NEAR(kWaitTime, finalTime - initialTime, 0.001);
41}