Skip to content

Commit

Permalink
add some equals tests
Browse files Browse the repository at this point in the history
  • Loading branch information
suyashkumar committed Aug 9, 2024
1 parent a69ec44 commit 87f9dc9
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/frame/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ func (n *NativeFrame[I]) Equals(target INativeFrame) bool {
}
if n.Rows() != target.Rows() ||
n.Cols() != target.Cols() ||
n.BitsPerSample() != n.BitsPerSample() {
n.BitsPerSample() != target.BitsPerSample() ||
n.SamplesPerPixel() != target.SamplesPerPixel() {
return false
}

Expand Down
86 changes: 86 additions & 0 deletions pkg/frame/native_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,92 @@ func TestNativeFrame_RawDataSlice(t *testing.T) {
}
}

func TestNativeFrame_Equals(t *testing.T) {
cases := []struct {
name string
a frame.NativeFrame[int]
b frame.NativeFrame[int]
equal bool
}{
{
name: "equal",
a: frame.NativeFrame[int]{
RawData: []int{1, 2, 3},
InternalSamplesPerPixel: 2,
InternalCols: 3,
InternalRows: 4,
InternalBitsPerSample: 64,
},
b: frame.NativeFrame[int]{
RawData: []int{1, 2, 3},
InternalSamplesPerPixel: 2,
InternalCols: 3,
InternalRows: 4,
InternalBitsPerSample: 64,
},
equal: true,
},
{
name: "mismatched data",
a: frame.NativeFrame[int]{
RawData: []int{1, 2, 3},
},
b: frame.NativeFrame[int]{
RawData: []int{2, 2, 3},
},
equal: false,
},
{
name: "mismatched BitsPerSample",
a: frame.NativeFrame[int]{
InternalBitsPerSample: 2,
},
b: frame.NativeFrame[int]{
InternalBitsPerSample: 4,
},
equal: false,
},
{
name: "mismatched SamplesPerPixel",
a: frame.NativeFrame[int]{
InternalSamplesPerPixel: 2,
},
b: frame.NativeFrame[int]{
InternalSamplesPerPixel: 4,
},
equal: false,
},
{
name: "mismatched Rows",
a: frame.NativeFrame[int]{
InternalRows: 2,
},
b: frame.NativeFrame[int]{
InternalRows: 4,
},
equal: false,
},
{
name: "mismatched Cols",
a: frame.NativeFrame[int]{
InternalCols: 2,
},
b: frame.NativeFrame[int]{
InternalCols: 4,
},
equal: false,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got := tc.a.Equals(&tc.b)
if got != tc.equal {
t.Errorf("Equals(%+v, %+v) got unexpected value. got: %v, want: %v", tc.a, tc.b, got, tc.equal)
}
})
}
}

// within returns true if pt is in the []point
func within(pt point, set []point) bool {
for _, item := range set {
Expand Down

0 comments on commit 87f9dc9

Please sign in to comment.