1// Copyright (C) 2019 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 {timeToCode} from './time';
16
17test('seconds to code', () => {
18  expect(timeToCode(3)).toEqual('3s');
19  expect(timeToCode(60)).toEqual('1m');
20  expect(timeToCode(63)).toEqual('1m 3s');
21  expect(timeToCode(63.2)).toEqual('1m 3s 200ms');
22  expect(timeToCode(63.2221)).toEqual('1m 3s 222ms 100us');
23  expect(timeToCode(63.2221111)).toEqual('1m 3s 222ms 111us 100ns');
24  expect(timeToCode(0.2221111)).toEqual('222ms 111us 100ns');
25  expect(timeToCode(0.000001)).toEqual('1us');
26  expect(timeToCode(0.000003)).toEqual('3us');
27  expect(timeToCode(1.000001)).toEqual('1s 1us');
28  expect(timeToCode(200.00000003)).toEqual('3m 20s 30ns');
29  expect(timeToCode(0)).toEqual('0s');
30});
31