From 6ea698d397fac2bb7ccc87e1c7445bffc701d220 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 8 Nov 2015 14:30:42 +0200 Subject: [PATCH] save some to_s code --- lib/soml/parfait/integer.soml | 35 ++++++++++++++ test/interpreter/test_puti.rb | 91 ----------------------------------- test/parfait/test_puti.rb | 15 ++++++ 3 files changed, 50 insertions(+), 91 deletions(-) create mode 100644 lib/soml/parfait/integer.soml delete mode 100644 test/interpreter/test_puti.rb create mode 100644 test/parfait/test_puti.rb diff --git a/lib/soml/parfait/integer.soml b/lib/soml/parfait/integer.soml new file mode 100644 index 00000000..4a5bb5a8 --- /dev/null +++ b/lib/soml/parfait/integer.soml @@ -0,0 +1,35 @@ +class Integer < Value + Word digit( int rest ) + if_zero( rest == 5 ) + return "5" + end + if_zero( rest == 1 ) + return "1" + end + if_zero( rest == 2 ) + return "2" + end + if_zero( rest == 3 ) + return "3" + end + if_zero( rest == 4 ) + return "4" + end + end + Word add_string(Word str) + int div + div = self / 10 + int rest + rest = self - div + if_notzero( rest ) + rest = self.digit( rest ) + else + str = div.add_string(str) + end + return str + end + Word to_string() + Word start = " " + return add_string( start ) + end +end diff --git a/test/interpreter/test_puti.rb b/test/interpreter/test_puti.rb deleted file mode 100644 index 1e72d754..00000000 --- a/test/interpreter/test_puti.rb +++ /dev/null @@ -1,91 +0,0 @@ -require_relative "helper" - -class AddTest < MiniTest::Test - include Ticker - include AST::Sexp - - def test_puti - @string_input = <