summary refs log tree commit diff stats
path: root/tests/accept/run/tromans.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-11-19 15:45:51 +0100
committerAraq <rumpf_a@web.de>2011-11-19 15:45:51 +0100
commita274f3bf5be3fc35f1538e5aab0e32fb9ed2ff82 (patch)
tree95dc5bf7fe3716a3ab266f78094fccce38c94ccf /tests/accept/run/tromans.nim
parentd0772feb08baaea12bfdad0a7c20a41733f977bd (diff)
downloadNim-a274f3bf5be3fc35f1538e5aab0e32fb9ed2ff82.tar.gz
got rid of 'accept' dir in the tests
Diffstat (limited to 'tests/accept/run/tromans.nim')
-rwxr-xr-xtests/accept/run/tromans.nim71
1 files changed, 0 insertions, 71 deletions
diff --git a/tests/accept/run/tromans.nim b/tests/accept/run/tromans.nim
deleted file mode 100755
index fa6a63595..000000000
--- a/tests/accept/run/tromans.nim
+++ /dev/null
@@ -1,71 +0,0 @@
-discard """
-  file: "tromans.nim"
-  output: "success"
-"""
-import
-  strutils
-
-## Convert an integer to a Roman numeral
-# See http://en.wikipedia.org/wiki/Roman_numerals for reference
-
-proc raiseInvalidValue(msg: string) {.noreturn.} =
-  # Yes, we really need a shorthand for this code...
-  var e: ref EInvalidValue
-  new(e)
-  e.msg = msg
-  raise e
-
-# I should use a class, perhaps.
-# --> No. Why introduce additional state into such a simple and nice
-# interface? State is evil. :D
-
-proc RomanToDecimal(romanVal: string): int =
-  result = 0
-  var prevVal = 0
-  for i in countdown(romanVal.len - 1, 0):
-    var val = 0
-    case romanVal[i]
-    of 'I', 'i': val = 1
-    of 'V', 'v': val = 5
-    of 'X', 'x': val = 10
-    of 'L', 'l': val = 50
-    of 'C', 'c': val = 100
-    of 'D', 'd': val = 500
-    of 'M', 'm': val = 1000
-    else: raiseInvalidValue("Incorrect character in roman numeral! (" & 
-                            $romanVal[i] & ")")
-    if val >= prevVal:
-      inc(result, val)
-    else:
-      dec(result, val)
-    prevVal = val
-
-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
-  # we rarely use huge Roman numeral.
-  const romanComposites = [
-    ("M", 1000), ("CM", 900),
-    ("D", 500), ("CD", 400), ("C", 100),
-    ("XC", 90), ("L", 50), ("XL", 40), ("X", 10), ("IX", 9),
-    ("V", 5), ("IV", 4), ("I", 1)]     
-  if decValParam < 1 or decValParam > 3999:
-    raiseInvalidValue("number not representable")
-  result = ""
-  var decVal = decValParam
-  for key, val in items(romanComposites):
-    while decVal >= val:
-      dec(decVal, val)
-      result.add(key)
-
-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
-
-
-