Skip to content

Commit

Permalink
Fix tests. Change back to config defaults.
Browse files Browse the repository at this point in the history
  • Loading branch information
alecpm committed Nov 9, 2024
1 parent 800794a commit 56f91bf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
3 changes: 2 additions & 1 deletion dlgr/griduniverse/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ auto_recruit = true
network = FullyConnected
max_participants = 1
num_rounds = 3
num_games = 1
time_per_round = 45
block_size = 20
columns = 200
Expand All @@ -13,7 +14,7 @@ window_columns = 20
use_identicons = true
show_chatroom = true
recruiter = hotair
num_games = 2
lock_table_when_creating_participant = false

[HIT Configuration]
title = Griduniverse
Expand Down
14 changes: 12 additions & 2 deletions dlgr/griduniverse/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"bot_policy": unicode,
"num_rounds": int,
"num_games": int,
"quorum": int,
"time_per_round": float,
"instruct": bool,
"columns": int,
Expand Down Expand Up @@ -1634,9 +1635,10 @@ def configure(self):
self.experiment_repeats = self.config.get("num_games", 1)
self.num_participants = self.config.get("max_participants", 3)
self.instruct = self.config.get("instruct", True)
self.quorum = self.num_participants
self.total_participants = self.num_participants * self.experiment_repeats
self.quorum = self.config.get("quorum", self.total_participants)
self.initial_recruitment_size = self.config.get(
"num_recruits", self.num_participants
"num_recruits", self.total_participants
)
self.network_factory = self.config.get("network", "FullyConnected")
self.num_colors = self.config.get("num_colors", 3)
Expand Down Expand Up @@ -1699,6 +1701,14 @@ def background_tasks(self):
return
return [self.start_games]

def is_overrecruited(self, waiting_count):
"""The experiment is overrecruited if the number of waiting players
exceeds the total number of participants allowed across all games.
"""
if not self.quorum:
return False
return waiting_count > self.total_participants

def instructions(self):
instructions_file_path = os.path.join(
os.path.dirname(__file__), "templates/instructions/instruct-ready.html"
Expand Down
16 changes: 13 additions & 3 deletions test/test_griduniverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,11 @@ def test_colors_distributed_evenly(self, exp, game, participants):
for participant in participants[:9]
]
colors = collections.Counter([player.color_idx for player in players])
assert colors == {0: 3, 1: 3, 2: 3}
# All colors are assigned to 3 players
assert set(colors.values()) == {3}

def test_colors_distributed_almost_evenly_if_on_edge(self, exp, game, participants):
game.grid.num_colors = 2
exp.num_colors = 2
game.grid.num_players = 9
exp.networks()[0].max_size = 10
players = [
Expand All @@ -219,7 +220,8 @@ def test_colors_distributed_almost_evenly_if_on_edge(self, exp, game, participan
for participant in participants[:9]
]
colors = collections.Counter([player.color_idx for player in players])
assert colors == {0: 5, 1: 4}
# One color is assigned to 4 players and the other is assigned to 5
assert set(colors.values()) == {4, 5}


@pytest.mark.usefixtures("env")
Expand Down Expand Up @@ -279,3 +281,11 @@ def test_does_not_republish_broadcasts(self, exp, a, pubsub):
)

pubsub.publish.assert_not_called()


@pytest.mark.usefixtures("env")
class TestInstructions(object):
def test_instructions(self, exp):
# Just test something basic
html = exp.instructions()
assert "🫐 Gooseberry (3 points)" in html
8 changes: 0 additions & 8 deletions test/test_gridworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,6 @@ def test_game_end(self, gridworld):
assert gridworld.game_over is True


@pytest.mark.usefixtures("env")
class TestInstructions(object):
def test_instructions(self, gridworld):
# Just test something basic
html = gridworld.instructions()
assert "🫐 Gooseberry (3 points)" in html


class TestMatrix2SerializedGridworld(object):
"""Tests for converting a list of lists extracted from matrix
representation of initial grid state into the format used in
Expand Down

0 comments on commit 56f91bf

Please sign in to comment.