You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

math_test.go 1.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package math2
  2. import (
  3. "testing"
  4. . "github.com/smartystreets/goconvey/convey"
  5. )
  6. func Test_SplitLessThan(t *testing.T) {
  7. checker := func(t *testing.T, arr []int, total int, maxValue int) {
  8. t.Logf("arr: %v, total: %d, maxValue: %d", arr, total, maxValue)
  9. sum := 0
  10. for _, v := range arr {
  11. sum += v
  12. if v > maxValue {
  13. t.Errorf("value should be less than %d", maxValue)
  14. }
  15. }
  16. if sum != total {
  17. t.Errorf("sum should be %d", total)
  18. }
  19. }
  20. Convey("测试", t, func() {
  21. checker(t, SplitLessThan(9, 9), 9, 9)
  22. checker(t, SplitLessThan(9, 3), 9, 3)
  23. checker(t, SplitLessThan(10, 3), 10, 3)
  24. checker(t, SplitLessThan(11, 3), 11, 3)
  25. checker(t, SplitLessThan(12, 3), 12, 3)
  26. })
  27. }
  28. func Test_SplitN(t *testing.T) {
  29. checker := func(t *testing.T, arr []int, total int) {
  30. t.Logf("arr: %v, total: %d", arr, total)
  31. sum := 0
  32. for _, v := range arr {
  33. sum += v
  34. }
  35. if sum != total {
  36. t.Errorf("sum should be %d", total)
  37. }
  38. }
  39. Convey("测试", t, func() {
  40. checker(t, SplitN(9, 9), 9)
  41. checker(t, SplitN(9, 3), 9)
  42. checker(t, SplitN(10, 3), 10)
  43. checker(t, SplitN(11, 3), 11)
  44. checker(t, SplitN(12, 3), 12)
  45. })
  46. }