check / check (push) Successful in 1m43s
An exact result outside the normal range of a double, such as 2^1200, 10^400 or 2^-1200, was refused because format wrote every result through float64. Such a result is now written from its exact value, rounded to 17 significant digits with trailing zeros dropped, through a big.Float precise enough to round as the exact value would. Results inside the range are written as before, and a power computed in float64 must still be a normal double. The tests check the written text of these results, the refusals just past the 4096-bit limit, and the time taken to write the largest and smallest numbers under it. Model: opus-5-5
41 lines
1.1 KiB
Go
41 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",
|
|
"2^1200": "1.7218479456385751e+361",
|
|
} {
|
|
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.",
|
|
"1e1300": "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)
|
|
}
|
|
}
|
|
}
|