def main(): try: parser = argparse.ArgumentParser() parser.add_argument('-v1', help='version 1') parser.add_argument('-v2', help='version 2') args = parser.parse_args() print(compare(args.v1, args.v2)) except Exception: raise parser.error('Invalid arguments')
def test_non_digit_input(self): with self.assertRaises(ValueError): compare('1.2.3', '1.2.#')
def test_non_string_input(self): with self.assertRaises(TypeError): compare('1.2', 1.2)
def test_diff_len_greater_with_space(self): self.assertEqual(compare(' 1.2.4.4 ', '1.2.3.4 '), 1)
def test_diff_len_equal_with_space(self): self.assertEqual(compare(' 1.2.3.4 ', '1.2.3.4 '), 0)
def test_diff_len_less_wish_space(self): self.assertEqual(compare(' 1.2.3.4 ', '1.2.4.4 '), -1)
def test_diff_len_greater(self): self.assertEqual(compare('1.2.4', '1.2.3.4'), 1)
def test_diff_len_equal(self): self.assertEqual(compare('1.2.3.0', '1.2.3'), 0)
def test_diff_len_less(self): self.assertEqual(compare('1.2.3.4', '1.2.4'), -1)
def test_same_len_greater(self): self.assertEqual(compare('1.2.4', '1.2.3'), 1)
def test_same_len_equal(self): self.assertEqual(compare('1.2.3', '1.2.3'), 0)
def test_same_len_less(self): self.assertEqual(compare('1.2.3', '1.2.4'), -1)
def test_greater(self): v1, v2 = 4.5, 3.4 self.assertEqual( compare(v1, v2), 'version {} is greater than version {}'.format(v1, v2))
def test_conv_ver_str(self): v1, v2 = '1.2', '2.3' self.assertEqual(compare(v1, v2), 'version {} is less than version {}'.format(1.2, 2.3))
def test_equal(self): v1, v2 = 1.0, 1.0 self.assertEqual(compare(v1, v2), 'version {} is equal to version {}'.format(v1, v2))
def test_less_than(self): v1, v2 = 2.5, 4.4 self.assertEqual(compare(v1, v2), 'version {} is less than version {}'.format(v1, v2))