-
Notifications
You must be signed in to change notification settings - Fork 263
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 a versus_test method to TestPlayer #875
Conversation
I like most of this. Some quick thoughts:
|
Yeah I wasn't completely sure about having two input possibilities. I'll make this tweak.
Can you expand on this a bit more? I'm not too sure I follow which issue you mean. |
I've also just pushed a refactor of the |
It's ok to use |
Did you mean to type that here or in the other issue? Surely that's overwriting the |
axelrod/tests/unit/test_grumpy.py
Outdated
@@ -45,7 +45,7 @@ def test_strategy(self): | |||
init_kwargs={"grumpy_threshold": 3, | |||
"nice_threshold": 0}) | |||
|
|||
def test_reset(self): | |||
def test_reset_state(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this test is unnecessary -- the default test catches any attribute changes.
axelrod/tests/unit/test_player.py
Outdated
actions is passed, a Mock Player is created that cycles over that | ||
sequence. | ||
expected_outcomes: List | ||
the expected outcomes of the match (list of tuples of actions). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
T
axelrod/tests/unit/test_player.py
Outdated
`{length:-1}` implies that the players do not know the length of the | ||
match. | ||
attrs: dict | ||
dictionary of internal attributes to check at the end of all plays |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
D
axelrod/tests/unit/test_rand.py
Outdated
self.responses_test([C], [C, D, C], [C, C, D], seed=1) | ||
|
||
opponent = axelrod.MockPlayer() | ||
outcomes = [(C, C), (D, C), (D, C)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tests the histories above but not the next move, so it's not exactly equivalent. Doesn't matter in this case of course.
axelrod/tests/unit/test_titfortat.py
Outdated
self.second_play_test(rCC=C, rCD=D, rDC=C, rDD=D) | ||
|
||
# Play against opponents | ||
outcomes = [(C, C), (C, D), (D, C), (C, D)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as before re: not checking the last move anymore.
@marcharper the particular test in I've fixed this (cff2e53 and a refactor here: b7ce33a) and ended up having to fix some strategies that were then failing. This is worth a slow and thorough review in case I've missed anything so no rush :) |
axelrod/tests/unit/test_player.py
Outdated
for k, v in clone.__dict__.items(): | ||
if isinstance(v, np.ndarray): | ||
self.assertTrue(np.array_equal(v, getattr(clone, k))) | ||
for attribute, value in player.__dict__.items(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would player == clone
work here now?
axelrod/tests/unit/test_meta.py
Outdated
player.play(opponent) | ||
player.reset() | ||
for i, p in enumerate(player.team): | ||
self.assertEqual(len(p.history), 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use player == clone
here?
axelrod.seed(seed) | ||
player.play(opponent) | ||
|
||
player.reset() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
player == clone
?
That's interesting. I remember catching a subtle bug with MetaPlayer with that test so that's surprising that it worked at all! I like the new additions, looks like maybe we could remove some redundant code by using We might consider updating MetaPlayer's clone method to clone all the team members, or just take a closer look at it. |
You might be able to tell from the commit history that I implemented a player
Perhaps for another PR? |
This does it by specifically creating the Matches.
- Refactor test for Tf2Ts. - Refactor tests for 2TfT - Refactor tests for Bully. - Refactor tests for SneakyTitForTat. - Refactor test for suspicious TfT. - Refactor test for AntiTitForTat - Refactor tests for HardTfT - Refactor tests for HardTf2T - Refactor OmegaTfT tests. - Refactor tests for Gradual. - Refactor tests for SlowTitForTwoTats - Refactor tests for AdaptiveTfT - Refactor tests for SpitefulTfT Also implement correct check for seed is not None. If we check `if seed` then when seed is passed as 0 it will not be set.
Add equality for a FSM.
This reverts commit 14e6a6b.
This makes it easier to test specific new attributes that might not fall under the scope of the global case.
I've just rebased on to I'm not sure if this means I'm going to miss any comments you wrote but I think all of them were suggesting |
OK. |
@@ -57,6 +64,7 @@ def __init__(self, transitions=None, initial_state=None, | |||
initial_action = C | |||
super().__init__() | |||
self.initial_state = initial_state | |||
self.state = initial_state |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed for the reset test. The cloned player did not have a self.state
attribute if it had not played yet.
Do we want to change |
Cool. Once this is in I'll open a couple of issues:
Good call. I've pushed that. |
@marcharper in bc398f2 I've gone a step further and removed My thinking is that we can test those properties using matches and it moves us away from the potential history mistmatches that can still occur with Can always revert if we don't think it's a good idea. |
I'd prefer to keep those tests -- the warnings for those are suppressed already. Or -- let's take that discussion to a new issue / PR? |
This reverts commit bc398f2.
Fine by me, I've reverted the commit. |
This one looks ready to roll to me. Anyone object? |
Not from me :) |
Addresses #874 with a tweaked testing framework.
The
versus_test
method removes the option to set player histories and can be used to test strategies (and player attributes during matches) by creating a match between the player in question and an opponent.The opponent can either be an actual player from the library or is defined as a cycle by a passed sequence of actions (there are examples of this in the docs and
test_titfortat.py
).I've refactored all the tests in
test_titfortat.py
(which is now one module that raises no warnings).When/if we're happy with this as a suggestion, we should open an issue about refactoring all the tests to use this approach. (This would be a big/important piece of work so we should ask for small contributions at a time to make sure we don't miss anything with the reviews).
Once that refactor is complete we could potentially remove unused methods in the
TestPlayer
class.