totals_test.go 680 B

1234567891011121314151617181920212223242526
  1. package opencost
  2. import (
  3. "math"
  4. "testing"
  5. )
  6. func TestComputeIdleCoefficients(t *testing.T) {
  7. // test that passing totals where total + adjustment == 0 returns a 0 coefficient
  8. at := make(map[string]*AllocationTotals)
  9. at["item1"] = &AllocationTotals{
  10. CPUCost: 1,
  11. CPUCostAdjustment: -1,
  12. RAMCost: 2,
  13. RAMCostAdjustment: -2,
  14. GPUCost: 3,
  15. GPUCostAdjustment: -3,
  16. }
  17. cpu, gpu, ram := ComputeIdleCoefficients("weighted", "item1", 100, 100, 100, at)
  18. if math.IsNaN(cpu) || math.IsNaN(gpu) || math.IsNaN(ram) || math.IsInf(cpu, 0) || math.IsInf(gpu, 0) || math.IsInf(ram, 0) {
  19. t.Errorf("Idle coefficients should not be NaN or Inf")
  20. }
  21. }