Skip to content

Commit 4d0b04c

Browse files
authored
Merge pull request #107 from MikeSmithEU/master
fix opcode counts bug
2 parents f03a3bb + 4e4add4 commit 4d0b04c

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0rc4
1+
1.0rc5

src/benchmarkstt/metrics/core.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@ def get_opcode_counts(opcodes):
2828
elif tag == 'delete':
2929
counts[tag] += ahi - alo
3030
elif tag == 'replace':
31-
counts[tag] += ahi - alo
32-
if ahi - alo < bhi - blo:
33-
c = bhi - blo - ahi + alo
34-
counts['insert'] += c
35-
counts[tag] -= c
36-
elif ahi - alo > bhi - blo:
37-
c = ahi - alo - bhi + blo
38-
counts['delete'] += c
39-
counts[tag] -= c
31+
ca = ahi - alo
32+
cb = bhi - blo
33+
if ca < cb:
34+
counts['insert'] += cb - ca
35+
counts['replace'] += ca
36+
elif ca > cb:
37+
counts['delete'] += ca - cb
38+
counts['replace'] += cb
39+
else:
40+
counts[tag] += ahi - alo
4041
return OpcodeCounts(counts['equal'], counts['replace'], counts['insert'], counts['delete'])
4142

4243

tests/benchmarkstt/test_diff.py

+9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ def test_one_insert(differ):
1414
assert list(sm.get_opcodes()) == [('equal', 0, 50, 0, 50),
1515
('insert', 50, 50, 50, 51),
1616
('equal', 50, 100, 51, 101)]
17+
ref = "a b c d e f"
18+
hyp = "a b d e kfmod fgdjn idf giudfg diuf dufg idgiudgd"
19+
sm = differ(ref, hyp)
20+
assert list(sm.get_opcodes()) == [('equal', 0, 3, 0, 3),
21+
('delete', 3, 5, 3, 3),
22+
('equal', 5, 10, 3, 8),
23+
('insert', 10, 10, 8, 9),
24+
('equal', 10, 11, 9, 10),
25+
('insert', 11, 11, 10, 49)]
1726

1827

1928
@differs_decorator

tests/benchmarkstt/test_metrics_core.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
['changes 1 word', 'changes one word', (2, 1, 0, 0)],
1616
['0 1 2 3 4', '0 1 22 2 3 4', (5, 0, 1, 0)],
1717
['0 1 2 3 4', '0 1 2 3 4', (5, 0, 0, 0)],
18+
['a b c d e f', 'a b d e kfmod fgdjn idf giudfg diuf dufg idgiudgd', (4, 1, 6, 1)],
19+
['HELLO CRUEL WORLD OF MINE', 'GOODBYE WORLD OF MINE', (3, 1, 0, 1)],
1820
])
1921
def test_diffcounts(a, b, exp):
2022
assert DiffCounts().compare(PlainText(a), PlainText(b)) == OpcodeCounts(*exp)
@@ -27,7 +29,8 @@ def test_diffcounts(a, b, exp):
2729
['aa bb cc dd', 'aa aa bb cc dd dd', (.5, .25)],
2830
['aa bb cc dd', '', (1, 0.5)],
2931
['', 'aa bb cc', (1, 1)],
30-
['aa', 'bb aa cc', (2, 1)]
32+
['aa', 'bb aa cc', (2, 1)],
33+
['a b c d e f', 'a b d e kfmod fgdjn idf giudfg diuf dufg idgiudgd', (8/6, 3/4)],
3134
])
3235
def test_wer(a, b, exp):
3336
wer_strict, wer_hunt = exp

0 commit comments

Comments
 (0)