1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
package platform
import (
"testing"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
func TestParsePossibleCPUs(t *testing.T) {
tests := []struct {
name string
input string
expected []int
}{
{
name: "Continuous Range",
input: "0-3",
expected: []int{0, 1, 2, 3},
},
{
name: "Non-Continuous Range",
input: "0-2,4,6-7",
expected: []int{0, 1, 2, 4, 6, 7},
},
{
name: "Single CPU",
input: "5",
expected: []int{5},
},
{
name: "Empty Input",
input: "",
expected: nil,
},
{
name: "Invalid Range",
input: "0-2,invalid",
expected: nil,
},
{
name: "Malformed Range",
input: "0-2-3",
expected: nil,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
result := parsePossibleCPUs(test.input)
assert.Assert(t, is.DeepEqual(result, test.expected), "Expected %v but got %v", test.expected, result)
})
}
}
|