[wpilibc] Add more unit tests (#3494)

This commit is contained in:
PJ Reiniger
2021-08-05 22:04:51 -04:00
committed by GitHub
parent b253246959
commit 94e0db7963
30 changed files with 2588 additions and 89 deletions

View File

@@ -0,0 +1,54 @@
// 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.
#include <hal/HAL.h>
#include "frc/DoubleSolenoid.h"
#include "frc/PneumaticsControlModule.h"
#include "frc/Solenoid.h"
#include "gtest/gtest.h"
namespace frc {
TEST(SolenoidTest, ValidInitialization) {
PneumaticsControlModule pcm{3};
Solenoid solenoid{pcm, 2};
EXPECT_EQ(2, solenoid.GetChannel());
solenoid.Set(true);
EXPECT_TRUE(solenoid.Get());
solenoid.Set(false);
EXPECT_FALSE(solenoid.Get());
}
TEST(SolenoidTest, DoubleInitialization) {
PneumaticsControlModule pcm{3};
Solenoid solenoid{&pcm, 2};
EXPECT_THROW(Solenoid(pcm, 2), std::runtime_error);
}
TEST(SolenoidTest, DoubleInitializationFromDoubleSolenoid) {
PneumaticsControlModule pcm{3};
DoubleSolenoid solenoid{pcm, 2, 3};
EXPECT_THROW(Solenoid(pcm, 2), std::runtime_error);
}
TEST(SolenoidTest, InvalidChannel) {
PneumaticsControlModule pcm{3};
EXPECT_THROW(Solenoid(pcm, 100), std::runtime_error);
}
TEST(SolenoidTest, Toggle) {
PneumaticsControlModule pcm{3};
Solenoid solenoid{pcm, 2};
solenoid.Set(true);
EXPECT_TRUE(solenoid.Get());
solenoid.Toggle();
EXPECT_FALSE(solenoid.Get());
solenoid.Toggle();
EXPECT_TRUE(solenoid.Get());
}
} // namespace frc