Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_unsigned_saturated_33bit(self):
dtype = parser.PrimitiveType(
parser.PrimitiveType.KIND_UNSIGNED_INT,
33,
parser.PrimitiveType.CAST_MODE_SATURATED)
value = transport.cast(0, dtype)
self.assertEqual(value, 0)
value = transport.cast(8589934591, dtype)
self.assertEqual(value, 8589934591)
value = transport.cast(8589934592, dtype)
self.assertEqual(value, 8589934591)
value = transport.cast(-1, dtype)
self.assertEqual(value, 0)
def test_unsigned_saturated_64bit(self):
dtype = parser.PrimitiveType(
parser.PrimitiveType.KIND_UNSIGNED_INT,
64,
parser.PrimitiveType.CAST_MODE_SATURATED)
value = transport.cast(0, dtype)
self.assertEqual(value, 0)
value = transport.cast(18446744073709551615, dtype)
self.assertEqual(value, 18446744073709551615)
value = transport.cast(-1, dtype)
self.assertEqual(value, 0)
value = transport.cast(18446744073709551617, dtype)
self.assertEqual(value, 18446744073709551615)
value = transport.cast(-18446744073709551615, dtype)
self.assertEqual(value, 0)
def test_truncated_33bit(self):
dtype = parser.PrimitiveType(
parser.PrimitiveType.KIND_UNSIGNED_INT,
33,
parser.PrimitiveType.CAST_MODE_TRUNCATED)
value = transport.cast(0, dtype)
self.assertEqual(value, 0)
value = transport.cast(8589934591, dtype)
self.assertEqual(value, 8589934591)
value = transport.cast(8589934592, dtype)
self.assertEqual(value, 0)
value = transport.cast(-1, dtype)
self.assertEqual(value, 8589934591)
def test_truncated_1bit(self):
dtype = parser.PrimitiveType(
parser.PrimitiveType.KIND_UNSIGNED_INT,
1,
parser.PrimitiveType.CAST_MODE_TRUNCATED)
value = transport.cast(0, dtype)
self.assertEqual(value, 0)
value = transport.cast(1, dtype)
self.assertEqual(value, 1)
value = transport.cast(2, dtype)
self.assertEqual(value, 0)
value = transport.cast(-1, dtype)
self.assertEqual(value, 1)
value = transport.cast(5, dtype)
self.assertEqual(value, 1)
value = transport.cast(-10, dtype)
self.assertEqual(value, 0)
def test_unsigned_saturated_1bit(self):
dtype = parser.PrimitiveType(
parser.PrimitiveType.KIND_UNSIGNED_INT,
1,
parser.PrimitiveType.CAST_MODE_SATURATED)
value = transport.cast(0, dtype)
self.assertEqual(value, 0)
value = transport.cast(1, dtype)
self.assertEqual(value, 1)
value = transport.cast(2, dtype)
self.assertEqual(value, 1)
value = transport.cast(-1, dtype)
self.assertEqual(value, 0)
value = transport.cast(5, dtype)
self.assertEqual(value, 1)
value = transport.cast(-10, dtype)
self.assertEqual(value, 0)
def test_unsigned_saturated_1bit(self):
dtype = parser.PrimitiveType(
parser.PrimitiveType.KIND_UNSIGNED_INT,
1,
parser.PrimitiveType.CAST_MODE_SATURATED)
value = transport.cast(0, dtype)
self.assertEqual(value, 0)
value = transport.cast(1, dtype)
self.assertEqual(value, 1)
value = transport.cast(2, dtype)
self.assertEqual(value, 1)
value = transport.cast(-1, dtype)
self.assertEqual(value, 0)
value = transport.cast(5, dtype)
self.assertEqual(value, 1)
value = transport.cast(-10, dtype)
self.assertEqual(value, 0)
def test_unsigned_saturated_33bit(self):
dtype = parser.PrimitiveType(
parser.PrimitiveType.KIND_UNSIGNED_INT,
33,
parser.PrimitiveType.CAST_MODE_SATURATED)
value = transport.cast(0, dtype)
self.assertEqual(value, 0)
value = transport.cast(8589934591, dtype)
self.assertEqual(value, 8589934591)
value = transport.cast(8589934592, dtype)
self.assertEqual(value, 8589934591)
value = transport.cast(-1, dtype)
self.assertEqual(value, 0)
def test_signed_saturated_64bit(self):
dtype = parser.PrimitiveType(
parser.PrimitiveType.KIND_SIGNED_INT,
64,
parser.PrimitiveType.CAST_MODE_SATURATED)
value = transport.cast(0, dtype)
self.assertEqual(value, 0)
value = transport.cast(18446744073709551615, dtype)
self.assertEqual(value, 9223372036854775808)
value = transport.cast(-1, dtype)
self.assertEqual(value, -1)
value = transport.cast(-18446744073709551617, dtype)
self.assertEqual(value, -9223372036854775809)
value = transport.cast(-9223372036854775808, dtype)
self.assertEqual(value, -9223372036854775808)
def test_unsigned_saturated_4bit(self):
dtype = parser.PrimitiveType(
parser.PrimitiveType.KIND_UNSIGNED_INT,
4,
parser.PrimitiveType.CAST_MODE_SATURATED)
value = transport.cast(0, dtype)
self.assertEqual(value, 0)
value = transport.cast(15, dtype)
self.assertEqual(value, 15)
value = transport.cast(16, dtype)
self.assertEqual(value, 15)
value = transport.cast(-1, dtype)
self.assertEqual(value, 0)
value = transport.cast(30, dtype)
self.assertEqual(value, 15)
def test_signed_saturated_64bit(self):
dtype = parser.PrimitiveType(
parser.PrimitiveType.KIND_SIGNED_INT,
64,
parser.PrimitiveType.CAST_MODE_SATURATED)
value = transport.cast(0, dtype)
self.assertEqual(value, 0)
value = transport.cast(18446744073709551615, dtype)
self.assertEqual(value, 9223372036854775808)
value = transport.cast(-1, dtype)
self.assertEqual(value, -1)
value = transport.cast(-18446744073709551617, dtype)
self.assertEqual(value, -9223372036854775809)
value = transport.cast(-9223372036854775808, dtype)
self.assertEqual(value, -9223372036854775808)