Switch from Asuka to MyGo, keeping the API client and the feature set: - servers: saved servers, passwordless and password login, proxy, self-signed certificates, per-server device tokens (Keystore), connect form, instance list sheet with switch/disconnect - sessions: virtualized list, search, new session, rename/archive/delete, running indicator, event stream keeps it live - chat: pushed window with system back bar, streaming Markdown via ui/markdown, reasoning and tool rows with image previews, footer menu (read aloud via a Kotlin TTS plugin, copy, fork), user message menu (copy, revert, fork), context usage ring and detail sheet, attachments (photos/files via the document picker), permissions - release builds allow plain http:// LAN servers (Go's net/http dials directly, no cleartext manifest needed) - a local fork of MyGo (third_party/mygo) lowers the Android host's minSdk to 24 (Android 7.0); Go 1.27.4 via mise Version 0.3.0.
85 lines
2.8 KiB
Go
85 lines
2.8 KiB
Go
package chart
|
|
|
|
import (
|
|
"math"
|
|
"slices"
|
|
"testing"
|
|
)
|
|
|
|
func TestMinMax(t *testing.T) {
|
|
nan := float32(math.NaN())
|
|
for _, tc := range []struct {
|
|
name string
|
|
xs, ys []float32
|
|
width int
|
|
indices []int
|
|
}{
|
|
{"extrema order", []float32{0, .01, .02, .03, .04, .05, .06}, []float32{3, 8, 2, 9, 0, 4, 5}, 1, []int{0, 3, 4, 6}},
|
|
{"two per bucket", []float32{0, .1, .2, .3, .4, .5, .6, .7, .8, .9}, []float32{2, 0, 4, 3, 2, 2, 0, 4, 3, 2}, 2, []int{0, 1, 2, 6, 7, 9}},
|
|
{"sparse", []float32{0, .3, .6, 1}, []float32{1, 2, 3, 4}, 100, []int{0, 1, 2, 3}},
|
|
{"duplicate x", []float32{.5, .5, .5, .5, .5}, []float32{2, 0, 3, 1, 2}, 10, []int{0, 1, 2, 4}},
|
|
{"edges", []float32{-2, -1, 0, .5, 1, 2, 3}, []float32{0, 1, 2, 3, 4, 5, 6}, 10, []int{1, 2, 3, 4, 5}},
|
|
{"crossing viewport", []float32{-2, -1, 2, 3}, []float32{0, 1, 2, 3}, 10, []int{1, 2}},
|
|
{"outside left", []float32{-2, -1}, []float32{0, 1}, 10, nil},
|
|
{"outside right", []float32{2, 3}, []float32{0, 1}, 10, nil},
|
|
{"empty", nil, nil, 10, nil},
|
|
{"zero width", []float32{0}, []float32{0}, 0, nil},
|
|
{"length mismatch", []float32{0, .5, 1}, []float32{1, 2}, 10, []int{0, 1}},
|
|
{"constant", []float32{0, .01, .02, .03}, []float32{1, 1, 1, 1}, 1, []int{0, 3}},
|
|
{"gap", []float32{0, .1, .2, .3, .4}, []float32{1, 2, nan, 3, 4}, 1, []int{0, 1, -1, 3, 4}},
|
|
{"infinity", []float32{0, .1, .2}, []float32{1, float32(math.Inf(1)), 2}, 1, []int{0, -1, 2}},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
x, y := MinMax(nil, nil, tc.xs, tc.ys, tc.width)
|
|
if len(x) != len(tc.indices) || len(y) != len(x) {
|
|
t.Fatalf("got %v %v", x, y)
|
|
}
|
|
for j, i := range tc.indices {
|
|
if i < 0 {
|
|
if !math.IsNaN(float64(x[j])) || !math.IsNaN(float64(y[j])) {
|
|
t.Fatal("missing break")
|
|
}
|
|
continue
|
|
}
|
|
if x[j] != tc.xs[i] || y[j] != tc.ys[i] {
|
|
t.Fatalf("point %d: %v %v", j, x, y)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestMinMaxReuseAndDensity(t *testing.T) {
|
|
xs, ys := make([]float32, 15000), make([]float32, 15000)
|
|
for i := range xs {
|
|
xs[i] = float32(i) / 14999
|
|
ys[i] = float32(math.Sin(float64(i)))
|
|
}
|
|
dx, dy := make([]float32, 0, 15000), make([]float32, 0, 15000)
|
|
if a := testing.AllocsPerRun(20, func() { dx, dy = MinMax(dx, dy, xs, ys, 1280) }); a != 0 {
|
|
t.Fatalf("%v allocations", a)
|
|
}
|
|
first := slices.Clone(dx)
|
|
dx, dy = MinMax(dx, dy, xs, ys, 2560)
|
|
if len(dx) <= len(first) || len(dx) > 2*2560+3 {
|
|
t.Fatal("wrong density", len(dx), len(first))
|
|
}
|
|
}
|
|
|
|
// BenchmarkMinMax reduces 45,000 samples into physical pixel buckets, reusing output.
|
|
func BenchmarkMinMax(b *testing.B) {
|
|
xs, ys := make([]float32, 15000), make([]float32, 15000)
|
|
for i := range xs {
|
|
xs[i] = float32(i) / 14999
|
|
ys[i] = float32(math.Sin(float64(i)))
|
|
}
|
|
var dx, dy []float32
|
|
dx, dy = MinMax(dx, dy, xs, ys, 1280)
|
|
b.ReportAllocs()
|
|
for b.Loop() {
|
|
for range 3 {
|
|
dx, dy = MinMax(dx, dy, xs, ys, 1280)
|
|
}
|
|
}
|
|
}
|