From 6e5c7cbb5923f7627abc3b720600b6f1df718132 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sun, 28 Aug 2016 02:36:40 +0200 Subject: Solve roman --- go/roman-numerals/roman_numerals_test.go | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 go/roman-numerals/roman_numerals_test.go (limited to 'go/roman-numerals/roman_numerals_test.go') diff --git a/go/roman-numerals/roman_numerals_test.go b/go/roman-numerals/roman_numerals_test.go new file mode 100644 index 0000000..637e52e --- /dev/null +++ b/go/roman-numerals/roman_numerals_test.go @@ -0,0 +1,39 @@ +package romannumerals + +import "testing" + +const targetTestVersion = 2 + +func TestRomanNumerals(t *testing.T) { + if testVersion != targetTestVersion { + t.Fatalf("Found testVersion = %v, want %v", testVersion, targetTestVersion) + } + tc := append(romanNumeralTests, []romanNumeralTest{ + {0, "", true}, + {-1, "", true}, + {4000, "", true}, + {3999, "MMMCMXCIX", false}, + }...) + for _, test := range tc { + actual, err := ToRomanNumeral(test.arabic) + if err == nil && test.hasError { + t.Errorf("ToRomanNumeral(%d) should return an error.", test.arabic) + continue + } + if err != nil && !test.hasError { + t.Errorf("ToRomanNumeral(%d) should not return an error.", test.arabic) + continue + } + if actual != test.roman { + t.Errorf("ToRomanNumeral(%d): %s, expected %s", test.arabic, actual, test.roman) + } + } +} + +func BenchmarkRomanNumerals(b *testing.B) { + for i := 0; i < b.N; i++ { + for _, test := range romanNumeralTests { + ToRomanNumeral(test.arabic) + } + } +} -- cgit v1.2.3