예제 #1
0
 def test_invalid_width(self):
   with self.assertRaises(AssertionError):
     twos(0, 0)
   with self.assertRaises(AssertionError):
     twos(0, 5)
예제 #2
0
 def test_64bit(self):
   self.assertEqual(twos(0, 8), 0)
   self.assertEqual(twos(-1, 8), 18446744073709551615)
   self.assertEqual(twos(-9223372036854775808, 8), 9223372036854775808)
   self.assertEqual(twos(9223372036854775807, 8), 9223372036854775807)
예제 #3
0
 def test_16bit(self):
   self.assertEqual(twos(0, 2), 0)
   self.assertEqual(twos(-1, 2), 65535)
   self.assertEqual(twos(-32768, 2), 32768)
   self.assertEqual(twos(32767, 2), 32767)
예제 #4
0
 def test_32bit(self):
   self.assertEqual(twos(0, 4), 0)
   self.assertEqual(twos(-1, 4), 4294967295)
   self.assertEqual(twos(-2147483648, 4), 2147483648)
   self.assertEqual(twos(2147483647, 4), 2147483647)
예제 #5
0
 def test_8bit(self):
   self.assertEqual(twos(0, 1), 0)
   self.assertEqual(twos(-1, 1), 255)
   self.assertEqual(twos(-128, 1), 128)
   self.assertEqual(twos(127, 1), 127)