Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import 'dart:collection'; | |
| 6 | |
| 7 | |
|
Lasse Reichstein Nielsen
2013/05/24 08:42:45
import "package:expect/expect.dart";
and use Expec
Anders Johnsen
2013/06/13 11:14:10
Done.
| |
| 8 class MyEntry extends LinkedListEntry<MyEntry> { | |
| 9 final int value; | |
| 10 | |
| 11 MyEntry(int this.value); | |
| 12 | |
| 13 String toString() => value.toString(); | |
| 14 } | |
| 15 | |
| 16 | |
| 17 testInsert() { | |
| 18 // Insert last. | |
| 19 var list = new LinkedList<MyEntry>(); | |
| 20 for (int i = 0; i < 10; i++) { | |
| 21 list.insertLast(new MyEntry(i)); | |
| 22 } | |
| 23 | |
| 24 if (list.length != 10) throw "bad length"; | |
| 25 | |
| 26 int i = 0; | |
| 27 for (var entry in list) { | |
| 28 if (entry.value != i++) throw "bad value"; | |
| 29 } | |
| 30 | |
| 31 if (i != 10) throw "bad length"; | |
| 32 | |
| 33 list.clear(); | |
| 34 | |
| 35 // Insert first. | |
| 36 for (int i = 0; i < 10; i++) { | |
| 37 list.insertFirst(new MyEntry(i)); | |
| 38 } | |
| 39 | |
| 40 if (list.length != 10) throw "bad length"; | |
| 41 | |
| 42 i = 10; | |
| 43 for (var entry in list) { | |
| 44 if (entry.value != --i) throw "bad value"; | |
| 45 } | |
| 46 if (i != 0) throw "bad length"; | |
| 47 | |
| 48 list.clear(); | |
| 49 | |
| 50 // Insert after. | |
| 51 list.insertFirst(new MyEntry(0)); | |
| 52 for (int i = 1; i < 10; i++) { | |
| 53 list.last.insertAfter(new MyEntry(i)); | |
| 54 } | |
| 55 | |
| 56 if (list.length != 10) throw "bad length"; | |
| 57 | |
| 58 i = 0; | |
| 59 for (var entry in list) { | |
| 60 if (entry.value != i++) throw "bad value"; | |
| 61 } | |
| 62 | |
| 63 if (i != 10) throw "bad length"; | |
| 64 | |
| 65 list.clear(); | |
| 66 | |
| 67 // Insert before. | |
| 68 list.insertFirst(new MyEntry(0)); | |
| 69 for (int i = 1; i < 10; i++) { | |
| 70 list.first.insertBefore(new MyEntry(i)); | |
| 71 } | |
| 72 | |
| 73 if (list.length != 10) throw "bad length"; | |
| 74 | |
| 75 i = 10; | |
| 76 for (var entry in list) { | |
| 77 if (entry.value != --i) throw "bad value"; | |
| 78 } | |
| 79 if (i != 0) throw "bad length"; | |
| 80 | |
| 81 list.clear(); | |
| 82 } | |
| 83 | |
| 84 | |
| 85 testRemove() { | |
| 86 var list = new LinkedList<MyEntry>(); | |
| 87 for (int i = 0; i < 10; i++) { | |
| 88 list.insertLast(new MyEntry(i)); | |
| 89 } | |
| 90 | |
| 91 if (list.length != 10) throw "bad length"; | |
| 92 | |
| 93 list.remove(list.skip(5).first); | |
| 94 | |
| 95 if (list.length != 9) throw "bad length"; | |
| 96 | |
| 97 int i = 0; | |
| 98 for (var entry in list) { | |
| 99 if (i == 5) i++; | |
| 100 if (entry.value != i++) throw "bad value"; | |
| 101 } | |
| 102 } | |
| 103 | |
| 104 | |
| 105 testBadAdd() { | |
| 106 print("here"); | |
| 107 var list1 = new LinkedList<MyEntry>(); | |
| 108 list1.insertFirst(new MyEntry(0)); | |
| 109 | |
| 110 var list2 = new LinkedList<MyEntry>(); | |
| 111 bool failed = false; | |
| 112 try { | |
| 113 list2.insertFirst(list1.first); | |
| 114 } on StateError catch (e) { | |
| 115 print(e); | |
| 116 failed = true; | |
| 117 } | |
| 118 if (!failed) throw "fail expected"; | |
| 119 } | |
| 120 | |
|
Lasse Reichstein Nielsen
2013/05/24 08:42:45
Test concurrent modification throws for all iterat
Anders Johnsen
2013/06/13 11:14:10
Done.
| |
| 121 | |
| 122 main() { | |
| 123 testInsert(); | |
| 124 testRemove(); | |
| 125 testBadAdd(); | |
| 126 } | |
| OLD | NEW |