From c92814440f85b23b5174e509ab53620d9342b8dc Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 10 Nov 2015 19:09:17 +0200 Subject: [PATCH] fix integer to_s and put, with tests --- lib/soml/parfait/integer.soml | 21 +++++++--- test/parfait/test_integer.rb | 72 +++++++++++++++++++++++++++++++++++ test/parfait/test_puti.rb | 16 -------- 3 files changed, 88 insertions(+), 21 deletions(-) create mode 100644 test/parfait/test_integer.rb delete mode 100644 test/parfait/test_puti.rb diff --git a/lib/soml/parfait/integer.soml b/lib/soml/parfait/integer.soml index 135e7359..19443679 100644 --- a/lib/soml/parfait/integer.soml +++ b/lib/soml/parfait/integer.soml @@ -1,20 +1,25 @@ class Integer < Value - int digit() - if_plus( self - 10) + + int as_char() + if_plus( self - 9) return 32 else Word numbers = "0123456789" - return numbers.at(self) + int index = self + 1 + return numbers.char_at(index) end end Word as_string(Word str) if_minus( self - 10 ) - int num = digit() - str = str.add_digit( num ) + int num = as_char() + str = str.push_char( num ) else int rest = self / 10 str = rest.as_string( str ) + rest = rest * 10 + rest = self - rest + str = rest.as_string(str) end return str end @@ -23,4 +28,10 @@ class Integer < Value Word start = " " return as_string( start ) end + + int puti() + Word str = self.to_s() + str.putstring() + return self + end end diff --git a/test/parfait/test_integer.rb b/test/parfait/test_integer.rb new file mode 100644 index 00000000..774256d6 --- /dev/null +++ b/test/parfait/test_integer.rb @@ -0,0 +1,72 @@ +require_relative 'helper' + +class TestPutiRT < MiniTest::Test + include RuntimeTests + + def test_as_char1 + @string_input = <