import Testing @testable import Ch11Kit @Suite("泛型容器") struct StackTests { @Test func pushPopAndPeek() { var stack = Stack() stack.push(1) stack.push(2) #expect(stack.count == 2) #expect(stack.peek() == 2) #expect(stack.pop() == 2) #expect(stack.elements == [1]) } @Test func popOnEmptyReturnsNil() { var stack = Stack() #expect(stack.pop() == nil) #expect(stack.isEmpty) } @Test func mapChangesElementType() { let stack = Stack([1, 2, 3]) let doubled = stack.map { $0 * 2 } #expect(doubled.elements == [2, 4, 6]) let strings = stack.map(String.init) #expect(strings.elements == ["1", "2", "3"]) } @Test func equatableConformanceIsConditional() { #expect(Stack([1, 2]) == Stack([1, 2])) #expect(Stack([1, 2]) != Stack([2, 1])) } }