1class RunewordsCalculator:
2 def __init__(self, recipies):
3 self.recipies = [(runeword, runes) for runeword, runes in recipies.items()]
4 self.runes = []
5
6 def add_runes(self, runes):
7 self.runes.extend(runes)
8
9 def __iter__(self):
10 return self
11
12 def __next__(self):
13 if not self.recipies:
14 raise StopIteration
15
16 for runeword, runes in self.recipies:
17 start = 0
18 found_indexes = []
19 for rune in runes:
20 if rune in self.runes[start:]:
21 index = self.runes.index(rune, start)
22 start = index + 1
23 found_indexes.append(index)
24 else:
25 break
26 if len(found_indexes) == len(runes):
27 self.runes = [rune for index, rune in enumerate(self.runes) if index not in found_indexes]
28 self.recipies.remove((runeword, runes))
29 return runeword
30 return None
.....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)