1class RunewordsCalculator:
2 def __init__(self, runewords):
3 self.runewords = list(runewords.items())
4 self.runes = []
5 self.returned = set()
6
7 def add_runes(self, runes):
8 self.runes.extend(runes)
9
10 def __iter__(self):
11 return self
12
13 def __next__(self):
14 if len(self.returned) == len(self.runewords):
15 raise StopIteration
16 for name, recipe in self.runewords:
17 if name in self.returned:
18 continue
19 indexes = self._find_indexes(recipe)
20 if indexes is not None:
21 self._delete_indexes(indexes)
22 self.returned.add(name)
23 return name
24 return None
25
26 def _find_indexes(self, recipe):
27 indexes = []
28 recipe_index = 0
29 for rune_index, rune in enumerate(self.runes):
30 if rune == recipe[recipe_index]:
31 indexes.append(rune_index)
32 recipe_index += 1
33 if recipe_index == len(recipe):
34 return indexes
35 return None
36
37 def _delete_indexes(self, indexes):
38 for rune_index in reversed(indexes):
39 self.runes.pop(rune_index)
.....F.
======================================================================
FAIL: test_returns_runewords_in_runeword_order (test.TestRunewordsCalculator.test_returns_runewords_in_runeword_order)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 55, in test_returns_runewords_in_runeword_order
self.assertEqual(next(iterator), "First")
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != 'First'
----------------------------------------------------------------------
Ran 7 tests in 0.001s
FAILED (failures=1)