general_test.go 590 B

123456789101112131415161718192021222324252627282930313233343536
  1. package help
  2. import (
  3. "reflect"
  4. "testing"
  5. )
  6. func TestChannelToChannel(t *testing.T) {
  7. input := []int{30, 40, 50}
  8. inpCh := make(chan interface{})
  9. resCh := make(chan interface{})
  10. go func() {
  11. for _, i := range input {
  12. inpCh <- i
  13. }
  14. close(inpCh)
  15. }()
  16. go func() {
  17. FromChannel(inpCh).Where(func(i interface{}) bool {
  18. return i.(int) > 20
  19. }).ToChannel(resCh)
  20. }()
  21. result := []int{}
  22. for value := range resCh {
  23. result = append(result, value.(int))
  24. }
  25. if !reflect.DeepEqual(result, input) {
  26. t.Errorf("FromChannel().ToChannel()=%v expected %v", result, input)
  27. }
  28. }