Exemplo n.º 1
0
 def test_signed_saturated_33bit(self):
     dtype = parser.PrimitiveType(parser.PrimitiveType.KIND_SIGNED_INT, 33,
                                  parser.PrimitiveType.CAST_MODE_SATURATED)
     value = transport.cast(0, dtype)
     self.assertEqual(value, 0)
     value = transport.cast(8589934591, dtype)
     self.assertEqual(value, 4294967295)
     value = transport.cast(-8589934592, dtype)
     self.assertEqual(value, -4294967296)
     value = transport.cast(-1, dtype)
     self.assertEqual(value, -1)
Exemplo n.º 2
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)
Exemplo n.º 3
0
 def test_signed_saturated_33bit(self):
     dtype = parser.PrimitiveType(
         parser.PrimitiveType.KIND_SIGNED_INT,
         33,
         parser.PrimitiveType.CAST_MODE_SATURATED)
     value = transport.cast(0, dtype)
     self.assertEqual(value, 0)
     value = transport.cast(8589934591, dtype)
     self.assertEqual(value, 4294967295)
     value = transport.cast(-8589934592, dtype)
     self.assertEqual(value, -4294967296)
     value = transport.cast(-1, dtype)
     self.assertEqual(value, -1)
Exemplo n.º 4
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)
Exemplo n.º 5
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)
Exemplo n.º 6
0
 def test_signed_saturated_4bit(self):
     dtype = parser.PrimitiveType(parser.PrimitiveType.KIND_SIGNED_INT, 4,
                                  parser.PrimitiveType.CAST_MODE_SATURATED)
     value = transport.cast(0, dtype)
     self.assertEqual(value, 0)
     value = transport.cast(15, dtype)
     self.assertEqual(value, 7)
     value = transport.cast(16, dtype)
     self.assertEqual(value, 7)
     value = transport.cast(-1, dtype)
     self.assertEqual(value, -1)
     value = transport.cast(-30, dtype)
     self.assertEqual(value, -8)
Exemplo n.º 7
0
 def test_truncated_4bit(self):
     dtype = parser.PrimitiveType(parser.PrimitiveType.KIND_UNSIGNED_INT, 4,
                                  parser.PrimitiveType.CAST_MODE_TRUNCATED)
     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, 0)
     value = transport.cast(-1, dtype)
     self.assertEqual(value, 15)
     value = transport.cast(30, dtype)
     self.assertEqual(value, 14)
Exemplo n.º 8
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)
Exemplo n.º 9
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)
Exemplo n.º 10
0
 def test_signed_saturated_4bit(self):
     dtype = parser.PrimitiveType(
         parser.PrimitiveType.KIND_SIGNED_INT,
         4,
         parser.PrimitiveType.CAST_MODE_SATURATED)
     value = transport.cast(0, dtype)
     self.assertEqual(value, 0)
     value = transport.cast(15, dtype)
     self.assertEqual(value, 7)
     value = transport.cast(16, dtype)
     self.assertEqual(value, 7)
     value = transport.cast(-1, dtype)
     self.assertEqual(value, -1)
     value = transport.cast(-30, dtype)
     self.assertEqual(value, -8)
Exemplo n.º 11
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)
Exemplo n.º 12
0
 def test_truncated_4bit(self):
     dtype = parser.PrimitiveType(
         parser.PrimitiveType.KIND_UNSIGNED_INT,
         4,
         parser.PrimitiveType.CAST_MODE_TRUNCATED)
     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, 0)
     value = transport.cast(-1, dtype)
     self.assertEqual(value, 15)
     value = transport.cast(30, dtype)
     self.assertEqual(value, 14)
Exemplo n.º 13
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)
Exemplo n.º 14
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)