<commit_before># coding=utf-8
import unittest

from operator import itemgetter

from simpleai.search.arc import constraint_wrapper, neighbors, all_arcs, revise, arc_consistency_3

first = itemgetter(0)


class TestNeighborsAndArcs(unittest.TestCase):

    def setUp(self):
        unit = self.unit = lambda vars_, values: False
        self.constraints = [(('A1', 'B2'), unit),
                            (('A1', 'C2'), unit),
                            (('D2', 'A1'), unit),
                            (('D2', 'C1'), unit),
                            (('E2', 'A1'), unit)]

    def test_neighbors(self):
        variables = map(lambda t: first(first(t)), neighbors('A1', self.constraints, 'B2'))
        self.assertEqual(set(variables), set(['C2', 'D2', 'E2']))

    def test_all_arcs(self):
        # does not check that the constraint function is well created
        variables = map(first, list(all_arcs(self.constraints)))
        arcs = [('A1', 'B2'),
                ('B2', 'A1'),
                ('A1', 'C2'),
                ('C2', 'A1'),
                ('D2', 'A1'),
                ('A1', 'D2'),
                ('D2', 'C1'),
                ('C1', 'D2'),
                ('E2', 'A1'),
                ('A1', 'E2')]
        self.assertEqual(variables, arcs)

    def test_constraint_wrapper(self):
        constraint = (('X', 'Y'), lambda vars_, values: values[0] ** 2 == values[1])
        wrapped = constraint_wrapper(*constraint)
        self.assertTrue(wrapped(('Y', 'X'), (25, 5)))

    def test_constraint_wrapper_raises_error(self):
        constraint = (('X', 'Y'), lambda vars_, values: values[0] ** 2 == values[1])
        wrapped = constraint_wrapper(*constraint)
        self.assertRaises(ValueError, wrapped, ('Y', 'Z'), (25, 5))


class TestReviseDomain(unittest.TestCase):

    def set_domains(self):
        self.domains = {'X': [1, 2, 3, 4, 5],
                        'Y': [1, 4, 9, 16, 20]}

    def setUp(self):
        self.set_domains()
        const = lambda vars_, values: values[0] ** 2 == values[1]
        self.constraint = constraint_wrapper(('X', 'Y'), const)

    def tearDown(self):
        self.set_domains()<commit_msg>Removed no longer needed tests, updated tests for all_arcs<commit_after># coding=utf-8
import unittest

from operator import itemgetter

from simpleai.search.arc import all_arcs, revise, arc_consistency_3

first = itemgetter(0)


class TestAllArcs(unittest.TestCase):

    def setUp(self):
        constraint = lambda variables, values: False
        self.constraints = [(('A', 'B'), constraint),
                            (('A', 'C'), constraint),
                            (('C', 'A'), constraint),
                            (('B', 'C'), constraint)]

    def test_all_arcs(self):
        # does not check that the constraint function is well created
        arcs_result = all_arcs(self.constraints)
        arcs_expected = [('A', 'B'),
                         ('B', 'A'),
                         ('A', 'C'),
                         ('C', 'A'),
                         ('B', 'C'),
                         ('C', 'B')]
        self.assertEqual(arcs_result, arcs_expected)


class TestReviseDomain(unittest.TestCase):

    def set_domains(self):
        self.domains = {'X': [1, 2, 3, 4, 5],
                        'Y': [1, 4, 9, 16, 20]}

    def setUp(self):
        self.set_domains()
        const = lambda vars_, values: values[0] ** 2 == values[1]
        self.constraint = constraint_wrapper(('X', 'Y'), const)

    def tearDown(self):
        self.set_domains()
{'fraction_non_alphanumeric': 0.16178128523111612, 'fraction_numerical': 0.0233934611048478, 'mean_word_length': 2.043739279588336, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5433597', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1071, 'n_words': 273}