# Path: mitty/lib/cigars.py
# def cigarv2_v1(cigar_v2):
#   """Convert a V2 cigar_v1 string to V1
# 
#   :param cigarstring:
#   :return:
#   """
#   values = pattern.split(cigar_v2.replace('=', 'M').replace('X', 'M'))
#   cigar_v1 = []
#   last_op, op_cnt = values[1], 0
#   for op in zip(values[::2], values[1::2]):
#     if op[1] == last_op:
#       op_cnt += int(op[0])
#     else:
#       cigar_v1 += [str(op_cnt), last_op]
#       last_op, op_cnt = op[1], int(op[0])
#   cigar_v1 += [str(op_cnt), last_op]
#   return ''.join(cigar_v1)


from mitty.lib.cigars import cigarv2_v1


def test_cigar_conversion():
  """Cigars: Converting cigar V2 to V1"""
  test_cases = [
    ('33=1X79=1X26=1X109=', '250M'),
    ('1X26=1X123=1X82=1X15=', '250M'),
    ('89=10D161=', '89M10D161M'),
    ('99M1X', '100M'),
    ('10M10D1X9M', '10M10D10M')
  ]
  for tc in test_cases:

# Path: mitty/lib/cigars.py
# def cigarv2_v1(cigar_v2):
#   """Convert a V2 cigar_v1 string to V1
# 
#   :param cigarstring:
#   :return:
#   """
#   values = pattern.split(cigar_v2.replace('=', 'M').replace('X', 'M'))
#   cigar_v1 = []
#   last_op, op_cnt = values[1], 0
#   for op in zip(values[::2], values[1::2]):
#     if op[1] == last_op:
#       op_cnt += int(op[0])
#     else:
#       cigar_v1 += [str(op_cnt), last_op]
#       last_op, op_cnt = op[1], int(op[0])
#   cigar_v1 += [str(op_cnt), last_op]
#   return ''.join(cigar_v1)


# Path: mitty/test/lib/test_cigars.py
from mitty.lib.cigars import cigarv2_v1



def test_cigar_conversion():
  """Cigars: Converting cigar V2 to V1"""
  test_cases = [
    ('33=1X79=1X26=1X109=', '250M'),
    ('1X26=1X123=1X82=1X15=', '250M'),
    ('89=10D161=', '89M10D161M'),
    ('99M1X', '100M'),
    ('10M10D1X9M', '10M10D10M')
  ]
  for tc in test_cases:

    assert cigarv2_v1(tc[0]) == tc[1], cigarv2_v1(tc[0])