blob: ad765730eac906b4296cf3005c71e289be7470ec [file] [log] [blame]
Michail Schwaba86aae42018-07-20 11:58:28 -04001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Michail Schwab7e4b89e2018-07-27 10:48:40 -040015import {getGridStepSize} from './gridline_helper';
Michail Schwaba86aae42018-07-20 11:58:28 -040016
17test('gridline helper to have sensible step sizes', () => {
Michail Schwab7e4b89e2018-07-27 10:48:40 -040018 expect(getGridStepSize(10, 14)).toEqual(1);
19 expect(getGridStepSize(30, 14)).toEqual(2);
20 expect(getGridStepSize(60, 14)).toEqual(5);
21 expect(getGridStepSize(100, 14)).toEqual(10);
22
23 expect(getGridStepSize(10, 21)).toEqual(0.5);
24 expect(getGridStepSize(30, 21)).toEqual(2);
25 expect(getGridStepSize(60, 21)).toEqual(2);
26 expect(getGridStepSize(100, 21)).toEqual(5);
27
28 expect(getGridStepSize(10, 3)).toEqual(5);
29 expect(getGridStepSize(30, 3)).toEqual(10);
30 expect(getGridStepSize(60, 3)).toEqual(20);
31 expect(getGridStepSize(100, 3)).toEqual(50);
32
33 expect(getGridStepSize(800, 4)).toEqual(200);
Michail Schwaba86aae42018-07-20 11:58:28 -040034});
35
36test('gridline helper to scale to very small and very large values', () => {
Michail Schwab7e4b89e2018-07-27 10:48:40 -040037 expect(getGridStepSize(.01, 14)).toEqual(.001);
38 expect(getGridStepSize(10000, 14)).toEqual(1000);
Michail Schwaba86aae42018-07-20 11:58:28 -040039});
40
41test('gridline helper to always return a reasonable number of steps', () => {
42 for (let i = 1; i <= 1000; i++) {
Michail Schwab7e4b89e2018-07-27 10:48:40 -040043 const stepSize = getGridStepSize(i, 14);
44 expect(Math.round(i / stepSize)).toBeGreaterThanOrEqual(7);
45 expect(Math.round(i / stepSize)).toBeLessThanOrEqual(21);
Michail Schwaba86aae42018-07-20 11:58:28 -040046 }
Michail Schwab7e4b89e2018-07-27 10:48:40 -040047});