package svg import ( "math" "regexp" "strconv" "strings" "testing" "time" ) func TestLocalSolarEclipseSVG(t *testing.T) { svg, ok := LocalSolarEclipseSVG( time.Date(2024, 4, 8, 12, 0, 0, 0, time.UTC), -96.7970, 32.7767, 0, LocalSolarEclipseSVGOptions{Width: 640, Height: 480, Step: 5 * time.Minute}, ) if !ok { t.Fatalf("expected local solar eclipse SVG") } for _, want := range []string{"`) matches := re.FindAllStringSubmatch(svg, -1) if got, want := len(matches), 5; got != want { t.Fatalf("stage sun count = %d, want %d", got, want) } first, err := strconv.ParseFloat(matches[0][1], 64) if err != nil { t.Fatalf("parse first radius: %v", err) } for i := 1; i < len(matches); i++ { radius, err := strconv.ParseFloat(matches[i][1], 64) if err != nil { t.Fatalf("parse radius %d: %v", i, err) } if math.Abs(radius-first) > 1e-9 { t.Fatalf("stage panel radii differ: first=%f current=%f", first, radius) } } } func TestLocalSolarEclipseSVGNoEvent(t *testing.T) { _, ok := LocalSolarEclipseSVG( time.Date(2024, 5, 15, 12, 0, 0, 0, time.UTC), -96.7970, 32.7767, 0, LocalSolarEclipseSVGOptions{}, ) if ok { t.Fatalf("unexpected local solar eclipse SVG for no-event date") } }