def test_partitions_of_n_cached(n, max_cache_size): # for some of these tests, 10 > total number of partitions, and for some it # is less, and the cache is needed. expected_partitions = partitions_of_n(n=n) actual_partitions = CachedPartitionsOfN(n=n, max_cache_size=max_cache_size) for i in range(len(expected_partitions)): assert expected_partitions[i][1] == actual_partitions[i]
def test_partitions_of_n_sublist_start_and_stop(): full_list_5 = list(enumerate( [[5], [4, 1], [3, 2], [3, 1, 1], [2, 2, 1], [2, 1, 1, 1], [1, 1, 1, 1, 1]])) assert partitions_of_n(n=5, start=2, stop=4) == full_list_5[2:5]
def test_count_partitions_of_n_size(n): assert count_partitions_of_n(n) == len(partitions_of_n(n))
def test_partitions_of_n_size(test_input, expected): assert len(partitions_of_n(test_input)) == expected
def test_partitions_of_n(test_input, expected): assert partitions_of_n(test_input) == expected
def __maybe_reset_current_level__(self): '''Idempotently compute the next level of the enumeration.''' if self.current_level[0] != self.search_index.level: self.current_level = partitions_of_n(self.search_index.level)