feat: initial release
Assisted-by: GLM 5.3 Flash
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user