OLD | NEW |
1 typedef void Test(); | 1 typedef void Test(); |
2 typedef void Operation(); | 2 typedef void Operation(); |
3 typedef void Reporter(Map<String, Result> results); | 3 typedef void Reporter(Map<String, Result> results); |
4 | 4 |
5 class Suite { | 5 class Suite { |
6 /** | 6 /** |
7 * Ctor. | 7 * Ctor. |
8 * [:_window:] The window of the suite. | 8 * [:_window:] The window of the suite. |
9 * [:_name:] The name of the suite. | 9 * [:_name:] The name of the suite. |
10 */ | 10 */ |
(...skipping 26 matching lines...) Expand all Loading... |
37 } | 37 } |
38 | 38 |
39 // How many times each individual test should be ran. | 39 // How many times each individual test should be ran. |
40 static final int _N_RUNS = 5; | 40 static final int _N_RUNS = 5; |
41 | 41 |
42 /** | 42 /** |
43 * Adds another test to the suite. | 43 * Adds another test to the suite. |
44 * [:name:] The unique name of the test | 44 * [:name:] The unique name of the test |
45 * [:test:] A function holding the test to run | 45 * [:test:] A function holding the test to run |
46 */ | 46 */ |
47 Suite test(String name, Test test) { | 47 Suite test(String name, Test test_) { |
48 _nTests++; | 48 _nTests++; |
49 // Don't execute the test immediately. | 49 // Don't execute the test immediately. |
50 return _addOperation(() { | 50 return _addOperation(() { |
51 // List of number of runs in seconds. | 51 // List of number of runs in seconds. |
52 List<double> runsPerSecond = new List<double>(); | 52 List<double> runsPerSecond = new List<double>(); |
53 | 53 |
54 // Run the test several times. | 54 // Run the test several times. |
55 try { | 55 try { |
56 // TODO(antonm): use .setTimeout to schedule next run as JS | 56 // TODO(antonm): use .setTimeout to schedule next run as JS |
57 // version does. That allows to report the intermidiate results | 57 // version does. That allows to report the intermidiate results |
58 // more smoothly as well. | 58 // more smoothly as well. |
59 for (int i = 0; i < _N_RUNS; i++) { | 59 for (int i = 0; i < _N_RUNS; i++) { |
60 int runs = 0; | 60 int runs = 0; |
61 final int start = new Date.now().value; | 61 final int start = new Date.now().value; |
62 | 62 |
63 int cur = new Date.now().value; | 63 int cur = new Date.now().value; |
64 while ((cur - start) < 1000) { | 64 while ((cur - start) < 1000) { |
65 test(); | 65 test_(); |
66 cur = new Date.now().value; | 66 cur = new Date.now().value; |
67 runs++; | 67 runs++; |
68 } | 68 } |
69 | 69 |
70 runsPerSecond.add((runs * 1000.0) / (cur - start)); | 70 runsPerSecond.add((runs * 1000.0) / (cur - start)); |
71 } | 71 } |
72 } catch(var exception, var stacktrace) { | 72 } catch(var exception, var stacktrace) { |
73 _window.alert('Exception ${exception}: ${stacktrace}'); | 73 _window.alert('Exception ${exception}: ${stacktrace}'); |
74 return; | 74 return; |
75 } | 75 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 | 126 |
127 List<Operation> _operations; | 127 List<Operation> _operations; |
128 int _nTests; | 128 int _nTests; |
129 int _nRanTests; | 129 int _nRanTests; |
130 | 130 |
131 Suite _addOperation(Operation operation) { | 131 Suite _addOperation(Operation operation) { |
132 _operations.add(operation); | 132 _operations.add(operation); |
133 return this; | 133 return this; |
134 } | 134 } |
135 } | 135 } |
OLD | NEW |