<s> import unittest <EOL> from operator import itemgetter <EOL> from simpleai . search import convert_to_binary <EOL> fst = itemgetter ( <NUM_LIT:0> ) <EOL> class TestHiddenVariableRepr ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> alldiff = lambda vars_ , values_ : len ( set ( values_ ) ) == len ( values_ ) <EOL> const = lambda vars_ , values_ : True <EOL> self . variables = ( '<STR_LIT:A>' , '<STR_LIT:B>' , '<STR_LIT:C>' ) <EOL> self . domains = { <EOL> '<STR_LIT:A>' : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , <EOL> '<STR_LIT:B>' : [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:4> ] , <EOL> '<STR_LIT:C>' : [ <NUM_LIT:1> , <NUM_LIT:2> ] , <EOL> } <EOL> self . constraints = [ <EOL> ( ( '<STR_LIT:A>' , '<STR_LIT:B>' , '<STR_LIT:C>' ) , alldiff ) , <EOL> ( ( '<STR_LIT:A>' , '<STR_LIT:C>' ) , const ) , <EOL> ( ( '<STR_LIT:A>' , '<STR_LIT:C>' ) , const ) , <EOL> ( ( '<STR_LIT:A>' , ) , lambda _vars , _value : _value [ <NUM_LIT:0> ] % <NUM_LIT:2> == <NUM_LIT:0> ) <EOL> ] <EOL> def test_conver_to_binary_adds_variables ( self ) : <EOL> v , d , c = convert_to_binary ( self . variables , self . domains , self . constraints ) <EOL> self . assertNotEqual ( v , self . variables ) <EOL> self . assertIn ( '<STR_LIT>' , v ) <EOL> self . assertIn ( '<STR_LIT>' , v ) <EOL> def test_conver_to_binary_constraints_variables ( self ) : <EOL> v , d , c = convert_to_binary ( self . variables , self . domains , self . constraints ) <EOL> var_tuples = map ( fst , c ) <EOL> self . assertIn ( ( '<STR_LIT>' , '<STR_LIT:A>' ) , var_tuples ) <EOL> self . assertIn ( ( '<STR_LIT>' , '<STR_LIT:B>' ) , var_tuples ) <EOL> self . assertIn ( ( '<STR_LIT>' , '<STR_LIT:C>' ) , var_tuples ) <EOL> self . assertIn ( ( '<STR_LIT>' , '<STR_LIT:A>' ) , var_tuples ) <EOL> def test_hidden_variable__domains_is_constraint_by_the_constraint_on_the_variable_it_hides ( self ) : <EOL> v , d , c = convert_to_binary ( self . variables , self . domains , self . constraints ) <EOL> domain = sorted ( d [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( domain , [ ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:2> ) , ( <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:2> ) , ( <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:1> ) , ( <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:1> ) , ( <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:2> ) , ( <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:1> ) , ( <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:2> ) ] ) <EOL> domain = sorted ( d [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( domain , [ ( <NUM_LIT:2> , ) ] ) </s>
