list_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package service
  2. import (
  3. "testing"
  4. . "github.com/smartystreets/goconvey/convey"
  5. )
  6. func TestWithinFloor(t *testing.T) {
  7. var (
  8. ids = []int64{3, 5, 7, 9, 11, 13, 15}
  9. )
  10. // within asc
  11. Convey("withinFloor asc without page 1", t, WithService(func(s *Service) {
  12. r := withinFloor(ids, 1, 1, 5, true)
  13. So(r, ShouldBeFalse)
  14. }))
  15. Convey("withinFloor asc within page 1", t, WithService(func(s *Service) {
  16. r := withinFloor(ids, 4, 1, 5, true)
  17. So(r, ShouldBeTrue)
  18. }))
  19. Convey("withinFloor asc within page 1", t, WithService(func(s *Service) {
  20. r := withinFloor(ids, 16, 1, 20, true)
  21. So(r, ShouldBeTrue)
  22. }))
  23. Convey("withinFloor asc without page 1", t, WithService(func(s *Service) {
  24. r := withinFloor(ids, 16, 1, 5, true)
  25. So(r, ShouldBeFalse)
  26. }))
  27. // within desc
  28. Convey("withinFloor desc within page 1", t, WithService(func(s *Service) {
  29. r := withinFloor(ids, 16, 1, 5, false)
  30. So(r, ShouldBeTrue)
  31. }))
  32. Convey("withinFloor desc within page 2", t, WithService(func(s *Service) {
  33. r := withinFloor(ids, 16, 2, 5, false)
  34. So(r, ShouldBeFalse)
  35. }))
  36. Convey("withinFloor desc within page 1", t, WithService(func(s *Service) {
  37. r := withinFloor(ids, 2, 3, 20, false)
  38. So(r, ShouldBeTrue)
  39. }))
  40. Convey("withinFloor desc without page 1", t, WithService(func(s *Service) {
  41. r := withinFloor(ids, 1, 1, 5, false)
  42. So(r, ShouldBeFalse)
  43. }))
  44. Convey("withinFloor desc within page 1", t, WithService(func(s *Service) {
  45. r := withinFloor(ids, 1, 1, 20, true)
  46. So(r, ShouldBeTrue)
  47. }))
  48. }