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.
98 lines
3.1 KiB
Go
98 lines
3.1 KiB
Go
package chart
|
|
|
|
import (
|
|
"compress/gzip"
|
|
"encoding/json"
|
|
"fmt"
|
|
"math"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
// Golden values come from the pinned d3-scale version recorded in the
|
|
// fixture, generated by scripts/chart-scales-golden.ts with Node.
|
|
func TestNonlinearMatchesD3(t *testing.T) {
|
|
f, err := os.Open("testdata/nonlinear_d3.json.gz")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer f.Close()
|
|
z, err := gzip.NewReader(f)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer z.Close()
|
|
var golden struct {
|
|
Version string
|
|
Cases []struct {
|
|
Kind string
|
|
Domain [2]float64
|
|
Parameter float64
|
|
Count int
|
|
Clamp bool
|
|
Values, Positions, Fractions, Inversions, Ticks []float64
|
|
Nice [2]float64
|
|
}
|
|
}
|
|
if err := json.NewDecoder(z).Decode(&golden); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if golden.Version != "4.0.2" || len(golden.Cases) == 0 {
|
|
t.Fatalf("invalid d3-scale reference: version %q, %d cases", golden.Version, len(golden.Cases))
|
|
}
|
|
t.Logf("%d d3-scale %s cases", len(golden.Cases), golden.Version)
|
|
near := func(a, b float64) bool {
|
|
return math.Abs(a-b) <= max(4*math.SmallestNonzeroFloat64, 1e-9*math.Abs(b))
|
|
}
|
|
for i, c := range golden.Cases {
|
|
t.Run(fmt.Sprintf("%s/%d", c.Kind, i), func(t *testing.T) {
|
|
var at func(float64) float32
|
|
var invert func(float32) float64
|
|
var ts []Tick
|
|
var nice [2]float64
|
|
if c.Kind == "log" {
|
|
s := NewLog(c.Domain[0], c.Domain[1])
|
|
s.Base, s.Clamp = c.Parameter, c.Clamp
|
|
at, invert, ts = s.At, s.Invert, s.Ticks(c.Count)
|
|
n := s.Nice()
|
|
nice = [2]float64{n.Lo, n.Hi}
|
|
} else {
|
|
s := NewSymLog(c.Domain[0], c.Domain[1])
|
|
s.Constant, s.Clamp = c.Parameter, c.Clamp
|
|
at, invert, ts = s.At, s.Invert, s.Ticks(c.Count)
|
|
n := s.Nice(c.Count)
|
|
nice = [2]float64{n.Lo, n.Hi}
|
|
}
|
|
for j, v := range c.Values {
|
|
if got := float64(at(v)); !finiteScale(got) || math.Abs(got-c.Positions[j]) > 2e-6 {
|
|
t.Fatalf("At(%v)=%v want %v; %+v", v, got, c.Positions[j], c)
|
|
}
|
|
}
|
|
for j, f := range c.Fractions {
|
|
if got := invert(float32(f)); !near(got, c.Inversions[j]) {
|
|
t.Fatalf("Invert(%v)=%v want %v; domain %v, parameter %v", f, got, c.Inversions[j], c.Domain, c.Parameter)
|
|
}
|
|
}
|
|
// D3 omits the tick of a constant log domain for noninteger
|
|
// bases; keep that value, as the other MyGo scales do.
|
|
wantTicks := c.Ticks
|
|
if c.Kind == "log" && c.Domain[0] == c.Domain[1] && len(wantTicks) == 0 {
|
|
wantTicks = []float64{c.Domain[0]}
|
|
}
|
|
if len(ts) != len(wantTicks) {
|
|
t.Fatalf("Ticks(%d)=%v want %v; domain %v, base %v", c.Count, tickValues(ts), wantTicks, c.Domain, c.Parameter)
|
|
}
|
|
for j, tick := range ts {
|
|
if !near(tick.Value, wantTicks[j]) {
|
|
t.Fatalf("tick %d=%v want %v", j, tick.Value, wantTicks[j])
|
|
}
|
|
}
|
|
for j, n := range nice {
|
|
if !near(n, c.Nice[j]) {
|
|
t.Fatalf("Nice=%v want %v; domain %v, parameter %v", nice, c.Nice, c.Domain, c.Parameter)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|