"use strict";
/**
 * Common Types单元测试
 * 测试DataSize类和其他通用类型
 */
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const common_1 = require("../../../src/types/common");
describe('DataSize Unit Tests', function () {
    describe('构造函数和基本转换', function () {
        it('应该能够从字节数创建DataSize', function () {
            const size = new common_1.DataSize(1024);
            (0, chai_1.expect)(size.bytes).to.equal(1024);
            (0, chai_1.expect)(size.toKB()).to.equal(1);
            (0, chai_1.expect)(size.toMB()).to.equal(1 / 1024);
        });
        it('应该正确转换各种单位', function () {
            const gb = new common_1.DataSize(1024 * 1024 * 1024); // 1GB
            (0, chai_1.expect)(gb.bytes).to.equal(1073741824);
            (0, chai_1.expect)(gb.toKB()).to.equal(1048576);
            (0, chai_1.expect)(gb.toMB()).to.equal(1024);
            (0, chai_1.expect)(gb.toGB()).to.equal(1);
            (0, chai_1.expect)(gb.toTB()).to.equal(1 / 1024);
        });
        it('应该处理零值', function () {
            const zero = new common_1.DataSize(0);
            (0, chai_1.expect)(zero.bytes).to.equal(0);
            (0, chai_1.expect)(zero.toKB()).to.equal(0);
            (0, chai_1.expect)(zero.toMB()).to.equal(0);
            (0, chai_1.expect)(zero.toGB()).to.equal(0);
            (0, chai_1.expect)(zero.toTB()).to.equal(0);
        });
    });
    describe('静态创建方法', function () {
        it('应该能够从KB创建', function () {
            const size = common_1.DataSize.fromKB(1);
            (0, chai_1.expect)(size.bytes).to.equal(1024);
            (0, chai_1.expect)(size.toKB()).to.equal(1);
        });
        it('应该能够从MB创建', function () {
            const size = common_1.DataSize.fromMB(1);
            (0, chai_1.expect)(size.bytes).to.equal(1024 * 1024);
            (0, chai_1.expect)(size.toMB()).to.equal(1);
        });
        it('应该能够从GB创建', function () {
            const size = common_1.DataSize.fromGB(1);
            (0, chai_1.expect)(size.bytes).to.equal(1024 * 1024 * 1024);
            (0, chai_1.expect)(size.toGB()).to.equal(1);
        });
        it('应该能够从字节创建', function () {
            const size = common_1.DataSize.fromBytes(2048);
            (0, chai_1.expect)(size.bytes).to.equal(2048);
            (0, chai_1.expect)(size.toKB()).to.equal(2);
        });
    });
    describe('格式化功能', function () {
        it('应该能够格式化为人性化字符串', function () {
            const tests = [
                { bytes: 512, expected: '512 B' },
                { bytes: 1024, expected: '1.00 KB' },
                { bytes: 1536, expected: '1.50 KB' },
                { bytes: 1024 * 1024, expected: '1.00 MB' },
                { bytes: 1024 * 1024 * 1024, expected: '1.00 GB' },
                { bytes: 1024 * 1024 * 1024 * 1024, expected: '1.00 TB' }
            ];
            tests.forEach(test => {
                const size = new common_1.DataSize(test.bytes);
                (0, chai_1.expect)(size.toString()).to.equal(test.expected);
            });
        });
        it('应该能够格式化为指定单位', function () {
            const size = new common_1.DataSize(1024 * 1024 * 1.5); // 1.5 MB
            (0, chai_1.expect)(size.toString('B')).to.equal('1572864 B');
            (0, chai_1.expect)(size.toString('KB')).to.equal('1536.00 KB');
            (0, chai_1.expect)(size.toString('MB')).to.equal('1.50 MB');
            (0, chai_1.expect)(size.toString('GB')).to.equal('0.00 GB');
        });
        it('应该支持自动选择最佳单位', function () {
            const size = new common_1.DataSize(1536); // 1.5 KB
            (0, chai_1.expect)(size.toString('auto')).to.equal('1.50 KB');
            (0, chai_1.expect)(size.toString()).to.equal('1.50 KB'); // 默认为auto
        });
    });
    describe('边界情况和错误处理', function () {
        it('应该拒绝负数', function () {
            (0, chai_1.expect)(() => new common_1.DataSize(-1024)).to.throw('Data size cannot be negative');
        });
        it('应该处理非常大的数值', function () {
            const size = new common_1.DataSize(Number.MAX_SAFE_INTEGER);
            (0, chai_1.expect)(size.bytes).to.equal(Number.MAX_SAFE_INTEGER);
        });
        it('应该处理小数字节数', function () {
            const size = new common_1.DataSize(1023.5);
            (0, chai_1.expect)(size.bytes).to.equal(1023.5);
            (0, chai_1.expect)(size.toKB()).to.be.closeTo(0.9995, 0.0001);
        });
    });
    describe('实用方法', function () {
        it('应该提供toBytes方法', function () {
            const size = new common_1.DataSize(1024);
            (0, chai_1.expect)(size.toBytes()).to.equal(1024);
            (0, chai_1.expect)(size.toBytes()).to.equal(size.bytes);
        });
        it('应该正确处理单位转换精度', function () {
            const size = new common_1.DataSize(1024 * 1024 + 512 * 1024); // 1.5 MB
            (0, chai_1.expect)(size.toMB()).to.equal(1.5);
            (0, chai_1.expect)(size.toKB()).to.equal(1536);
        });
    });
    describe('静态工厂方法验证', function () {
        it('所有静态方法应该返回正确的DataSize实例', function () {
            const fromBytes = common_1.DataSize.fromBytes(1024);
            const fromKB = common_1.DataSize.fromKB(1);
            const fromMB = common_1.DataSize.fromMB(1 / 1024);
            const fromGB = common_1.DataSize.fromGB(1 / (1024 * 1024));
            (0, chai_1.expect)(fromBytes.bytes).to.equal(1024);
            (0, chai_1.expect)(fromKB.bytes).to.equal(1024);
            (0, chai_1.expect)(fromMB.bytes).to.equal(1024);
            (0, chai_1.expect)(fromGB.bytes).to.equal(1024);
        });
    });
    describe('字符串表示', function () {
        it('应该提供有意义的字符串表示', function () {
            const size = new common_1.DataSize(2048);
            const str = size.toString();
            (0, chai_1.expect)(str).to.include('2.00');
            (0, chai_1.expect)(str).to.include('KB');
        });
        it('应该支持所有单位的强制格式化', function () {
            const size = new common_1.DataSize(1024 * 1024); // 1 MB
            (0, chai_1.expect)(size.toString('B')).to.include('1048576');
            (0, chai_1.expect)(size.toString('KB')).to.include('1024.00');
            (0, chai_1.expect)(size.toString('MB')).to.include('1.00');
            (0, chai_1.expect)(size.toString('GB')).to.include('0.00');
            (0, chai_1.expect)(size.toString('TB')).to.include('0.00');
        });
    });
});
//# sourceMappingURL=common.test.js.map