mirror of
https://github.com/ollama/ollama.git
synced 2025-05-10 18:06:33 +02:00
This commit copies (without history) the bmizerany/ollama-go repository with the intention of integrating it into the ollama as a replacement for the pushing, and pulling of models, and management of the cache they are pushed and pulled from. New homes for these packages will be determined as they are integrated and we have a better understanding of proper package boundaries.
65 lines
1.1 KiB
Go
65 lines
1.1 KiB
Go
package chunks
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
)
|
|
|
|
func TestOf(t *testing.T) {
|
|
cases := []struct {
|
|
total int64
|
|
chunkSize int64
|
|
want []Chunk
|
|
}{
|
|
{0, 1, nil},
|
|
{1, 1, []Chunk{{0, 0}}},
|
|
{1, 2, []Chunk{{0, 0}}},
|
|
{2, 1, []Chunk{{0, 0}, {1, 1}}},
|
|
{10, 9, []Chunk{{0, 8}, {9, 9}}},
|
|
}
|
|
|
|
for _, tt := range cases {
|
|
got := slices.Collect(Of(tt.total, tt.chunkSize))
|
|
if !slices.Equal(got, tt.want) {
|
|
t.Errorf("[%d/%d]: got %v; want %v", tt.total, tt.chunkSize, got, tt.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSize(t *testing.T) {
|
|
cases := []struct {
|
|
c Chunk
|
|
want int64
|
|
}{
|
|
{Chunk{0, 0}, 1},
|
|
{Chunk{0, 1}, 2},
|
|
{Chunk{3, 4}, 2},
|
|
}
|
|
|
|
for _, tt := range cases {
|
|
got := tt.c.Size()
|
|
if got != tt.want {
|
|
t.Errorf("%v: got %d; want %d", tt.c, got, tt.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestCount(t *testing.T) {
|
|
cases := []struct {
|
|
total int64
|
|
chunkSize int64
|
|
want int64
|
|
}{
|
|
{0, 1, 0},
|
|
{1, 1, 1},
|
|
{1, 2, 1},
|
|
{2, 1, 2},
|
|
{10, 9, 2},
|
|
}
|
|
for _, tt := range cases {
|
|
got := Count(tt.total, tt.chunkSize)
|
|
if got != tt.want {
|
|
t.Errorf("[%d/%d]: got %d; want %d", tt.total, tt.chunkSize, got, tt.want)
|
|
}
|
|
}
|
|
}
|