Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for game state #122

Merged
merged 2 commits into from
Jul 28, 2018
Merged

Conversation

frank-weinberg
Copy link
Contributor

These tests verify the behaviour of the game state as displayed on the main
scoreboard (except Jammer names).

Not included:

  • Undo. This will be added together with the switch to a snapshot model
    in a separate PR.
  • Game Statistics (Penalties, Lineups)
  • Settings other than WFTDA sanctioned (with a few exceptions).

In addition the PR contains fixes for a few minor bugs uncovered by the tests.

These tests verify the behaviour of the game state as displayed on the main
scoreboard (except Jammer names).

Not included:
- Undo. This will be added together with the switch to a snapshot model
in a separate PR.
- Game Statistics (Penalties, Lineups)
- Settings other than WFTDA sanctioned (with a few exceptions).
Copy link
Contributor

@brian-brazil brian-brazil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this, it must have been fairly mind numbing.

protected boolean checkStop() {
return (getTime() == (isCountDirectionDown() ? getMinimumTime() : getMaximumTime()));
protected boolean isDisplayChange(long current, long last) {
//on count down clocks are rounded down for display, on count up they are rounded down.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment reads oddly, and I don't understand why the directions have different logic.

@Test
public void syncTimeTest() {
public void test_reset() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we be consistent in how we name tests/methods? camelCase seems to be our standard.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eclipse auto generates tests with testMethodName or testMethodNameArgumentTypes (when there are multiple methods with the same name). Where I have multiple tests for one method I use testMethodName_scenario as I find that makes it easier to see at a glance what is being tested here. I'll change the older tests in ClockModel to that format.

clock.addScoreBoardListener(new ConditionalScoreBoardListener(clock, Clock.EVENT_DIRECTION, listener));

clock.setCountDirectionDown(true);
advance(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

advance(0) seems a bit weird, maybe it'd be clearer to say that you're waiting for the events to propagate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied that from you. :)
And after using it 5 times it becomes pretty natural.


@Test
public void testStartOvertime_default() {
ClockModel pc = sbm.getClockModel(Clock.ID_PERIOD);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably have these as part of the object, as they're used a lot.

ClockModel lc = sbm.getClockModel(Clock.ID_LINEUP);
ClockModel tc = sbm.getClockModel(Clock.ID_TIMEOUT);
ClockModel ic = sbm.getClockModel(Clock.ID_INTERMISSION);
((DefaultSettingsModel) sbm.getSettings()).set("Clock." + Clock.ID_LINEUP + ".OvertimeTime", "60000");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use getSettingsModel

assertEquals(5, event.getValue());
assertEquals(0, event.getPreviousValue());

//values higher than score are truncated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/truncated/clamped/

Truncation is a type of rounding.

@frank-weinberg
Copy link
Contributor Author

And yes, it was rather tedious.

@brian-brazil brian-brazil merged commit a783de1 into rollerderby:dev Jul 28, 2018
@brian-brazil
Copy link
Contributor

Thanks!

advance(0);

assertFalse(pc.isRunning());
assertEquals(2, pc.getNumber());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is failing. I'm not sure what this is meant to be testing, as there's no jam running when you stop it.

Copy link
Contributor Author

@frank-weinberg frank-weinberg Jul 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stopJam() is not accurately named anymore as it also stops Timeouts or starts a lineup clock before period start. This test is for the latter behaviour. (My clock code overhaul will be renaming the function to stopJamTO())

The failure is caused by the change in #123: The new period number is no longer based off the old period number but off the intermission number, which the test doesn't set to 1, as it should be after period 1. A fix is included in the clock overhaul (which I will be submitting shortly).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering if it was a merge conflict.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And small correction: The fix for the test is already in #124, not in the upcoming rewrite. (Which I now decided to hold back as it's buit atop #124, which in turn is built atop this PR, amassing a lot of old commits that show up as part of the new PR though they aren't. I want to do a rebase to get the spurious commits removed before submitting. But this is best done after #124 is merged.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That needs rebasing before merging, as I'm not quite sure what Github will do otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you talking about #124? Then we should probably move the discussion there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants