NerfUS mobile node that manages a target for the Nerf gun firing range
Dependencies: LedController mbed-rtos mbed NerfUSXbee Servomotor TargetManager
Fork of NerfUS by
Diff: TESTS/TargetManagerTest.cpp
- Revision:
- 32:50b777bab5a4
- Parent:
- 31:c6dc9811ed14
- Child:
- 34:85994e0501fb
--- a/TESTS/TargetManagerTest.cpp Mon Mar 27 19:10:07 2017 -0400 +++ b/TESTS/TargetManagerTest.cpp Mon Mar 27 20:39:08 2017 -0400 @@ -33,3 +33,60 @@ target_manager.target_missed(0); target_manager.target_hit(0); } + +TEST_F(TargetManagerTest, WhenExecutingAllyTargetThenUseTheCorrectTargetTypeAndTimeout) +{ + EXPECT_CALL(mock_target_a, ally_command()); + EXPECT_CALL(mock_nerfus_ticker, start(1000)); + + TargetManager target_manager(targets, mock_nerfus_ticker); + std::vector<TargetInfo> sequence; + sequence.push_back(make_TargetInfo(0, TARGET_TYPE_ALLY, 1000)); + target_manager.execute(sequence); +} + +TEST_F(TargetManagerTest, WhenExecutingEnemyTargetThenUseTheCorrectTargetTypeAndTimeout) +{ + EXPECT_CALL(mock_target_b, enemy_command()); + EXPECT_CALL(mock_nerfus_ticker, start(2000)); + + TargetManager target_manager(targets, mock_nerfus_ticker); + std::vector<TargetInfo> sequence; + sequence.push_back(make_TargetInfo(1, TARGET_TYPE_ENEMY, 2000)); + target_manager.execute(sequence); +} + +TEST_F(TargetManagerTest, WhenActiveTargetIsHitThenSendTheEvent) +{ + EXPECT_CALL(mock_target_a, ally_command()); + EXPECT_CALL(mock_nerfus_ticker, start(1000)); + EXPECT_CALL(mock_nerfus_ticker, get_time_ms()) + .WillOnce(::testing::Return(42)); + EXPECT_CALL(mock_nerfus_ticker, stop()); + EXPECT_CALL(mock_target_a, hit(42)); + + TargetManager target_manager(targets, mock_nerfus_ticker); + std::vector<TargetInfo> sequence; + sequence.push_back(make_TargetInfo(0, TARGET_TYPE_ALLY, 1000)); + target_manager.execute(sequence); + + target_manager.target_hit(0); +} + +TEST_F(TargetManagerTest, WhenActiveTargetIsMissedThenSendTheEvent) +{ + EXPECT_CALL(mock_target_a, ally_command()); + EXPECT_CALL(mock_nerfus_ticker, start(1000)); + EXPECT_CALL(mock_nerfus_ticker, get_time_ms()) + .WillOnce(::testing::Return(42)); + EXPECT_CALL(mock_nerfus_ticker, stop()); + EXPECT_CALL(mock_target_a, timeout(42)); + + TargetManager target_manager(targets, mock_nerfus_ticker); + std::vector<TargetInfo> sequence; + sequence.push_back(make_TargetInfo(0, TARGET_TYPE_ALLY, 1000)); + target_manager.execute(sequence); + + target_manager.target_missed(0); +} +