#!/usr/bin/env bats # Tests for lib/format.sh — pure formatting functions load test_helper.sh setup() { source_lib common.sh source_lib format.sh } # ── human_bytes ────────────────────────────────────────── @test "human_bytes: 0 bytes" { run human_bytes 0 assert_output "0 B" } @test "human_bytes: small value (500 bytes)" { run human_bytes 500 assert_output "500 B" } @test "human_bytes: exactly 1 KiB" { run human_bytes 1024 assert_output "1 KiB" } @test "human_bytes: exactly 1 MiB" { run human_bytes 1048576 assert_output "1 MiB" } @test "human_bytes: exactly 1 GiB" { run human_bytes 1073741824 assert_output "1.0 GiB" } @test "human_bytes: 32 GiB (typical VRAM)" { run human_bytes 34359738368 assert_output "32.0 GiB" } @test "human_bytes: 512 MiB (optimal VRAM)" { run human_bytes 536870912 assert_output "512 MiB" } @test "human_bytes: sub-GiB value formats with leading zero (0.5 GiB)" { # 0.5 GiB = 536870912 bytes — should NOT be "0.5 GiB" since < 1 GiB uses MiB run human_bytes 536870912 assert_output "512 MiB" } @test "human_bytes: 1.5 GiB has correct decimal" { run human_bytes 1610612736 assert_output "1.5 GiB" } @test "human_bytes: empty/missing argument defaults to 0" { run human_bytes "" assert_output "0 B" } @test "human_bytes: 64 GiB" { run human_bytes 68719476736 assert_output "64.0 GiB" } # ── human_mib ──────────────────────────────────────────── @test "human_mib: 0 MiB" { run human_mib 0 assert_output "0 MiB" } @test "human_mib: 512 MiB (stays as MiB)" { run human_mib 512 assert_output "512 MiB" } @test "human_mib: 1023 MiB (just under GiB threshold)" { run human_mib 1023 assert_output "1023 MiB" } @test "human_mib: 1024 MiB = 1.0 GiB" { run human_mib 1024 assert_output "1.0 GiB" } @test "human_mib: 60416 MiB (recommended GTT for 64GB system)" { run human_mib 60416 assert_output "59.0 GiB" } @test "human_mib: 61440 MiB = 60.0 GiB" { run human_mib 61440 assert_output "60.0 GiB" } @test "human_mib: empty argument defaults to 0" { run human_mib "" assert_output "0 MiB" }