Files
simplexcalc/internal/bot/bot_test.go
T
clawbot a1125e59dd
check / check (push) Successful in 1m4s
Refuse numbers a double cannot hold; exact powers up to the limit (closes #3)
A power computed in float64 is refused unless its base and its result
are normal doubles, and so is a result other than zero that is not one:
below about 2.2e-308 a double keeps fewer digits, and at 0 or infinity
none. A literal that go/constant reads as 0 though it is not, such as
1e-999999999, is refused too.

A whole exponent up to 4096 either way is computed exactly and kept
when go/constant holds the result exactly, so 2^-1400 is exact.

ErrTooLarge becomes ErrOutOfRange, and its reply, "That needs a number
too large or too small for me.", is true of both.

Model: opus-5-5
2026-09-29 01:23:40 +00:00

40 lines
1.1 KiB
Go

package bot_test
import (
"strings"
"testing"
"sneak.berlin/go/simplexcalc/internal/bot"
"sneak.berlin/go/simplexcalc/internal/calc"
)
// TestReply: a result is sent bare, and every way of failing gets its
// own short explanation rather than silence.
func TestReply(t *testing.T) {
t.Parallel()
for in, want := range map[string]string{
"2 + 2": "4",
"5 * 5/2": "12.5",
"2^10": "1024",
"7 % 3": "1",
} {
if got := bot.Reply(in); got != want {
t.Errorf("Reply(%q) = %q, want %q", in, got, want)
}
}
for in, want := range map[string]string{
"hello": "I only understand arithmetic",
"1 / 0": "I cannot divide by zero.",
"1e400": "That needs a number too large or too small for me.",
"1e-1300": "That needs a number too large or too small for me.",
"(-8)^0.5": "A negative number to a fractional power has no real",
strings.Repeat("1+", calc.MaxInputLength) + "1": "That is too long for me",
} {
if got := bot.Reply(in); !strings.HasPrefix(got, want) {
t.Errorf("Reply(%q) = %q, want it to start %q", in, got, want)
}
}
}