def test_is_sparse(self): test_data = [ (0, True), (0b1, True), (0b10, True), (0b11, False), (0b100, True), (0b101, True), (5, True), (0b110, False), (0b1010010010001010001, True), (0b1100010010001010001, False) ] for (number, expected) in test_data: self.assertEqual(expected, sparse_binary_number.is_sparse(number), "expected {0} for number 0b{1:b}" .format(str(expected), number))
def test_is_sparse_leading_ones(self): self.assertEqual(False, sparse_binary_number.is_sparse(0b110000))
def test_is_sparse_trailing_ones(self): self.assertEqual(False, sparse_binary_number.is_sparse(0b000011))
def test_is_sparse_middle_ones(self): self.assertEqual(False, sparse_binary_number.is_sparse(0b001100))
def test_is_sparse_0b1(self): self.assertEqual(True, sparse_binary_number.is_sparse(0b1))