-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BE-586 | Add tests for slices, orderbook packages
- Loading branch information
1 parent
3d1c9b6
commit c548460
Showing
3 changed files
with
174 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package slices_test | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/osmosis-labs/sqs/domain/slices" | ||
) | ||
|
||
func TestSplit(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input []int | ||
size int | ||
expected [][]int | ||
}{ | ||
{ | ||
name: "empty slice", | ||
input: []int{}, | ||
size: 3, | ||
expected: nil, | ||
}, | ||
{ | ||
name: "slice smaller than chunk size", | ||
input: []int{1, 2}, | ||
size: 3, | ||
expected: [][]int{{1, 2}}, | ||
}, | ||
{ | ||
name: "slice equal to chunk size", | ||
input: []int{1, 2, 3}, | ||
size: 3, | ||
expected: [][]int{{1, 2, 3}}, | ||
}, | ||
{ | ||
name: "slice larger than chunk size", | ||
input: []int{1, 2, 3, 4, 5}, | ||
size: 2, | ||
expected: [][]int{{1, 2}, {3, 4}, {5}}, | ||
}, | ||
{ | ||
name: "slice multiple of chunk size", | ||
input: []int{1, 2, 3, 4, 5, 6}, | ||
size: 2, | ||
expected: [][]int{{1, 2}, {3, 4}, {5, 6}}, | ||
}, | ||
{ | ||
name: "chunk size of 1", | ||
input: []int{1, 2, 3}, | ||
size: 1, | ||
expected: [][]int{{1}, {2}, {3}}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result := slices.Split(tt.input, tt.size) | ||
if !reflect.DeepEqual(result, tt.expected) { | ||
t.Errorf("Split(%v, %d) = %v, want %v", tt.input, tt.size, result, tt.expected) | ||
} | ||
}) | ||
} | ||
} |