2015-11-10 18:08:48 +01:00
|
|
|
require_relative 'helper'
|
|
|
|
|
|
|
|
class TestwordRT < MiniTest::Test
|
2015-11-18 12:04:57 +01:00
|
|
|
include ParfaitTests
|
2015-11-10 18:08:48 +01:00
|
|
|
|
|
|
|
def test_len
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = <<HERE
|
2015-11-10 18:08:48 +01:00
|
|
|
Word w = " "
|
|
|
|
return w.char_length
|
|
|
|
HERE
|
2015-11-20 12:28:49 +01:00
|
|
|
check 1
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_set_len
|
|
|
|
@main = <<HERE
|
|
|
|
Word w = " "
|
|
|
|
w.set_length(2)
|
|
|
|
return w.char_length
|
|
|
|
HERE
|
|
|
|
check 2
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_set_char_len
|
|
|
|
@main = <<HERE
|
|
|
|
Word w = " "
|
|
|
|
w.set_char_at(1 , 30)
|
|
|
|
return w.char_length
|
|
|
|
HERE
|
|
|
|
check 1
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_set_char_len2
|
|
|
|
@main = <<HERE
|
|
|
|
Word w = " "
|
|
|
|
w.set_length(2)
|
|
|
|
w.set_char_at(2 , 30)
|
|
|
|
return w.char_length
|
|
|
|
HERE
|
|
|
|
check 2
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_set_char_len3
|
|
|
|
@main = <<HERE
|
|
|
|
Word w = " "
|
|
|
|
w.set_length(2)
|
|
|
|
w.set_char_at(2 , 30)
|
|
|
|
return w.get_char_at(2)
|
|
|
|
HERE
|
|
|
|
check 30
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_set_char_len4
|
|
|
|
@main = <<HERE
|
|
|
|
Word w = " "
|
|
|
|
w.set_char_at(1 , 20)
|
|
|
|
w.set_length(2)
|
|
|
|
return w.get_char_at(1)
|
|
|
|
HERE
|
|
|
|
check 20
|
2015-11-10 18:08:48 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_space
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = <<HERE
|
2015-11-10 18:08:48 +01:00
|
|
|
Word w = " "
|
2015-11-19 15:40:00 +01:00
|
|
|
return w.get_char_at(1)
|
2015-11-10 18:08:48 +01:00
|
|
|
HERE
|
|
|
|
assert_equal 32 , " ".codepoints[0] # just checking
|
2015-11-20 12:28:49 +01:00
|
|
|
check 32
|
2015-11-10 18:08:48 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_add_doesnt_change1
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = <<HERE
|
2015-11-10 18:08:48 +01:00
|
|
|
Word w = " "
|
2015-11-11 19:36:07 +01:00
|
|
|
w.push_char(48)
|
2015-11-19 15:40:00 +01:00
|
|
|
return w.get_char_at(1)
|
2015-11-10 18:08:48 +01:00
|
|
|
HERE
|
2015-11-20 12:28:49 +01:00
|
|
|
check 32
|
2015-11-10 18:08:48 +01:00
|
|
|
end
|
2015-11-19 09:09:55 +01:00
|
|
|
|
2015-11-10 18:08:48 +01:00
|
|
|
def test_after_add_get_works
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = <<HERE
|
2015-11-10 18:08:48 +01:00
|
|
|
Word w = " "
|
2015-11-11 19:36:07 +01:00
|
|
|
w.push_char(48)
|
2015-11-19 15:40:00 +01:00
|
|
|
return w.get_char_at(2)
|
2015-11-10 18:08:48 +01:00
|
|
|
HERE
|
2015-11-20 12:28:49 +01:00
|
|
|
check 48
|
2015-11-10 18:08:48 +01:00
|
|
|
end
|
2015-11-11 19:36:07 +01:00
|
|
|
|
2015-11-10 18:08:48 +01:00
|
|
|
def test_after_add_length_works
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = <<HERE
|
2015-11-10 18:08:48 +01:00
|
|
|
Word w = " "
|
|
|
|
w.push_char(32)
|
|
|
|
return w.char_length
|
|
|
|
HERE
|
2015-11-20 12:28:49 +01:00
|
|
|
check 2
|
2015-11-10 18:08:48 +01:00
|
|
|
end
|
2015-11-11 19:36:07 +01:00
|
|
|
|
|
|
|
def test_get1
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = <<HERE
|
2015-11-11 19:36:07 +01:00
|
|
|
Word w = "12345"
|
2015-11-19 15:40:00 +01:00
|
|
|
return w.get_char_at(1)
|
2015-11-11 19:36:07 +01:00
|
|
|
HERE
|
2015-11-20 12:28:49 +01:00
|
|
|
check 49
|
2015-11-11 19:36:07 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_get2
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = <<HERE
|
2015-11-11 19:36:07 +01:00
|
|
|
Word w = "12345"
|
2015-11-19 15:40:00 +01:00
|
|
|
return w.get_char_at(2)
|
2015-11-11 19:36:07 +01:00
|
|
|
HERE
|
2015-11-20 12:28:49 +01:00
|
|
|
check 50
|
2015-11-11 19:36:07 +01:00
|
|
|
end
|
2015-11-19 09:09:55 +01:00
|
|
|
|
|
|
|
def test_set2
|
|
|
|
@main = <<HERE
|
|
|
|
Word w = "12345"
|
|
|
|
w.set_char_at(2 , 51)
|
2015-11-19 15:40:00 +01:00
|
|
|
return w.get_char_at(2)
|
2015-11-19 09:09:55 +01:00
|
|
|
HERE
|
2015-11-20 12:28:49 +01:00
|
|
|
check 51
|
2015-11-19 09:09:55 +01:00
|
|
|
end
|
|
|
|
|
2015-11-20 12:28:49 +01:00
|
|
|
def test_push
|
|
|
|
@main = <<HERE
|
|
|
|
Word w = "1"
|
|
|
|
w.push_char(56)
|
|
|
|
return w.get_char_at(2)
|
|
|
|
HERE
|
|
|
|
check 56
|
|
|
|
end
|
|
|
|
def test_push1
|
|
|
|
@main = <<HERE
|
|
|
|
Word w = "1"
|
|
|
|
w.push_char(56)
|
|
|
|
return w.get_char_at(1)
|
|
|
|
HERE
|
|
|
|
check 49
|
|
|
|
end
|
|
|
|
def test_push_inlined
|
|
|
|
@main = <<HERE
|
|
|
|
Word w = "1"
|
|
|
|
int index = w.char_length + 1
|
|
|
|
w.set_length(index)
|
|
|
|
|
|
|
|
w.set_char_at(index , 56)
|
|
|
|
|
|
|
|
return w.char_length
|
|
|
|
HERE
|
|
|
|
check 2
|
|
|
|
end
|
|
|
|
def test_push_inlined2
|
|
|
|
@main = <<HERE
|
|
|
|
Word w = "1"
|
|
|
|
int index = w.char_length + 1
|
|
|
|
w.set_length(index)
|
|
|
|
|
|
|
|
return w.char_length
|
|
|
|
HERE
|
|
|
|
check 2
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_push_len
|
|
|
|
@main = <<HERE
|
|
|
|
Word w = "1"
|
|
|
|
w.push_char(56)
|
|
|
|
return w.char_length
|
|
|
|
HERE
|
|
|
|
check 2
|
|
|
|
end
|
|
|
|
def test_push3_len
|
|
|
|
@main = <<HERE
|
|
|
|
Word w = "1"
|
|
|
|
w.push_char(56)
|
|
|
|
w.push_char(56)
|
|
|
|
w.push_char(56)
|
|
|
|
return w.char_length
|
|
|
|
HERE
|
|
|
|
check 4
|
|
|
|
end
|
2015-11-10 18:08:48 +01:00
|
|
|
end
|