| /** |
| * @license |
| * Copyright 2021 The Chromium Authors. All rights reserved. |
| * Use of this source code is governed by a BSD-style license that can be |
| * found in the LICENSE file. |
| */ |
| |
| import {assert} from '@open-wc/testing'; |
| import './test-setup'; |
| import { |
| humanByteSize, |
| humanByteSizeDelta, |
| percentSizeDelta, |
| } from './binary-size-table'; |
| |
| suite('binary-size-table basic tests', () => { |
| test('humanByteSize below first threshold', () => { |
| assert.equal(humanByteSize(1024), '1024 B'); |
| }); |
| |
| test('humanByteSize KiB', () => { |
| assert.equal(humanByteSize(2048), '2.00 KiB'); |
| }); |
| |
| test('humanByteSize MiB', () => { |
| assert.equal(humanByteSize(12345678), '11.774 MiB'); |
| }); |
| |
| test('humanByteSize above last threshold', () => { |
| assert.equal(humanByteSize(111222333444555), '103583.8699 GiB'); |
| }); |
| |
| test('humanByteSizeDelta zero', () => { |
| assert.equal(humanByteSizeDelta(0, 0), '—'); |
| }); |
| |
| test('humanByteSizeDelta positive', () => { |
| assert.equal(humanByteSizeDelta(0, 1), '+1 B'); |
| }); |
| |
| test('humanByteSizeDelta negative', () => { |
| assert.equal(humanByteSizeDelta(123456, 0), '−120.56 KiB'); |
| }); |
| |
| test('percentSizeDelta negative', () => { |
| assert.equal(percentSizeDelta(10000000, 9686630), '−3.1337%'); |
| }); |
| }); |