SEPR-EEP / taxe-game-3

0 stars 0 forks source link

GameTest.testPlayerChanged fails #5

Closed AlfioEmanueleFresta closed 9 years ago

AlfioEmanueleFresta commented 9 years ago

We have all tests passing except this one.

    @Test
    public void testPlayerChanged() throws Exception {
        Player p1 = pm.getCurrentPlayer();
        int resourceCount = p1.getResources().size();
        int goalCount = p1.getGoals().size();

        pm.turnOver();
        pm.turnOver();

        // resource count should increase when p1 has another turn
        assertTrue(p1.getResources().size() > resourceCount);
        assertTrue(p1.getGoals().size() > goalCount); // <- This fails :(
    }
rc1035 commented 9 years ago

The assertion was incorrect. At the start of a game the player is always given three goals, which is the maximum number of goals a player can have simultaneously. Therefore, when the turn increments, the number of goals a player has should not increase!

I've rewritten the tests for this unit to make them more rigorous..

rc1035 commented 9 years ago

Reopening issue....

Most of the time the test passes, however now and again (as shown by the Travis log) it will fail with the following assertionError:

Player should still have maximum of three goals expected:<3> but was:<4> Expected :3 Actual :4

Obviously a player should never have four goals. I'll start looking into why this is happening, although help would be appreciated on this one - I don't have a clue atm!

rc1035 commented 9 years ago

The problem was caused by using .getSize() for the array of goals. This array also contains no longer active goals (i.e. goals that have been completed or have failed). In these tests, if the player is given a goal that must be completed in X turns, once X turns have passed and the goal has failed, the player will be given another goal. Therefore, the size of the array will become 4.

This has been fixed by refactoring the Player method to have a new method getNumberOfIncompleteGoals(), which should be used instead.