<s> from __future__ import print_function , unicode_literals <EOL> import unittest <EOL> import test . unit . configuration as configuration_module <EOL> import voodoo . configuration as ConfigurationManager <EOL> import experiments . logic . server as LogicExperiment <EOL> class CircuitGeneratorTestCase ( unittest . TestCase ) : <EOL> def test_switch ( self ) : <EOL> switch = LogicExperiment . Switch ( ) <EOL> self . assertFalse ( switch . turned ) <EOL> switch . set_turned ( True ) <EOL> self . assertTrue ( switch . turned ) <EOL> def test_gate ( self ) : <EOL> switch1 = LogicExperiment . Switch ( ) <EOL> switch2 = LogicExperiment . Switch ( ) <EOL> switch3 = LogicExperiment . Switch ( ) <EOL> switch4 = LogicExperiment . Switch ( ) <EOL> gate2 = LogicExperiment . Gate ( '<STR_LIT>' , switch1 , switch2 ) <EOL> gate3 = LogicExperiment . Gate ( '<STR_LIT>' , switch3 , switch4 ) <EOL> gate1 = LogicExperiment . Gate ( '<STR_LIT>' , gate2 , gate3 ) <EOL> self . assertFalse ( gate1 . turned ) <EOL> switch1 . set_turned ( True ) <EOL> self . assertFalse ( gate1 . turned ) <EOL> switch2 . set_turned ( True ) <EOL> self . assertTrue ( gate1 . turned ) <EOL> switch2 . set_turned ( False ) <EOL> self . assertFalse ( gate1 . turned ) <EOL> switch3 . set_turned ( True ) <EOL> self . assertFalse ( gate1 . turned ) <EOL> switch4 . set_turned ( True ) <EOL> self . assertTrue ( gate1 . turned ) <EOL> def test_generator ( self ) : <EOL> cg = LogicExperiment . CircuitGenerator ( ) <EOL> for _ in xrange ( <NUM_LIT:50> ) : <EOL> circuit = cg . generate ( ) <EOL> self . assertTrue ( circuit . is_correct_sample ( ) ) <EOL> class WrappedLogicExperiment ( LogicExperiment . LogicExperiment ) : <EOL> def turn_off ( self , * args ) : <EOL> pass <EOL> def send ( self , * args ) : <EOL> pass <EOL> class LogicExperimentTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> cfg_manager = ConfigurationManager . ConfigurationManager ( ) <EOL> cfg_manager . append_module ( configuration_module ) <EOL> self . experiment = WrappedLogicExperiment ( None , None , cfg_manager ) <EOL> self . experiment . do_start_experiment ( "<STR_LIT:{}>" , "<STR_LIT:{}>" ) <EOL> def test_get_circuit ( self ) : <EOL> circuit1a = self . experiment . do_send_command_to_device ( '<STR_LIT>' ) <EOL> circuit1b = self . experiment . do_send_command_to_device ( '<STR_LIT>' ) <EOL> self . assertEquals ( circuit1a , circuit1b ) <EOL> any_ok = False <EOL> for _ in xrange ( <NUM_LIT:10> ) : <EOL> for operation in LogicExperiment . Gate . operations : <EOL> result = self . experiment . do_send_command_to_device ( '<STR_LIT>' % operation ) <EOL> if result . startswith ( '<STR_LIT:OK>' ) : <EOL> self . assertEquals ( result , '<STR_LIT>' ) <EOL> any_ok = True <EOL> break <EOL> if any_ok : <EOL> break <EOL> self . assertTrue ( any_ok ) <EOL> circuit2 = self . experiment . do_send_command_to_device ( '<STR_LIT>' ) <EOL> self . assertNotEquals ( circuit1a , circuit2 ) <EOL> def test_invalid_command ( self ) : <EOL> response = self . experiment . do_send_command_to_device ( '<STR_LIT:foo>' ) <EOL> self . assertTrue ( response . startswith ( '<STR_LIT>' ) ) <EOL> def test_invalid_operation ( self ) : <EOL> response = self . experiment . do_send_command_to_device ( '<STR_LIT>' ) <EOL> self . assertTrue ( response . startswith ( '<STR_LIT>' ) ) <EOL> def suite ( ) : <EOL> return unittest . TestSuite ( ( <EOL> unittest . makeSuite ( CircuitGeneratorTestCase ) , <EOL> unittest . makeSuite ( LogicExperimentTestCase ) <EOL> ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
