Files
tensor/spmd/partition_test.go
T
petrbalvin af4ee19703
Release / gates (push) Successful in 4m38s
Test / test (push) Successful in 5m16s
Release / release (push) Successful in 35s
feat: initial release
Assisted-by: GLM 5.3 Flash
2026-09-03 10:00:00 +02:00

45 lines
1.3 KiB
Go

// Copyright (c) 2026 Petr Balvín <opensource@petrbalvin.org> (https://petrbalvin.org)
// SPDX-License-Identifier: MIT
package spmd
import (
"strings"
"testing"
)
// mustPartition is Partition for the tests' fixed valid arguments: the
// piece, or a failure the tests can never meet. Benchmarks pass their
// own tb.
func mustPartition(tb testing.TB, globalN, size, rank int) Span {
tb.Helper()
span, err := Partition(globalN, size, rank)
if err != nil {
tb.Fatal(err)
}
return span
}
// TestPartitionRefusesInvalidArguments: the inputs Partition refuses
// come back as errors naming the input, never as panics.
func TestPartitionRefusesInvalidArguments(t *testing.T) {
for _, tc := range []struct {
name string
globalN, size, rank int
want string
}{
{"negative global length", -1, 4, 0, "Partition of a negative global length -1"},
{"empty world", 100, 0, 0, "Partition of rank 0 in a world of 0"},
{"negative rank", 100, 4, -1, "Partition of rank -1 in a world of 4"},
{"rank past the world", 100, 4, 4, "Partition of rank 4 in a world of 4"},
} {
span, err := Partition(tc.globalN, tc.size, tc.rank)
if err == nil {
t.Fatalf("%s: Partition answered %v", tc.name, span)
}
if !strings.Contains(err.Error(), tc.want) {
t.Fatalf("%s: the error does not name the input: %v", tc.name, err)
}
}
}