|
| 1 | +# Copyright 2026 DeepMind Technologies Limited. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +"""Validation tests for SanctionerAlternator.""" |
| 15 | + |
| 16 | +from unittest import mock |
| 17 | + |
| 18 | +from absl.testing import absltest |
| 19 | +from absl.testing import parameterized |
| 20 | +from meltingpot.utils.puppeteers import clean_up |
| 21 | + |
| 22 | + |
| 23 | +class SanctionerAlternatorValidationTest(parameterized.TestCase): |
| 24 | + |
| 25 | + @parameterized.parameters(0, -1) |
| 26 | + def test_rejects_nonpositive_alternating_steps(self, alternating_steps): |
| 27 | + with self.assertRaisesRegex(ValueError, 'alternating_steps must be positive'): |
| 28 | + clean_up.SanctionerAlternator( |
| 29 | + cooperate_goal=mock.sentinel.cooperate, |
| 30 | + defect_goal=mock.sentinel.defect, |
| 31 | + sanction_goal=mock.sentinel.sanction, |
| 32 | + num_others_cooperating_cumulant='NUM_OTHERS_COOPERATING', |
| 33 | + threshold=1, |
| 34 | + alternating_steps=alternating_steps, |
| 35 | + ) |
| 36 | + |
| 37 | + |
| 38 | +if __name__ == '__main__': |
| 39 | + absltest.main() |
0 commit comments