fix some word with tests

This commit is contained in:
Torsten Ruger 2015-11-10 19:08:48 +02:00
parent 6c2ce66bfc
commit 760a4beb86
2 changed files with 60 additions and 3 deletions

View File

@ -1,9 +1,19 @@
class Word < Object
int at(int index)
int char_at(int index)
index = index + 2
return get_internal(index)
end
Word add_digit( int i)
int l = self.char_length + 2
int set_length(int i)
set_internal( 2 , i)
return i
end
Word push_char(int i)
int l = self.char_length + 1
self.set_length(l)
l = l + 2
set_internal( l , i)
return self
end

47
test/parfait/test_word.rb Normal file
View File

@ -0,0 +1,47 @@
require_relative 'helper'
class TestwordRT < MiniTest::Test
include RuntimeTests
def test_len
@string_input = <<HERE
Word w = " "
return w.char_length
HERE
check_return 1
end
def test_space
@string_input = <<HERE
Word w = " "
return w.char_at(1)
HERE
assert_equal 32 , " ".codepoints[0] # just checking
check_return 32
end
def test_add_doesnt_change1
@string_input = <<HERE
Word w = " "
w.push_char(32)
return w.char_at(1)
HERE
check_return 32
end
def test_after_add_get_works
@string_input = <<HERE
Word w = " "
w.push_char(32)
return w.char_at(2)
HERE
check_return 32
end
def test_after_add_length_works
@string_input = <<HERE
Word w = " "
w.push_char(32)
return w.char_length
HERE
check_return 2
end
end