repos
/ orchard main

orchard

mirror

Every site I host, in one repo, along with the Cloudflare Tunnel and Caddy that front them. It's all Go, Vite, and SQLite, and it runs on a desktop at home with nothing listening on an inbound port.

blogbuncaddycloudflare-tunneldockergogolanghomelabhtml-templatemonorepoself-hostedseosqlitestatic-sitetypstuptime-monitoringviteweb-analytics

1.3 KB · 55 lines · Go Raw History
 1package skills
 2
 3import "testing"
 4
 5func TestCalculator(t *testing.T) {
 6	ok := []struct {
 7		in   string
 8		want string
 9	}{
10		{"30*27", "810"},
11		{"what is 30 * 27", "810"},
12		{"30 times 27?", "810"},
13		{"1,234 + 766", "2,000"},
14		{"2^10", "1,024"},
15		{"(3+4)*5", "35"},
16		{"10/4", "2.5"},
17		{"what's 15% of 200", "30"},
18		{"100 - 250", "-150"},
19		{"7 % 3", "1"},
20		{"2^3^2", "512"}, // right associative
21		{"-5 + 3", "-2"},
22		{"1000000*1000", "1,000,000,000"},
23	}
24	for _, c := range ok {
25		got, hit := TryCalculate(c.in)
26		if !hit {
27			t.Errorf("%q: not recognised as arithmetic", c.in)
28			continue
29		}
30		if got.Pretty != c.want {
31			t.Errorf("%q = %s, want %s", c.in, got.Pretty, c.want)
32		}
33	}
34
35	// The important half: things that must go to the web instead. A calculator
36	// that guesses at these is worse than no calculator.
37	no := []string{
38		"what is the deepest river in the US",
39		"how do i make a breakfast burrito",
40		"5 star hotels in paris",
41		"42",              // a bare number is not a question
42		"go 1.24 release", // version numbers are not arithmetic
43		"3 +",
44		"(3+4",
45		"10/0",
46		"what is sqlite wal mode",
47		"top 10 go projects 2026",
48	}
49	for _, q := range no {
50		if got, hit := TryCalculate(q); hit {
51			t.Errorf("%q was answered as arithmetic: %s", q, got.Pretty)
52		}
53	}
54}