2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2016-01-02 03:02:34 -08:00
|
|
|
|
2014-05-23 13:28:58 -04:00
|
|
|
package edu.wpi.first.wpilibj;
|
|
|
|
|
|
2014-06-13 15:03:38 -04:00
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
2018-05-24 00:31:04 -04:00
|
|
|
import org.junit.Test;
|
|
|
|
|
|
2014-05-23 13:28:58 -04:00
|
|
|
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
|
|
|
|
|
2016-05-20 12:07:40 -04:00
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
|
2014-05-23 13:28:58 -04:00
|
|
|
|
|
|
|
|
public class TimerTest extends AbstractComsSetup {
|
2015-06-25 15:07:55 -04:00
|
|
|
private static final Logger logger = Logger.getLogger(TimerTest.class.getName());
|
|
|
|
|
private static final long TIMER_TOLERANCE = (long) (2.5 * 1000);
|
|
|
|
|
private static final long TIMER_RUNTIME = 5 * 1000000;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected Logger getClassLogger() {
|
|
|
|
|
return logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void delayTest() {
|
|
|
|
|
// Given
|
2017-12-10 21:52:49 -08:00
|
|
|
long startTime = RobotController.getFPGATime();
|
2015-06-25 15:07:55 -04:00
|
|
|
|
|
|
|
|
// When
|
|
|
|
|
Timer.delay(TIMER_RUNTIME / 1000000);
|
2017-12-10 21:52:49 -08:00
|
|
|
long endTime = RobotController.getFPGATime();
|
2015-06-25 15:07:55 -04:00
|
|
|
long difference = endTime - startTime;
|
|
|
|
|
|
|
|
|
|
// Then
|
|
|
|
|
long offset = difference - TIMER_RUNTIME;
|
|
|
|
|
assertEquals("Timer.delay ran " + offset + " microseconds too long", TIMER_RUNTIME, difference,
|
|
|
|
|
TIMER_TOLERANCE);
|
|
|
|
|
}
|
2014-05-23 13:28:58 -04:00
|
|
|
|
|
|
|
|
}
|