func ArrayEach(expectedValue interface{}) TestDeep
ArrayEach
operator has to be applied on arrays or slices or on
pointers on array/slice. It compares each item of data array/slice
against expectedValue. During a match, all items have to match to
succeed.
See also ArrayEach godoc.
t := &testing.T{}
got := [3]int{42, 58, 26}
ok := Cmp(t, got, ArrayEach(Between(25, 60)),
"checks each item of array %v is in [25 .. 60]", got)
fmt.Println(ok)
// Output:
// true
t := &testing.T{}
type MyArray [3]int
got := MyArray{42, 58, 26}
ok := Cmp(t, got, ArrayEach(Between(25, 60)),
"checks each item of typed array %v is in [25 .. 60]", got)
fmt.Println(ok)
ok = Cmp(t, &got, ArrayEach(Between(25, 60)),
"checks each item of typed array pointer %v is in [25 .. 60]", got)
fmt.Println(ok)
// Output:
// true
// true
t := &testing.T{}
got := []int{42, 58, 26}
ok := Cmp(t, got, ArrayEach(Between(25, 60)),
"checks each item of slice %v is in [25 .. 60]", got)
fmt.Println(ok)
// Output:
// true
t := &testing.T{}
type MySlice []int
got := MySlice{42, 58, 26}
ok := Cmp(t, got, ArrayEach(Between(25, 60)),
"checks each item of typed slice %v is in [25 .. 60]", got)
fmt.Println(ok)
ok = Cmp(t, &got, ArrayEach(Between(25, 60)),
"checks each item of typed slice pointer %v is in [25 .. 60]", got)
fmt.Println(ok)
// Output:
// true
// true
func CmpArrayEach(t TestingT, got interface{}, expectedValue interface{}, args ...interface{}) bool
CmpArrayEach is a shortcut for:
Cmp(t, got, ArrayEach(expectedValue), args...)
See above for details.
Returns true if the test is OK, false if it fails.
args… are optional and allow to name the test. This name is
used in case of failure to qualify the test. If len(args) > 1
and
the first item of args is a string
and contains a ‘%’ rune
then
fmt.Fprintf
is used to compose the name, else args are passed to
fmt.Fprint
. Do not forget it is the name of the test, not the
reason of a potential failure.
See also CmpArrayEach godoc.
t := &testing.T{}
got := [3]int{42, 58, 26}
ok := CmpArrayEach(t, got, Between(25, 60),
"checks each item of array %v is in [25 .. 60]", got)
fmt.Println(ok)
// Output:
// true
t := &testing.T{}
type MyArray [3]int
got := MyArray{42, 58, 26}
ok := CmpArrayEach(t, got, Between(25, 60),
"checks each item of typed array %v is in [25 .. 60]", got)
fmt.Println(ok)
ok = CmpArrayEach(t, &got, Between(25, 60),
"checks each item of typed array pointer %v is in [25 .. 60]", got)
fmt.Println(ok)
// Output:
// true
// true
t := &testing.T{}
got := []int{42, 58, 26}
ok := CmpArrayEach(t, got, Between(25, 60),
"checks each item of slice %v is in [25 .. 60]", got)
fmt.Println(ok)
// Output:
// true
t := &testing.T{}
type MySlice []int
got := MySlice{42, 58, 26}
ok := CmpArrayEach(t, got, Between(25, 60),
"checks each item of typed slice %v is in [25 .. 60]", got)
fmt.Println(ok)
ok = CmpArrayEach(t, &got, Between(25, 60),
"checks each item of typed slice pointer %v is in [25 .. 60]", got)
fmt.Println(ok)
// Output:
// true
// true
func (t *T) ArrayEach(got interface{}, expectedValue interface{}, args ...interface{}) bool
ArrayEach
is a shortcut for:
t.Cmp(got, ArrayEach(expectedValue), args...)
See above for details.
Returns true if the test is OK, false if it fails.
args… are optional and allow to name the test. This name is
used in case of failure to qualify the test. If len(args) > 1
and
the first item of args is a string
and contains a ‘%’ rune
then
fmt.Fprintf
is used to compose the name, else args are passed to
fmt.Fprint
. Do not forget it is the name of the test, not the
reason of a potential failure.
See also T.ArrayEach godoc.
t := NewT(&testing.T{})
got := [3]int{42, 58, 26}
ok := t.ArrayEach(got, Between(25, 60),
"checks each item of array %v is in [25 .. 60]", got)
fmt.Println(ok)
// Output:
// true
t := NewT(&testing.T{})
type MyArray [3]int
got := MyArray{42, 58, 26}
ok := t.ArrayEach(got, Between(25, 60),
"checks each item of typed array %v is in [25 .. 60]", got)
fmt.Println(ok)
ok = t.ArrayEach(&got, Between(25, 60),
"checks each item of typed array pointer %v is in [25 .. 60]", got)
fmt.Println(ok)
// Output:
// true
// true
t := NewT(&testing.T{})
got := []int{42, 58, 26}
ok := t.ArrayEach(got, Between(25, 60),
"checks each item of slice %v is in [25 .. 60]", got)
fmt.Println(ok)
// Output:
// true
t := NewT(&testing.T{})
type MySlice []int
got := MySlice{42, 58, 26}
ok := t.ArrayEach(got, Between(25, 60),
"checks each item of typed slice %v is in [25 .. 60]", got)
fmt.Println(ok)
ok = t.ArrayEach(&got, Between(25, 60),
"checks each item of typed slice pointer %v is in [25 .. 60]", got)
fmt.Println(ok)
// Output:
// true
// true