LCOV - code coverage report
Current view: top level - test - basic.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 40 40 100.0 %
Date: 2020-10-15 20:26:03 Functions: 25 26 96.2 %

          Line data    Source code
       1             : /// @copyright Boost License 1.0, http://boost.org/LICENSE_1_0.txt
       2             : /// @date 2019
       3             : /// @author Joakim Brännström (joakim.brannstrom@gmx.com)
       4             : 
       5             : #include "gtest/gtest.h"
       6             : 
       7             : #include "game.h"
       8             : 
       9             : #include <memory>
      10             : 
      11           5 : class Basic : public ::testing::Test {
      12             : protected:
      13           5 :     Basic() : window{new Window}, game{new Game{*window}} {}
      14             : 
      15           5 :     void SetUp() override { game->setup(); }
      16             : 
      17             :     std::unique_ptr<Window> window;
      18             :     std::unique_ptr<Game> game;
      19             : };
      20             : 
      21           5 : TEST_F(Basic, OneGameStep) {
      22           1 :     game->update();
      23           1 :     game->render();
      24           1 :     window->render();
      25             : 
      26           1 :     EXPECT_EQ(window->layoutEvents.size(), 35160);
      27           1 : }
      28             : 
      29           5 : TEST_F(Basic, StepLeft) {
      30             :     // act
      31           1 :     window->inject(WindowEvent::ArrowLeft);
      32           1 :     game->update();
      33           1 :     game->render();
      34           1 :     window->render();
      35             : 
      36             :     // assert
      37             :     // This is fragil because internal changes to the game which do not
      38             :     // actually affect the funtionality may lead to this test failing. This is
      39             :     // why it would never be accepted by a competent peer reviewer.
      40           1 :     EXPECT_EQ(window->layoutEvents.size(), 35150);
      41           1 : }
      42             : 
      43           5 : TEST_F(Basic, StepRight) {
      44             :     // act
      45           1 :     window->inject(WindowEvent::ArrowRight);
      46           1 :     game->update();
      47           1 :     game->render();
      48           1 :     window->render();
      49             : 
      50             :     // assert
      51             :     // This is fragil because internal changes to the game which do not
      52             :     // actually affect the funtionality may lead to this test failing. This is
      53             :     // why it would never be accepted by a competent peer reviewer.
      54           1 :     EXPECT_EQ(window->layoutEvents.size(), 35163);
      55           1 : }
      56             : 
      57           5 : TEST_F(Basic, ArrowDown) {
      58             :     // act
      59           1 :     window->inject(WindowEvent::ArrowDown);
      60           1 :     game->update();
      61           1 :     game->render();
      62           1 :     window->render();
      63             : 
      64             :     // assert
      65             :     // This is fragil because internal changes to the game which do not
      66             :     // actually affect the funtionality may lead to this test failing. This is
      67             :     // why it would never be accepted by a competent peer reviewer.
      68           1 :     EXPECT_EQ(window->layoutEvents.size(), 35163);
      69           1 : }
      70             : 
      71           5 : TEST_F(Basic, ArrowUp) {
      72             :     // act
      73             : 
      74           1 :     game->update();
      75           1 :     game->render();
      76           1 :     window->render();
      77             : 
      78           1 :     vec2<int32_t> pos {(1,2), (3,4)};
      79             :     EvSpawnMob ev;
      80           1 :     ev.type = MobType::Snake;
      81           1 :     ev.position = pos;
      82           1 :     game->queueEvent(ev);
      83             : 
      84           1 :     EXPECT_EQ(game->onScreen(pos), true);
      85             :     // assert
      86             :     // This is fragil because internal changes to the game which do not
      87             :     // actually affect the funtionality may lead to this test failing. This is
      88             :     // why it would never be accepted by a competent peer reviewer.
      89             :     //EXPECT_EQ(window->layoutEvents.size(), 35159);
      90           4 : }

Generated by: LCOV version 1.13