Michail Schwab | a86aae4 | 2018-07-20 11:58:28 -0400 | [diff] [blame] | 1 | // 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 Schwab | 7e4b89e | 2018-07-27 10:48:40 -0400 | [diff] [blame] | 15 | import {getGridStepSize} from './gridline_helper'; |
Michail Schwab | a86aae4 | 2018-07-20 11:58:28 -0400 | [diff] [blame] | 16 | |
| 17 | test('gridline helper to have sensible step sizes', () => { |
Michail Schwab | 7e4b89e | 2018-07-27 10:48:40 -0400 | [diff] [blame] | 18 | 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 Schwab | a86aae4 | 2018-07-20 11:58:28 -0400 | [diff] [blame] | 34 | }); |
| 35 | |
| 36 | test('gridline helper to scale to very small and very large values', () => { |
Michail Schwab | 7e4b89e | 2018-07-27 10:48:40 -0400 | [diff] [blame] | 37 | expect(getGridStepSize(.01, 14)).toEqual(.001); |
| 38 | expect(getGridStepSize(10000, 14)).toEqual(1000); |
Michail Schwab | a86aae4 | 2018-07-20 11:58:28 -0400 | [diff] [blame] | 39 | }); |
| 40 | |
| 41 | test('gridline helper to always return a reasonable number of steps', () => { |
| 42 | for (let i = 1; i <= 1000; i++) { |
Michail Schwab | 7e4b89e | 2018-07-27 10:48:40 -0400 | [diff] [blame] | 43 | const stepSize = getGridStepSize(i, 14); |
| 44 | expect(Math.round(i / stepSize)).toBeGreaterThanOrEqual(7); |
| 45 | expect(Math.round(i / stepSize)).toBeLessThanOrEqual(21); |
Michail Schwab | a86aae4 | 2018-07-20 11:58:28 -0400 | [diff] [blame] | 46 | } |
Michail Schwab | 7e4b89e | 2018-07-27 10:48:40 -0400 | [diff] [blame] | 47 | }); |