中级农民
- 积分
- 106
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2016-4-22
- 最后登录
- 1970-1-1
|
- Part 1:
- An empty list should be [ ]: [ ]
- l.isEmpty() should be true: true
- l.length() should be 0: 0
- Finding front node p of l.
- p.isValidNode() should be false: false
- p.item() should throw an exception, and did.
- p.setItem() should throw an exception, and did.
- p.next() should throw an exception, and did.
- p.prev() should throw an exception, and did.
- p.insertBefore() should throw an exception, and did.
- p.insertAfter() should throw an exception, and did.
- p.remove() should throw an exception, and did.
- Finding back node p of l.
- p.isValidNode() should be false: false
- p.item() should throw an exception, and did.
- p.setItem() should throw an exception, and did.
- p.next() should throw an exception, and did.
- p.prev() should throw an exception, and did.
- p.insertBefore() should throw an exception, and did.
- p.insertAfter() should throw an exception, and did.
- p.remove() should throw an exception, and did.
- l after insertFront(10) should be [ 10 ]: [ 10 ]
- l is a list of 3 elements: [ 1 2 3 ]
- n.item() should be 1: 1
- n.item() should be 2: 2
- n.item() should be 2: 2
- n.item() should be 4: 4
- n.item() should be 3: 3
- n.item() should be 6: 6
- After doubling all elements of l: [ 2 4 6 ]
- p.isValidNode() should be false: false
- p.item() should throw an exception, and did.
- p.setItem() should throw an exception, and did.
- p.next() should throw an exception, and did.
- p.prev() should throw an exception, and did.
- p.insertBefore() should throw an exception, and did.
- p.insertAfter() should throw an exception, and did.
- p.remove() should throw an exception, and did.
- n.item() should be 6: 6
- n.item() should be 12: 12
- n.item() should be 4: 4
- n.item() should be 8: 8
- n.item() should be 2: 2
- n.item() should be 4: 4
- After doubling all elements of l again: [ 4 8 12 ]
- p.isValidNode() should be false: false
- p.item() should throw an exception, and did.
- p.setItem() should throw an exception, and did.
- p.next() should throw an exception, and did.
- p.prev() should throw an exception, and did.
- p.insertBefore() should throw an exception, and did.
- p.insertAfter() should throw an exception, and did.
- p.remove() should throw an exception, and did.
- Removing middle element (8) of l: 8
- l is now: [ 4 12 ]
- p.isValidNode() should be false: false
- p.item() should throw an exception, and did.
- p.setItem() should throw an exception, and did.
- p.next() should throw an exception, and did.
- p.prev() should throw an exception, and did.
- p.insertBefore() should throw an exception, and did.
- p.insertAfter() should throw an exception, and did.
- p.remove() should throw an exception, and did.
- Removing end element (12) of l: 12
- l is now: [ 4 ]
- p.isValidNode() should be false: false
- p.item() should throw an exception, and did.
- p.setItem() should throw an exception, and did.
- p.next() should throw an exception, and did.
- p.prev() should throw an exception, and did.
- p.insertBefore() should throw an exception, and did.
- p.insertAfter() should throw an exception, and did.
- p.remove() should throw an exception, and did.
- Removing first element (4) of l: 4
- l is now: [ ]
- p.isValidNode() should be false: false
- p.item() should throw an exception, and did.
- p.setItem() should throw an exception, and did.
- p.next() should throw an exception, and did.
- p.prev() should throw an exception, and did.
- p.insertBefore() should throw an exception, and did.
- p.insertAfter() should throw an exception, and did.
- p.remove() should throw an exception, and did.
复制代码
- Part 2:
- Set s = [ 3 4 ]
- Set s2 = [ 4 5 ]
- Set s3 = [ 3 5 8 ]
- After s.union(s2), s = [ 3 4 5 ]
- After s.intersect(s3), s = [ 3 5 ]
- s.cardinality() = 2
复制代码
- Test :
- Testing insert()
- Set s should be { 3 4 }: [ 3 4 ]
- Set s2 should be { 4 5 }: [ 4 5 ]
- Set s3 should be { 3 5 8 }: [ 3 5 8 ]
- Tesing union()
- After s.union(s2), s should be { 3 4 5 }: [ 3 4 5 ]
- After s2.union(s3), s2 should be { 3 4 5 8 }: [ 3 4 5 8 ]
- Empty set s4 = [ ]
- After s.union(s4), s should be { 3 4 5 }: [ 3 4 5 ]
- After s4.union(s), s4 should be { 3 4 5 }: [ 3 4 5 ]
- Tesing intersect()
- {}.intersect({1}) should be { }: [ ]
- {1}.intersect({}) should be { }: [ ]
- {1}.intersect({1 2}) should be { 1 }: [ 1 ]
- {1 2 3}.intersect({1 2}) should be { 1 2 }: [ 1 2 ]
- {1 2 4 7}.intersect({1 2 3 5}) should be { 1 2 }: [ 1 2 ]
- Tesing cardinality()
- s.cardinality() should be 3: 3
- s4.cardinality() should be 3: 3
- s5.cardinality() should be 0: 0
- s6.cardinality() should be 4: 4
- s7.cardinality() should be 2: 2
复制代码 |
|