OLD | NEW |
(Empty) | |
| 1 dart_library.library('corelib/set_iterator_test', null, /* Imports */[ |
| 2 'dart_sdk', |
| 3 'expect' |
| 4 ], function load__set_iterator_test(exports, dart_sdk, expect) { |
| 5 'use strict'; |
| 6 const core = dart_sdk.core; |
| 7 const dart = dart_sdk.dart; |
| 8 const dartx = dart_sdk.dartx; |
| 9 const expect$ = expect.expect; |
| 10 const set_iterator_test = Object.create(null); |
| 11 let SetOfint = () => (SetOfint = dart.constFn(core.Set$(core.int)))(); |
| 12 let SetOfString = () => (SetOfString = dart.constFn(core.Set$(core.String)))()
; |
| 13 let VoidTodynamic = () => (VoidTodynamic = dart.constFn(dart.definiteFunctionT
ype(dart.dynamic, [])))(); |
| 14 const _hashCode = Symbol('_hashCode'); |
| 15 set_iterator_test.FixedHashCode = class FixedHashCode extends core.Object { |
| 16 new(hashCode) { |
| 17 this[_hashCode] = hashCode; |
| 18 } |
| 19 get hashCode() { |
| 20 return this[_hashCode]; |
| 21 } |
| 22 }; |
| 23 dart.setSignature(set_iterator_test.FixedHashCode, { |
| 24 constructors: () => ({new: dart.definiteFunctionType(set_iterator_test.Fixed
HashCode, [core.int])}) |
| 25 }); |
| 26 set_iterator_test.SetIteratorTest = class SetIteratorTest extends core.Object
{ |
| 27 static testMain() { |
| 28 set_iterator_test.SetIteratorTest.testSmallSet(); |
| 29 set_iterator_test.SetIteratorTest.testLargeSet(); |
| 30 set_iterator_test.SetIteratorTest.testEmptySet(); |
| 31 set_iterator_test.SetIteratorTest.testSetWithDeletedEntries(); |
| 32 set_iterator_test.SetIteratorTest.testBug5116829(); |
| 33 set_iterator_test.SetIteratorTest.testDifferentSizes(); |
| 34 set_iterator_test.SetIteratorTest.testDifferentHashCodes(); |
| 35 } |
| 36 static sum(expected, it) { |
| 37 let count = 0; |
| 38 while (dart.test(it.moveNext())) { |
| 39 count = dart.notNull(count) + dart.notNull(it.current); |
| 40 } |
| 41 expect$.Expect.equals(expected, count); |
| 42 } |
| 43 static testSmallSet() { |
| 44 let set = SetOfint().new(); |
| 45 set.add(1); |
| 46 set.add(2); |
| 47 set.add(3); |
| 48 let it = set.iterator; |
| 49 set_iterator_test.SetIteratorTest.sum(6, it); |
| 50 expect$.Expect.isFalse(it.moveNext()); |
| 51 expect$.Expect.isNull(it.current); |
| 52 } |
| 53 static testLargeSet() { |
| 54 let set = SetOfint().new(); |
| 55 let count = 0; |
| 56 for (let i = 0; i < 100; i++) { |
| 57 count = count + i; |
| 58 set.add(i); |
| 59 } |
| 60 let it = set.iterator; |
| 61 set_iterator_test.SetIteratorTest.sum(count, it); |
| 62 expect$.Expect.isFalse(it.moveNext()); |
| 63 expect$.Expect.isNull(it.current); |
| 64 } |
| 65 static testEmptySet() { |
| 66 let set = SetOfint().new(); |
| 67 let it = set.iterator; |
| 68 set_iterator_test.SetIteratorTest.sum(0, it); |
| 69 expect$.Expect.isFalse(it.moveNext()); |
| 70 expect$.Expect.isNull(it.current); |
| 71 } |
| 72 static testSetWithDeletedEntries() { |
| 73 let set = SetOfint().new(); |
| 74 for (let i = 0; i < 100; i++) { |
| 75 set.add(i); |
| 76 } |
| 77 for (let i = 0; i < 100; i++) { |
| 78 set.remove(i); |
| 79 } |
| 80 let it = set.iterator; |
| 81 expect$.Expect.isFalse(it.moveNext()); |
| 82 it = set.iterator; |
| 83 set_iterator_test.SetIteratorTest.sum(0, it); |
| 84 expect$.Expect.isFalse(it.moveNext()); |
| 85 expect$.Expect.isNull(it.current); |
| 86 let count = 0; |
| 87 for (let i = 0; i < 100; i++) { |
| 88 set.add(i); |
| 89 if (i[dartx['%']](2) == 0) |
| 90 set.remove(i); |
| 91 else { |
| 92 count = count + i; |
| 93 } |
| 94 } |
| 95 it = set.iterator; |
| 96 set_iterator_test.SetIteratorTest.sum(count, it); |
| 97 expect$.Expect.isFalse(it.moveNext()); |
| 98 expect$.Expect.isNull(it.current); |
| 99 } |
| 100 static testBug5116829() { |
| 101 let mystrs = SetOfString().new(); |
| 102 mystrs.add("A"); |
| 103 let seen = 0; |
| 104 for (let elt of mystrs) { |
| 105 seen++; |
| 106 expect$.Expect.equals("A", elt); |
| 107 } |
| 108 expect$.Expect.equals(1, seen); |
| 109 } |
| 110 static testDifferentSizes() { |
| 111 for (let i = 1; i < 20; i++) { |
| 112 let set = core.Set.new(); |
| 113 let sum = 0; |
| 114 for (let j = 0; j < i; j++) { |
| 115 set.add(j); |
| 116 sum = sum + j; |
| 117 } |
| 118 let count = 0; |
| 119 let controlSum = 0; |
| 120 for (let x of set) { |
| 121 core.int._check(x); |
| 122 controlSum = controlSum + dart.notNull(x); |
| 123 count++; |
| 124 } |
| 125 expect$.Expect.equals(i, count); |
| 126 expect$.Expect.equals(sum, controlSum); |
| 127 } |
| 128 } |
| 129 static testDifferentHashCodes() { |
| 130 for (let i = -20; i < 20; i++) { |
| 131 let set = core.Set.new(); |
| 132 let element = new set_iterator_test.FixedHashCode(i); |
| 133 set.add(element); |
| 134 expect$.Expect.equals(1, set.length); |
| 135 let foundIt = false; |
| 136 for (let x of set) { |
| 137 foundIt = true; |
| 138 expect$.Expect.equals(true, core.identical(x, element)); |
| 139 } |
| 140 expect$.Expect.equals(true, foundIt); |
| 141 } |
| 142 } |
| 143 }; |
| 144 dart.setSignature(set_iterator_test.SetIteratorTest, { |
| 145 statics: () => ({ |
| 146 testMain: dart.definiteFunctionType(dart.dynamic, []), |
| 147 sum: dart.definiteFunctionType(core.int, [core.int, core.Iterator$(core.in
t)]), |
| 148 testSmallSet: dart.definiteFunctionType(dart.void, []), |
| 149 testLargeSet: dart.definiteFunctionType(dart.void, []), |
| 150 testEmptySet: dart.definiteFunctionType(dart.void, []), |
| 151 testSetWithDeletedEntries: dart.definiteFunctionType(dart.void, []), |
| 152 testBug5116829: dart.definiteFunctionType(dart.void, []), |
| 153 testDifferentSizes: dart.definiteFunctionType(dart.void, []), |
| 154 testDifferentHashCodes: dart.definiteFunctionType(dart.void, []) |
| 155 }), |
| 156 names: ['testMain', 'sum', 'testSmallSet', 'testLargeSet', 'testEmptySet', '
testSetWithDeletedEntries', 'testBug5116829', 'testDifferentSizes', 'testDiffere
ntHashCodes'] |
| 157 }); |
| 158 set_iterator_test.main = function() { |
| 159 set_iterator_test.SetIteratorTest.testMain(); |
| 160 }; |
| 161 dart.fn(set_iterator_test.main, VoidTodynamic()); |
| 162 // Exports: |
| 163 exports.set_iterator_test = set_iterator_test; |
| 164 }); |
OLD | NEW |