jackhammer

Utilities for Go
Log | Files | Refs | README | LICENSE

iterx_test.go (496B)


      1 package iterx
      2 
      3 import (
      4 	"slices"
      5 	"strconv"
      6 	"testing"
      7 )
      8 
      9 func TestMap(t *testing.T) {
     10 	values := []string{}
     11 	for ii := 0; ii < 100; ii += 1 {
     12 		values = append(values, strconv.Itoa(ii))
     13 	}
     14 
     15 	iterator := Map(slices.Values(values), func(s string) int {
     16 		n, err := strconv.Atoi(s)
     17 		if err != nil {
     18 			panic(err)
     19 		}
     20 		return n
     21 	})
     22 
     23 	for ii, n := range slices.Collect(iterator) {
     24 		want := values[ii]
     25 		got := strconv.Itoa(n)
     26 		if want != got {
     27 			t.Fatalf("got=%s, want=%s", got, want)
     28 		}
     29 	}
     30 }