Skip to content

Commit

Permalink
Add tests form moving up and down in menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
przemek83 committed Oct 3, 2024
1 parent 1444e2f commit b159efe
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
17 changes: 12 additions & 5 deletions test/FakeInput.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
#pragma once

#include <vector>

#include <src/Input.h>
#include "src/InputAction.h"
#include <src/InputAction.h>

class FakeInput : public Input
{
public:
FakeInput(InputAction imenuInputAction,
FakeInput(std::vector<InputAction> menuInputActions,
std::set<InputAction> gameInputActions,
std::pair<int, int> mousePosition)
: menuInputAction_{imenuInputAction},
: menuInputActions_{menuInputActions},
gameInputActions_{std::move(gameInputActions)},
mousePosition_{mousePosition}
{
}

InputAction getMenuAction() override { return menuInputAction_; }
InputAction getMenuAction() override
{
InputAction action{menuInputActions_.front()};
menuInputActions_.erase(menuInputActions_.begin());
return action;
}

std::set<InputAction> getGameActions() override
{
Expand All @@ -28,7 +35,7 @@ class FakeInput : public Input
}

private:
InputAction menuInputAction_;
std::vector<InputAction> menuInputActions_;

std::set<InputAction> gameInputActions_;

Expand Down
27 changes: 22 additions & 5 deletions test/MenuTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,56 @@ TEST_CASE("Menu usage", "[Menu]")

SECTION("getUserChoice EXIT")
{
FakeInput input{InputAction::QUIT, {}, {}};
FakeInput input{{InputAction::QUIT}, {}, {}};
UserChoice choice{menu.getUserChoice(input)};
REQUIRE(choice == UserChoice::EXIT);
}

SECTION("getUserChoice accept in main menu")
{
menu.refresh(UserChoice::MAIN_MENU);
FakeInput input{InputAction::ACCEPT, {}, {}};
FakeInput input{{InputAction::ACCEPT}, {}, {}};
UserChoice choice{menu.getUserChoice(input)};
REQUIRE(choice == UserChoice::LEVEL_MENU);
}

SECTION("getUserChoice back in main menu")
{
menu.refresh(UserChoice::MAIN_MENU);
FakeInput input{InputAction::BACK, {}, {}};
FakeInput input{{InputAction::BACK}, {}, {}};
UserChoice choice{menu.getUserChoice(input)};
REQUIRE(choice == UserChoice::EXIT);
}

SECTION("getUserChoice back in level menu")
{
menu.refresh(UserChoice::LEVEL_MENU);
FakeInput input{InputAction::BACK, {}, {}};
FakeInput input{{InputAction::BACK}, {}, {}};
UserChoice choice{menu.getUserChoice(input)};
REQUIRE(choice == UserChoice::BACK);
}

SECTION("getUserChoice accept in level menu")
{
menu.refresh(UserChoice::LEVEL_MENU);
FakeInput input{InputAction::ACCEPT, {}, {}};
FakeInput input{{InputAction::ACCEPT}, {}, {}};
UserChoice choice{menu.getUserChoice(input)};
REQUIRE(choice == UserChoice::LEVEL_1);
}

SECTION("getUserChoice down and accept in level menu")
{
menu.refresh(UserChoice::LEVEL_MENU);
FakeInput input{{InputAction::DOWN, InputAction::ACCEPT}, {}, {}};
UserChoice choice{menu.getUserChoice(input)};
REQUIRE(choice == UserChoice::LEVEL_2);
}

SECTION("getUserChoice down and accept in level menu")
{
menu.refresh(UserChoice::LEVEL_MENU);
FakeInput input{
{InputAction::DOWN, InputAction::UP, InputAction::ACCEPT}, {}, {}};
UserChoice choice{menu.getUserChoice(input)};
REQUIRE(choice == UserChoice::LEVEL_1);
}
Expand Down

0 comments on commit b159efe

Please sign in to comment.