//go:build windows package stats import "testing" func TestFiletimeToUint64(t *testing.T) { ft := filetime{LowDateTime: 0xDEADBEEF, HighDateTime: 0x00001234} want := (uint64(0x1234) << 32) | 0xDEADBEEF if got := filetimeToUint64(ft); got != want { t.Fatalf("got %x want %x", got, want) } if filetimeToUint64(filetime{}) != 0 { t.Fatal("zero filetime should be 0") } } func TestCPUBusyPercentFromDeltas(t *testing.T) { tests := []struct { idle, total float64 want float64 }{ {idle: 25, total: 100, want: 75}, {idle: 0, total: 100, want: 100}, {idle: 100, total: 100, want: 0}, {idle: 0, total: 0, want: 0}, {idle: -10, total: 50, want: 100}, // over 100% busy clamped {idle: 200, total: 100, want: 0}, // negative busy clamped to 0 } for _, tc := range tests { if got := cpuBusyPercentFromDeltas(tc.idle, tc.total); got != tc.want { t.Fatalf("idle=%v total=%v: got %v want %v", tc.idle, tc.total, got, tc.want) } } }