Skip to content

Instantly share code, notes, and snippets.

@nobiinu-and
Created April 15, 2017 14:26
Show Gist options
  • Save nobiinu-and/00fd02976074e48f77ab9ac175ccb052 to your computer and use it in GitHub Desktop.
Save nobiinu-and/00fd02976074e48f77ab9ac175ccb052 to your computer and use it in GitHub Desktop.
ローマ数字の計算機のElmコード。Assert関数は自前で用意。モブプログラミングでTDDで書いたもの。アジャイルジャパン2017にて / Roman Numerals Calculator elm code written in a mob programming session in TDD way at Ajile Japan 2017
import Html exposing (li, text, ul)
import String exposing (split)
add a b =
numberToRoman ((romanToNumber a) + (romanToNumber b))
romanToNumber roman =
List.length(split "" roman)
{- case roman of
"I" -> 1
"II" -> 2
"III" -> 3
"IV" -> 4
_ -> -1
-}
numberToRoman number =
case number of
1 -> "I"
2 -> "II"
3 -> "III"
4 ->"IV"
_ -> ""
assert a b =
if a == b then "ok" else "ng"
main =
ul []
[ li [] [text (assert (romanToNumber "I") 1)]
, li [] [text (assert (romanToNumber "II") 2)]
, li [] [text (assert (romanToNumber "IV") 4)]
, li [] [text (assert (numberToRoman 1) "I")]
, li [] [text (assert (add "I" "I") "II")]
, li [] [text (assert (add "I" "II") "III")]
, li [] [text (assert (add "II" "II") "IV")]
, li [] [text (assert )]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment