<commit_before>import unittest
import mock

from meld.remd import adaptor


class TestAdaptationUsesPolicy(unittest.TestCase):
    def setUp(self):
        self.mock_adapt_policy = mock.Mock(spec_set=adaptor.AdaptationPolicy)
        self.adaptor = adaptor.EqualAcceptanceAdaptor(n_replicas=3, adaptation_policy=self.mock_adapt_policy)

    def test_calls_should_adapt(self):
        "the adaptor should ask the adaptation_policy if it should adapt this step"
        STEP = 10

        self.adaptor.adapt([0., 0.5, 1.], STEP)

        self.mock_adapt_policy.should_adapt.assert_called_once_with(STEP)

    def test_calls_reset(self):
        "if the adaptation_policy says so, we should reset"
        STEP = 10
        # False, True => No adapt, but reset
        self.mock_adapt_policy.should_adapt.return_value = adaptor.AdaptationPolicy.AdaptationRequired(False, True)
        # set one success; this should be removed by the reset
        self.adaptor.update(0, True)

        self.adaptor.adapt([0., 0.5, 1.], STEP)

        self.assertEqual(self.adaptor.success[0], 0)

    def test_no_adapt_unless_policy_says(self):
        "if the adaptation_policy says not to adapt, we should not adapt"
        STEP = 10
        # setup some fake updates
        for i in range(10):
            self.adaptor.update(0, True)
            self.adaptor.update(1, False)
        for i in range(5):
            self.adaptor.update(0, False)
            self.adaptor.update(1, True)
        # adpatation_policy says not to adapt
        self.mock_adapt_policy.should_adapt.return_value = adaptor.AdaptationPolicy.AdaptationRequired(False, False)

        results = self.adaptor.adapt([0.0, 0.5, 1.0], step=STEP)

        # we shouldn't adapt
        self.assertEqual(results[0], 0.0)
        self.assertEqual(results[1], 0.5)
        self.assertEqual(results[2], 1.0)<commit_msg>Added missing test for adaptor<commit_after>import unittest
import mock

from meld.remd import adaptor


class TestAdaptationUsesPolicy(unittest.TestCase):
    "tests to see if adaptor delegates decisions to adapt or reset to the adapation_policy"
    def setUp(self):
        self.mock_adapt_policy = mock.Mock(spec_set=adaptor.AdaptationPolicy)
        self.adaptor = adaptor.EqualAcceptanceAdaptor(n_replicas=3, adaptation_policy=self.mock_adapt_policy)

    def test_calls_should_adapt(self):
        "the adaptor should ask the adaptation_policy if it should adapt this step"
        STEP = 10

        self.adaptor.adapt([0., 0.5, 1.], STEP)

        self.mock_adapt_policy.should_adapt.assert_called_once_with(STEP)

    def test_calls_reset(self):
        "if the adaptation_policy says so, we should reset"
        STEP = 10
        # False, True => No adapt, but reset
        self.mock_adapt_policy.should_adapt.return_value = adaptor.AdaptationPolicy.AdaptationRequired(False, True)
        # set one success; this should be removed by the reset
        self.adaptor.update(0, True)

        self.adaptor.adapt([0., 0.5, 1.], STEP)

        self.assertEqual(self.adaptor.success[0], 0)

    def test_no_adapt_unless_policy_says(self):
        "if the adaptation_policy says not to adapt, we should not adapt"
        STEP = 10
        # setup some fake updates
        for i in range(10):
            self.adaptor.update(0, True)
            self.adaptor.update(1, False)
        for i in range(5):
            self.adaptor.update(0, False)
            self.adaptor.update(1, True)
        # adpatation_policy says not to adapt
        self.mock_adapt_policy.should_adapt.return_value = adaptor.AdaptationPolicy.AdaptationRequired(False, False)

        results = self.adaptor.adapt([0.0, 0.5, 1.0], step=STEP)

        # we shouldn't adapt
        self.assertEqual(results[0], 0.0)
        self.assertEqual(results[1], 0.5)
        self.assertEqual(results[2], 1.0)

    def test_adapt_if_policy_says(self):
        "if the adaptation_policy says to adapt, we should adapt"
        STEP = 10
        # setup some fake updates
        for i in range(10):
            self.adaptor.update(0, True)
            self.adaptor.update(1, False)
        for i in range(5):
            self.adaptor.update(0, False)
            self.adaptor.update(1, True)
        # adpatation_policy says to adapt
        self.mock_adapt_policy.should_adapt.return_value = adaptor.AdaptationPolicy.AdaptationRequired(True, False)

        results = self.adaptor.adapt([0.0, 0.5, 1.0], step=STEP)

        # we should adapt
        self.assertEqual(results[0], 0.0)
        self.assertAlmostEqual(results[1], 0.598, places=3)
        self.assertEqual(results[2], 1.0)
{'fraction_non_alphanumeric': 0.09560891196192949, 'fraction_numerical': 0.023145143845987454, 'mean_word_length': 2.7562956945572705, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7533005', 'n_tokens_mistral': 1568, 'n_tokens_neox': 1440, 'n_words': 340}