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