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

Side by Side Diff: packages/charted/test.disabled/scale/linear_scale_test.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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 /*
2 * Copyright 2014 Google Inc. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style
5 * license that can be found in the LICENSE file or at
6 * https://developers.google.com/open-source/licenses/bsd
7 */
8
9 part of charted.test.scale;
10
11 testLinearScale() {
12 group('LinearScale', () {
13 test('applies a bilinearScale when domain length is 2', () {
14 LinearScale linear = new LinearScale([1, 2], [5, 8]);
15 expect(linear.apply(0), equals(2));
16 expect(linear.apply(1), equals(5));
17 expect(linear.apply(1.5), equals(6.5));
18 expect(linear.apply(2), equals(8));
19 expect(linear.invert(5), equals(1));
20 expect(linear.invert(6.5), equals(1.5));
21 expect(linear.invert(8), equals(2));
22 });
23 test('applies a polylinearScale when domain length is larger than 2', () {
24 LinearScale linear = new LinearScale([1, 2, 3], [5, 8, 7]);
25 expect(linear.apply(1), equals(5));
26 expect(linear.apply(1.5), equals(6.5));
27 expect(linear.apply(2), equals(8));
28 expect(linear.apply(2.5), equals(7.5));
29 expect(linear.apply(3), equals(7));
30 });
31 });
32
33 test('LinearScale supports setting clamp to clamp range', () {
34 LinearScale linear = new LinearScale([1, 2], [5, 8],
35 interpolateNumber, true);
36 expect(linear.apply(0), equals(5));
37 expect(linear.apply(1), equals(5));
38 expect(linear.apply(1.5), equals(6.5));
39 expect(linear.apply(2), equals(8));
40 expect(linear.apply(5), equals(8));
41 });
42
43 test('LinearScale.rangeRound sets the interpolator to interpolateRound', () {
44 LinearScale linear = new LinearScale([1, 2]);
45 linear.rangeRound([5, 8]);
46 expect(linear.apply(1), equals(5));
47 expect(linear.apply(1.5), equals(7));
48 expect(linear.apply(2), equals(8));
49 });
50
51 test('LinearScale.ticks sets tick number and returns tick values', () {
52 LinearScale linear = new LinearScale([0, 10], [1, 100]);
53 expect(linear.ticks(2), orderedEquals([0, 5, 10]));
54 expect(linear.ticks(3), orderedEquals([0, 5, 10]));
55 expect(linear.ticks(4), orderedEquals([0, 2, 4, 6, 8, 10]));
56 expect(linear.ticks(5), orderedEquals([0, 2, 4, 6, 8, 10]));
57 expect(linear.ticks(6), orderedEquals([0, 2, 4, 6, 8, 10]));
58 expect(linear.ticks(7), orderedEquals([0, 2, 4, 6, 8, 10]));
59 expect(linear.ticks(8), orderedEquals([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));
60 expect(linear.ticks(9), orderedEquals([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));
61 expect(linear.ticks(10), orderedEquals([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));
62 });
63
64 test('LinearScale.tickFormat formats tick values by specified formatter', () {
65 // Default formatter
66 LinearScale linear = new LinearScale([0, 1], [1, 100]);
67 expect(linear.ticks(2).map((d) => linear.createTickFormatter(2)(d)),
68 orderedEquals(['0.0', '0.5', '1.0']));
69 expect(linear.ticks(5).map((d) => linear.createTickFormatter(5)(d)),
70 orderedEquals(['0.0', '0.2', '0.4', '0.6', '0.8', '1.0']));
71 expect(linear.ticks(10).map((d) => linear.createTickFormatter(10)(d)),
72 orderedEquals(['0.0', '0.1', '0.2', '0.3', '0.4', '0.5',
73 '0.6', '0.7', '0.8', '0.9', '1.0' ]));
74 // Specified formatter
75 expect(linear.ticks(2).map((d) => linear.createTickFormatter(2, '+%')(d)),
76 orderedEquals(['+0%', '+50%', '+100%']));
77 expect(linear.ticks(5).map((d) => linear.createTickFormatter(5, '+%')(d)),
78 orderedEquals(['+0%', '+20%', '+40%', '+60%', '+80%', '+100%']));
79 expect(linear.ticks(10).map((d) => linear.createTickFormatter(10, '+%')(d)),
80 orderedEquals(['+0%', '+10%', '+20%', '+30%', '+40%', '+50%',
81 '+60%', '+70%', '+80%', '+90%', '+100%']));
82 });
83
84 test('LinearScale.nice extends the domain to nice round values', () {
85 LinearScale linear = new LinearScale([0.5, 10.6], [1, 100]);
86 linear.nice(10);
87 expect(linear.domain, orderedEquals([0, 11]));
88 linear.domain = [0.5, 10.6];
89 linear.nice(4);
90 expect(linear.domain, orderedEquals([0, 12]));
91 });
92 }
OLDNEW
« no previous file with comments | « packages/charted/test.disabled/locale/time_format_test.dart ('k') | packages/charted/test.disabled/scale/log_scale_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698