def test_permutations(self): data = ['abc', 'acb', 'bac', 'cab', 'cba', 'bca'] result = [] p = iter(Permutations()) for i in data: result.append(next(p)) self.assertCountEqual(result, data) self.assertRaises(StopIteration, next, p)
def test_permutations(self): data = ['abc', 'acb', 'bac', 'cab', 'cba', 'bca'] result = [] p = iter(Permutations()) for i in data: result.append(next(p)) assert len(result) == len(data) with pytest.raises(StopIteration): next(p)
def test_permutations(): expected_result = ['abc', 'acb', 'bac', 'cab', 'cba', 'bca'] result = [] p = iter(Permutations('abc')) while True: try: result.append(next(p)) except StopIteration: break # Check length of result assert len(result) == len(expected_result) # Check that all result values are in expected_result for value in result: assert value in expected_result expected_result.remove(value)
def test_permutations_is_iterator(): assert '__init__' in dir(Permutations) iterator = iter(Permutations()) assert '__next__' in dir(iterator)
def test_is_iterator(self): self.assertIn('__init__', dir(Permutations)) iterator = iter(Permutations()) self.assertIn('__next__', dir(iterator))