summary refs log tree commit diff stats
path: root/tests/tromans.nim
diff options
context:
space:
mode:
authorAndreas Rumpf <andreas@andreas-desktop>2009-11-16 08:38:31 +0100
committerAndreas Rumpf <andreas@andreas-desktop>2009-11-16 08:38:31 +0100
commit3710309d39f65718ab5990d53a977acb241432a9 (patch)
tree572893ca9aa111e3356a3892a4ba6729c12c6c65 /tests/tromans.nim
parent281609c358b139d55461af842ce29f39f01b2441 (diff)
downloadNim-3710309d39f65718ab5990d53a977acb241432a9.tar.gz
nimrod compiles again
Diffstat (limited to 'tests/tromans.nim')
-rwxr-xr-xtests/tromans.nim19
1 files changed, 10 insertions, 9 deletions
diff --git a/tests/tromans.nim b/tests/tromans.nim
index 89e3deba8..12deca1ea 100755
--- a/tests/tromans.nim
+++ b/tests/tromans.nim
@@ -1,5 +1,5 @@
 import
-  math, strutils
+  strutils
 
 ## Convert an integer to a Roman numeral
 # See http://en.wikipedia.org/wiki/Roman_numerals for reference
@@ -15,7 +15,7 @@ proc raiseInvalidValue(msg: string) {.noreturn.} =
 # --> No. Why introduce additional state into such a simple and nice
 # interface? State is evil. :D
 
-proc ConvertRomanToDecimal(romanVal: string): int =
+proc RomanToDecimal(romanVal: string): int =
   result = 0
   var prevVal = 0
   for i in countdown(romanVal.len - 1, 0):
@@ -36,7 +36,7 @@ proc ConvertRomanToDecimal(romanVal: string): int =
       dec(result, val)
     prevVal = val
 
-proc ConvertDecimalToRoman(decValParam: int): string =
+proc DecimalToRoman(decValParam: int): string =
   # Apparently numbers cannot be above 4000
   # Well, they can be (using overbar or parenthesis notation)
   # but I see little interest (beside coding challenge) in coding them as
@@ -55,10 +55,11 @@ proc ConvertDecimalToRoman(decValParam: int): string =
       dec(decVal, val)
       result.add(key)
 
-randomize()
-for i in 1 .. 10:
-  var rnd = 1 + random(3990)
-  var roman = ConvertDecimalToRoman(rnd)
-  var decimal = ConvertRomanToDecimal(roman)
-  echo("$# => $# => $#" % [ $rnd, roman, $decimal ])
+for i in 1..100:
+  if RomanToDecimal(DecimalToRoman(i)) != i: quit "BUG"
+
+for i in items([1238, 1777, 3830, 2401, 379, 33, 940, 3973]):
+  if RomanToDecimal(DecimalToRoman(i)) != i: quit "BUG"
+ 
+echo "success" #OUT success