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

Side by Side Diff: packages/charted/test.disabled/scale/scale_util_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 testScaleUtil() {
12 group('ScaleUtil::nice()', () {
13 Nice nice = new Nice((num x) => x.ceil(), (num x) => x.floor());
14 test('extends domain extent to nice values '
15 'when domain[0] <= domain[last]', () {
16 expect(ScaleUtil.nice([0, 5], nice), orderedEquals([0, 5]));
17 expect(ScaleUtil.nice([0.5, 4.5], nice), orderedEquals([0, 5]));
18 });
19 test('extends domain extent to nice values '
20 'when domain[0] > domain[last]', () {
21 expect(ScaleUtil.nice([5, 0], nice), orderedEquals([5, 0]));
22 expect(ScaleUtil.nice([4.5, 0.5], nice), orderedEquals([5, 0]));
23 });
24 });
25
26 group('ScaleUtil::niceStep()', () {
27 Nice nice = ScaleUtil.niceStep(5);
28 test('aligns a number to the nearest multiple of step less than num '
29 'when step > 0', () {
30 expect(nice.ceil(4), equals(5));
31 expect(nice.ceil(5), equals(5));
32 expect(nice.ceil(6), equals(10));
33 expect(nice.floor(4), equals(0));
34 expect(nice.floor(5), equals(5));
35 expect(nice.floor(6), equals(5));
36 });
37 Nice nice2 = ScaleUtil.niceStep(0);
38 test('returns the number itself when step <= 0', () {
39 expect(nice2.ceil(4), equals(4));
40 expect(nice2.ceil(5), equals(5));
41 expect(nice2.floor(4), equals(4));
42 expect(nice2.floor(6), equals(6));
43 });
44 });
45
46 test('ScaleUtil::bilinearScale() returns a Function mapping a value '
47 'on domain to corrsponding value on bilinear scale range', () {
48 /* Polylinear scale maps [1, 5] to [2, 10] */
49 Function domain2Range = ScaleUtil.bilinearScale(
50 [1, 5], [2, 10], uninterpolateNumber, interpolateNumber);
51 expect(domain2Range(1), equals(2));
52 expect(domain2Range(5), equals(10));
53 expect(domain2Range(2.5), equals(5));
54 /* Polylinear scale maps [1, 5] to [10, 2] */
55 domain2Range = ScaleUtil.bilinearScale(
56 [1, 5], [10, 2], uninterpolateNumber, interpolateNumber);
57 expect(domain2Range(1), equals(10));
58 expect(domain2Range(5), equals(2));
59 expect(domain2Range(2.5), equals(7));
60 });
61
62 test('ScaleUtil::polylinearScale() returns a Function mapping a value '
63 'on domain to corrsponding value on polylinear scale range', () {
64 /* Polylinear scale maps [1, 7, 9, 15] to [2, 10, 12, 15] */
65 Function domain2Range = ScaleUtil.polylinearScale(
66 [1, 7, 9, 15], [2, 10, 12, 15], uninterpolateNumber, interpolateNumber);
67 /* Values less than 1 use the first segment */
68 expect(domain2Range(-2), equals(-2));
69 /* Values use the first segment */
70 expect(domain2Range(1), equals(2));
71 expect(domain2Range(2.5), equals(4));
72 /* Values use the second segment */
73 expect(domain2Range(7), equals(10));
74 expect(domain2Range(8), equals(11));
75 /* Values use the thrid segment */
76 expect(domain2Range(9), equals(12));
77 expect(domain2Range(12), equals(13.5));
78 expect(domain2Range(15), equals(15));
79 /* Values larger than 15 use the last segment */
80 expect(domain2Range(20), equals(17.5));
81 });
82
83 test('ScaleUtil::bisectLeft() returns the insertion point for x such that'
84 'all left values are smaller than x', () {
85 /* Bisect in the whole segment */
86 expect(ScaleUtil.bisectLeft([0, 1, 2, 3, 4], 1), equals(1));
87 expect(ScaleUtil.bisectLeft([0, 1, 2, 3, 4], 1.5), equals(2));
88 /* Bisect in the segment starting from the third element */
89 expect(ScaleUtil.bisectLeft([0, 1, 2, 3, 4], 1.4, 3), equals(3));
90 /* Bisect in specific segment */
91 expect(ScaleUtil.bisectLeft([0, 1, 2, 3, 4], 1, 3, 4), equals(3));
92 expect(ScaleUtil.bisectLeft([0, 1, 2, 3, 4], 5, 1, 2), equals(2));
93 });
94
95 test('ScaleUtil::bisectRight() returns the insertion point for x such that'
96 'all left values are smaller or equal to x', () {
97 /* Bisect in the whole segment */
98 expect(ScaleUtil.bisectRight([0, 1, 2, 3, 4], 1), equals(2));
99 expect(ScaleUtil.bisectRight([0, 1, 2, 3, 4], 1.5), equals(2));
100 /* Bisect in the segment starting from the third element */
101 expect(ScaleUtil.bisectRight([0, 1, 2, 3, 4], 1, 3), equals(3));
102 /* Bisect in specific segment */
103 expect(ScaleUtil.bisectRight([0, 1, 2, 3, 4], 1, 3, 4), equals(3));
104 expect(ScaleUtil.bisectRight([0, 1, 2, 3, 4], 5, 1, 2), equals(2));
105 });
106
107 }
OLDNEW
« no previous file with comments | « packages/charted/test.disabled/scale/scale_test.dart ('k') | packages/charted/test.disabled/scale/time_scale_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698