"""Tests for helper functions.""" import pandas as pd import pytest from disk_checker.core.helpers import human_count, percentile_table class TestHumanCount: """Tests for human_count function.""" def test_small_number(self): """Test formatting of small numbers.""" assert human_count(100) == "100" assert human_count(50) == "50" def test_thousands(self): """Test formatting of thousands.""" assert human_count(1500) == "2k" assert human_count(2500) == "3k" assert human_count(1000) == "1k" assert human_count(999) == "999" def test_millions(self): """Test formatting of millions.""" assert human_count(1500000) == "1.5M" assert human_count(2750000) == "2.8M" def test_billions(self): """Test formatting of billions.""" assert human_count(1500000000) == "1.5G" assert human_count(2750000000) == "2.8G" def test_zero(self): """Test formatting of zero.""" assert human_count(0) == "0" def test_position_argument_ignored(self): """Test that _pos argument is ignored.""" assert human_count(1000, 0) == "1k" class TestPercentileTable: """Tests for percentile_table function.""" def test_basic_percentiles(self): """Test basic percentile table generation.""" df = pd.DataFrame({ "metric": ["read_clat"] * 3, "latency_ns": [1000, 2000, 3000], "count": [1, 2, 1], }) result = percentile_table(df, "read_clat", "us", [50, 90]) assert "Metric: read_clat" in result assert "total I/Os: 4" in result assert "percentile" in result assert "latency" in result def test_missing_metric(self): """Test percentile table with missing metric.""" df = pd.DataFrame({ "metric": ["read_clat"], "latency_ns": [1000], "count": [1], }) result = percentile_table(df, "write_clat", "us", [50]) assert "(no data for metric write_clat)" in result def test_unit_display(self): """Test that correct unit is displayed.""" df = pd.DataFrame({ "metric": ["read_clat"], "latency_ns": [1000000], # 1ms in ns "count": [1], }) result = percentile_table(df, "read_clat", "ms", [50]) assert "ms" in result