コード例 #1
0
    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)
コード例 #2
0
    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)
コード例 #3
0
    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)
コード例 #4
0
 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))
コード例 #5
0
 def testInitializeRegisterWithInvalidBitstringRaisesAnError(self):
     qcomp = get_functional_computer(nregisters=4, sqrt_size=3)
     value = "00102010001"
     with self.assertRaises(ValueError):
         qcomp.execute(instr_initialize(0, value))
コード例 #6
0
    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)