154 lines
5.1 KiB
Go
154 lines
5.1 KiB
Go
|
package meta
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestPlan_EvenStride_Full(t *testing.T) {
|
||
|
params := Params{
|
||
|
Size: 18,
|
||
|
Stride: 2,
|
||
|
Shards: 3,
|
||
|
Parity: 2,
|
||
|
}
|
||
|
|
||
|
expected := []ChunkShardMeta{
|
||
|
ChunkShardMeta{Shard: 3, ShardOffset: 1, Chunk: 0, ChunkOffset: 3, GlobalOffset: 7, Size: 1},
|
||
|
ChunkShardMeta{Shard: 4, ShardOffset: 0, Chunk: 1, ChunkOffset: 2, GlobalOffset: 8, Size: 2},
|
||
|
ChunkShardMeta{Shard: 5, ShardOffset: 0, Chunk: 2, ChunkOffset: 2, GlobalOffset: 10, Size: 2},
|
||
|
ChunkShardMeta{Shard: 6, ShardOffset: 0, Chunk: 0, ChunkOffset: 4, GlobalOffset: 12, Size: 2},
|
||
|
}
|
||
|
actual := params.Plan(7, 7)
|
||
|
|
||
|
if len(actual) != len(expected) {
|
||
|
t.Errorf(`Expected output to have length of %x, got %x`, len(expected), len(actual))
|
||
|
}
|
||
|
|
||
|
for i, actualItem := range actual {
|
||
|
if fmt.Sprintf("%#v", actualItem) != fmt.Sprintf("%#v", expected[i]) {
|
||
|
t.Errorf("Expected \n%#v to equal \n%#v at %d", actualItem, expected[i], i)
|
||
|
} else {
|
||
|
// fmt.Printf("ok: %#v\n", actualItem)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestPlan_EvenStride_Short2(t *testing.T) {
|
||
|
params := Params{
|
||
|
Size: 16,
|
||
|
Stride: 2,
|
||
|
Shards: 3,
|
||
|
Parity: 2,
|
||
|
}
|
||
|
|
||
|
expected := []ChunkShardMeta{
|
||
|
ChunkShardMeta{Shard: 3, ShardOffset: 1, Chunk: 0, ChunkOffset: 3, GlobalOffset: 7, Size: 1},
|
||
|
ChunkShardMeta{Shard: 4, ShardOffset: 0, Chunk: 1, ChunkOffset: 2, GlobalOffset: 8, Size: 2},
|
||
|
ChunkShardMeta{Shard: 5, ShardOffset: 0, Chunk: 2, ChunkOffset: 2, GlobalOffset: 10, Size: 2},
|
||
|
ChunkShardMeta{Shard: 6, ShardOffset: 0, Chunk: 0, ChunkOffset: 4, GlobalOffset: 12, Size: 2},
|
||
|
}
|
||
|
actual := params.Plan(7, 7)
|
||
|
|
||
|
if len(actual) != len(expected) {
|
||
|
t.Errorf(`Expected output to have length of %x, got %x`, len(expected), len(actual))
|
||
|
}
|
||
|
|
||
|
for i, actualItem := range actual {
|
||
|
if fmt.Sprintf("%#v", actualItem) != fmt.Sprintf("%#v", expected[i]) {
|
||
|
t.Errorf(`Expected %#v to equal %#v at %d`, actualItem, expected[i], i)
|
||
|
} else {
|
||
|
// fmt.Printf("ok: %#v\n", actualItem)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestPlan_EvenStride_Short1(t *testing.T) {
|
||
|
params := Params{
|
||
|
Size: 17,
|
||
|
Stride: 2,
|
||
|
Shards: 3,
|
||
|
Parity: 2,
|
||
|
}
|
||
|
|
||
|
expected := []ChunkShardMeta{
|
||
|
ChunkShardMeta{Shard: 3, ShardOffset: 1, Chunk: 0, ChunkOffset: 3, GlobalOffset: 7, Size: 1},
|
||
|
ChunkShardMeta{Shard: 4, ShardOffset: 0, Chunk: 1, ChunkOffset: 2, GlobalOffset: 8, Size: 2},
|
||
|
ChunkShardMeta{Shard: 5, ShardOffset: 0, Chunk: 2, ChunkOffset: 2, GlobalOffset: 10, Size: 2},
|
||
|
ChunkShardMeta{Shard: 6, ShardOffset: 0, Chunk: 0, ChunkOffset: 4, GlobalOffset: 12, Size: 2},
|
||
|
}
|
||
|
actual := params.Plan(7, 7)
|
||
|
|
||
|
if len(actual) != len(expected) {
|
||
|
t.Errorf(`Expected output to have length of %x, got %x`, len(expected), len(actual))
|
||
|
}
|
||
|
|
||
|
for i, actualItem := range actual {
|
||
|
if fmt.Sprintf("%#v", actualItem) != fmt.Sprintf("%#v", expected[i]) {
|
||
|
t.Errorf(`Expected %#v to equal %#v at %d`, actualItem, expected[i], i)
|
||
|
} else {
|
||
|
// fmt.Printf("ok: %#v\n", actualItem)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestPlan_OddStride_Short1(t *testing.T) {
|
||
|
params := Params{
|
||
|
Size: 13,
|
||
|
Stride: 2,
|
||
|
Shards: 3,
|
||
|
Parity: 2,
|
||
|
}
|
||
|
|
||
|
expected := []ChunkShardMeta{
|
||
|
ChunkShardMeta{Shard: 3, ShardOffset: 1, Chunk: 0, ChunkOffset: 3, GlobalOffset: 7, Size: 1},
|
||
|
ChunkShardMeta{Shard: 4, ShardOffset: 0, Chunk: 1, ChunkOffset: 2, GlobalOffset: 8, Size: 2},
|
||
|
ChunkShardMeta{Shard: 5, ShardOffset: 0, Chunk: 2, ChunkOffset: 2, GlobalOffset: 10, Size: 2},
|
||
|
ChunkShardMeta{Shard: 6, ShardOffset: 0, Chunk: 0, ChunkOffset: 4, GlobalOffset: 12, Size: 1},
|
||
|
ChunkShardMeta{Shard: 7, ShardOffset: 0, Chunk: 1, ChunkOffset: 4, GlobalOffset: 13, Size: 1},
|
||
|
}
|
||
|
actual := params.Plan(7, 7)
|
||
|
|
||
|
if len(actual) != len(expected) {
|
||
|
t.Errorf(`Expected output to have length of %x, got %x`, len(expected), len(actual))
|
||
|
}
|
||
|
|
||
|
for i, actualItem := range actual {
|
||
|
if fmt.Sprintf("%#v", actualItem) != fmt.Sprintf("%#v", expected[i]) {
|
||
|
t.Errorf(`Expected %#v to equal %#v at %d`, actualItem, expected[i], i)
|
||
|
} else {
|
||
|
// fmt.Printf("ok: %#v\n", actualItem)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestPlan_OddStride_Full(t *testing.T) {
|
||
|
params := Params{
|
||
|
Size: 14,
|
||
|
Stride: 2,
|
||
|
Shards: 3,
|
||
|
Parity: 2,
|
||
|
}
|
||
|
|
||
|
expected := []ChunkShardMeta{
|
||
|
ChunkShardMeta{Shard: 3, ShardOffset: 1, Chunk: 0, ChunkOffset: 3, GlobalOffset: 7, Size: 1},
|
||
|
ChunkShardMeta{Shard: 4, ShardOffset: 0, Chunk: 1, ChunkOffset: 2, GlobalOffset: 8, Size: 2},
|
||
|
ChunkShardMeta{Shard: 5, ShardOffset: 0, Chunk: 2, ChunkOffset: 2, GlobalOffset: 10, Size: 2},
|
||
|
ChunkShardMeta{Shard: 6, ShardOffset: 0, Chunk: 0, ChunkOffset: 4, GlobalOffset: 12, Size: 1},
|
||
|
ChunkShardMeta{Shard: 7, ShardOffset: 0, Chunk: 1, ChunkOffset: 4, GlobalOffset: 13, Size: 1},
|
||
|
}
|
||
|
actual := params.Plan(7, 7)
|
||
|
|
||
|
if len(actual) != len(expected) {
|
||
|
t.Errorf(`Expected output to have length of %x, got %x`, len(expected), len(actual))
|
||
|
}
|
||
|
|
||
|
for i, actualItem := range actual {
|
||
|
if fmt.Sprintf("%#v", actualItem) != fmt.Sprintf("%#v", expected[i]) {
|
||
|
t.Errorf(`Expected %#v to equal %#v at %d`, actualItem, expected[i], i)
|
||
|
} else {
|
||
|
// fmt.Printf("ok: %#v\n", actualItem)
|
||
|
}
|
||
|
}
|
||
|
}
|