Skip to content

Commit

Permalink
test of a component to set the pattern for future tests
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 588107004
Change-Id: I495412edf5b319a4763da69fbd919a521c55d238
  • Loading branch information
jzleibo authored and copybara-github committed Dec 5, 2023
1 parent b81c219 commit 6ad76fc
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion concordia/components/game_master/player_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def partial_state(
return self._partial_states[player_name]

def update(self) -> None:
self._state = '\n'
self._state = ''
self._partial_states = {name: '' for name in self._player_names}
per_player_prompt = {}
for player_name in self._player_names:
Expand Down
56 changes: 56 additions & 0 deletions concordia/components/game_master/player_status_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2023 DeepMind Technologies Limited.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests for player_status.py."""

import datetime
from unittest import mock

from absl.testing import absltest
from absl.testing import parameterized
from concordia.associative_memory import associative_memory
from concordia.components.game_master import player_status
from concordia.language_model import language_model


def _clock_now() -> datetime.datetime:
return datetime.datetime(2023, 1, 1, 0, 0, 0)


class PlayerStatusTest(parameterized.TestCase):

@parameterized.named_parameters(
dict(testcase_name="library", location="at the library"),
dict(testcase_name="memory", location="at the pub"),
)
def test_output_in_right_format(self, location):
model = mock.create_autospec(
language_model.LanguageModel, instance=True, spec_set=True)
model.sample_text.return_value = location
memory = mock.create_autospec(associative_memory.AssociativeMemory,
instance=True)
memory.retrieve_associative.return_value = "gibberish"
player_names = ["Alice", "Bob"]
component = player_status.PlayerStatus(
clock_now=_clock_now,
model=model,
memory=memory,
player_names=player_names)
component.update()
expected = "\n".join([f" {name} is {location}" for name in player_names])
self.assertEqual(component.state(), expected + "\n")


if __name__ == "__main__":
absltest.main()

0 comments on commit 6ad76fc

Please sign in to comment.