这似乎是一个愚蠢的问题,但我真的很喜欢你的评论,并想验证我的测试人员的想法..
I can think of following test cases:
1) Pop element from empty stack should return error
2) Push n+1 elements in stack should return error during insertion of n+1th element
3) validate empty,full and top functions of stack.
4) if stack is used in multithreaded environment , make sure it is synchronized.
5) validate stack functionality:
push element (x)
pop element: it should return x
评论?
如果在面试中问这个问题,可能的答案是什么? 我的回答是否足够有效?
最佳答案
我认为您已经涵盖了所有内容,除了可能会检查 3) 之前推送的 n
元素是否符合您的预期。这将捕获错误的边界条件检查,即仅在写入新元素后才检查堆栈是否已满。
此外,我会对您的测试用例进行不同的分组,并针对每个测试用例测试 top、pop、push、empty、full:
- 清空堆栈
- 堆叠一个元素*
- 堆叠一些元素,可能调用 pop/push 两次或更多次
- 堆栈接近满(n-1 个元素)*
- 全栈
*不是必需的,但可能是一个极端情况。
关于testing - 如何测试n个元素的栈?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/464031/