TupleVariation: round deltas before encoding (#861)
* TupleVariationTest.test_compileDeltaValues(): also test floats * TupleVariation: round deltas before encoding Python 3 was raising 'struct.error: required argument is not an integer' and Python 2 was truncating when deltas are floats
This commit is contained in:
parent
55a5ace5d8
commit
891405fd68
@ -366,7 +366,7 @@ class TupleVariation(object):
|
||||
assert runLength >= 1 and runLength <= 64
|
||||
stream.write(bytechr(runLength - 1))
|
||||
for i in range(offset, pos):
|
||||
stream.write(struct.pack('b', deltas[i]))
|
||||
stream.write(struct.pack('b', round(deltas[i])))
|
||||
return pos
|
||||
|
||||
@staticmethod
|
||||
@ -400,7 +400,7 @@ class TupleVariation(object):
|
||||
assert runLength >= 1 and runLength <= 64
|
||||
stream.write(bytechr(DELTAS_ARE_WORDS | (runLength - 1)))
|
||||
for i in range(offset, pos):
|
||||
stream.write(struct.pack('>h', deltas[i]))
|
||||
stream.write(struct.pack('>h', round(deltas[i])))
|
||||
return pos
|
||||
|
||||
@staticmethod
|
||||
|
@ -512,6 +512,11 @@ class TupleVariationTest(unittest.TestCase):
|
||||
# words, zeroes
|
||||
self.assertEqual("40 66 66 80", compileDeltaValues([0x6666, 0]))
|
||||
self.assertEqual("40 66 66 81", compileDeltaValues([0x6666, 0, 0]))
|
||||
# bytes or words from floats
|
||||
self.assertEqual("00 01", compileDeltaValues([1.1]))
|
||||
self.assertEqual("00 02", compileDeltaValues([1.9]))
|
||||
self.assertEqual("40 66 66", compileDeltaValues([0x6666 + 0.1]))
|
||||
self.assertEqual("40 66 66", compileDeltaValues([0x6665 + 0.9]))
|
||||
|
||||
def test_decompileDeltas(self):
|
||||
decompileDeltas = TupleVariation.decompileDeltas_
|
||||
|
Loading…
x
Reference in New Issue
Block a user