From e517a37a52ce26573217de12b63b98b115137cf0 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 26 Jul 2018 11:17:21 -0700 Subject: [PATCH] fix: migrate to modern dependencies, prepare to release 1.0.5 (#36) --- .gitignore | 9 +- changelog.md | 3 + example/DeltaBlue.dart | 85 +++++------ example/FluidMotion/dart/FluidMotion.dart | 166 ++++++++++++---------- example/Richards.dart | 38 ++--- example/Template.dart | 7 +- example/Tracer/dart/Tracer.dart | 1 + example/Tracer/dart/app.dart | 14 +- example/Tracer/dart/color.dart | 9 +- example/Tracer/dart/engine.dart | 49 +++---- example/Tracer/dart/index.html | 4 +- example/Tracer/dart/materials.dart | 21 ++- example/Tracer/dart/readme.md | 4 + example/Tracer/dart/renderscene.dart | 96 +++++-------- example/Tracer/dart/scene.dart | 12 +- example/Tracer/dart/shapes.dart | 22 ++- example/Tracer/dart/vector.dart | 5 +- lib/src/benchmark_base.dart | 18 +-- pubspec.yaml | 18 +-- test/benchmark_harness_test.dart | 2 +- test/drone.sh | 8 -- test/fixed-unittest.dart | 9 -- test/result_emitter_test.dart | 35 ++--- tool/hop_runner.dart | 38 ----- 24 files changed, 274 insertions(+), 399 deletions(-) create mode 100644 changelog.md create mode 100644 example/Tracer/dart/readme.md delete mode 100755 test/drone.sh delete mode 100644 test/fixed-unittest.dart delete mode 100755 tool/hop_runner.dart diff --git a/.gitignore b/.gitignore index b30294d..2afa93d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,4 @@ -.children -.project -.DS_Store -packages +.dart_tool +.packages +.pub pubspec.lock -*.sublime-workspace -*.sublime-project diff --git a/changelog.md b/changelog.md new file mode 100644 index 0000000..75f765c --- /dev/null +++ b/changelog.md @@ -0,0 +1,3 @@ +### 1.0.5 + +* Updates to support Dart 2. diff --git a/example/DeltaBlue.dart b/example/DeltaBlue.dart index 152a3dd..f234f74 100644 --- a/example/DeltaBlue.dart +++ b/example/DeltaBlue.dart @@ -40,10 +40,8 @@ main() { new DeltaBlue().report(); } - /// Benchmark class required to report results. class DeltaBlue extends BenchmarkBase { - const DeltaBlue() : super("DeltaBlue"); void run() { @@ -52,7 +50,6 @@ class DeltaBlue extends BenchmarkBase { } } - /** * Strengths are used to measure the relative importance of constraints. * New strengths may be inserted in the strength hierarchy without @@ -60,15 +57,19 @@ class DeltaBlue extends BenchmarkBase { * this class, so == can be used for value comparison. */ class Strength { - final int value; final String name; const Strength(this.value, this.name); - Strength nextWeaker() => - const [WEAKEST, WEAK_DEFAULT, NORMAL, STRONG_DEFAULT, - PREFERRED, STRONG_REFERRED][value]; + Strength nextWeaker() => const [ + WEAKEST, + WEAK_DEFAULT, + NORMAL, + STRONG_DEFAULT, + PREFERRED, + STRONG_REFERRED + ][value]; static bool stronger(Strength s1, Strength s2) { return s1.value < s2.value; @@ -87,19 +88,16 @@ class Strength { } } - // Compile time computed constants. -const REQUIRED = const Strength(0, "required"); +const REQUIRED = const Strength(0, "required"); const STRONG_REFERRED = const Strength(1, "strongPreferred"); -const PREFERRED = const Strength(2, "preferred"); -const STRONG_DEFAULT = const Strength(3, "strongDefault"); -const NORMAL = const Strength(4, "normal"); -const WEAK_DEFAULT = const Strength(5, "weakDefault"); -const WEAKEST = const Strength(6, "weakest"); - +const PREFERRED = const Strength(2, "preferred"); +const STRONG_DEFAULT = const Strength(3, "strongDefault"); +const NORMAL = const Strength(4, "normal"); +const WEAK_DEFAULT = const Strength(5, "weakDefault"); +const WEAKEST = const Strength(6, "weakest"); abstract class Constraint { - final Strength strength; const Constraint(this.strength); @@ -163,7 +161,6 @@ abstract class Constraint { * Abstract superclass for constraints having a single possible output variable. */ abstract class UnaryConstraint extends Constraint { - final Variable myOutput; bool satisfied = false; @@ -179,8 +176,8 @@ abstract class UnaryConstraint extends Constraint { /// Decides if this constraint can be satisfied and records that decision. void chooseMethod(int mark) { - satisfied = (myOutput.mark != mark) - && Strength.stronger(strength, myOutput.walkStrength); + satisfied = (myOutput.mark != mark) && + Strength.stronger(strength, myOutput.walkStrength); } /// Returns true if this constraint is satisfied in the current solution. @@ -217,7 +214,6 @@ abstract class UnaryConstraint extends Constraint { } } - /** * Variables that should, with some level of preference, stay the same. * Planners may exploit the fact that instances, if satisfied, will not @@ -225,7 +221,6 @@ abstract class UnaryConstraint extends Constraint { * optimization". */ class StayConstraint extends UnaryConstraint { - StayConstraint(Variable v, Strength str) : super(v, str); void execute() { @@ -233,13 +228,11 @@ class StayConstraint extends UnaryConstraint { } } - /** * A unary input constraint used to mark a variable that the client * wishes to change. */ class EditConstraint extends UnaryConstraint { - EditConstraint(Variable v, Strength str) : super(v, str); /// Edits indicate that a variable is to be changed by imperative code. @@ -250,19 +243,16 @@ class EditConstraint extends UnaryConstraint { } } - // Directions. const int NONE = 1; const int FORWARD = 2; const int BACKWARD = 0; - /** * Abstract superclass for constraints having two possible output * variables. */ abstract class BinaryConstraint extends Constraint { - Variable v1; Variable v2; int direction = NONE; @@ -278,21 +268,23 @@ abstract class BinaryConstraint extends Constraint { */ void chooseMethod(int mark) { if (v1.mark == mark) { - direction = (v2.mark != mark && - Strength.stronger(strength, v2.walkStrength)) - ? FORWARD : NONE; + direction = + (v2.mark != mark && Strength.stronger(strength, v2.walkStrength)) + ? FORWARD + : NONE; } if (v2.mark == mark) { - direction = (v1.mark != mark && - Strength.stronger(strength, v1.walkStrength)) - ? BACKWARD : NONE; + direction = + (v1.mark != mark && Strength.stronger(strength, v1.walkStrength)) + ? BACKWARD + : NONE; } if (Strength.weaker(v1.walkStrength, v2.walkStrength)) { - direction = Strength.stronger(strength, v1.walkStrength) - ? BACKWARD : NONE; + direction = + Strength.stronger(strength, v1.walkStrength) ? BACKWARD : NONE; } else { - direction = Strength.stronger(strength, v2.walkStrength) - ? FORWARD : BACKWARD; + direction = + Strength.stronger(strength, v2.walkStrength) ? FORWARD : BACKWARD; } } @@ -346,7 +338,6 @@ abstract class BinaryConstraint extends Constraint { } } - /** * Relates two variables by the linear scaling relationship: "v2 = * (v1 * scale) + offset". Either v1 or v2 may be changed to maintain @@ -355,13 +346,12 @@ abstract class BinaryConstraint extends Constraint { */ class ScaleConstraint extends BinaryConstraint { - final Variable scale; final Variable offset; - ScaleConstraint(Variable src, this.scale, this.offset, - Variable dest, Strength strength) - : super(src, dest, strength); + ScaleConstraint( + Variable src, this.scale, this.offset, Variable dest, Strength strength) + : super(src, dest, strength); /// Adds this constraint to the constraint graph. void addToGraph() { @@ -401,17 +391,14 @@ class ScaleConstraint extends BinaryConstraint { out.stay = ihn.stay && scale.stay && offset.stay; if (out.stay) execute(); } - } - /** * Constrains two variables to have the same value. */ class EqualityConstraint extends BinaryConstraint { - EqualityConstraint(Variable v1, Variable v2, Strength strength) - : super(v1, v2, strength); + : super(v1, v2, strength); /// Enforce this constraint. Assume that it is satisfied. void execute() { @@ -419,7 +406,6 @@ class EqualityConstraint extends BinaryConstraint { } } - /** * A constrained variable. In addition to its value, it maintain the * structure of the constraint graph, the current dataflow graph, and @@ -427,7 +413,6 @@ class EqualityConstraint extends BinaryConstraint { * constraint solver. **/ class Variable { - List constraints = []; Constraint determinedBy; int mark = 0; @@ -453,9 +438,7 @@ class Variable { } } - class Planner { - int currentMark = 0; /** @@ -474,7 +457,7 @@ class Planner { */ void incrementalAdd(Constraint c) { int mark = newMark(); - for(Constraint overridden = c.satisfy(mark); + for (Constraint overridden = c.satisfy(mark); overridden != null; overridden = overridden.satisfy(mark)); } @@ -621,7 +604,6 @@ class Planner { } } - /** * A Plan is an ordered list of constraints to be executed in sequence * to resatisfy all currently satisfiable constraints in the face of @@ -643,7 +625,6 @@ class Plan { } } - /** * This is the standard DeltaBlue benchmark. A long chain of equality * constraints is constructed with a stay constraint on one end. An diff --git a/example/FluidMotion/dart/FluidMotion.dart b/example/FluidMotion/dart/FluidMotion.dart index b4e887b..69e3ccb 100644 --- a/example/FluidMotion/dart/FluidMotion.dart +++ b/example/FluidMotion/dart/FluidMotion.dart @@ -47,7 +47,7 @@ class FluidMotion extends BenchmarkBase { framesTillAddingPoints = 0; framesBetweenAddingPoints = 5; solver = new FluidField.create(null, 128, 128, 20); - solver.setDisplayFunction((a){}); + solver.setDisplayFunction((a) {}); solver.setUICallback(prepareFrame); } @@ -96,7 +96,6 @@ class FluidMotion extends BenchmarkBase { } } - // Code from Oliver Hunt (http://nerget.com/fluidSim/pressure.js) starts here. class FluidField { @@ -114,7 +113,7 @@ class FluidField { static FluidField _lastCreated; static bool approxEquals(double a, double b) => (a - b).abs() < 0.000001; - + validate(expectedDens, expectedU, expectedV) { var sumDens = 0.0; var sumU = 0.0; @@ -124,14 +123,13 @@ class FluidField { sumU += u[i]; sumV += v[i]; } - + if (!approxEquals(sumDens, expectedDens) || !approxEquals(sumU, expectedU) || !approxEquals(sumV, expectedV)) { throw "Incorrect result"; } } - // Allocates a new FluidField or return previously allocated field if the // size is too large. @@ -143,16 +141,15 @@ class FluidField { _lastCreated = new FluidField(canvas, 64, 64, iterations); } assert((canvas == _lastCreated.canvas) && - (iterations == _lastCreated.iterations)); + (iterations == _lastCreated.iterations)); return _lastCreated; } - - FluidField(this.canvas, int hRes, int wRes, this.iterations) : - width = wRes, - height = hRes, - rowSize = (wRes + 2), - size = (wRes + 2) * (hRes + 2) { + FluidField(this.canvas, int hRes, int wRes, this.iterations) + : width = wRes, + height = hRes, + rowSize = (wRes + 2), + size = (wRes + 2) * (hRes + 2) { reset(); } @@ -167,15 +164,15 @@ class FluidField { } void addFields(Float64List x, Float64List s, double dt) { - for (var i=0; i< size ; i++) x[i] += dt*s[i]; + for (var i = 0; i < size; i++) x[i] += dt * s[i]; } void set_bnd(int b, Float64List x) { - if (b==1) { + if (b == 1) { var i = 1; for (; i <= width; i++) { - x[i] = x[i + rowSize]; - x[i + (height+1) *rowSize] = x[i + height * rowSize]; + x[i] = x[i + rowSize]; + x[i + (height + 1) * rowSize] = x[i + height * rowSize]; } for (var j = 1; j <= height; j++) { @@ -189,31 +186,31 @@ class FluidField { } for (var j = 1; j <= height; j++) { - x[j * rowSize] = x[1 + j * rowSize]; - x[(width + 1) + j * rowSize] = x[width + j * rowSize]; + x[j * rowSize] = x[1 + j * rowSize]; + x[(width + 1) + j * rowSize] = x[width + j * rowSize]; } } else { for (var i = 1; i <= width; i++) { - x[i] = x[i + rowSize]; + x[i] = x[i + rowSize]; x[i + (height + 1) * rowSize] = x[i + height * rowSize]; } for (var j = 1; j <= height; j++) { - x[j * rowSize] = x[1 + j * rowSize]; - x[(width + 1) + j * rowSize] = x[width + j * rowSize]; + x[j * rowSize] = x[1 + j * rowSize]; + x[(width + 1) + j * rowSize] = x[width + j * rowSize]; } } var maxEdge = (height + 1) * rowSize; - x[0] = 0.5 * (x[1] + x[rowSize]); - x[maxEdge] = 0.5 * (x[1 + maxEdge] + x[height * rowSize]); - x[(width+1)] = 0.5 * (x[width] + x[(width + 1) + rowSize]); - x[(width+1)+maxEdge] = 0.5 * (x[width + maxEdge] + x[(width + 1) + - height * rowSize]); + x[0] = 0.5 * (x[1] + x[rowSize]); + x[maxEdge] = 0.5 * (x[1 + maxEdge] + x[height * rowSize]); + x[(width + 1)] = 0.5 * (x[width] + x[(width + 1) + rowSize]); + x[(width + 1) + maxEdge] = + 0.5 * (x[width + maxEdge] + x[(width + 1) + height * rowSize]); } void lin_solve(int b, Float64List x, Float64List x0, int a, int c) { if (a == 0 && c == 1) { - for (var j=1 ; j<=height; j++) { + for (var j = 1; j <= height; j++) { var currentRow = j * rowSize; ++currentRow; for (var i = 0; i < width; i++) { @@ -224,16 +221,21 @@ class FluidField { set_bnd(b, x); } else { var invC = 1 / c; - for (var k=0 ; k Wp5) - x = Wp5; + else if (x > Wp5) x = Wp5; var i0 = x.toInt(); var i1 = i0 + 1; if (y < 0.5) y = 0.5; - else if (y > Hp5) - y = Hp5; + else if (y > Hp5) y = Hp5; var j0 = y.toInt(); var j1 = j0 + 1; var s1 = x - i0; @@ -324,70 +329,75 @@ class FluidField { set_bnd(b, d); } - void project(Float64List u, Float64List v, - Float64List p, Float64List div) { + void project(Float64List u, Float64List v, Float64List p, Float64List div) { var h = -0.5 / sqrt(width * height); - for (var j = 1 ; j <= height; j++ ) { + for (var j = 1; j <= height; j++) { var row = j * rowSize; var previousRow = (j - 1) * rowSize; var prevValue = row - 1; var currentRow = row; var nextValue = row + 1; var nextRow = (j + 1) * rowSize; - for (var i = 1; i <= width; i++ ) { - div[++currentRow] = h * (u[++nextValue] - u[++prevValue] + - v[++nextRow] - v[++previousRow]); + for (var i = 1; i <= width; i++) { + div[++currentRow] = h * + (u[++nextValue] - u[++prevValue] + v[++nextRow] - v[++previousRow]); p[currentRow] = 0.0; } } set_bnd(0, div); set_bnd(0, p); - lin_solve(0, p, div, 1, 4 ); + lin_solve(0, p, div, 1, 4); var wScale = 0.5 * width; var hScale = 0.5 * height; - for (var j = 1; j<= height; j++ ) { + for (var j = 1; j <= height; j++) { var prevPos = j * rowSize - 1; var currentPos = j * rowSize; var nextPos = j * rowSize + 1; var prevRow = (j - 1) * rowSize; - var currentRow = j * rowSize; var nextRow = (j + 1) * rowSize; - for (var i = 1; i<= width; i++) { + for (var i = 1; i <= width; i++) { u[++currentPos] -= wScale * (p[++nextPos] - p[++prevPos]); - v[currentPos] -= hScale * (p[++nextRow] - p[++prevRow]); + v[currentPos] -= hScale * (p[++nextRow] - p[++prevRow]); } } set_bnd(1, u); set_bnd(2, v); } - void dens_step(Float64List x, Float64List x0, - Float64List u, Float64List v, double dt) { + void dens_step( + Float64List x, Float64List x0, Float64List u, Float64List v, double dt) { addFields(x, x0, dt); - diffuse(0, x0, x, dt ); - advect(0, x, x0, u, v, dt ); + diffuse(0, x0, x, dt); + advect(0, x, x0, u, v, dt); } - void vel_step(Float64List u, Float64List v, - Float64List u0, Float64List v0, double dt) { - addFields(u, u0, dt ); - addFields(v, v0, dt ); - var temp = u0; u0 = u; u = temp; - temp = v0; v0 = v; v = temp; - diffuse2(u,u0,v,v0, dt); + void vel_step( + Float64List u, Float64List v, Float64List u0, Float64List v0, double dt) { + addFields(u, u0, dt); + addFields(v, v0, dt); + var temp = u0; + u0 = u; + u = temp; + temp = v0; + v0 = v; + v = temp; + diffuse2(u, u0, v, v0, dt); project(u, v, u0, v0); - temp = u0; u0 = u; u = temp; - temp = v0; v0 = v; v = temp; + temp = u0; + u0 = u; + u = temp; + temp = v0; + v0 = v; + v = temp; advect(1, u, u0, u0, v0, dt); advect(2, v, v0, u0, v0, dt); - project(u, v, u0, v0 ); + project(u, v, u0, v0); } var uiCallback; - void setDisplayFunction(func) { displayFunc = func; } @@ -424,7 +434,7 @@ class Field { } double getDensity(int x, int y) { - return dens[(x + 1) + (y + 1) * rowSize]; // rowSize from FluidField? + return dens[(x + 1) + (y + 1) * rowSize]; // rowSize from FluidField? } void setVelocity(int x, int y, double xv, double yv) { diff --git a/example/Richards.dart b/example/Richards.dart index 89af958..0659bac 100644 --- a/example/Richards.dart +++ b/example/Richards.dart @@ -36,17 +36,14 @@ import 'package:benchmark_harness/benchmark_harness.dart'; - main() { new Richards().report(); } - /** * Richards imulates the task dispatcher of an operating system. **/ class Richards extends BenchmarkBase { - const Richards() : super("Richards"); void run() { @@ -76,7 +73,7 @@ class Richards extends BenchmarkBase { if (scheduler.queueCount != EXPECTED_QUEUE_COUNT || scheduler.holdCount != EXPECTED_HOLD_COUNT) { print("Error during execution: queueCount = ${scheduler.queueCount}" - ", holdCount = ${scheduler.holdCount}."); + ", holdCount = ${scheduler.holdCount}."); } if (EXPECTED_QUEUE_COUNT != scheduler.queueCount) { throw "bad scheduler queue-count"; @@ -111,21 +108,19 @@ class Richards extends BenchmarkBase { static const int KIND_WORK = 1; } - /** * A scheduler can be used to schedule a set of tasks based on their relative * priorities. Scheduling is done by maintaining a list of task control blocks * which holds tasks and the data queue they are processing. */ class Scheduler { - int queueCount = 0; int holdCount = 0; TaskControlBlock currentTcb; int currentId; TaskControlBlock list; List blocks = - new List(Richards.NUMBER_OF_IDS); + new List(Richards.NUMBER_OF_IDS); /// Add an idle task to this scheduler. void addIdleTask(int id, int priority, Packet queue, int count) { @@ -134,10 +129,8 @@ class Scheduler { /// Add a work task to this scheduler. void addWorkerTask(int id, int priority, Packet queue) { - addTask(id, - priority, - queue, - new WorkerTask(this, Richards.ID_HANDLER_A, 0)); + addTask( + id, priority, queue, new WorkerTask(this, Richards.ID_HANDLER_A, 0)); } /// Add a handler task to this scheduler. @@ -221,15 +214,13 @@ class Scheduler { } } - /** * A task control block manages a task and the queue of work packages associated * with it. */ class TaskControlBlock { - TaskControlBlock link; - int id; // The id of this block. + int id; // The id of this block. int priority; // The priority of this block. Packet queue; // The queue of packages to be processed by the task. Task task; @@ -270,8 +261,7 @@ class TaskControlBlock { } bool isHeldOrSuspended() { - return (state & STATE_HELD) != 0 || - (state == STATE_SUSPENDED); + return (state & STATE_HELD) != 0 || (state == STATE_SUSPENDED); } void markAsSuspended() { @@ -318,7 +308,6 @@ class TaskControlBlock { * Abstract task that manipulates work packets. */ abstract class Task { - Scheduler scheduler; // The scheduler that manages this task. Task(this.scheduler); @@ -331,8 +320,7 @@ abstract class Task { * device tasks. */ class IdleTask extends Task { - - int v1; // A seed value that controls how the device tasks are scheduled. + int v1; // A seed value that controls how the device tasks are scheduled. int count; // The number of times this task should be scheduled. IdleTask(Scheduler scheduler, this.v1, this.count) : super(scheduler); @@ -351,13 +339,11 @@ class IdleTask extends Task { String toString() => "IdleTask"; } - /** * A task that suspends itself after each time it has been run to simulate * waiting for data from an external device. */ class DeviceTask extends Task { - Packet v1; DeviceTask(Scheduler scheduler) : super(scheduler); @@ -376,12 +362,10 @@ class DeviceTask extends Task { String toString() => "DeviceTask"; } - /** * A task that manipulates work packets. */ class WorkerTask extends Task { - int v1; // A seed used to specify how work packets are manipulated. int v2; // Another seed used to specify how work packets are manipulated. @@ -409,12 +393,10 @@ class WorkerTask extends Task { String toString() => "WorkerTask"; } - /** * A task that manipulates work packets and then suspends itself. */ class HandlerTask extends Task { - Packet v1; Packet v2; @@ -451,7 +433,6 @@ class HandlerTask extends Task { String toString() => "HandlerTask"; } - /** * A simple package of data that is manipulated by the tasks. The exact layout * of the payload data carried by a packet is not importaint, and neither is the @@ -460,10 +441,9 @@ class HandlerTask extends Task { * data and worklists. */ class Packet { - Packet link; // The tail of the linked list of packets. - int id; // An ID for this packet. - int kind; // The type of this packet. + int id; // An ID for this packet. + int kind; // The type of this packet. int a1 = 0; List a2 = new List(Richards.DATA_SIZE); diff --git a/example/Template.dart b/example/Template.dart index f6a62f1..b930809 100644 --- a/example/Template.dart +++ b/example/Template.dart @@ -12,14 +12,13 @@ class TemplateBenchmark extends BenchmarkBase { } // The benchmark code. - void run() { - } + void run() {} // Not measured setup code executed prior to the benchmark runs. - void setup() { } + void setup() {} // Not measures teardown code executed after the benchark runs. - void teardown() { } + void teardown() {} } main() { diff --git a/example/Tracer/dart/Tracer.dart b/example/Tracer/dart/Tracer.dart index 7a4f5f3..4c7bd14 100644 --- a/example/Tracer/dart/Tracer.dart +++ b/example/Tracer/dart/Tracer.dart @@ -7,6 +7,7 @@ library ray_trace; +import 'dart:html'; import 'dart:math'; import 'package:benchmark_harness/benchmark_harness.dart'; diff --git a/example/Tracer/dart/app.dart b/example/Tracer/dart/app.dart index f07f077..28c9cb5 100644 --- a/example/Tracer/dart/app.dart +++ b/example/Tracer/dart/app.dart @@ -15,15 +15,17 @@ part 'renderscene.dart'; var checkNumber; main() { - var button = query('#render'); - var canvas = query('#canvas'); - var time = query('#time'); + var button = querySelector('#render'); + var canvas = querySelector('#canvas') as CanvasElement; + var time = querySelector('#time'); button.onClick.listen((e) { - canvas.width = int.parse(query('#imageWidth').value); - canvas.height = int.parse(query('#imageHeight').value); + canvas.width = + int.parse((querySelector('#imageWidth') as InputElement).value); + canvas.height = + int.parse((querySelector('#imageHeight') as InputElement).value); var sw = new Stopwatch()..start(); renderScene(e); sw.stop(); time.text = sw.elapsedMilliseconds.toString(); }); -} \ No newline at end of file +} diff --git a/example/Tracer/dart/color.dart b/example/Tracer/dart/color.dart index d71b295..ca2a63e 100644 --- a/example/Tracer/dart/color.dart +++ b/example/Tracer/dart/color.dart @@ -15,17 +15,16 @@ class Color { void limit() { this.red = (this.red > 0.0) ? ((this.red > 1.0) ? 1.0 : this.red) : 0.0; - this.green = (this.green > 0.0) ? - ((this.green > 1.0) ? 1.0 : this.green) : 0.0; - this.blue = (this.blue > 0.0) ? - ((this.blue > 1.0) ? 1.0 : this.blue) : 0.0; + this.green = + (this.green > 0.0) ? ((this.green > 1.0) ? 1.0 : this.green) : 0.0; + this.blue = (this.blue > 0.0) ? ((this.blue > 1.0) ? 1.0 : this.blue) : 0.0; } Color operator +(Color c2) { return new Color(red + c2.red, green + c2.green, blue + c2.blue); } - Color addScalar(double s){ + Color addScalar(double s) { var result = new Color(red + s, green + s, blue + s); result.limit(); return result; diff --git a/example/Tracer/dart/engine.dart b/example/Tracer/dart/engine.dart index 9e53724..2696059 100644 --- a/example/Tracer/dart/engine.dart +++ b/example/Tracer/dart/engine.dart @@ -18,7 +18,6 @@ class IntersectionInfo { String toString() => 'Intersection [$position]'; } - class Engine { int canvasWidth; int canvasHeight; @@ -27,16 +26,21 @@ class Engine { int rayDepth; var canvas; - Engine({this.canvasWidth : 100, this.canvasHeight : 100, - this.pixelWidth : 2, this.pixelHeight : 2, - this.renderDiffuse : false, this.renderShadows : false, - this.renderHighlights : false, this.renderReflections : false, - this.rayDepth : 2}) { + Engine( + {this.canvasWidth: 100, + this.canvasHeight: 100, + this.pixelWidth: 2, + this.pixelHeight: 2, + this.renderDiffuse: false, + this.renderShadows: false, + this.renderHighlights: false, + this.renderReflections: false, + this.rayDepth: 2}) { canvasHeight = canvasHeight ~/ pixelHeight; canvasWidth = canvasWidth ~/ pixelWidth; } - void setPixel(int x, int y, Color color){ + void setPixel(int x, int y, Color color) { var pxW, pxH; pxW = this.pixelWidth; pxH = this.pixelHeight; @@ -60,8 +64,8 @@ class Engine { var canvasHeight = this.canvasHeight; var canvasWidth = this.canvasWidth; - for(var y = 0; y < canvasHeight; y++){ - for(var x = 0; x < canvasWidth; x++){ + for (var y = 0; y < canvasHeight; y++) { + for (var x = 0; x < canvasWidth; x++) { var yp = y * 1.0 / canvasHeight * 2 - 1; var xp = x * 1.0 / canvasWidth * 2 - 1; @@ -75,9 +79,9 @@ class Engine { } } - Color getPixelColor(Ray ray, Scene scene){ + Color getPixelColor(Ray ray, Scene scene) { var info = this.testIntersection(ray, scene, null); - if(info.isHit){ + if (info.isHit) { var color = this.rayTrace(info, ray, scene, 0); return color; } @@ -89,14 +93,14 @@ class Engine { IntersectionInfo best = new IntersectionInfo(); best.distance = 2000; - for(var i=0; i < scene.shapes.length; i++){ + for (var i = 0; i < scene.shapes.length; i++) { var shape = scene.shapes[i]; - if(shape != exclude){ + if (shape != exclude) { IntersectionInfo info = shape.intersect(ray); if (info.isHit && (info.distance >= 0) && - (info.distance < best.distance)){ + (info.distance < best.distance)) { best = info; hits++; } @@ -106,19 +110,18 @@ class Engine { return best; } - Ray getReflectionRay(Vector P, Vector N, Vector V){ + Ray getReflectionRay(Vector P, Vector N, Vector V) { var c1 = -N.dot(V); - var R1 = N.multiplyScalar(2*c1) + V; + var R1 = N.multiplyScalar(2 * c1) + V; return new Ray(P, R1); } Color rayTrace(IntersectionInfo info, Ray ray, Scene scene, int depth) { // Calc ambient Color color = info.color.multiplyScalar(scene.background.ambience); - var oldColor = color; var shininess = pow(10, info.shape.material.gloss + 1); - for(var i = 0; i < scene.lights.length; i++) { + for (var i = 0; i < scene.lights.length; i++) { var light = scene.lights[i]; // Calc diffuse lighting @@ -136,12 +139,11 @@ class Engine { if (depth <= this.rayDepth) { // calculate reflection ray if (this.renderReflections && info.shape.material.reflection > 0) { - var reflectionRay = this.getReflectionRay(info.position, - info.normal, - ray.direction); + var reflectionRay = + this.getReflectionRay(info.position, info.normal, ray.direction); var refl = this.testIntersection(reflectionRay, scene, info.shape); - if (refl.isHit && refl.distance > 0){ + if (refl.isHit && refl.distance > 0) { refl.color = this.rayTrace(refl, reflectionRay, scene, depth + 1); } else { refl.color = scene.background.color; @@ -160,8 +162,7 @@ class Engine { var shadowRay = new Ray(info.position, v); shadowInfo = this.testIntersection(shadowRay, scene, info.shape); - if (shadowInfo.isHit && - shadowInfo.shape != info.shape + if (shadowInfo.isHit && shadowInfo.shape != info.shape /*&& shadowInfo.shape.type != 'PLANE'*/) { var vA = color.multiplyScalar(0.5); var dB = (0.5 * pow(shadowInfo.shape.material.transparency, 0.5)); diff --git a/example/Tracer/dart/index.html b/example/Tracer/dart/index.html index 3d62186..dba6329 100644 --- a/example/Tracer/dart/index.html +++ b/example/Tracer/dart/index.html @@ -33,8 +33,6 @@
Time (ms):
- - - + diff --git a/example/Tracer/dart/materials.dart b/example/Tracer/dart/materials.dart index 51a43cd..e05df23 100644 --- a/example/Tracer/dart/materials.dart +++ b/example/Tracer/dart/materials.dart @@ -7,9 +7,9 @@ part of ray_trace; abstract class Materials { - final gloss; // [0...infinity] 0 = matt - final transparency; // 0=opaque - final reflection; // [0...infinity] 0 = no reflection + final gloss; // [0...infinity] 0 = matt + final transparency; // 0=opaque + final reflection; // [0...infinity] 0 = no reflection var refraction = 0.50; var hasTexture = false; @@ -19,22 +19,18 @@ abstract class Materials { wrapUp(t) { t = t % 2.0; - if(t < -1) t += 2.0; - if(t >= 1) t -= 2.0; + if (t < -1) t += 2.0; + if (t >= 1) t -= 2.0; return t; } } - class Chessboard extends Materials { var colorEven, colorOdd, density; - Chessboard(this.colorEven, - this.colorOdd, - reflection, - transparency, - gloss, - this.density) : super(reflection, transparency, gloss) { + Chessboard(this.colorEven, this.colorOdd, reflection, transparency, gloss, + this.density) + : super(reflection, transparency, gloss) { this.hasTexture = true; } @@ -49,7 +45,6 @@ class Chessboard extends Materials { } } - class Solid extends Materials { var color; diff --git a/example/Tracer/dart/readme.md b/example/Tracer/dart/readme.md new file mode 100644 index 0000000..dc3b17d --- /dev/null +++ b/example/Tracer/dart/readme.md @@ -0,0 +1,4 @@ +To run: + + 1) `pub run build_runner serve example` from the root + 2) Navigate to http://localhost:8080/Tracer/dart/ diff --git a/example/Tracer/dart/renderscene.dart b/example/Tracer/dart/renderscene.dart index 49324aa..e995741 100644 --- a/example/Tracer/dart/renderscene.dart +++ b/example/Tracer/dart/renderscene.dart @@ -14,66 +14,33 @@ class Light { Light(this.position, this.color, [this.intensity = 10.0]); } - // 'event' null means that we are benchmarking void renderScene(event) { var scene = new Scene(); scene.camera = new Camera(new Vector(0.0, 0.0, -15.0), - new Vector(-0.2, 0.0, 5.0), - new Vector(0.0, 1.0, 0.0)); + new Vector(-0.2, 0.0, 5.0), new Vector(0.0, 1.0, 0.0)); scene.background = new Background(new Color(0.5, 0.5, 0.5), 0.4); - var sphere = new Sphere( - new Vector(-1.5, 1.5, 2.0), - 1.5, - new Solid( - new Color(0.0, 0.5, 0.5), - 0.3, - 0.0, - 0.0, - 2.0 - ) - ); + var sphere = new Sphere(new Vector(-1.5, 1.5, 2.0), 1.5, + new Solid(new Color(0.0, 0.5, 0.5), 0.3, 0.0, 0.0, 2.0)); - var sphere1 = new Sphere( - new Vector(1.0, 0.25, 1.0), - 0.5, - new Solid( - new Color(0.9,0.9,0.9), - 0.1, - 0.0, - 0.0, - 1.5 - ) - ); + var sphere1 = new Sphere(new Vector(1.0, 0.25, 1.0), 0.5, + new Solid(new Color(0.9, 0.9, 0.9), 0.1, 0.0, 0.0, 1.5)); var plane = new Plane( new Vector(0.1, 0.9, -0.5).normalize(), 1.2, - new Chessboard( - new Color(1.0, 1.0, 1.0), - new Color(0.0, 0.0, 0.0), - 0.2, - 0.0, - 1.0, - 0.7 - ) - ); + new Chessboard(new Color(1.0, 1.0, 1.0), new Color(0.0, 0.0, 0.0), 0.2, + 0.0, 1.0, 0.7)); scene.shapes.add(plane); scene.shapes.add(sphere); scene.shapes.add(sphere1); - var light = new Light( - new Vector(5.0, 10.0, -1.0), - new Color(0.8, 0.8, 0.8) - ); + var light = new Light(new Vector(5.0, 10.0, -1.0), new Color(0.8, 0.8, 0.8)); - var light1 = new Light( - new Vector(-3.0, 5.0, -15.0), - new Color(0.8, 0.8, 0.8), - 100.0 - ); + var light1 = + new Light(new Vector(-3.0, 5.0, -15.0), new Color(0.8, 0.8, 0.8), 100.0); scene.lights.add(light); scene.lights.add(light1); @@ -91,27 +58,34 @@ void renderScene(event) { renderReflections = true; canvas = null; } else { - imageWidth = int.parse(query('#imageWidth').value); - imageHeight = int.parse(query('#imageHeight').value); - pixelSize = int.parse(query('#pixelSize').value.split(',')[0]); - renderDiffuse = query('#renderDiffuse').checked; - renderShadows = query('#renderShadows').checked; - renderHighlights = query('#renderHighlights').checked; - renderReflections = query('#renderReflections').checked; - canvas = query("#canvas"); + imageWidth = + int.parse((querySelector('#imageWidth') as InputElement).value); + imageHeight = + int.parse((querySelector('#imageHeight') as InputElement).value); + pixelSize = int.parse( + (querySelector('#pixelSize') as InputElement).value.split(',')[0]); + renderDiffuse = + (querySelector('#renderDiffuse') as CheckboxInputElement).checked; + renderShadows = + (querySelector('#renderShadows') as CheckboxInputElement).checked; + renderHighlights = + (querySelector('#renderHighlights') as CheckboxInputElement).checked; + renderReflections = + (querySelector('#renderReflections') as CheckboxInputElement).checked; + canvas = querySelector("#canvas"); } int rayDepth = 2; - var raytracer = new Engine(canvasWidth:imageWidth, - canvasHeight:imageHeight, - pixelWidth: pixelSize, - pixelHeight: pixelSize, - renderDiffuse: renderDiffuse, - renderShadows: renderShadows, - renderReflections: renderReflections, - renderHighlights: renderHighlights, - rayDepth: rayDepth - ); + var raytracer = new Engine( + canvasWidth: imageWidth, + canvasHeight: imageHeight, + pixelWidth: pixelSize, + pixelHeight: pixelSize, + renderDiffuse: renderDiffuse, + renderShadows: renderShadows, + renderReflections: renderReflections, + renderHighlights: renderHighlights, + rayDepth: rayDepth); raytracer.renderScene(scene, canvas); } diff --git a/example/Tracer/dart/scene.dart b/example/Tracer/dart/scene.dart index 4c9674f..499ec84 100644 --- a/example/Tracer/dart/scene.dart +++ b/example/Tracer/dart/scene.dart @@ -16,7 +16,6 @@ class Ray { } } - class Camera { final position; final lookAt; @@ -29,8 +28,8 @@ class Camera { } Ray getRay(double vx, double vy) { - var pos = screen - - (this.equator.multiplyScalar(vx) - this.up.multiplyScalar(vy)); + var pos = + screen - (this.equator.multiplyScalar(vx) - this.up.multiplyScalar(vy)); pos.y = pos.y * -1.0; var dir = pos - this.position; var ray = new Ray(pos, dir.normalize()); @@ -42,7 +41,6 @@ class Camera { } } - class Background { final Color color; final double ambience; @@ -50,16 +48,14 @@ class Background { Background(this.color, this.ambience); } - class Scene { var camera; var shapes; var lights; var background; Scene() { - camera = new Camera(new Vector(0.0, 0.0, -0.5), - new Vector(0.0, 0.0, 1.0), - new Vector(0.0, 1.0, 0.0)); + camera = new Camera(new Vector(0.0, 0.0, -0.5), new Vector(0.0, 0.0, 1.0), + new Vector(0.0, 1.0, 0.0)); shapes = new List(); lights = new List(); background = new Background(new Color(0.0, 0.0, 0.5), 0.2); diff --git a/example/Tracer/dart/shapes.dart b/example/Tracer/dart/shapes.dart index 9dc9923..254ece8 100644 --- a/example/Tracer/dart/shapes.dart +++ b/example/Tracer/dart/shapes.dart @@ -17,7 +17,6 @@ class BaseShape { } } - class Plane extends BaseShape { final d; @@ -38,14 +37,14 @@ class Plane extends BaseShape { info.normal = this.position; info.distance = t; - if(this.material.hasTexture){ + if (this.material.hasTexture) { var vU = new Vector(this.position.y, this.position.z, -this.position.x); var vV = vU.cross(this.position); var u = info.position.dot(vU); var v = info.position.dot(vV); - info.color = this.material.getColor(u,v); + info.color = this.material.getColor(u, v); } else { - info.color = this.material.getColor(0,0); + info.color = this.material.getColor(0, 0); } return info; @@ -56,12 +55,11 @@ class Plane extends BaseShape { } } - class Sphere extends BaseShape { var radius; - Sphere(pos, radius, material) : super(pos, material), this.radius = radius; + Sphere(pos, this.radius, material) : super(pos, material); - IntersectionInfo intersect(Ray ray){ + IntersectionInfo intersect(Ray ray) { var info = new IntersectionInfo(); info.shape = this; @@ -71,14 +69,15 @@ class Sphere extends BaseShape { var C = dst.dot(dst) - (this.radius * this.radius); var D = (B * B) - C; - if (D > 0) { // intersection! + if (D > 0) { + // intersection! info.isHit = true; info.distance = (-B) - sqrt(D); - info.position = ray.position + - ray.direction.multiplyScalar(info.distance); + info.position = + ray.position + ray.direction.multiplyScalar(info.distance); info.normal = (info.position - this.position).normalize(); - info.color = this.material.getColor(0,0); + info.color = this.material.getColor(0, 0); } else { info.isHit = false; } @@ -89,4 +88,3 @@ class Sphere extends BaseShape { return 'Sphere [position=$position, radius=$radius]'; } } - diff --git a/example/Tracer/dart/vector.dart b/example/Tracer/dart/vector.dart index ab3495b..4763fad 100644 --- a/example/Tracer/dart/vector.dart +++ b/example/Tracer/dart/vector.dart @@ -26,9 +26,8 @@ class Vector { } Vector cross(Vector w) { - return new Vector(-this.z * w.y + this.y * w.z, - this.z * w.x - this.x * w.z, - -this.y * w.x + this.x * w.y); + return new Vector(-this.z * w.y + this.y * w.z, this.z * w.x - this.x * w.z, + -this.y * w.x + this.x * w.y); } double dot(Vector w) { diff --git a/lib/src/benchmark_base.dart b/lib/src/benchmark_base.dart index c72b330..9273ebf 100644 --- a/lib/src/benchmark_base.dart +++ b/lib/src/benchmark_base.dart @@ -7,14 +7,13 @@ class BenchmarkBase { final ScoreEmitter emitter; // Empty constructor. - const BenchmarkBase(String name, - { ScoreEmitter emitter: const PrintEmitter() }) + const BenchmarkBase(String name, {ScoreEmitter emitter: const PrintEmitter()}) : this.name = name, this.emitter = emitter; // The benchmark code. // This function is not used, if both [warmup] and [exercise] are overwritten. - void run() { } + void run() {} // Runs a short version of the benchmark. By default invokes [run] once. void warmup() { @@ -29,10 +28,10 @@ class BenchmarkBase { } // Not measured setup code executed prior to the benchmark runs. - void setup() { } + void setup() {} // Not measures teardown code executed after the benchark runs. - void teardown() { } + void teardown() {} // Measures the score for this benchmark by executing it repeately until // time minimum has been reached. @@ -54,9 +53,13 @@ class BenchmarkBase { double measure() { setup(); // Warmup for at least 100ms. Discard result. - measureFor(() { this.warmup(); }, 100); + measureFor(() { + this.warmup(); + }, 100); // Run the benchmark for at least 2000ms. - double result = measureFor(() { this.exercise(); }, 2000); + double result = measureFor(() { + this.exercise(); + }, 2000); teardown(); return result; } @@ -64,5 +67,4 @@ class BenchmarkBase { void report() { emitter.emit(name, measure()); } - } diff --git a/pubspec.yaml b/pubspec.yaml index 600ef22..fab6326 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,13 +1,15 @@ name: benchmark_harness -version: 1.0.5-dev +version: 1.0.5 author: Dart Team description: The official Dart project benchmark harness. homepage: https://github.com/dart-lang/benchmark_harness -dependencies: - browser: '>=0.10.0+2 <0.11.0' + +environment: + sdk: ">=2.0.0-dev <3.0.0" + dev_dependencies: - hop: '>=0.30.3 <0.32.0' - hop_unittest: any - mock: '>=0.11.0 <0.12.0' - path: '>=1.1.0 <2.0.0' - unittest: '>=0.10.0 <0.12.0' + build_runner: ^0.9.0 + build_web_compilers: ^0.4.0 + mockito: ^3.0.0 + path: ^1.1.0 + test: ^1.0.0 diff --git a/test/benchmark_harness_test.dart b/test/benchmark_harness_test.dart index ae06e7a..c1b287f 100644 --- a/test/benchmark_harness_test.dart +++ b/test/benchmark_harness_test.dart @@ -5,7 +5,7 @@ library benchmark_harness_test; import 'package:benchmark_harness/benchmark_harness.dart'; -import 'package:unittest/unittest.dart'; +import 'package:test/test.dart'; void main() { group('benchmark_harness', () { diff --git a/test/drone.sh b/test/drone.sh deleted file mode 100755 index 2568f38..0000000 --- a/test/drone.sh +++ /dev/null @@ -1,8 +0,0 @@ -# get the packages -pub install - -# analyze the code -dart tool/hop_runner.dart analyze_all - -# run the tests -dart tool/hop_runner.dart test diff --git a/test/fixed-unittest.dart b/test/fixed-unittest.dart deleted file mode 100644 index 4f8951c..0000000 --- a/test/fixed-unittest.dart +++ /dev/null @@ -1,9 +0,0 @@ -library fixed_unittest; - -import 'package:unittest/unittest.dart'; - -export 'package:unittest/unittest.dart'; - -// Jasmine-like syntax for unittest. -void describe(String spec, TestFunction body) => group(spec, body); -void it(String spec, TestFunction body) => test(spec, body); diff --git a/test/result_emitter_test.dart b/test/result_emitter_test.dart index ef4b61a..82c45a7 100644 --- a/test/result_emitter_test.dart +++ b/test/result_emitter_test.dart @@ -1,38 +1,26 @@ library result_emitter_test; import 'package:benchmark_harness/benchmark_harness.dart'; -import 'package:mock/mock.dart'; +import 'package:mockito/mockito.dart'; -import 'fixed-unittest.dart'; +import 'package:test/test.dart'; void main() { benchmarkHarnessTest(); } -class MockResultEmitter extends Mock implements ScoreEmitter { - var hasEmitted = false; - - MockResultEmitter() { - when(callsTo('emit')).alwaysCall(fakeEmit); - } - - void fakeEmit(String name, double value) { - hasEmitted = true; - } - - // Added to quiet an analyzer warning. - noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); -} +class MockResultEmitter extends Mock implements ScoreEmitter {} // Create a new benchmark which has an emitter. class BenchmarkWithResultEmitter extends BenchmarkBase { - const BenchmarkWithResultEmitter(ScoreEmitter emitter) : super("Template", emitter: emitter); + const BenchmarkWithResultEmitter(ScoreEmitter emitter) + : super("Template", emitter: emitter); - void run() { } + void run() {} - void setup() { } + void setup() {} - void teardown() { } + void teardown() {} } benchmarkHarnessTest() { @@ -41,12 +29,13 @@ benchmarkHarnessTest() { return emitter; } - describe('ResultEmitter', () { - it('should be called when emitter is provided', () { + group('ResultEmitter', () { + test('should be called when emitter is provided', () { MockResultEmitter emitter = createMockEmitter(); var testBenchmark = new BenchmarkWithResultEmitter(emitter); testBenchmark.report(); - emitter.getLogs(callsTo('emit')).verify(happenedOnce); + + verify(emitter.emit(any, any)).called(1); }); }); } diff --git a/tool/hop_runner.dart b/tool/hop_runner.dart deleted file mode 100755 index 30df07a..0000000 --- a/tool/hop_runner.dart +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env dart -library hop_runner; - -import 'dart:async'; -import 'dart:io'; - -import 'package:hop/hop.dart'; -import 'package:hop/hop_tasks.dart'; -import 'package:hop_unittest/hop_unittest.dart'; - -import 'package:path/path.dart' as path; - -import '../test/benchmark_harness_test.dart' as benchmark_harness_test; -import '../test/result_emitter_test.dart' as result_emitter_test; - -void main(List args) { - addTask('analyze_libs', createAnalyzerTask(_getDartFiles('lib'))); - addTask('analyze_examples', createAnalyzerTask(_getDartFiles('example'))); - addTask('analyze_tests', createAnalyzerTask(_getDartFiles('test'))); - - addChainedTask('analyze_all', - ['analyze_libs', 'analyze_examples', 'analyze_tests']); - - addTask('test', createUnitTestTask((){ - benchmark_harness_test.main(); - result_emitter_test.main(); - })); - - runHop(args); -} - -Future> _getDartFiles(String directory) => - new Directory(directory) - .list() - .where((FileSystemEntity fse) => fse is File) - .map((File file) => file.path) - .where((String filePath) => path.extension(filePath) == '.dart') - .toList();