Beispiel #1
0
 def test_execute(self):
     circuit = Circuit(self.commands)
     self.assertEqual(circuit.get_value('x'), 123)
     self.assertEqual(circuit.get_value('y'), 456)
     self.assertEqual(circuit.get_value('d'), 72)
     self.assertEqual(circuit.get_value('e'), 507)
     self.assertEqual(circuit.get_value('f'), 492)
     self.assertEqual(circuit.get_value('g'), 114)
     self.assertEqual(circuit.get_value('h'), 65412)
     self.assertEqual(circuit.get_value('i'), 65079)
Beispiel #2
0
 def test_integers_and(self):
     circuit = Circuit()
     circuit.store_direction('123 -> x')
     circuit.store_direction('x AND 456 -> y')
     circuit.store_direction('456 AND x -> z')
     self.assertAlmostEqual(circuit.get_signal('y'), 72)
     self.assertAlmostEqual(circuit.get_signal('z'), 72)
Beispiel #3
0
 def test_not(self):
     circuit = Circuit()
     circuit.store_direction('123 -> x')
     circuit.store_direction('456 -> y')
     circuit.store_direction('NOT x -> h')
     circuit.store_direction('NOT y -> i')
     self.assertAlmostEqual(circuit.get_signal('h'), 65412)
     self.assertAlmostEqual(circuit.get_signal('i'), 65079)
Beispiel #4
0
 def test_wire_assignment(self):
     circuit = Circuit()
     circuit.store_direction('123 -> x')
     circuit.store_direction('x -> y')
     self.assertAlmostEqual(circuit.get_signal('x'), 123)
     self.assertAlmostEqual(circuit.get_signal('y'), 123)
Beispiel #5
0
    def test_set_signal(self):

        circuit = Circuit()
        circuit.set_signal('x', 123)
        self.assertAlmostEqual(circuit.get_signal('x'), 123)
Beispiel #6
0
 def test_out_of_order(self):
     circuit = Circuit()
     circuit.store_direction('x AND y -> d')
     circuit.store_direction('y RSHIFT 2 -> g')
     circuit.store_direction('NOT x -> h')
     circuit.store_direction('x LSHIFT 2 -> f')
     circuit.store_direction('NOT y -> i')
     circuit.store_direction('123 -> x')
     circuit.store_direction('x OR y -> e')
     circuit.store_direction('456 -> y')
     self.assertAlmostEqual(circuit.get_signal('x'), 123)
     self.assertAlmostEqual(circuit.get_signal('y'), 456)
     self.assertAlmostEqual(circuit.get_signal('d'), 72)
     self.assertAlmostEqual(circuit.get_signal('e'), 507)
     self.assertAlmostEqual(circuit.get_signal('f'), 492)
     self.assertAlmostEqual(circuit.get_signal('g'), 114)
     self.assertAlmostEqual(circuit.get_signal('h'), 65412)
     self.assertAlmostEqual(circuit.get_signal('i'), 65079)
Beispiel #7
0
 def test_rshift(self):
     circuit = Circuit()
     circuit.store_direction('123 -> x')
     circuit.store_direction('456 -> y')
     circuit.store_direction('y RSHIFT 2 -> g')
     self.assertAlmostEqual(circuit.get_signal('g'), 114)
Beispiel #8
0
 def test_lshift(self):
     circuit = Circuit()
     circuit.store_direction('123 -> x')
     circuit.store_direction('456 -> y')
     circuit.store_direction('x LSHIFT 2 -> f')
     self.assertAlmostEqual(circuit.get_signal('f'), 492)
Beispiel #9
0
 def test_or(self):
     circuit = Circuit()
     circuit.store_direction('123 -> x')
     circuit.store_direction('456 -> y')
     circuit.store_direction('x OR y -> e')
     self.assertAlmostEqual(circuit.get_signal('e'), 507)
Beispiel #10
0
 def test_and(self):
     circuit = Circuit()
     circuit.store_direction('123 -> x')
     circuit.store_direction('456 -> y')
     circuit.store_direction('x AND y -> d')
     self.assertAlmostEqual(circuit.get_signal('d'), 72)
Beispiel #11
0
 def test_store_direction_numeric(self):
     circuit = Circuit()
     circuit.store_direction('123 -> x')
     circuit.store_direction('456 -> y')
     self.assertAlmostEqual(circuit.get_signal('x'), 123)
     self.assertAlmostEqual(circuit.get_signal('y'), 456)
Beispiel #12
0
 def test_parses(self):
     for c in self.commands:
         self.assertTrue(Circuit.parse(c))