OLD | NEW |
| (Empty) |
1 import 'dart:math'; | |
2 import 'package:kernel/type_propagation/canonicalizer.dart'; | |
3 import 'package:test/test.dart'; | |
4 | |
5 Random random = new Random(12345); | |
6 | |
7 main() { | |
8 test('Uint31PairMap randomized tests', runTest); | |
9 } | |
10 | |
11 runTest() { | |
12 const int trials = 1000; | |
13 const int insertions = 1000; | |
14 const int uniqueKeys = 900; | |
15 for (int trial = 0; trial < trials; ++trial) { | |
16 int nextValue = 1; | |
17 Map<Point<int>, int> trusted = <Point<int>, int>{}; | |
18 Uint31PairMap candidate = new Uint31PairMap(); | |
19 for (int i = 0; i < insertions; ++i) { | |
20 int x = random.nextInt(uniqueKeys); | |
21 int y = random.nextInt(uniqueKeys); | |
22 Point key = new Point(x, y); | |
23 int trustedValue = trusted[key]; | |
24 int candidateValue = candidate.lookup(x, y); | |
25 expect(candidateValue, equals(trustedValue)); | |
26 if (trustedValue == null) { | |
27 int newValue = nextValue++; | |
28 trusted[key] = newValue; | |
29 candidate.put(newValue); | |
30 } | |
31 } | |
32 } | |
33 } | |
OLD | NEW |