Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
|
Dmitry Stefantsov
2017/08/24 11:49:57
Please, use one-line comments in the preamble and
sjindel
2017/08/24 14:50:13
Done, but why does it matter?
Dmitry Stefantsov
2017/08/24 15:07:28
So that the next reader experiences less distracti
sjindel
2017/08/24 15:14:11
I think this is Green vs. Orange thinking :P
Dmitry Stefantsov
2017/08/24 15:17:28
Or Gold ;)
| |
| 2 * Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | |
| 3 * for details. All rights reserved. Use of this source code is governed by a | |
| 4 * BSD-style license that can be found in the LICENSE file. | |
| 5 */ | |
| 6 void doit(int x) { | |
| 7 final int max = 10; | |
| 8 final double expectedSum = ((max - 1) * max) / 2; | |
| 9 | |
| 10 int counter = 0; | |
| 11 var calls = []; | |
| 12 while (counter < max) { | |
| 13 int pos = counter; | |
| 14 calls.add(() => pos + x); | |
| 15 counter++; | |
| 16 } | |
| 17 | |
| 18 double sum = 0.0; | |
| 19 for (var c in calls) sum += c(); | |
| 20 if (sum != expectedSum) | |
| 21 throw new Exception("Unexpected sum = $sum != $expectedSum"); | |
| 22 } | |
| 23 | |
| 24 void main() { | |
| 25 doit(0); | |
| 26 } | |
| OLD | NEW |