2020-07-12 23:56:55 +08:00
|
|
|
import unittest
|
2017-03-30 17:44:27 +08:00
|
|
|
|
|
|
|
|
2020-07-12 23:56:55 +08:00
|
|
|
class TestBits(unittest.TestCase):
|
2017-03-30 17:44:27 +08:00
|
|
|
|
|
|
|
def test_print_binary(self):
|
|
|
|
bit = Bits()
|
2020-07-12 23:56:55 +08:00
|
|
|
self.assertEqual(bit.print_binary(None), 'ERROR')
|
|
|
|
self.assertEqual(bit.print_binary(0), 'ERROR')
|
|
|
|
self.assertEqual(bit.print_binary(1), 'ERROR')
|
2017-03-30 17:44:27 +08:00
|
|
|
num = 0.625
|
|
|
|
expected = '0.101'
|
2020-07-12 23:56:55 +08:00
|
|
|
self.assertEqual(bit.print_binary(num), expected)
|
2017-03-30 17:44:27 +08:00
|
|
|
num = 0.987654321
|
2020-07-12 23:56:55 +08:00
|
|
|
self.assertEqual(bit.print_binary(num), 'ERROR')
|
2017-03-30 17:44:27 +08:00
|
|
|
print('Success: test_print_binary')
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
test = TestBits()
|
|
|
|
test.test_print_binary()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2020-07-12 23:56:55 +08:00
|
|
|
main()
|