def testManualPrecision1(self): # Check that the encoded -ve number is precise enough... val, prec = -3.171234e-7, 1e-8 encoding = self.EncodedNumberCls.encode(self.public_key, val, precision=prec) decoded = encoding.decode() self.assertInRange(decoded, val - prec, val + prec) # Well, that didn't actually prove much - what if val happens # to be conveniently representable in BASE? # `decoded` *is* conveniently representable in BASE, so let's # play with that a little encoding2 = self.EncodedNumberCls.encode(self.public_key, decoded + 0.500001 * prec, precision=prec) decoded2 = encoding2.decode() self.assertNotEqual(decoded, decoded2) self.assertInRange(decoded2, val, val + prec) # Check it's not too precise: val3 = decoded + prec / self.EncodedNumberCls.BASE encoding3 = self.EncodedNumberCls.encode(self.public_key, val3, precision=prec) decoded3 = encoding3.decode() self.assertEqual(decoded, decoded3)