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.
got:=[]Person{{Name:"Bob",Age:42},{Name:"Alice",Age:24},}td.Cmp(t,got,td.ArrayEach(td.Struct(Person{},td.StructFields{Age:td.Between(20,45),})),)// succeeds, each Person has Age field between 20 and 45
t:=&testing.T{}got:=[3]int{42,58,26}ok:=td.Cmp(t,got,td.ArrayEach(td.Between(25,60)),"checks each item of array %v is in [25 .. 60]",got)fmt.Println(ok)// Output:// true
TypedArray example
t:=&testing.T{}typeMyArray[3]intgot:=MyArray{42,58,26}ok:=td.Cmp(t,got,td.ArrayEach(td.Between(25,60)),"checks each item of typed array %v is in [25 .. 60]",got)fmt.Println(ok)ok=td.Cmp(t,&got,td.ArrayEach(td.Between(25,60)),"checks each item of typed array pointer %v is in [25 .. 60]",got)fmt.Println(ok)// Output:// true// true
Slice example
t:=&testing.T{}got:=[]int{42,58,26}ok:=td.Cmp(t,got,td.ArrayEach(td.Between(25,60)),"checks each item of slice %v is in [25 .. 60]",got)fmt.Println(ok)// Output:// true
TypedSlice example
t:=&testing.T{}typeMySlice[]intgot:=MySlice{42,58,26}ok:=td.Cmp(t,got,td.ArrayEach(td.Between(25,60)),"checks each item of typed slice %v is in [25 .. 60]",got)fmt.Println(ok)ok=td.Cmp(t,&got,td.ArrayEach(td.Between(25,60)),"checks each item of typed slice pointer %v is in [25 .. 60]",got)fmt.Println(ok)// Output:// true// true
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.
t:=&testing.T{}got:=[3]int{42,58,26}ok:=td.CmpArrayEach(t,got,td.Between(25,60),"checks each item of array %v is in [25 .. 60]",got)fmt.Println(ok)// Output:// true
TypedArray example
t:=&testing.T{}typeMyArray[3]intgot:=MyArray{42,58,26}ok:=td.CmpArrayEach(t,got,td.Between(25,60),"checks each item of typed array %v is in [25 .. 60]",got)fmt.Println(ok)ok=td.CmpArrayEach(t,&got,td.Between(25,60),"checks each item of typed array pointer %v is in [25 .. 60]",got)fmt.Println(ok)// Output:// true// true
Slice example
t:=&testing.T{}got:=[]int{42,58,26}ok:=td.CmpArrayEach(t,got,td.Between(25,60),"checks each item of slice %v is in [25 .. 60]",got)fmt.Println(ok)// Output:// true
TypedSlice example
t:=&testing.T{}typeMySlice[]intgot:=MySlice{42,58,26}ok:=td.CmpArrayEach(t,got,td.Between(25,60),"checks each item of typed slice %v is in [25 .. 60]",got)fmt.Println(ok)ok=td.CmpArrayEach(t,&got,td.Between(25,60),"checks each item of typed slice pointer %v is in [25 .. 60]",got)fmt.Println(ok)// Output:// true// true
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.
t:=td.NewT(&testing.T{})got:=[3]int{42,58,26}ok:=t.ArrayEach(got,td.Between(25,60),"checks each item of array %v is in [25 .. 60]",got)fmt.Println(ok)// Output:// true
TypedArray example
t:=td.NewT(&testing.T{})typeMyArray[3]intgot:=MyArray{42,58,26}ok:=t.ArrayEach(got,td.Between(25,60),"checks each item of typed array %v is in [25 .. 60]",got)fmt.Println(ok)ok=t.ArrayEach(&got,td.Between(25,60),"checks each item of typed array pointer %v is in [25 .. 60]",got)fmt.Println(ok)// Output:// true// true
Slice example
t:=td.NewT(&testing.T{})got:=[]int{42,58,26}ok:=t.ArrayEach(got,td.Between(25,60),"checks each item of slice %v is in [25 .. 60]",got)fmt.Println(ok)// Output:// true
TypedSlice example
t:=td.NewT(&testing.T{})typeMySlice[]intgot:=MySlice{42,58,26}ok:=t.ArrayEach(got,td.Between(25,60),"checks each item of typed slice %v is in [25 .. 60]",got)fmt.Println(ok)ok=t.ArrayEach(&got,td.Between(25,60),"checks each item of typed slice pointer %v is in [25 .. 60]",got)fmt.Println(ok)// Output:// true// true