def test_invalid_width(self): with self.assertRaises(AssertionError): twos(0, 0) with self.assertRaises(AssertionError): twos(0, 5)
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)
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)
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)
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)