Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: test/codegen/expect/DeltaBlue.js

Issue 1988503002: Move generated files to gen/. (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 dart_library.library('DeltaBlue', null, /* Imports */[
2 'dart_sdk'
3 ], function(exports, dart_sdk) {
4 'use strict';
5 const core = dart_sdk.core;
6 const dart = dart_sdk.dart;
7 const dartx = dart_sdk.dartx;
8 const DeltaBlue$ = Object.create(null);
9 const BenchmarkBase$ = Object.create(null);
10 DeltaBlue$.main = function() {
11 new DeltaBlue$.DeltaBlue().report();
12 };
13 dart.fn(DeltaBlue$.main);
14 BenchmarkBase$.BenchmarkBase = class BenchmarkBase extends core.Object {
15 BenchmarkBase(name) {
16 this.name = name;
17 }
18 run() {}
19 warmup() {
20 this.run();
21 }
22 exercise() {
23 for (let i = 0; i < 10; i++) {
24 this.run();
25 }
26 }
27 setup() {}
28 teardown() {}
29 static measureFor(f, timeMinimum) {
30 let time = 0;
31 let iter = 0;
32 let watch = new core.Stopwatch();
33 watch.start();
34 let elapsed = 0;
35 while (dart.notNull(elapsed) < dart.notNull(timeMinimum)) {
36 dart.dcall(f);
37 elapsed = watch.elapsedMilliseconds;
38 iter++;
39 }
40 return 1000.0 * dart.notNull(elapsed) / iter;
41 }
42 measure() {
43 this.setup();
44 BenchmarkBase$.BenchmarkBase.measureFor(dart.fn(() => {
45 this.warmup();
46 }), 100);
47 let result = BenchmarkBase$.BenchmarkBase.measureFor(dart.fn(() => {
48 this.exercise();
49 }), 2000);
50 this.teardown();
51 return result;
52 }
53 report() {
54 let score = this.measure();
55 core.print(`${this.name}(RunTime): ${score} us.`);
56 }
57 };
58 dart.setSignature(BenchmarkBase$.BenchmarkBase, {
59 constructors: () => ({BenchmarkBase: [BenchmarkBase$.BenchmarkBase, [core.St ring]]}),
60 methods: () => ({
61 run: [dart.void, []],
62 warmup: [dart.void, []],
63 exercise: [dart.void, []],
64 setup: [dart.void, []],
65 teardown: [dart.void, []],
66 measure: [core.double, []],
67 report: [dart.void, []]
68 }),
69 statics: () => ({measureFor: [core.double, [core.Function, core.int]]}),
70 names: ['measureFor']
71 });
72 DeltaBlue$.DeltaBlue = class DeltaBlue extends BenchmarkBase$.BenchmarkBase {
73 DeltaBlue() {
74 super.BenchmarkBase("DeltaBlue");
75 }
76 run() {
77 DeltaBlue$.chainTest(100);
78 DeltaBlue$.projectionTest(100);
79 }
80 };
81 dart.setSignature(DeltaBlue$.DeltaBlue, {
82 constructors: () => ({DeltaBlue: [DeltaBlue$.DeltaBlue, []]})
83 });
84 DeltaBlue$.Strength = class Strength extends core.Object {
85 Strength(value, name) {
86 this.value = value;
87 this.name = name;
88 }
89 nextWeaker() {
90 return dart.const(dart.list([DeltaBlue$.STRONG_PREFERRED, DeltaBlue$.PREFE RRED, DeltaBlue$.STRONG_DEFAULT, DeltaBlue$.NORMAL, DeltaBlue$.WEAK_DEFAULT, Del taBlue$.WEAKEST], DeltaBlue$.Strength))[dartx.get](this.value);
91 }
92 static stronger(s1, s2) {
93 return dart.notNull(s1.value) < dart.notNull(s2.value);
94 }
95 static weaker(s1, s2) {
96 return dart.notNull(s1.value) > dart.notNull(s2.value);
97 }
98 static weakest(s1, s2) {
99 return dart.notNull(DeltaBlue$.Strength.weaker(s1, s2)) ? s1 : s2;
100 }
101 static strongest(s1, s2) {
102 return dart.notNull(DeltaBlue$.Strength.stronger(s1, s2)) ? s1 : s2;
103 }
104 };
105 dart.setSignature(DeltaBlue$.Strength, {
106 constructors: () => ({Strength: [DeltaBlue$.Strength, [core.int, core.String ]]}),
107 methods: () => ({nextWeaker: [DeltaBlue$.Strength, []]}),
108 statics: () => ({
109 stronger: [core.bool, [DeltaBlue$.Strength, DeltaBlue$.Strength]],
110 weaker: [core.bool, [DeltaBlue$.Strength, DeltaBlue$.Strength]],
111 weakest: [DeltaBlue$.Strength, [DeltaBlue$.Strength, DeltaBlue$.Strength]] ,
112 strongest: [DeltaBlue$.Strength, [DeltaBlue$.Strength, DeltaBlue$.Strength ]]
113 }),
114 names: ['stronger', 'weaker', 'weakest', 'strongest']
115 });
116 DeltaBlue$.REQUIRED = dart.const(new DeltaBlue$.Strength(0, "required"));
117 DeltaBlue$.STRONG_PREFERRED = dart.const(new DeltaBlue$.Strength(1, "strongPre ferred"));
118 DeltaBlue$.PREFERRED = dart.const(new DeltaBlue$.Strength(2, "preferred"));
119 DeltaBlue$.STRONG_DEFAULT = dart.const(new DeltaBlue$.Strength(3, "strongDefau lt"));
120 DeltaBlue$.NORMAL = dart.const(new DeltaBlue$.Strength(4, "normal"));
121 DeltaBlue$.WEAK_DEFAULT = dart.const(new DeltaBlue$.Strength(5, "weakDefault") );
122 DeltaBlue$.WEAKEST = dart.const(new DeltaBlue$.Strength(6, "weakest"));
123 DeltaBlue$.Constraint = class Constraint extends core.Object {
124 Constraint(strength) {
125 this.strength = strength;
126 }
127 addConstraint() {
128 this.addToGraph();
129 DeltaBlue$.planner.incrementalAdd(this);
130 }
131 satisfy(mark) {
132 this.chooseMethod(dart.as(mark, core.int));
133 if (!dart.notNull(this.isSatisfied())) {
134 if (dart.equals(this.strength, DeltaBlue$.REQUIRED)) {
135 core.print("Could not satisfy a required constraint!");
136 }
137 return null;
138 }
139 this.markInputs(dart.as(mark, core.int));
140 let out = this.output();
141 let overridden = out.determinedBy;
142 if (overridden != null) overridden.markUnsatisfied();
143 out.determinedBy = this;
144 if (!dart.notNull(DeltaBlue$.planner.addPropagate(this, dart.as(mark, core .int)))) core.print("Cycle encountered");
145 out.mark = dart.as(mark, core.int);
146 return overridden;
147 }
148 destroyConstraint() {
149 if (dart.notNull(this.isSatisfied())) DeltaBlue$.planner.incrementalRemove (this);
150 this.removeFromGraph();
151 }
152 isInput() {
153 return false;
154 }
155 };
156 dart.setSignature(DeltaBlue$.Constraint, {
157 constructors: () => ({Constraint: [DeltaBlue$.Constraint, [DeltaBlue$.Streng th]]}),
158 methods: () => ({
159 addConstraint: [dart.void, []],
160 satisfy: [DeltaBlue$.Constraint, [dart.dynamic]],
161 destroyConstraint: [dart.void, []],
162 isInput: [core.bool, []]
163 })
164 });
165 DeltaBlue$.UnaryConstraint = class UnaryConstraint extends DeltaBlue$.Constrai nt {
166 UnaryConstraint(myOutput, strength) {
167 this.myOutput = myOutput;
168 this.satisfied = false;
169 super.Constraint(strength);
170 this.addConstraint();
171 }
172 addToGraph() {
173 this.myOutput.addConstraint(this);
174 this.satisfied = false;
175 }
176 chooseMethod(mark) {
177 this.satisfied = this.myOutput.mark != mark && dart.notNull(DeltaBlue$.Str ength.stronger(this.strength, this.myOutput.walkStrength));
178 }
179 isSatisfied() {
180 return this.satisfied;
181 }
182 markInputs(mark) {}
183 output() {
184 return this.myOutput;
185 }
186 recalculate() {
187 this.myOutput.walkStrength = this.strength;
188 this.myOutput.stay = !dart.notNull(this.isInput());
189 if (dart.notNull(this.myOutput.stay)) this.execute();
190 }
191 markUnsatisfied() {
192 this.satisfied = false;
193 }
194 inputsKnown(mark) {
195 return true;
196 }
197 removeFromGraph() {
198 if (this.myOutput != null) this.myOutput.removeConstraint(this);
199 this.satisfied = false;
200 }
201 };
202 dart.setSignature(DeltaBlue$.UnaryConstraint, {
203 constructors: () => ({UnaryConstraint: [DeltaBlue$.UnaryConstraint, [DeltaBl ue$.Variable, DeltaBlue$.Strength]]}),
204 methods: () => ({
205 addToGraph: [dart.void, []],
206 chooseMethod: [dart.void, [core.int]],
207 isSatisfied: [core.bool, []],
208 markInputs: [dart.void, [core.int]],
209 output: [DeltaBlue$.Variable, []],
210 recalculate: [dart.void, []],
211 markUnsatisfied: [dart.void, []],
212 inputsKnown: [core.bool, [core.int]],
213 removeFromGraph: [dart.void, []]
214 })
215 });
216 DeltaBlue$.StayConstraint = class StayConstraint extends DeltaBlue$.UnaryConst raint {
217 StayConstraint(v, str) {
218 super.UnaryConstraint(v, str);
219 }
220 execute() {}
221 };
222 dart.setSignature(DeltaBlue$.StayConstraint, {
223 constructors: () => ({StayConstraint: [DeltaBlue$.StayConstraint, [DeltaBlue $.Variable, DeltaBlue$.Strength]]}),
224 methods: () => ({execute: [dart.void, []]})
225 });
226 DeltaBlue$.EditConstraint = class EditConstraint extends DeltaBlue$.UnaryConst raint {
227 EditConstraint(v, str) {
228 super.UnaryConstraint(v, str);
229 }
230 isInput() {
231 return true;
232 }
233 execute() {}
234 };
235 dart.setSignature(DeltaBlue$.EditConstraint, {
236 constructors: () => ({EditConstraint: [DeltaBlue$.EditConstraint, [DeltaBlue $.Variable, DeltaBlue$.Strength]]}),
237 methods: () => ({execute: [dart.void, []]})
238 });
239 DeltaBlue$.NONE = 1;
240 DeltaBlue$.FORWARD = 2;
241 DeltaBlue$.BACKWARD = 0;
242 DeltaBlue$.BinaryConstraint = class BinaryConstraint extends DeltaBlue$.Constr aint {
243 BinaryConstraint(v1, v2, strength) {
244 this.v1 = v1;
245 this.v2 = v2;
246 this.direction = DeltaBlue$.NONE;
247 super.Constraint(strength);
248 this.addConstraint();
249 }
250 chooseMethod(mark) {
251 if (this.v1.mark == mark) {
252 this.direction = this.v2.mark != mark && dart.notNull(DeltaBlue$.Strengt h.stronger(this.strength, this.v2.walkStrength)) ? DeltaBlue$.FORWARD : DeltaBlu e$.NONE;
253 }
254 if (this.v2.mark == mark) {
255 this.direction = this.v1.mark != mark && dart.notNull(DeltaBlue$.Strengt h.stronger(this.strength, this.v1.walkStrength)) ? DeltaBlue$.BACKWARD : DeltaBl ue$.NONE;
256 }
257 if (dart.notNull(DeltaBlue$.Strength.weaker(this.v1.walkStrength, this.v2. walkStrength))) {
258 this.direction = dart.notNull(DeltaBlue$.Strength.stronger(this.strength , this.v1.walkStrength)) ? DeltaBlue$.BACKWARD : DeltaBlue$.NONE;
259 } else {
260 this.direction = dart.notNull(DeltaBlue$.Strength.stronger(this.strength , this.v2.walkStrength)) ? DeltaBlue$.FORWARD : DeltaBlue$.BACKWARD;
261 }
262 }
263 addToGraph() {
264 this.v1.addConstraint(this);
265 this.v2.addConstraint(this);
266 this.direction = DeltaBlue$.NONE;
267 }
268 isSatisfied() {
269 return this.direction != DeltaBlue$.NONE;
270 }
271 markInputs(mark) {
272 this.input().mark = mark;
273 }
274 input() {
275 return this.direction == DeltaBlue$.FORWARD ? this.v1 : this.v2;
276 }
277 output() {
278 return this.direction == DeltaBlue$.FORWARD ? this.v2 : this.v1;
279 }
280 recalculate() {
281 let ihn = this.input(), out = this.output();
282 out.walkStrength = DeltaBlue$.Strength.weakest(this.strength, ihn.walkStre ngth);
283 out.stay = ihn.stay;
284 if (dart.notNull(out.stay)) this.execute();
285 }
286 markUnsatisfied() {
287 this.direction = DeltaBlue$.NONE;
288 }
289 inputsKnown(mark) {
290 let i = this.input();
291 return i.mark == mark || dart.notNull(i.stay) || i.determinedBy == null;
292 }
293 removeFromGraph() {
294 if (this.v1 != null) this.v1.removeConstraint(this);
295 if (this.v2 != null) this.v2.removeConstraint(this);
296 this.direction = DeltaBlue$.NONE;
297 }
298 };
299 dart.setSignature(DeltaBlue$.BinaryConstraint, {
300 constructors: () => ({BinaryConstraint: [DeltaBlue$.BinaryConstraint, [Delta Blue$.Variable, DeltaBlue$.Variable, DeltaBlue$.Strength]]}),
301 methods: () => ({
302 chooseMethod: [dart.void, [core.int]],
303 addToGraph: [dart.void, []],
304 isSatisfied: [core.bool, []],
305 markInputs: [dart.void, [core.int]],
306 input: [DeltaBlue$.Variable, []],
307 output: [DeltaBlue$.Variable, []],
308 recalculate: [dart.void, []],
309 markUnsatisfied: [dart.void, []],
310 inputsKnown: [core.bool, [core.int]],
311 removeFromGraph: [dart.void, []]
312 })
313 });
314 DeltaBlue$.ScaleConstraint = class ScaleConstraint extends DeltaBlue$.BinaryCo nstraint {
315 ScaleConstraint(src, scale, offset, dest, strength) {
316 this.scale = scale;
317 this.offset = offset;
318 super.BinaryConstraint(src, dest, strength);
319 }
320 addToGraph() {
321 super.addToGraph();
322 this.scale.addConstraint(this);
323 this.offset.addConstraint(this);
324 }
325 removeFromGraph() {
326 super.removeFromGraph();
327 if (this.scale != null) this.scale.removeConstraint(this);
328 if (this.offset != null) this.offset.removeConstraint(this);
329 }
330 markInputs(mark) {
331 super.markInputs(mark);
332 this.scale.mark = this.offset.mark = mark;
333 }
334 execute() {
335 if (this.direction == DeltaBlue$.FORWARD) {
336 this.v2.value = dart.notNull(this.v1.value) * dart.notNull(this.scale.va lue) + dart.notNull(this.offset.value);
337 } else {
338 this.v1.value = ((dart.notNull(this.v2.value) - dart.notNull(this.offset .value)) / dart.notNull(this.scale.value))[dartx.truncate]();
339 }
340 }
341 recalculate() {
342 let ihn = this.input(), out = this.output();
343 out.walkStrength = DeltaBlue$.Strength.weakest(this.strength, ihn.walkStre ngth);
344 out.stay = dart.notNull(ihn.stay) && dart.notNull(this.scale.stay) && dart .notNull(this.offset.stay);
345 if (dart.notNull(out.stay)) this.execute();
346 }
347 };
348 dart.setSignature(DeltaBlue$.ScaleConstraint, {
349 constructors: () => ({ScaleConstraint: [DeltaBlue$.ScaleConstraint, [DeltaBl ue$.Variable, DeltaBlue$.Variable, DeltaBlue$.Variable, DeltaBlue$.Variable, Del taBlue$.Strength]]}),
350 methods: () => ({execute: [dart.void, []]})
351 });
352 DeltaBlue$.EqualityConstraint = class EqualityConstraint extends DeltaBlue$.Bi naryConstraint {
353 EqualityConstraint(v1, v2, strength) {
354 super.BinaryConstraint(v1, v2, strength);
355 }
356 execute() {
357 this.output().value = this.input().value;
358 }
359 };
360 dart.setSignature(DeltaBlue$.EqualityConstraint, {
361 constructors: () => ({EqualityConstraint: [DeltaBlue$.EqualityConstraint, [D eltaBlue$.Variable, DeltaBlue$.Variable, DeltaBlue$.Strength]]}),
362 methods: () => ({execute: [dart.void, []]})
363 });
364 DeltaBlue$.Variable = class Variable extends core.Object {
365 Variable(name, value) {
366 this.constraints = dart.list([], DeltaBlue$.Constraint);
367 this.name = name;
368 this.value = value;
369 this.determinedBy = null;
370 this.mark = 0;
371 this.walkStrength = DeltaBlue$.WEAKEST;
372 this.stay = true;
373 }
374 addConstraint(c) {
375 this.constraints[dartx.add](c);
376 }
377 removeConstraint(c) {
378 this.constraints[dartx.remove](c);
379 if (dart.equals(this.determinedBy, c)) this.determinedBy = null;
380 }
381 };
382 dart.setSignature(DeltaBlue$.Variable, {
383 constructors: () => ({Variable: [DeltaBlue$.Variable, [core.String, core.int ]]}),
384 methods: () => ({
385 addConstraint: [dart.void, [DeltaBlue$.Constraint]],
386 removeConstraint: [dart.void, [DeltaBlue$.Constraint]]
387 })
388 });
389 DeltaBlue$.Planner = class Planner extends core.Object {
390 Planner() {
391 this.currentMark = 0;
392 }
393 incrementalAdd(c) {
394 let mark = this.newMark();
395 for (let overridden = c.satisfy(mark); overridden != null; overridden = ov erridden.satisfy(mark))
396 ;
397 }
398 incrementalRemove(c) {
399 let out = c.output();
400 c.markUnsatisfied();
401 c.removeFromGraph();
402 let unsatisfied = this.removePropagateFrom(out);
403 let strength = DeltaBlue$.REQUIRED;
404 do {
405 for (let i = 0; i < dart.notNull(unsatisfied[dartx.length]); i++) {
406 let u = unsatisfied[dartx.get](i);
407 if (dart.equals(u.strength, strength)) this.incrementalAdd(u);
408 }
409 strength = strength.nextWeaker();
410 } while (!dart.equals(strength, DeltaBlue$.WEAKEST));
411 }
412 newMark() {
413 return this.currentMark = dart.notNull(this.currentMark) + 1;
414 }
415 makePlan(sources) {
416 let mark = this.newMark();
417 let plan = new DeltaBlue$.Plan();
418 let todo = sources;
419 while (dart.notNull(todo[dartx.length]) > 0) {
420 let c = todo[dartx.removeLast]();
421 if (c.output().mark != mark && dart.notNull(c.inputsKnown(mark))) {
422 plan.addConstraint(c);
423 c.output().mark = mark;
424 this.addConstraintsConsumingTo(c.output(), todo);
425 }
426 }
427 return plan;
428 }
429 extractPlanFromConstraints(constraints) {
430 let sources = dart.list([], DeltaBlue$.Constraint);
431 for (let i = 0; i < dart.notNull(constraints[dartx.length]); i++) {
432 let c = constraints[dartx.get](i);
433 if (dart.notNull(c.isInput()) && dart.notNull(c.isSatisfied())) sources[ dartx.add](c);
434 }
435 return this.makePlan(sources);
436 }
437 addPropagate(c, mark) {
438 let todo = dart.list([c], DeltaBlue$.Constraint);
439 while (dart.notNull(todo[dartx.length]) > 0) {
440 let d = todo[dartx.removeLast]();
441 if (d.output().mark == mark) {
442 this.incrementalRemove(c);
443 return false;
444 }
445 d.recalculate();
446 this.addConstraintsConsumingTo(d.output(), todo);
447 }
448 return true;
449 }
450 removePropagateFrom(out) {
451 out.determinedBy = null;
452 out.walkStrength = DeltaBlue$.WEAKEST;
453 out.stay = true;
454 let unsatisfied = dart.list([], DeltaBlue$.Constraint);
455 let todo = dart.list([out], DeltaBlue$.Variable);
456 while (dart.notNull(todo[dartx.length]) > 0) {
457 let v = todo[dartx.removeLast]();
458 for (let i = 0; i < dart.notNull(v.constraints[dartx.length]); i++) {
459 let c = v.constraints[dartx.get](i);
460 if (!dart.notNull(c.isSatisfied())) unsatisfied[dartx.add](c);
461 }
462 let determining = v.determinedBy;
463 for (let i = 0; i < dart.notNull(v.constraints[dartx.length]); i++) {
464 let next = v.constraints[dartx.get](i);
465 if (!dart.equals(next, determining) && dart.notNull(next.isSatisfied() )) {
466 next.recalculate();
467 todo[dartx.add](next.output());
468 }
469 }
470 }
471 return unsatisfied;
472 }
473 addConstraintsConsumingTo(v, coll) {
474 let determining = v.determinedBy;
475 for (let i = 0; i < dart.notNull(v.constraints[dartx.length]); i++) {
476 let c = v.constraints[dartx.get](i);
477 if (!dart.equals(c, determining) && dart.notNull(c.isSatisfied())) coll[ dartx.add](c);
478 }
479 }
480 };
481 dart.setSignature(DeltaBlue$.Planner, {
482 methods: () => ({
483 incrementalAdd: [dart.void, [DeltaBlue$.Constraint]],
484 incrementalRemove: [dart.void, [DeltaBlue$.Constraint]],
485 newMark: [core.int, []],
486 makePlan: [DeltaBlue$.Plan, [core.List$(DeltaBlue$.Constraint)]],
487 extractPlanFromConstraints: [DeltaBlue$.Plan, [core.List$(DeltaBlue$.Const raint)]],
488 addPropagate: [core.bool, [DeltaBlue$.Constraint, core.int]],
489 removePropagateFrom: [core.List$(DeltaBlue$.Constraint), [DeltaBlue$.Varia ble]],
490 addConstraintsConsumingTo: [dart.void, [DeltaBlue$.Variable, core.List$(De ltaBlue$.Constraint)]]
491 })
492 });
493 DeltaBlue$.Plan = class Plan extends core.Object {
494 Plan() {
495 this.list = dart.list([], DeltaBlue$.Constraint);
496 }
497 addConstraint(c) {
498 this.list[dartx.add](c);
499 }
500 size() {
501 return this.list[dartx.length];
502 }
503 execute() {
504 for (let i = 0; i < dart.notNull(this.list[dartx.length]); i++) {
505 this.list[dartx.get](i).execute();
506 }
507 }
508 };
509 dart.setSignature(DeltaBlue$.Plan, {
510 methods: () => ({
511 addConstraint: [dart.void, [DeltaBlue$.Constraint]],
512 size: [core.int, []],
513 execute: [dart.void, []]
514 })
515 });
516 DeltaBlue$.chainTest = function(n) {
517 DeltaBlue$.planner = new DeltaBlue$.Planner();
518 let prev = null, first = null, last = null;
519 for (let i = 0; i <= dart.notNull(n); i++) {
520 let v = new DeltaBlue$.Variable("v", 0);
521 if (prev != null) new DeltaBlue$.EqualityConstraint(prev, v, DeltaBlue$.RE QUIRED);
522 if (i == 0) first = v;
523 if (i == n) last = v;
524 prev = v;
525 }
526 new DeltaBlue$.StayConstraint(last, DeltaBlue$.STRONG_DEFAULT);
527 let edit = new DeltaBlue$.EditConstraint(first, DeltaBlue$.PREFERRED);
528 let plan = DeltaBlue$.planner.extractPlanFromConstraints(dart.list([edit], D eltaBlue$.Constraint));
529 for (let i = 0; i < 100; i++) {
530 first.value = i;
531 plan.execute();
532 if (last.value != i) {
533 core.print("Chain test failed:");
534 core.print(`Expected last value to be ${i} but it was ${last.value}.`);
535 }
536 }
537 };
538 dart.fn(DeltaBlue$.chainTest, dart.void, [core.int]);
539 DeltaBlue$.projectionTest = function(n) {
540 DeltaBlue$.planner = new DeltaBlue$.Planner();
541 let scale = new DeltaBlue$.Variable("scale", 10);
542 let offset = new DeltaBlue$.Variable("offset", 1000);
543 let src = null, dst = null;
544 let dests = dart.list([], DeltaBlue$.Variable);
545 for (let i = 0; i < dart.notNull(n); i++) {
546 src = new DeltaBlue$.Variable("src", i);
547 dst = new DeltaBlue$.Variable("dst", i);
548 dests[dartx.add](dst);
549 new DeltaBlue$.StayConstraint(src, DeltaBlue$.NORMAL);
550 new DeltaBlue$.ScaleConstraint(src, scale, offset, dst, DeltaBlue$.REQUIRE D);
551 }
552 DeltaBlue$.change(src, 17);
553 if (dst.value != 1170) core.print("Projection 1 failed");
554 DeltaBlue$.change(dst, 1050);
555 if (src.value != 5) core.print("Projection 2 failed");
556 DeltaBlue$.change(scale, 5);
557 for (let i = 0; i < dart.notNull(n) - 1; i++) {
558 if (dests[dartx.get](i).value != i * 5 + 1000) core.print("Projection 3 fa iled");
559 }
560 DeltaBlue$.change(offset, 2000);
561 for (let i = 0; i < dart.notNull(n) - 1; i++) {
562 if (dests[dartx.get](i).value != i * 5 + 2000) core.print("Projection 4 fa iled");
563 }
564 };
565 dart.fn(DeltaBlue$.projectionTest, dart.void, [core.int]);
566 DeltaBlue$.change = function(v, newValue) {
567 let edit = new DeltaBlue$.EditConstraint(v, DeltaBlue$.PREFERRED);
568 let plan = DeltaBlue$.planner.extractPlanFromConstraints(dart.list([edit], D eltaBlue$.EditConstraint));
569 for (let i = 0; i < 10; i++) {
570 v.value = newValue;
571 plan.execute();
572 }
573 edit.destroyConstraint();
574 };
575 dart.fn(DeltaBlue$.change, dart.void, [DeltaBlue$.Variable, core.int]);
576 DeltaBlue$.planner = null;
577 BenchmarkBase$.Expect = class Expect extends core.Object {
578 static equals(expected, actual) {
579 if (!dart.equals(expected, actual)) {
580 dart.throw(`Values not equal: ${expected} vs ${actual}`);
581 }
582 }
583 static listEquals(expected, actual) {
584 if (expected[dartx.length] != actual[dartx.length]) {
585 dart.throw(`Lists have different lengths: ${expected[dartx.length]} vs $ {actual[dartx.length]}`);
586 }
587 for (let i = 0; i < dart.notNull(actual[dartx.length]); i++) {
588 BenchmarkBase$.Expect.equals(expected[dartx.get](i), actual[dartx.get](i ));
589 }
590 }
591 fail(message) {
592 dart.throw(message);
593 }
594 };
595 dart.setSignature(BenchmarkBase$.Expect, {
596 methods: () => ({fail: [dart.dynamic, [dart.dynamic]]}),
597 statics: () => ({
598 equals: [dart.void, [dart.dynamic, dart.dynamic]],
599 listEquals: [dart.void, [core.List, core.List]]
600 }),
601 names: ['equals', 'listEquals']
602 });
603 // Exports:
604 exports.DeltaBlue = DeltaBlue$;
605 exports.BenchmarkBase = BenchmarkBase$;
606 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698