def testInitializeRegisterWithBitString(self):
        qcomp = get_functional_computer(nregisters=4, sqrt_size=3)
        value = "101100010"
        qcomp.execute(instr_initialize(0, value))

        cvalue = ComplexM(3, 3, bitstring_to_matrix(value, 3))

        self.assertEqual(cvalue, qcomp.registers[0].value)
    def testRegisterInitializationOnlyInitializedTheGivenRegister(self):
        qcomp = get_functional_computer(nregisters=4)
        qcomp.execute(instr_initialize(1))

        self.assertTrue(qcomp.registers[1].is_initialized)
        self.assertFalse(qcomp.registers[0].is_initialized)
        self.assertFalse(qcomp.registers[2].is_initialized)
        self.assertFalse(qcomp.registers[3].is_initialized)
    def testSelectValueFromInitializedRegister(self):
        qcomp = get_functional_computer(nregisters=4, sqrt_size=3)
        value = "001001001"
        expected_value = ComplexM(1, 9, [[0, 0, 1, 0, 0, 1, 0, 0, 1]])

        qcomp.execute(instr_initialize(0, value))
        qcomp.execute(instr_select('V1', 0, 0, 9))

        self.assertEquals(expected_value, qcomp.variables['V1'].value)
 def testSelectOutOfBoundsRaiseAnError(self):
     qcomp = get_functional_computer(nregisters=4, sqrt_size=3)
     qcomp.execute(instr_initialize(0))
     with self.assertRaises(IndexError):
         qcomp.execute(instr_select('V1', 0, 0, 10))
    def testSelectFromNotInitializedRegistersRaisesAnError(self):
        qcomp = get_functional_computer(nregisters=4, sqrt_size=3)

        with self.assertRaises(UnboundLocalError):
            qcomp.execute(instr_select('V1', 0, 1, 2))
 def testInitializeRegisterWithInvalidBitstringRaisesAnError(self):
     qcomp = get_functional_computer(nregisters=4, sqrt_size=3)
     value = "00102010001"
     with self.assertRaises(ValueError):
         qcomp.execute(instr_initialize(0, value))
    def testRegistersAreInitializedToTheZeroMatrixByDefault(self):
        qcomp = get_functional_computer(nregisters=4, sqrt_size=3)
        qcomp.execute(instr_initialize(2))

        self.assertEqual(zero_matrix(qcomp.sqrt_size), qcomp.registers[2].value)