MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / TestRomanToInt

Function TestRomanToInt

conversion/romantoint_test.go:24–46  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22}
23
24func TestRomanToInt(t *testing.T) {
25 for input, expected := range romanTestCases {
26 out, err := RomanToInt(input)
27 if err != nil {
28 t.Errorf("RomanToInt(%s) returned an error %s", input, err.Error())
29 }
30 if out != expected {
31 t.Errorf("RomanToInt(%s) = %d; want %d", input, out, expected)
32 }
33 }
34 _, err := RomanToInt("IVCMXCIX")
35 if err == nil {
36 t.Error("RomanToInt(IVCMXCIX) expected an error")
37 }
38
39 val, err := RomanToInt("")
40 if val != 0 {
41 t.Errorf("RomanToInt(\"\") = %d; want 0", val)
42 }
43 if err != nil {
44 t.Errorf("RomanToInt(\"\") returned an error %s", err.Error())
45 }
46}
47
48func BenchmarkRomanToInt(b *testing.B) {
49 b.ReportAllocs()

Callers

nothing calls this directly

Calls 1

RomanToIntFunction · 0.85

Tested by

no test coverage detected