fix incorrect editops validation
This commit is contained in:
parent
1eeb085733
commit
dd9021e312
|
@ -75,12 +75,10 @@ cdef RfEditops list_to_editops(ops, Py_ssize_t src_len, Py_ssize_t dest_len) exc
|
|||
if src_pos > src_len or dest_pos > dest_len:
|
||||
raise ValueError("List of edit operations invalid")
|
||||
|
||||
if edit_type == EditType.Insert:
|
||||
if src_pos == src_len:
|
||||
raise ValueError("List of edit operations invalid")
|
||||
elif edit_type == EditType.Delete:
|
||||
if dest_pos == dest_len:
|
||||
raise ValueError("List of edit operations invalid")
|
||||
if src_pos == src_len and edit_type != EditType.Insert:
|
||||
raise ValueError("List of edit operations invalid")
|
||||
elif dest_pos == dest_len and edit_type != EditType.Delete:
|
||||
raise ValueError("List of edit operations invalid")
|
||||
|
||||
result.emplace_back(edit_type, src_pos, dest_pos)
|
||||
|
||||
|
|
|
@ -119,5 +119,9 @@ def test_list_initialization():
|
|||
ops2 = Opcodes(ops.as_list(), ops.src_len, ops.dest_len)
|
||||
assert ops.as_opcodes() == ops2
|
||||
|
||||
ops = Levenshtein.editops("skdsakldsakdlasda", "djkajkdfkdgkhdfjrmecsidjf")
|
||||
ops2 = Opcodes(ops.as_list(), ops.src_len, ops.dest_len)
|
||||
assert ops.as_opcodes() == ops2
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Loading…
Reference in New Issue