github.com/synesissoftware/ANGoLS@v0.0.0-20190330004400-955d82dbf73b/select_test.go (about) 1 2 package angols_test 3 4 import ( 5 6 "github.com/synesissoftware/ANGoLS" 7 8 "strconv" 9 "strings" 10 "testing" 11 ) 12 13 func Test_SelectSliceOfInt_1(t *testing.T) { 14 15 input, err := angols.GenerateSliceOfInt(10, func(index int) (int, error) { return index, nil }) 16 if err != nil { 17 18 t.Errorf("GenerateSliceOfInt() failed: %v\n", err) 19 } else { 20 21 actual, err := angols.SelectSliceOfInt(input, func(index int, value int) (bool, error) { return 0 == (value % 2), nil }) 22 if err != nil { 23 24 t.Errorf("SelectSliceOfInt() failed: %v\n", err) 25 } else { 26 27 expected := []int{ 0, 2, 4, 6, 8 } 28 29 if !angols.EqualSliceOfInt(expected, actual) { 30 31 t.Errorf("actual value '%v' does not equal expected value '%v'", actual, expected) 32 } 33 34 if !angols.EqualSlice(expected, actual) { 35 36 t.Errorf("actual value '%v' does not equal expected value '%v'", actual, expected) 37 } 38 } 39 } 40 } 41 42 func Test_SelectSliceOfUInt_1(t *testing.T) { 43 44 input, err := angols.GenerateSliceOfUInt(10, func(index int) (uint, error) { return uint(index), nil }) 45 if err != nil { 46 47 t.Errorf("GenerateSliceOfUInt() failed: %v\n", err) 48 } else { 49 50 actual, err := angols.SelectSliceOfUInt(input, func(index int, value uint) (bool, error) { return 0 == (value % 2), nil }) 51 if err != nil { 52 53 t.Errorf("SelectSliceOfUInt() failed: %v\n", err) 54 } else { 55 56 expected := []uint{ 0, 2, 4, 6, 8 } 57 58 if !angols.EqualSliceOfUInt(expected, actual) { 59 60 t.Errorf("actual value '%v' does not equal expected value '%v'", actual, expected) 61 } 62 63 if !angols.EqualSlice(expected, actual) { 64 65 t.Errorf("actual value '%v' does not equal expected value '%v'", actual, expected) 66 } 67 } 68 } 69 } 70 71 func Test_SelectSliceOfString_1(t *testing.T) { 72 73 input, err := angols.GenerateSliceOfString(10, func(index int) (string, error) { return strconv.Itoa(index), nil }) 74 if err != nil { 75 76 t.Errorf("GenerateSliceOfString() failed: %v\n", err) 77 } else { 78 79 actual, err := angols.SelectSliceOfString(input, func(index int, value string) (bool, error) { return strings.IndexAny(value[:1], "2457") >= 0, nil }) 80 if err != nil { 81 82 t.Errorf("SelectSliceOfString() failed: %v\n", err) 83 } else { 84 85 expected := []string{ "2", "4", "5", "7" } 86 87 if !angols.EqualSliceOfString(expected, actual) { 88 89 t.Errorf("actual value '%v' does not equal expected value '%v'", actual, expected) 90 } 91 92 if !angols.EqualSlice(expected, actual) { 93 94 t.Errorf("actual value '%v' does not equal expected value '%v'", actual, expected) 95 } 96 } 97 } 98 } 99