def test_push_increases_the_stack_size(): stack = Stack() previous_size = stack.size stack.push(42) assert stack.size == (previous_size + 1)
def test_push_items(self): stack = Stack() tests = [1, '0', Stack, lambda x: x, {}, [], None] for test in tests: stack.push(test) assert len(tests) == len(stack)
def test_pop_all(self): tests = [1, '0', Stack, lambda x: x, {}, [], None] stack = Stack(tests) assert len(stack) == len(tests) stack.pop_all() assert stack.is_empty() is True
def test_pop_items_with_initial_stack(self): tests = [1, '0', Stack, lambda x: x, {}, [], None] stack = Stack(tests) assert len(stack) == len(tests) for _ in tests: stack.pop() assert stack.is_empty() is True
def test_is_empty(self): stack = Stack() assert stack.is_empty() is True stack.push(1) assert stack.is_empty() is False stack.pop() assert stack.is_empty() is True
def test_str_prints_the_stack_and_its_elements(): stack = Stack() stack.push(42) stack.push("Second element") stack.push(True) assert str(stack) == "Stack(True, 'Second element', 42)"
def test_stack_push_pop_with_elements(self): stack = Stack() stack.push(1) stack.push(2) stack.push(5) assert stack.pop() == 5 assert stack.pop() == 2 assert stack.pop() == 1
def eval_push_time_ratios(problem_size: int = 3000) -> Optional[TimeRatioType]: """ Function that calculates the execution time ratios, for the different time complexities. Here, a process pool is created in order to speed up the process of generating the lists of time ratios, for each time complexity. """ stack: Stack = Stack() time_ratios: Dict[str, Union[str, List[Number]]] = { func_name: [] for func_name in TIME_COMPLEXITIES } arguments: List[Any] = [ (stack, problem_size, function) for function in TIME_COMPLEXITIES ] pool: ProcessPoolType = ProcessPool(get_cpu_count(), set_low_priority_to_process) for response in pool.imap(_push_time_ratio_worker, arguments): time_ratios.update(response) time_ratios.update({ 'data_struct_name': Stack.__name__.lower(), 'target_name': Stack.push.__name__, }) return time_ratios
def test_size_returns_the_number_of_elements_in_the_stack(): stack = Stack() stack.push(42) stack.push(42) stack.push(42) assert stack.size == 3
def test_pop_decreases_the_stack_size(): stack = Stack() stack.push(42) previous_size = stack.size stack.pop() assert stack.size == (previous_size - 1)
def test_peek_does_not_change_the_stack_size(): stack = Stack() stack.push(42) previous_size = stack.size stack.peek() assert stack.size == previous_size
def test_size(self): stack = Stack() assert len(stack) == 0 stack.push(1) assert len(stack) == 1 stack.pop() assert len(stack) == 0
def test_stack_as_string(self): stack = Stack() assert str(stack) == '' stack.push(3) stack.push(1) stack.push(2) assert repr(stack) == '2 -> 1 -> 3'
def test_pop_items(self): stack = Stack() with self.assertRaises(StackPopException): stack.pop() one = 1 two = 2 stack.push(one) stack.push(two) assert len(stack) == 2 assert stack.pop() == two assert stack.pop() == one assert len(stack) == 0
def test_size_on_empty_stack_returns_zero(): stack = Stack() assert stack.size == 0
def test_pop_returns_the_latest_element_pushed(): stack = Stack() stack.push("First") stack.push(42) assert stack.pop() == 42
def test_peek_returns_the_element_on_top(): stack = Stack() stack.push(42) assert stack.peek() == 42
def test_push_one(self): stack = Stack(lambda z: z) assert len(stack) == 1
def step_impl(context): context.stack = Stack()
def test_peek_on_empty_stack_returns_none(): stack = Stack() assert stack.peek() == None
def test_push_sets_the_element_on_top(): stack = Stack() stack.push(42) assert stack.peek() == 42
def test_is_empty_returns_false_on_stack_with_elements(): stack = Stack() stack.push(42) assert not stack.is_empty()
def test_is_empty_returns_true_on_empty_stack(): stack = Stack() assert stack.is_empty()