calcAVG_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. package solver
  2. import (
  3. "testing"
  4. )
  5. // Test the calcAVG function.
  6. func TestCalcAVG(t *testing.T) {
  7. // Create a new Solver struct.
  8. solver := Solver{}
  9. // Populate the solver.rates[] slice with some values and check if the average is calculated correctly.
  10. solver.rates = []uint64{1, 2, 3, 4, 5}
  11. if solver.calcAVG() != 3 {
  12. t.Error("Expected 3, got", solver.calcAVG())
  13. }
  14. // Populate the solver.Rate[] slice with some values and check if the average is calculated correctly.
  15. solver.rates = []uint64{1, 2, 3, 4, 5, 6}
  16. if solver.calcAVG() != 3 {
  17. t.Error("Expected 3, got", solver.calcAVG())
  18. }
  19. // Populate the solver.Rate[] slice with some values and check if the average is calculated correctly.
  20. solver.rates = []uint64{1, 2, 3, 4, 5, 6, 7}
  21. if solver.calcAVG() != 4 {
  22. t.Error("Expected 4, got", solver.calcAVG())
  23. }
  24. // Populate the solver.Rate[] slice with some values and check if the average is calculated correctly.
  25. solver.rates = []uint64{1, 2, 3, 4, 5, 6, 7, 8}
  26. if solver.calcAVG() != 4 {
  27. t.Error("Expected 4, got", solver.calcAVG())
  28. }
  29. }