b****g 发帖数: 625 | 1 Suppose there is a C function to count and return thhe number of nodes in a
linked list.
What cases would you cover in unit tests of this function?
I can only think of two testing cases
(1): An empty list.
(2): An extrem long list with the length of the maximum value of unsigned
int.
Any other testing cases? |
h**k 发帖数: 3368 | 2 第二个case实际做起来不容易吧,非常多的node就可以了。
第三个case,传递进取的指向链表的指针是null
更狠的,链表本身结构错误,比如存在a->b->c->a这样的
a
【在 b****g 的大作中提到】 : Suppose there is a C function to count and return thhe number of nodes in a : linked list. : What cases would you cover in unit tests of this function? : I can only think of two testing cases : (1): An empty list. : (2): An extrem long list with the length of the maximum value of unsigned : int. : Any other testing cases?
|
f****b 发帖数: 486 | 3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
这个不能叫错误吧,有loop也可以返回链表的节点个数
circular list, list with loop, two lists merging at some node, empty list,
single node list, single node circular list ...
【在 h**k 的大作中提到】 : 第二个case实际做起来不容易吧,非常多的node就可以了。 : 第三个case,传递进取的指向链表的指针是null : 更狠的,链表本身结构错误,比如存在a->b->c->a这样的 : : a
|
r****o 发帖数: 1950 | 4 how about test
one-node list
two-node list
?
a
【在 b****g 的大作中提到】 : Suppose there is a C function to count and return thhe number of nodes in a : linked list. : What cases would you cover in unit tests of this function? : I can only think of two testing cases : (1): An empty list. : (2): An extrem long list with the length of the maximum value of unsigned : int. : Any other testing cases?
|
J**********g 发帖数: 213 | |
h**k 发帖数: 3368 | 6 一般都assume链表里没有loop的
【在 f****b 的大作中提到】 : : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ : 这个不能叫错误吧,有loop也可以返回链表的节点个数 : circular list, list with loop, two lists merging at some node, empty list, : single node list, single node circular list ...
|
f****b 发帖数: 486 | 7 面试里链表的loop detection是最常见的题目了吧
【在 h**k 的大作中提到】 : 一般都assume链表里没有loop的
|
h**k 发帖数: 3368 | 8 除了记录每个访问过的node,还有什么好办法么?
【在 f****b 的大作中提到】 : 面试里链表的loop detection是最常见的题目了吧
|
f****b 发帖数: 486 | 9 one fast pointer + one slow pointer, if u don't know it, google Floyd's Cycl
e-Finding Algorithm
【在 h**k 的大作中提到】 : 除了记录每个访问过的node,还有什么好办法么?
|
h**k 发帖数: 3368 | 10 Thanks. Got it.
Cycl
【在 f****b 的大作中提到】 : one fast pointer + one slow pointer, if u don't know it, google Floyd's Cycl : e-Finding Algorithm
|