def _testRead(self, arrayTraits, arrayValues): def _checkOffsetMethod(_index, _bitOffset): pass array = Array(arrayTraits, arrayValues) writer = BitStreamWriter() array.write(writer) reader = BitStreamReader(writer.getByteArray()) emptyArray = Array(arrayTraits) emptyArray.read(reader, len(array.getRawArray())) self.assertEqual(array, emptyArray) autoArray = Array(arrayTraits, arrayValues, isAuto=True) writer = BitStreamWriter() autoArray.write(writer) reader = BitStreamReader(writer.getByteArray()) emptyAutoArray = Array(arrayTraits, isAuto=True) emptyAutoArray.read(reader, len(autoArray.getRawArray())) self.assertEqual(autoArray, emptyAutoArray) alignedArray = Array(arrayTraits, arrayValues, checkOffsetMethod=_checkOffsetMethod) writer = BitStreamWriter() alignedArray.write(writer) reader = BitStreamReader(writer.getByteArray()) emptyAlignedArray = Array(arrayTraits, checkOffsetMethod=_checkOffsetMethod) emptyAlignedArray.read(reader, len(alignedArray.getRawArray())) self.assertEqual(alignedArray, emptyAlignedArray) implicitArray = Array(arrayTraits, arrayValues, isImplicit=True) writer = BitStreamWriter() implicitArray.write(writer) reader = BitStreamReader(writer.getByteArray()) emptyImplicitArray = Array(arrayTraits, isImplicit=True) emptyImplicitArray.read(reader) # read implicit array can be bigger (for example, BoolArray) implicitRawArray = implicitArray.getRawArray() emptyImplicitRawArray = emptyImplicitArray.getRawArray() for index, implicitRawArrayElement in enumerate(implicitRawArray): self.assertEqual(implicitRawArrayElement, emptyImplicitRawArray[index])
def _testRead(self, arrayTraits, arrayValues): def _checkOffsetMethod(_index, _bitOffset): pass array = Array(arrayTraits, arrayValues) writer = BitStreamWriter() array.write(writer) reader = BitStreamReader(writer.getByteArray()) readArray = Array(arrayTraits) readArray.read(reader, len(array.getRawArray())) self.assertEqual(array, readArray) autoArray = Array(arrayTraits, arrayValues, isAuto=True) writer = BitStreamWriter() autoArray.write(writer) reader = BitStreamReader(writer.getByteArray()) readAutoArray = Array(arrayTraits, isAuto=True) readAutoArray.read(reader, len(autoArray.getRawArray())) self.assertEqual(autoArray, readAutoArray) alignedArray = Array(arrayTraits, arrayValues, checkOffsetMethod=_checkOffsetMethod) writer = BitStreamWriter() alignedArray.write(writer) reader = BitStreamReader(writer.getByteArray()) readAlignedArray = Array(arrayTraits, checkOffsetMethod=_checkOffsetMethod) readAlignedArray.read(reader, len(alignedArray.getRawArray())) self.assertEqual(alignedArray, readAlignedArray) if arrayTraits.HAS_BITSIZEOF_CONSTANT and arrayTraits.bitSizeOf( ) % 8 == 0: implicitArray = Array(arrayTraits, arrayValues, isImplicit=True) writer = BitStreamWriter() implicitArray.write(writer) reader = BitStreamReader(writer.getByteArray()) readImplicitArray = Array(arrayTraits, isImplicit=True) readImplicitArray.read(reader) self.assertEqual(implicitArray, readImplicitArray) elif not arrayTraits.HAS_BITSIZEOF_CONSTANT: with self.assertRaises(PythonRuntimeException): Array(arrayTraits, isImplicit=True).read(reader)
def _testSetItem(self, arrayTraits, arrayValues): array = Array(arrayTraits, arrayValues) rawArray = array.getRawArray() self.assertTrue(len(array) > 1) firstValue = array[0] secondValue = array[1] array[0] = secondValue self.assertEqual(array[0], rawArray[0]) rawArray[0] = firstValue # return the original value for other tests self.assertEqual(array[0], rawArray[0])
def _testGetRawArray(self, arrayTraits, array1Values, array2Values): array1 = Array(arrayTraits, array1Values) array2 = Array(arrayTraits, array2Values) array3 = Array(arrayTraits, array1Values) self.assertNotEqual(array1.getRawArray(), array2.getRawArray()) self.assertEqual(array1.getRawArray(), array3.getRawArray())
def _testGetItem(self, arrayTraits, arrayValues): array = Array(arrayTraits, arrayValues) rawArray = array.getRawArray() for value, rawValue in zip(array, rawArray): self.assertEqual(value, rawValue)
def _testLen(self, arrayTraits, arrayValues): array = Array(arrayTraits, arrayValues) rawArray = array.getRawArray() self.assertEqual(len(rawArray), len(array))