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:
- 38:70a1c8bd2877
- Parent:
- 37:8fc7845ae95b
- Child:
- 51:6bf268cd1a1b
diff -r 8fc7845ae95b -r 70a1c8bd2877 TESTS/TargetManagerTest.cpp --- a/TESTS/TargetManagerTest.cpp Sat Apr 08 14:08:37 2017 -0400 +++ b/TESTS/TargetManagerTest.cpp Sun Apr 09 13:12:22 2017 -0400 @@ -14,23 +14,28 @@ { targets.push_back(&mock_target_a); targets.push_back(&mock_target_b); + + tickers.push_back(&mock_nerfus_ticker_a); + tickers.push_back(&mock_nerfus_ticker_b); } MockTarget mock_target_a; MockTarget mock_target_b; std::vector<TargetInterface*> targets; - MockNerfusTicker mock_nerfus_ticker; + MockNerfusTicker mock_nerfus_ticker_a; + MockNerfusTicker mock_nerfus_ticker_b; + std::vector<NerfusTickerInterface*> tickers; }; TEST_F(TargetManagerTest, LibraryBuilds) { - TargetManager target_manager(targets, mock_nerfus_ticker); + TargetManager target_manager(targets, tickers); } TEST_F(TargetManagerTest, WhenNoTargetIsActiveThenCallsToTargetHitAndTargetMissedDoNothing) { - TargetManager target_manager(targets, mock_nerfus_ticker); + TargetManager target_manager(targets, tickers); target_manager.target_missed(0); target_manager.target_hit(0); @@ -39,31 +44,31 @@ TEST_F(TargetManagerTest, WhenExecutingAllyTargetThenUseTheCorrectTargetTypeAndTimeout) { EXPECT_CALL(mock_target_a, ally_command()); - EXPECT_CALL(mock_nerfus_ticker, start(1000)); + EXPECT_CALL(mock_nerfus_ticker_a, start(1000)); - TargetManager target_manager(targets, mock_nerfus_ticker); + TargetManager target_manager(targets, tickers); target_manager.execute(make_TargetInfo(0, TARGET_TYPE_ALLY, 1000)); } TEST_F(TargetManagerTest, WhenExecutingEnemyTargetThenUseTheCorrectTargetTypeAndTimeout) { EXPECT_CALL(mock_target_b, enemy_command()); - EXPECT_CALL(mock_nerfus_ticker, start(2000)); + EXPECT_CALL(mock_nerfus_ticker_b, start(2000)); - TargetManager target_manager(targets, mock_nerfus_ticker); + TargetManager target_manager(targets, tickers); target_manager.execute(make_TargetInfo(1, TARGET_TYPE_ENEMY, 2000)); } 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()) + EXPECT_CALL(mock_nerfus_ticker_a, start(1000)); + EXPECT_CALL(mock_nerfus_ticker_a, get_time_ms()) .WillOnce(::testing::Return(42)); - EXPECT_CALL(mock_nerfus_ticker, stop()); + EXPECT_CALL(mock_nerfus_ticker_a, stop()); EXPECT_CALL(mock_target_a, hit(42)); - TargetManager target_manager(targets, mock_nerfus_ticker); + TargetManager target_manager(targets, tickers); target_manager.execute(make_TargetInfo(0, TARGET_TYPE_ALLY, 1000)); target_manager.target_hit(0); @@ -72,13 +77,13 @@ 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()) + EXPECT_CALL(mock_nerfus_ticker_a, start(1000)); + EXPECT_CALL(mock_nerfus_ticker_a, get_time_ms()) .WillOnce(::testing::Return(42)); - EXPECT_CALL(mock_nerfus_ticker, stop()); + EXPECT_CALL(mock_nerfus_ticker_a, stop()); EXPECT_CALL(mock_target_a, timeout(42)); - TargetManager target_manager(targets, mock_nerfus_ticker); + TargetManager target_manager(targets, tickers); target_manager.execute(make_TargetInfo(0, TARGET_TYPE_ALLY, 1000)); target_manager.target_missed(0); @@ -86,10 +91,10 @@ TEST_F(TargetManagerTest, WhenReceivingCommandInBytesThenExecuteIt) { - TargetManager target_manager(targets, mock_nerfus_ticker); + TargetManager target_manager(targets, tickers); EXPECT_CALL(mock_target_b, ally_command()); - EXPECT_CALL(mock_nerfus_ticker, start(0x1234)); + EXPECT_CALL(mock_nerfus_ticker_b, start(0x1234)); std::vector<uint8_t> target_info_bytes; target_info_bytes.push_back(0x01); //Second target