Fix latest pedantic lints – and a few more (#47)
diff --git a/.travis.yml b/.travis.yml
index 50ef28c..55deef0 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,7 +2,7 @@
dart:
- dev
- - 2.0.0
+ - 2.1.0
dart_task:
- test
diff --git a/analysis_options.yaml b/analysis_options.yaml
index d76cc45..9f8005b 100644
--- a/analysis_options.yaml
+++ b/analysis_options.yaml
@@ -1,11 +1,11 @@
include: package:pedantic/analysis_options.yaml
-#analyzer:
-# strong-mode:
-# implicit-casts: false
+
+analyzer:
+ strong-mode:
+ implicit-casts: false
+
linter:
rules:
- #- always_declare_return_types
- #- annotate_overrides
- avoid_empty_else
- avoid_function_literals_in_foreach_calls
- avoid_init_to_null
@@ -53,14 +53,13 @@
- prefer_contains
- prefer_equal_for_default_values
- prefer_generic_function_type_aliases
- #- prefer_final_fields
+ - prefer_final_fields
#- prefer_final_locals
- prefer_initializing_formals
- prefer_interpolation_to_compose_strings
- prefer_is_empty
- prefer_is_not_empty
- #- prefer_single_quotes
- #- prefer_typing_uninitialized_variables
+ - prefer_typing_uninitialized_variables
- recursive_getters
- slash_for_doc_comments
- test_types_in_equals
@@ -76,7 +75,6 @@
- unnecessary_null_aware_assignments
- unnecessary_parenthesis
- unnecessary_statements
- #- unnecessary_this
- unrelated_type_equality_checks
- use_function_type_syntax_for_parameters
- use_rethrow_when_possible
diff --git a/changelog.md b/changelog.md
index 75f765c..d5f5088 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,3 +1,7 @@
-### 1.0.5
+## 1.0.6
-* Updates to support Dart 2.
+- Require at least Dart 2.1.
+
+## 1.0.5
+
+- Updates to support Dart 2.
diff --git a/example/DeltaBlue.dart b/example/DeltaBlue.dart
index 3732925..c676748 100644
--- a/example/DeltaBlue.dart
+++ b/example/DeltaBlue.dart
@@ -46,14 +46,15 @@
/// I've kept it this way to avoid deviating too much from the original
/// implementation.
-main() {
+void main() {
const DeltaBlue().report();
}
/// Benchmark class required to report results.
class DeltaBlue extends BenchmarkBase {
- const DeltaBlue() : super("DeltaBlue");
+ const DeltaBlue() : super('DeltaBlue');
+ @override
void run() {
chainTest(100);
projectionTest(100);
@@ -97,13 +98,13 @@
}
// Compile time computed constants.
-const REQUIRED = Strength(0, "required");
-const STRONG_REFERRED = Strength(1, "strongPreferred");
-const PREFERRED = Strength(2, "preferred");
-const STRONG_DEFAULT = Strength(3, "strongDefault");
-const NORMAL = Strength(4, "normal");
-const WEAK_DEFAULT = Strength(5, "weakDefault");
-const WEAKEST = Strength(6, "weakest");
+const REQUIRED = Strength(0, 'required');
+const STRONG_REFERRED = Strength(1, 'strongPreferred');
+const PREFERRED = Strength(2, 'preferred');
+const STRONG_DEFAULT = Strength(3, 'strongDefault');
+const NORMAL = Strength(4, 'normal');
+const WEAK_DEFAULT = Strength(5, 'weakDefault');
+const WEAKEST = Strength(6, 'weakest');
abstract class Constraint {
final Strength strength;
@@ -145,16 +146,16 @@
chooseMethod(mark);
if (!isSatisfied()) {
if (strength == REQUIRED) {
- print("Could not satisfy a required constraint!");
+ print('Could not satisfy a required constraint!');
}
return null;
}
markInputs(mark);
- Variable out = output();
- Constraint overridden = out.determinedBy;
+ var out = output();
+ var overridden = out.determinedBy;
if (overridden != null) overridden.markUnsatisfied();
out.determinedBy = this;
- if (!planner.addPropagate(this, mark)) print("Cycle encountered");
+ if (!planner.addPropagate(this, mark)) print('Cycle encountered');
out.mark = mark;
return overridden;
}
@@ -180,30 +181,36 @@
}
/// Adds this constraint to the constraint graph
+ @override
void addToGraph() {
myOutput.addConstraint(this);
satisfied = false;
}
/// Decides if this constraint can be satisfied and records that decision.
+ @override
void chooseMethod(int mark) {
satisfied = (myOutput.mark != mark) &&
Strength.stronger(strength, myOutput.walkStrength);
}
/// Returns true if this constraint is satisfied in the current solution.
+ @override
bool isSatisfied() => satisfied;
+ @override
void markInputs(int mark) {
// has no inputs.
}
/// Returns the current output variable.
+ @override
Variable output() => myOutput;
/// Calculate the walkabout strength, the stay flag, and, if it is
/// 'stay', the value for the current output of this constraint. Assume
/// this constraint is satisfied.
+ @override
void recalculate() {
myOutput.walkStrength = strength;
myOutput.stay = !isInput();
@@ -211,12 +218,15 @@
}
/// Records that this constraint is unsatisfied.
+ @override
void markUnsatisfied() {
satisfied = false;
}
+ @override
bool inputsKnown(int mark) => true;
+ @override
void removeFromGraph() {
if (myOutput != null) myOutput.removeConstraint(this);
satisfied = false;
@@ -230,6 +240,7 @@
class StayConstraint extends UnaryConstraint {
StayConstraint(Variable v, Strength str) : super(v, str);
+ @override
void execute() {
// Stay constraints do nothing.
}
@@ -241,8 +252,10 @@
EditConstraint(Variable v, Strength str) : super(v, str);
/// Edits indicate that a variable is to be changed by imperative code.
+ @override
bool isInput() => true;
+ @override
void execute() {
// Edit constraints do nothing.
}
@@ -267,6 +280,7 @@
/// Decides if this constraint can be satisfied and which way it
/// should flow based on the relative strength of the variables related,
/// and record that decision.
+ @override
void chooseMethod(int mark) {
if (v1.mark == mark) {
direction =
@@ -290,6 +304,7 @@
}
/// Add this constraint to the constraint graph.
+ @override
void addToGraph() {
v1.addConstraint(this);
v2.addConstraint(this);
@@ -297,9 +312,11 @@
}
/// Answer true if this constraint is satisfied in the current solution.
+ @override
bool isSatisfied() => direction != NONE;
/// Mark the input variable with the given mark.
+ @override
void markInputs(int mark) {
input().mark = mark;
}
@@ -308,28 +325,33 @@
Variable input() => direction == FORWARD ? v1 : v2;
/// Returns the current output variable.
+ @override
Variable output() => direction == FORWARD ? v2 : v1;
/// Calculate the walkabout strength, the stay flag, and, if it is
/// 'stay', the value for the current output of this
/// constraint. Assume this constraint is satisfied.
+ @override
void recalculate() {
- Variable ihn = input(), out = output();
+ var ihn = input(), out = output();
out.walkStrength = Strength.weakest(strength, ihn.walkStrength);
out.stay = ihn.stay;
if (out.stay) execute();
}
/// Record the fact that this constraint is unsatisfied.
+ @override
void markUnsatisfied() {
direction = NONE;
}
+ @override
bool inputsKnown(int mark) {
- Variable i = input();
+ var i = input();
return i.mark == mark || i.stay || i.determinedBy == null;
}
+ @override
void removeFromGraph() {
if (v1 != null) v1.removeConstraint(this);
if (v2 != null) v2.removeConstraint(this);
@@ -351,24 +373,28 @@
: super(src, dest, strength);
/// Adds this constraint to the constraint graph.
+ @override
void addToGraph() {
super.addToGraph();
scale.addConstraint(this);
offset.addConstraint(this);
}
+ @override
void removeFromGraph() {
super.removeFromGraph();
if (scale != null) scale.removeConstraint(this);
if (offset != null) offset.removeConstraint(this);
}
+ @override
void markInputs(int mark) {
super.markInputs(mark);
scale.mark = offset.mark = mark;
}
/// Enforce this constraint. Assume that it is satisfied.
+ @override
void execute() {
if (direction == FORWARD) {
v2.value = v1.value * scale.value + offset.value;
@@ -380,8 +406,9 @@
/// Calculate the walkabout strength, the stay flag, and, if it is
/// 'stay', the value for the current output of this constraint. Assume
/// this constraint is satisfied.
+ @override
void recalculate() {
- Variable ihn = input(), out = output();
+ var ihn = input(), out = output();
out.walkStrength = Strength.weakest(strength, ihn.walkStrength);
out.stay = ihn.stay && scale.stay && offset.stay;
if (out.stay) execute();
@@ -394,6 +421,7 @@
: super(v1, v2, strength);
/// Enforce this constraint. Assume that it is satisfied.
+ @override
void execute() {
output().value = input().value;
}
@@ -443,8 +471,8 @@
/// the algorithm to avoid getting into an infinite loop even if the
/// constraint graph has an inadvertent cycle.
void incrementalAdd(Constraint c) {
- int mark = newMark();
- for (Constraint overridden = c.satisfy(mark);
+ var mark = newMark();
+ for (var overridden = c.satisfy(mark);
overridden != null;
overridden = overridden.satisfy(mark)) {
// NOOP
@@ -461,14 +489,14 @@
/// unnecessarily adding and then overriding weak constraints.
/// Assume: [c] is satisfied.
void incrementalRemove(Constraint c) {
- Variable out = c.output();
+ var out = c.output();
c.markUnsatisfied();
c.removeFromGraph();
- List<Constraint> unsatisfied = removePropagateFrom(out);
- Strength strength = REQUIRED;
+ var unsatisfied = removePropagateFrom(out);
+ var strength = REQUIRED;
do {
- for (int i = 0; i < unsatisfied.length; i++) {
- Constraint u = unsatisfied[i];
+ for (var i = 0; i < unsatisfied.length; i++) {
+ var u = unsatisfied[i];
if (u.strength == strength) incrementalAdd(u);
}
strength = strength.nextWeaker();
@@ -496,11 +524,11 @@
/// any constraint.
/// Assume: [sources] are all satisfied.
Plan makePlan(List<Constraint> sources) {
- int mark = newMark();
- Plan plan = Plan();
- List<Constraint> todo = sources;
+ var mark = newMark();
+ var plan = Plan();
+ var todo = sources;
while (todo.isNotEmpty) {
- Constraint c = todo.removeLast();
+ var c = todo.removeLast();
if (c.output().mark != mark && c.inputsKnown(mark)) {
plan.addConstraint(c);
c.output().mark = mark;
@@ -513,9 +541,9 @@
/// Extract a plan for resatisfying starting from the output of the
/// given [constraints], usually a set of input constraints.
Plan extractPlanFromConstraints(List<Constraint> constraints) {
- List<Constraint> sources = <Constraint>[];
- for (int i = 0; i < constraints.length; i++) {
- Constraint c = constraints[i];
+ var sources = <Constraint>[];
+ for (var i = 0; i < constraints.length; i++) {
+ var c = constraints[i];
// if not in plan already and eligible for inclusion.
if (c.isInput() && c.isSatisfied()) sources.add(c);
}
@@ -534,9 +562,9 @@
/// the output constraint means that there is a path from the
/// constraint's output to one of its inputs.
bool addPropagate(Constraint c, int mark) {
- List<Constraint> todo = <Constraint>[c];
+ var todo = <Constraint>[c];
while (todo.isNotEmpty) {
- Constraint d = todo.removeLast();
+ var d = todo.removeLast();
if (d.output().mark == mark) {
incrementalRemove(c);
return false;
@@ -554,17 +582,17 @@
out.determinedBy = null;
out.walkStrength = WEAKEST;
out.stay = true;
- List<Constraint> unsatisfied = <Constraint>[];
- List<Variable> todo = <Variable>[out];
+ var unsatisfied = <Constraint>[];
+ var todo = <Variable>[out];
while (todo.isNotEmpty) {
- Variable v = todo.removeLast();
- for (int i = 0; i < v.constraints.length; i++) {
- Constraint c = v.constraints[i];
+ var v = todo.removeLast();
+ for (var i = 0; i < v.constraints.length; i++) {
+ var c = v.constraints[i];
if (!c.isSatisfied()) unsatisfied.add(c);
}
- Constraint determining = v.determinedBy;
- for (int i = 0; i < v.constraints.length; i++) {
- Constraint next = v.constraints[i];
+ var determining = v.determinedBy;
+ for (var i = 0; i < v.constraints.length; i++) {
+ var next = v.constraints[i];
if (next != determining && next.isSatisfied()) {
next.recalculate();
todo.add(next.output());
@@ -575,9 +603,9 @@
}
void addConstraintsConsumingTo(Variable v, List<Constraint> coll) {
- Constraint determining = v.determinedBy;
- for (int i = 0; i < v.constraints.length; i++) {
- Constraint c = v.constraints[i];
+ var determining = v.determinedBy;
+ for (var i = 0; i < v.constraints.length; i++) {
+ var c = v.constraints[i];
if (c != determining && c.isSatisfied()) coll.add(c);
}
}
@@ -596,7 +624,7 @@
int size() => list.length;
void execute() {
- for (int i = 0; i < list.length; i++) {
+ for (var i = 0; i < list.length; i++) {
list[i].execute();
}
}
@@ -617,21 +645,21 @@
planner = Planner();
Variable prev, first, last;
// Build chain of n equality constraints.
- for (int i = 0; i <= n; i++) {
- Variable v = Variable("v", 0);
+ for (var i = 0; i <= n; i++) {
+ var v = Variable('v', 0);
if (prev != null) EqualityConstraint(prev, v, REQUIRED);
if (i == 0) first = v;
if (i == n) last = v;
prev = v;
}
StayConstraint(last, STRONG_DEFAULT);
- EditConstraint edit = EditConstraint(first, PREFERRED);
- Plan plan = planner.extractPlanFromConstraints(<Constraint>[edit]);
- for (int i = 0; i < 100; i++) {
+ var edit = EditConstraint(first, PREFERRED);
+ var plan = planner.extractPlanFromConstraints(<Constraint>[edit]);
+ for (var i = 0; i < 100; i++) {
first.value = i;
plan.execute();
if (last.value != i) {
- print("Chain test failed.\n{last.value)\n{i}");
+ print('Chain test failed.\n{last.value)\n{i}');
}
}
}
@@ -642,36 +670,36 @@
/// mapping and to change the scale and offset factors.
void projectionTest(int n) {
planner = Planner();
- Variable scale = Variable("scale", 10);
- Variable offset = Variable("offset", 1000);
+ var scale = Variable('scale', 10);
+ var offset = Variable('offset', 1000);
Variable src, dst;
- List<Variable> dests = <Variable>[];
- for (int i = 0; i < n; i++) {
- src = Variable("src", i);
- dst = Variable("dst", i);
+ var dests = <Variable>[];
+ for (var i = 0; i < n; i++) {
+ src = Variable('src', i);
+ dst = Variable('dst', i);
dests.add(dst);
StayConstraint(src, NORMAL);
ScaleConstraint(src, scale, offset, dst, REQUIRED);
}
change(src, 17);
- if (dst.value != 1170) print("Projection 1 failed");
+ if (dst.value != 1170) print('Projection 1 failed');
change(dst, 1050);
- if (src.value != 5) print("Projection 2 failed");
+ if (src.value != 5) print('Projection 2 failed');
change(scale, 5);
- for (int i = 0; i < n - 1; i++) {
- if (dests[i].value != i * 5 + 1000) print("Projection 3 failed");
+ for (var i = 0; i < n - 1; i++) {
+ if (dests[i].value != i * 5 + 1000) print('Projection 3 failed');
}
change(offset, 2000);
- for (int i = 0; i < n - 1; i++) {
- if (dests[i].value != i * 5 + 2000) print("Projection 4 failed");
+ for (var i = 0; i < n - 1; i++) {
+ if (dests[i].value != i * 5 + 2000) print('Projection 4 failed');
}
}
void change(Variable v, int newValue) {
- EditConstraint edit = EditConstraint(v, PREFERRED);
- Plan plan = planner.extractPlanFromConstraints(<EditConstraint>[edit]);
- for (int i = 0; i < 10; i++) {
+ var edit = EditConstraint(v, PREFERRED);
+ var plan = planner.extractPlanFromConstraints(<EditConstraint>[edit]);
+ for (var i = 0; i < 10; i++) {
v.value = newValue;
plan.execute();
}
diff --git a/example/FluidMotion/dart/FluidMotion.dart b/example/FluidMotion/dart/FluidMotion.dart
index d638035..1031b42 100644
--- a/example/FluidMotion/dart/FluidMotion.dart
+++ b/example/FluidMotion/dart/FluidMotion.dart
@@ -1,9 +1,11 @@
+import 'dart:html';
+
/// Copyright 2013 the V8 project authors. All rights reserved.
/// Copyright 2009 Oliver Hunt <http://nerget.com>
///
/// Permission is hereby granted, free of charge, to any person
/// obtaining a copy of this software and associated documentation
-/// files (the "Software"), to deal in the Software without
+/// files (the 'Software'), to deal in the Software without
/// restriction, including without limitation the rights to use,
/// copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the
@@ -13,7 +15,7 @@
/// The above copyright notice and this permission notice shall be
/// included in all copies or substantial portions of the Software.
///
-/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+/// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
/// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
/// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
/// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
@@ -34,7 +36,7 @@
///
/// Permission is hereby granted, free of charge, to any person
/// obtaining a copy of this software and associated documentation
-/// files (the "Software"), to deal in the Software without
+/// files (the 'Software'), to deal in the Software without
/// restriction, including without limitation the rights to use,
/// copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the
@@ -44,7 +46,7 @@
/// The above copyright notice and this permission notice shall be
/// included in all copies or substantial portions of the Software.
///
-/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+/// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
/// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
/// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
/// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
@@ -59,7 +61,7 @@
///
/// Permission is hereby granted, free of charge, to any person
/// obtaining a copy of this software and associated documentation
-/// files (the "Software"), to deal in the Software without
+/// files (the 'Software'), to deal in the Software without
/// restriction, including without limitation the rights to use,
/// copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the
@@ -69,7 +71,7 @@
/// The above copyright notice and this permission notice shall be
/// included in all copies or substantial portions of the Software.
///
-/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+/// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
/// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
/// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
/// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
@@ -80,7 +82,7 @@
// Ported from the v8 benchmark suite by Google 2013.
// Uses Float64List for data.
-main() {
+void main() {
const FluidMotion().report();
}
@@ -101,7 +103,7 @@
static void runFluidMotion() {
setupFluidMotion();
- for (int i = 0; i < 10; i++) {
+ for (var i = 0; i < 10; i++) {
solver.update();
}
solver.validate(758.9012130174812, -352.56376676179076, -357.3690235879736);
@@ -135,10 +137,12 @@
// Overrides of BenchmarkBase.
+ @override
void warmup() {
runFluidMotion();
}
+ @override
void exercise() {
runFluidMotion();
}
@@ -147,7 +151,7 @@
// Code from Oliver Hunt (http://nerget.com/fluidSim/pressure.js) starts here.
class FluidField {
- final canvas;
+ final CanvasElement canvas;
final int iterations;
final double dt = 0.1;
final int size;
@@ -156,17 +160,17 @@
Float64List v, v_prev;
final int width, height;
final int rowSize;
- var displayFunc;
+ void Function(Field) displayFunc;
static FluidField _lastCreated;
static bool approxEquals(double a, double b) => (a - b).abs() < 0.000001;
- validate(expectedDens, expectedU, expectedV) {
+ void validate(double expectedDens, double expectedU, double expectedV) {
var sumDens = 0.0;
var sumU = 0.0;
var sumV = 0.0;
- for (int i = 0; i < dens.length; i++) {
+ for (var i = 0; i < dens.length; i++) {
sumDens += dens[i];
sumU += u[i];
sumV += v[i];
@@ -175,13 +179,14 @@
if (!approxEquals(sumDens, expectedDens) ||
!approxEquals(sumU, expectedU) ||
!approxEquals(sumV, expectedV)) {
- throw "Incorrect result";
+ throw 'Incorrect result';
}
}
// Allocates a new FluidField or return previously allocated field if the
// size is too large.
- factory FluidField.create(canvas, int hRes, int wRes, int iterations) {
+ factory FluidField.create(
+ CanvasElement canvas, int hRes, int wRes, int iterations) {
final res = wRes * hRes;
if ((res > 0) && (res < 1000000)) {
_lastCreated = FluidField(canvas, hRes, wRes, iterations);
@@ -223,13 +228,13 @@
}
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] = -1 * x[width + j * rowSize];
}
} else if (b == 2) {
for (var i = 1; i <= width; i++) {
- x[i] = -x[i + rowSize];
- x[i + (height + 1) * rowSize] = -x[i + height * rowSize];
+ x[i] = -1 * x[i + rowSize];
+ x[i + (height + 1) * rowSize] = -1 * x[i + height * rowSize];
}
for (var j = 1; j <= height; j++) {
@@ -338,7 +343,8 @@
}
}
- void diffuse2(Float64List x, Float64List x0, y, Float64List y0, double dt) {
+ void diffuse2(
+ Float64List x, Float64List x0, Float64List y, Float64List y0, double dt) {
var a = 0;
lin_solve2(x, x0, y, y0, a, 1 + 4 * a);
}
@@ -444,13 +450,13 @@
project(u, v, u0, v0);
}
- var uiCallback;
+ void Function(Field) uiCallback;
- void setDisplayFunction(func) {
+ void setDisplayFunction(void Function(Field) func) {
displayFunc = func;
}
- void setUICallback(callback) {
+ void setUICallback(void Function(Field) callback) {
uiCallback = callback;
}
diff --git a/example/Richards.dart b/example/Richards.dart
index 3cbae66..79487a6 100644
--- a/example/Richards.dart
+++ b/example/Richards.dart
@@ -14,7 +14,7 @@
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
@@ -36,19 +36,20 @@
import 'package:benchmark_harness/benchmark_harness.dart';
-main() {
+void main() {
const Richards().report();
}
/// Richards imulates the task dispatcher of an operating system.
class Richards extends BenchmarkBase {
- const Richards() : super("Richards");
+ const Richards() : super('Richards');
+ @override
void run() {
- Scheduler scheduler = Scheduler();
+ var scheduler = Scheduler();
scheduler.addIdleTask(ID_IDLE, 0, null, COUNT);
- Packet queue = Packet(null, ID_WORKER, KIND_WORK);
+ var queue = Packet(null, ID_WORKER, KIND_WORK);
queue = Packet(queue, ID_WORKER, KIND_WORK);
scheduler.addWorkerTask(ID_WORKER, 1000, queue);
@@ -70,14 +71,14 @@
if (scheduler.queueCount != EXPECTED_QUEUE_COUNT ||
scheduler.holdCount != EXPECTED_HOLD_COUNT) {
- print("Error during execution: queueCount = ${scheduler.queueCount}"
- ", holdCount = ${scheduler.holdCount}.");
+ print('Error during execution: queueCount = ${scheduler.queueCount}'
+ ', holdCount = ${scheduler.holdCount}.');
}
if (EXPECTED_QUEUE_COUNT != scheduler.queueCount) {
- throw "bad scheduler queue-count";
+ throw 'bad scheduler queue-count';
}
if (EXPECTED_HOLD_COUNT != scheduler.holdCount) {
- throw "bad scheduler hold-count";
+ throw 'bad scheduler hold-count';
}
}
@@ -164,7 +165,7 @@
/// Release a task that is currently blocked and return the next block to run.
TaskControlBlock release(int id) {
- TaskControlBlock tcb = blocks[id];
+ var tcb = blocks[id];
if (tcb == null) return tcb;
tcb.markAsNotHeld();
if (tcb.priority > currentTcb.priority) return tcb;
@@ -192,7 +193,7 @@
/// associated with the packet and make the task runnable if it is currently
/// suspended.
TaskControlBlock queue(Packet packet) {
- TaskControlBlock t = blocks[packet.id];
+ var t = blocks[packet.id];
if (t == null) return t;
queueCount++;
packet.link = null;
@@ -282,7 +283,8 @@
return task;
}
- String toString() => "tcb { $task@$state }";
+ @override
+ String toString() => 'tcb { $task@$state }';
}
/// Abstract task that manipulates work packets.
@@ -302,6 +304,7 @@
IdleTask(Scheduler scheduler, this.v1, this.count) : super(scheduler);
+ @override
TaskControlBlock run(Packet packet) {
count--;
if (count == 0) return scheduler.holdCurrent();
@@ -313,7 +316,8 @@
return scheduler.release(Richards.ID_DEVICE_B);
}
- String toString() => "IdleTask";
+ @override
+ String toString() => 'IdleTask';
}
/// A task that suspends itself after each time it has been run to simulate
@@ -323,10 +327,11 @@
DeviceTask(Scheduler scheduler) : super(scheduler);
+ @override
TaskControlBlock run(Packet packet) {
if (packet == null) {
if (v1 == null) return scheduler.suspendCurrent();
- Packet v = v1;
+ var v = v1;
v1 = null;
return scheduler.queue(v);
}
@@ -334,7 +339,8 @@
return scheduler.holdCurrent();
}
- String toString() => "DeviceTask";
+ @override
+ String toString() => 'DeviceTask';
}
/// A task that manipulates work packets.
@@ -344,6 +350,7 @@
WorkerTask(Scheduler scheduler, this.v1, this.v2) : super(scheduler);
+ @override
TaskControlBlock run(Packet packet) {
if (packet == null) {
return scheduler.suspendCurrent();
@@ -355,7 +362,7 @@
}
packet.id = v1;
packet.a1 = 0;
- for (int i = 0; i < Richards.DATA_SIZE; i++) {
+ for (var i = 0; i < Richards.DATA_SIZE; i++) {
v2++;
if (v2 > 26) v2 = 1;
packet.a2[i] = v2;
@@ -363,7 +370,8 @@
return scheduler.queue(packet);
}
- String toString() => "WorkerTask";
+ @override
+ String toString() => 'WorkerTask';
}
/// A task that manipulates work packets and then suspends itself.
@@ -373,6 +381,7 @@
HandlerTask(Scheduler scheduler) : super(scheduler);
+ @override
TaskControlBlock run(Packet packet) {
if (packet != null) {
if (packet.kind == Richards.KIND_WORK) {
@@ -382,7 +391,7 @@
}
}
if (v1 != null) {
- int count = v1.a1;
+ var count = v1.a1;
Packet v;
if (count < Richards.DATA_SIZE) {
if (v2 != null) {
@@ -401,7 +410,8 @@
return scheduler.suspendCurrent();
}
- String toString() => "HandlerTask";
+ @override
+ String toString() => 'HandlerTask';
}
/// A simple package of data that is manipulated by the tasks. The exact layout
@@ -431,5 +441,6 @@
return queue;
}
- String toString() => "Packet";
+ @override
+ String toString() => 'Packet';
}
diff --git a/example/Template.dart b/example/Template.dart
index 2d9d0de..3f569b4 100644
--- a/example/Template.dart
+++ b/example/Template.dart
@@ -5,23 +5,26 @@
// Create a new benchmark by extending BenchmarkBase
class TemplateBenchmark extends BenchmarkBase {
- const TemplateBenchmark() : super("Template");
+ const TemplateBenchmark() : super('Template');
static void main() {
const TemplateBenchmark().report();
}
// The benchmark code.
+ @override
void run() {}
// Not measured setup code executed prior to the benchmark runs.
+ @override
void setup() {}
// Not measures teardown code executed after the benchark runs.
+ @override
void teardown() {}
}
-main() {
+void main() {
// Run TemplateBenchmark
TemplateBenchmark.main();
}
diff --git a/example/Tracer/dart/Tracer.dart b/example/Tracer/dart/Tracer.dart
index d4dc31c..fa4a308 100644
--- a/example/Tracer/dart/Tracer.dart
+++ b/example/Tracer/dart/Tracer.dart
@@ -20,21 +20,19 @@
part 'vector.dart';
part 'renderscene.dart';
-// Dummy HTML definition.
-
-query(a) {}
-
// Variable used to hold a number that can be used to verify that
// the scene was ray traced correctly.
-var checkNumber;
+int checkNumber;
class TracerBenchmark extends BenchmarkBase {
- const TracerBenchmark() : super("Tracer");
+ const TracerBenchmark() : super('Tracer');
+ @override
void warmup() {
renderScene(null);
}
+ @override
void exercise() {
renderScene(null);
}
diff --git a/example/Tracer/dart/app.dart b/example/Tracer/dart/app.dart
index add8b30..08d5ca3 100644
--- a/example/Tracer/dart/app.dart
+++ b/example/Tracer/dart/app.dart
@@ -12,9 +12,9 @@
part 'renderscene.dart';
// used to check if raytrace was correct (used by benchmarks)
-var checkNumber;
+int checkNumber;
-main() {
+void main() {
var button = querySelector('#render');
var canvas = querySelector('#canvas') as CanvasElement;
var time = querySelector('#time');
diff --git a/example/Tracer/dart/color.dart b/example/Tracer/dart/color.dart
index 72253e8..ecf8e10 100644
--- a/example/Tracer/dart/color.dart
+++ b/example/Tracer/dart/color.dart
@@ -14,10 +14,9 @@
Color(this.red, this.green, this.blue);
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;
+ red = (red > 0.0) ? ((red > 1.0) ? 1.0 : red) : 0.0;
+ green = (green > 0.0) ? ((green > 1.0) ? 1.0 : green) : 0.0;
+ blue = (blue > 0.0) ? ((blue > 1.0) ? 1.0 : blue) : 0.0;
}
Color operator +(Color c2) {
@@ -41,21 +40,22 @@
}
Color blend(Color c2, double w) {
- var result = this.multiplyScalar(1.0 - w) + c2.multiplyScalar(w);
+ var result = multiplyScalar(1.0 - w) + c2.multiplyScalar(w);
return result;
}
int brightness() {
- var r = (this.red * 255).toInt();
- var g = (this.green * 255).toInt();
- var b = (this.blue * 255).toInt();
+ var r = (red * 255).toInt();
+ var g = (green * 255).toInt();
+ var b = (blue * 255).toInt();
return (r * 77 + g * 150 + b * 29) >> 8;
}
+ @override
String toString() {
- var r = (this.red * 255).toInt();
- var g = (this.green * 255).toInt();
- var b = (this.blue * 255).toInt();
+ var r = (red * 255).toInt();
+ var g = (green * 255).toInt();
+ var b = (blue * 255).toInt();
return 'rgb($r,$g,$b)';
}
diff --git a/example/Tracer/dart/engine.dart b/example/Tracer/dart/engine.dart
index ab2998f..5d710e8 100644
--- a/example/Tracer/dart/engine.dart
+++ b/example/Tracer/dart/engine.dart
@@ -9,12 +9,17 @@
class IntersectionInfo {
bool isHit = false;
int hitCount = 0;
- var shape, position, normal, color, distance;
+ BaseShape shape;
+ Vector position;
+ Vector normal;
+ Color color;
+ double distance;
IntersectionInfo() {
- this.color = Color(0.0, 0.0, 0.0);
+ color = Color(0.0, 0.0, 0.0);
}
+ @override
String toString() => 'Intersection [$position]';
}
@@ -24,10 +29,10 @@
int pixelWidth, pixelHeight;
bool renderDiffuse, renderShadows, renderHighlights, renderReflections;
int rayDepth;
- var canvas;
+ CanvasRenderingContext2D canvas;
Engine(
- {this.canvasWidth = 100,
+ {canvasWidth = 100,
this.canvasHeight = 100,
this.pixelWidth = 2,
this.pixelHeight = 2,
@@ -41,13 +46,13 @@
}
void setPixel(int x, int y, Color color) {
- var pxW, pxH;
- pxW = this.pixelWidth;
- pxH = this.pixelHeight;
+ int pxW, pxH;
+ pxW = pixelWidth;
+ pxH = pixelHeight;
- if (this.canvas != null) {
- this.canvas.fillStyle = color.toString();
- this.canvas.fillRect(x * pxW, y * pxH, pxW, pxH);
+ if (canvas != null) {
+ canvas.fillStyle = color.toString();
+ canvas.fillRect(x * pxW, y * pxH, pxW, pxH);
} else {
if (x == y) {
checkNumber += color.brightness();
@@ -56,10 +61,10 @@
}
// 'canvas' can be null if raytracer runs as benchmark
- void renderScene(Scene scene, canvas) {
+ void renderScene(Scene scene, CanvasElement canvas) {
checkNumber = 0;
/* Get canvas */
- this.canvas = canvas == null ? null : canvas.getContext("2d");
+ this.canvas = canvas?.context2D;
var canvasHeight = this.canvasHeight;
var canvasWidth = this.canvasWidth;
@@ -70,34 +75,34 @@
var xp = x * 1.0 / canvasWidth * 2 - 1;
var ray = scene.camera.getRay(xp, yp);
- this.setPixel(x, y, this.getPixelColor(ray, scene));
+ setPixel(x, y, getPixelColor(ray, scene));
}
}
if ((canvas == null) && (checkNumber != 2321)) {
// Used for benchmarking.
- throw "Scene rendered incorrectly";
+ throw 'Scene rendered incorrectly';
}
}
Color getPixelColor(Ray ray, Scene scene) {
- var info = this.testIntersection(ray, scene, null);
+ var info = testIntersection(ray, scene, null);
if (info.isHit) {
- var color = this.rayTrace(info, ray, scene, 0);
+ var color = rayTrace(info, ray, scene, 0);
return color;
}
return scene.background.color;
}
IntersectionInfo testIntersection(Ray ray, Scene scene, BaseShape exclude) {
- int hits = 0;
- IntersectionInfo best = IntersectionInfo();
+ var hits = 0;
+ var best = IntersectionInfo();
best.distance = 2000;
for (var i = 0; i < scene.shapes.length; i++) {
var shape = scene.shapes[i];
if (shape != exclude) {
- IntersectionInfo info = shape.intersect(ray);
+ var info = shape.intersect(ray);
if (info.isHit &&
(info.distance >= 0) &&
(info.distance < best.distance)) {
@@ -118,7 +123,7 @@
Color rayTrace(IntersectionInfo info, Ray ray, Scene scene, int depth) {
// Calc ambient
- Color color = info.color.multiplyScalar(scene.background.ambience);
+ var color = info.color.multiplyScalar(scene.background.ambience);
var shininess = pow(10, info.shape.material.gloss + 1);
for (var i = 0; i < scene.lights.length; i++) {
@@ -127,7 +132,7 @@
// Calc diffuse lighting
var v = (light.position - info.position).normalize();
- if (this.renderDiffuse) {
+ if (renderDiffuse) {
var L = v.dot(info.normal);
if (L > 0.0) {
color = color + info.color * light.color.multiplyScalar(L);
@@ -136,15 +141,15 @@
// The greater the depth the more accurate the colours, but
// this is exponentially (!) expensive
- if (depth <= this.rayDepth) {
+ if (depth <= rayDepth) {
// calculate reflection ray
- if (this.renderReflections && info.shape.material.reflection > 0) {
+ if (renderReflections && info.shape.material.reflection > 0) {
var reflectionRay =
- this.getReflectionRay(info.position, info.normal, ray.direction);
- var refl = this.testIntersection(reflectionRay, scene, info.shape);
+ getReflectionRay(info.position, info.normal, ray.direction);
+ var refl = testIntersection(reflectionRay, scene, info.shape);
if (refl.isHit && refl.distance > 0) {
- refl.color = this.rayTrace(refl, reflectionRay, scene, depth + 1);
+ refl.color = rayTrace(refl, reflectionRay, scene, depth + 1);
} else {
refl.color = scene.background.color;
}
@@ -156,12 +161,12 @@
}
/* Render shadows and highlights */
- IntersectionInfo shadowInfo = IntersectionInfo();
+ var shadowInfo = IntersectionInfo();
- if (this.renderShadows) {
+ if (renderShadows) {
var shadowRay = Ray(info.position, v);
- shadowInfo = this.testIntersection(shadowRay, scene, info.shape);
+ shadowInfo = testIntersection(shadowRay, scene, info.shape);
if (shadowInfo.isHit && shadowInfo.shape != info.shape
/*&& shadowInfo.shape.type != 'PLANE'*/) {
var vA = color.multiplyScalar(0.5);
@@ -170,7 +175,7 @@
}
}
// Phong specular highlights
- if (this.renderHighlights &&
+ if (renderHighlights &&
!shadowInfo.isHit &&
(info.shape.material.gloss > 0)) {
var Lv = (info.shape.position - light.position).normalize();
@@ -179,7 +184,7 @@
var H = (E - Lv).normalize();
- var glossWeight = pow(max(info.normal.dot(H), 0), shininess);
+ var glossWeight = pow(max(info.normal.dot(H), 0), shininess).toDouble();
color = light.color.multiplyScalar(glossWeight) + color;
}
}
@@ -187,6 +192,7 @@
return color;
}
+ @override
String toString() {
return 'Engine [canvasWidth: $canvasWidth, canvasHeight: $canvasHeight]';
}
diff --git a/example/Tracer/dart/materials.dart b/example/Tracer/dart/materials.dart
index e05df23..e12aeb3 100644
--- a/example/Tracer/dart/materials.dart
+++ b/example/Tracer/dart/materials.dart
@@ -7,17 +7,17 @@
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 double gloss; // [0...infinity] 0 = matt
+ final double transparency; // 0=opaque
+ final double reflection; // [0...infinity] 0 = no reflection
var refraction = 0.50;
var hasTexture = false;
Materials(this.reflection, this.transparency, this.gloss);
- Color getColor(num u, num v);
+ Color getColor(double u, double v);
- wrapUp(t) {
+ double wrapUp(double t) {
t = t % 2.0;
if (t < -1) t += 2.0;
if (t >= 1) t -= 2.0;
@@ -26,35 +26,37 @@
}
class Chessboard extends Materials {
- var colorEven, colorOdd, density;
+ Color colorEven, colorOdd;
+ double density;
- Chessboard(this.colorEven, this.colorOdd, reflection, transparency, gloss,
- this.density)
+ Chessboard(this.colorEven, this.colorOdd, double reflection,
+ double transparency, double gloss, this.density)
: super(reflection, transparency, gloss) {
- this.hasTexture = true;
+ hasTexture = true;
}
- Color getColor(num u, num v) {
- var t = this.wrapUp(u * this.density) * this.wrapUp(v * this.density);
+ @override
+ Color getColor(double u, double v) {
+ var t = wrapUp(u * density) * wrapUp(v * density);
if (t < 0.0) {
- return this.colorEven;
+ return colorEven;
} else {
- return this.colorOdd;
+ return colorOdd;
}
}
}
class Solid extends Materials {
- var color;
+ Color color;
- Solid(this.color, reflection, refraction, transparency, gloss)
+ Solid(this.color, double reflection, double refraction, double transparency,
+ double gloss)
: super(reflection, transparency, gloss) {
- this.hasTexture = false;
+ hasTexture = false;
this.refraction = refraction;
}
- Color getColor(num u, num v) {
- return this.color;
- }
+ @override
+ Color getColor(num u, num v) => color;
}
diff --git a/example/Tracer/dart/renderscene.dart b/example/Tracer/dart/renderscene.dart
index c2860f1..5e87f41 100644
--- a/example/Tracer/dart/renderscene.dart
+++ b/example/Tracer/dart/renderscene.dart
@@ -7,9 +7,9 @@
part of ray_trace;
class Light {
- final position;
- final color;
- final intensity;
+ final Vector position;
+ final Color color;
+ final double intensity;
Light(this.position, this.color, [this.intensity = 10.0]);
}
@@ -46,7 +46,7 @@
int imageWidth, imageHeight, pixelSize;
bool renderDiffuse, renderShadows, renderHighlights, renderReflections;
- var canvas;
+ CanvasElement canvas;
if (event == null) {
imageWidth = 100;
imageHeight = 100;
@@ -71,9 +71,9 @@
(querySelector('#renderHighlights') as CheckboxInputElement).checked;
renderReflections =
(querySelector('#renderReflections') as CheckboxInputElement).checked;
- canvas = querySelector("#canvas");
+ canvas = querySelector('#canvas') as CanvasElement;
}
- int rayDepth = 2;
+ var rayDepth = 2;
var raytracer = Engine(
canvasWidth: imageWidth,
diff --git a/example/Tracer/dart/scene.dart b/example/Tracer/dart/scene.dart
index 92bbe88..3de2f09 100644
--- a/example/Tracer/dart/scene.dart
+++ b/example/Tracer/dart/scene.dart
@@ -7,36 +7,38 @@
part of ray_trace;
class Ray {
- final position;
- final direction;
+ final Vector position;
+ final Vector direction;
Ray(this.position, this.direction);
+
+ @override
String toString() {
return 'Ray [$position, $direction]';
}
}
class Camera {
- final position;
- final lookAt;
- final up;
- var equator, screen;
+ final Vector position;
+ final Vector lookAt;
+ final Vector up;
+ Vector equator, screen;
Camera(this.position, this.lookAt, this.up) {
- this.equator = lookAt.normalize().cross(this.up);
- this.screen = this.position + this.lookAt;
+ equator = lookAt.normalize().cross(up);
+ screen = position + lookAt;
}
Ray getRay(double vx, double vy) {
- var pos =
- screen - (this.equator.multiplyScalar(vx) - this.up.multiplyScalar(vy));
+ var pos = screen - (equator.multiplyScalar(vx) - up.multiplyScalar(vy));
pos.y = pos.y * -1.0;
- var dir = pos - this.position;
+ var dir = pos - position;
var ray = Ray(pos, dir.normalize());
return ray;
}
- toString() {
+ @override
+ String toString() {
return 'Camera []';
}
}
@@ -49,10 +51,11 @@
}
class Scene {
- var camera;
- var shapes;
- var lights;
- var background;
+ Camera camera;
+ List<BaseShape> shapes;
+ List<Light> lights;
+ Background background;
+
Scene() {
camera = Camera(
Vector(0.0, 0.0, -0.5), Vector(0.0, 0.0, 1.0), Vector(0.0, 1.0, 0.0));
diff --git a/example/Tracer/dart/shapes.dart b/example/Tracer/dart/shapes.dart
index 6685b65..6fb33d4 100644
--- a/example/Tracer/dart/shapes.dart
+++ b/example/Tracer/dart/shapes.dart
@@ -6,67 +6,74 @@
// Ported from the v8 benchmark suite by Google 2012.
part of ray_trace;
-class BaseShape {
- final position;
- final material;
+abstract class BaseShape {
+ final Vector position;
+ final Materials material;
BaseShape(this.position, this.material);
+ IntersectionInfo intersect(Ray ray);
+
+ @override
String toString() {
return 'BaseShape';
}
}
class Plane extends BaseShape {
- final d;
+ final double d;
- Plane(pos, this.d, material) : super(pos, material);
+ Plane(Vector pos, this.d, Materials material) : super(pos, material);
+ @override
IntersectionInfo intersect(Ray ray) {
var info = IntersectionInfo();
- var Vd = this.position.dot(ray.direction);
+ var Vd = position.dot(ray.direction);
if (Vd == 0) return info; // no intersection
- var t = -(this.position.dot(ray.position) + this.d) / Vd;
+ var t = -(position.dot(ray.position) + d) / Vd;
if (t <= 0) return info;
info.shape = this;
info.isHit = true;
info.position = ray.position + ray.direction.multiplyScalar(t);
- info.normal = this.position;
+ info.normal = position;
info.distance = t;
- if (this.material.hasTexture) {
- var vU = Vector(this.position.y, this.position.z, -this.position.x);
- var vV = vU.cross(this.position);
+ if (material.hasTexture) {
+ var vU = Vector(position.y, position.z, -position.x);
+ var vV = vU.cross(position);
var u = info.position.dot(vU);
var v = info.position.dot(vV);
- info.color = this.material.getColor(u, v);
+ info.color = material.getColor(u, v);
} else {
- info.color = this.material.getColor(0, 0);
+ info.color = material.getColor(0, 0);
}
return info;
}
+ @override
String toString() {
return 'Plane [$position, d=$d]';
}
}
class Sphere extends BaseShape {
- var radius;
- Sphere(pos, this.radius, material) : super(pos, material);
+ double radius;
+ Sphere(Vector pos, this.radius, Materials material) : super(pos, material);
+
+ @override
IntersectionInfo intersect(Ray ray) {
var info = IntersectionInfo();
info.shape = this;
- var dst = ray.position - this.position;
+ var dst = ray.position - position;
var B = dst.dot(ray.direction);
- var C = dst.dot(dst) - (this.radius * this.radius);
+ var C = dst.dot(dst) - (radius * radius);
var D = (B * B) - C;
if (D > 0) {
@@ -75,15 +82,16 @@
info.distance = (-B) - sqrt(D);
info.position =
ray.position + ray.direction.multiplyScalar(info.distance);
- info.normal = (info.position - this.position).normalize();
+ info.normal = (info.position - position).normalize();
- info.color = this.material.getColor(0, 0);
+ info.color = material.getColor(0, 0);
} else {
info.isHit = false;
}
return info;
}
+ @override
String toString() {
return 'Sphere [position=$position, radius=$radius]';
}
diff --git a/example/Tracer/dart/vector.dart b/example/Tracer/dart/vector.dart
index 27c1639..1694922 100644
--- a/example/Tracer/dart/vector.dart
+++ b/example/Tracer/dart/vector.dart
@@ -11,27 +11,26 @@
Vector(this.x, this.y, this.z);
void copy(Vector v) {
- this.x = v.x;
- this.y = v.y;
- this.z = v.z;
+ x = v.x;
+ y = v.y;
+ z = v.z;
}
Vector normalize() {
- var m = this.magnitude();
- return Vector(this.x / m, this.y / m, this.z / m);
+ var m = magnitude();
+ return Vector(x / m, y / m, z / m);
}
double magnitude() {
- return sqrt((this.x * this.x) + (this.y * this.y) + (this.z * this.z));
+ return sqrt((x * x) + (y * y) + (z * z));
}
Vector cross(Vector w) {
- return 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 Vector(-z * w.y + y * w.z, z * w.x - x * w.z, -y * w.x + x * w.y);
}
double dot(Vector w) {
- return this.x * w.x + this.y * w.y + this.z * w.z;
+ return x * w.x + y * w.y + z * w.z;
}
Vector operator +(Vector w) {
@@ -50,6 +49,7 @@
return Vector(x * w, y * w, z * w);
}
+ @override
String toString() {
return 'Vector [$x, $y ,$z ]';
}
diff --git a/lib/src/benchmark_base.dart b/lib/src/benchmark_base.dart
index 7410a2c..b47167d 100644
--- a/lib/src/benchmark_base.dart
+++ b/lib/src/benchmark_base.dart
@@ -20,7 +20,7 @@
// Exercices the benchmark. By default invokes [run] 10 times.
void exercise() {
- for (int i = 0; i < 10; i++) {
+ for (var i = 0; i < 10; i++) {
run();
}
}
@@ -34,11 +34,11 @@
// Measures the score for this benchmark by executing it repeately until
// time minimum has been reached.
static double measureFor(Function f, int minimumMillis) {
- int minimumMicros = minimumMillis * 1000;
- int iter = 0;
- Stopwatch watch = Stopwatch();
+ var minimumMicros = minimumMillis * 1000;
+ var iter = 0;
+ var watch = Stopwatch();
watch.start();
- int elapsed = 0;
+ var elapsed = 0;
while (elapsed < minimumMicros) {
f();
elapsed = watch.elapsedMicroseconds;
@@ -53,7 +53,7 @@
// Warmup for at least 100ms. Discard result.
measureFor(warmup, 100);
// Run the benchmark for at least 2000ms.
- double result = measureFor(exercise, 2000);
+ var result = measureFor(exercise, 2000);
teardown();
return result;
}
diff --git a/lib/src/score_emitter.dart b/lib/src/score_emitter.dart
index 47f26bd..0e807d7 100644
--- a/lib/src/score_emitter.dart
+++ b/lib/src/score_emitter.dart
@@ -7,7 +7,8 @@
class PrintEmitter implements ScoreEmitter {
const PrintEmitter();
+ @override
void emit(String testName, double value) {
- print("$testName(RunTime): $value us.");
+ print('$testName(RunTime): $value us.');
}
}
diff --git a/pubspec.yaml b/pubspec.yaml
index 56364a1..271c025 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -5,7 +5,7 @@
homepage: https://github.com/dart-lang/benchmark_harness
environment:
- sdk: ">=2.0.0 <3.0.0"
+ sdk: ">=2.1.0 <3.0.0"
dev_dependencies:
build_runner: ^1.1.0
diff --git a/test/benchmark_harness_test.dart b/test/benchmark_harness_test.dart
index bcb225d..836d812 100644
--- a/test/benchmark_harness_test.dart
+++ b/test/benchmark_harness_test.dart
@@ -10,8 +10,8 @@
void main() {
group('benchmark_harness', () {
test('run is called', () {
- MockBenchmark benchmark = MockBenchmark();
- double micros = benchmark.measure();
+ var benchmark = MockBenchmark();
+ var micros = benchmark.measure();
expect(micros, isPositive);
expect(benchmark.runCount, isPositive);
});
@@ -23,6 +23,7 @@
MockBenchmark() : super('mock benchmark');
+ @override
void run() {
runCount++;
}
diff --git a/test/result_emitter_test.dart b/test/result_emitter_test.dart
index f145c1a..0205163 100644
--- a/test/result_emitter_test.dart
+++ b/test/result_emitter_test.dart
@@ -14,24 +14,27 @@
// Create a new benchmark which has an emitter.
class BenchmarkWithResultEmitter extends BenchmarkBase {
const BenchmarkWithResultEmitter(ScoreEmitter emitter)
- : super("Template", emitter: emitter);
+ : super('Template', emitter: emitter);
+ @override
void run() {}
+ @override
void setup() {}
+ @override
void teardown() {}
}
-benchmarkHarnessTest() {
+void benchmarkHarnessTest() {
MockResultEmitter createMockEmitter() {
- MockResultEmitter emitter = MockResultEmitter();
+ var emitter = MockResultEmitter();
return emitter;
}
group('ResultEmitter', () {
test('should be called when emitter is provided', () {
- MockResultEmitter emitter = createMockEmitter();
+ var emitter = createMockEmitter();
var testBenchmark = BenchmarkWithResultEmitter(emitter);
testBenchmark.report();