all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
26
Task/Test-a-function/Ruby/test-a-function-1.rb
Normal file
26
Task/Test-a-function/Ruby/test-a-function-1.rb
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
def palindrome?(s)
|
||||
s == s.reverse
|
||||
end
|
||||
|
||||
require 'test/unit'
|
||||
class MyTests < Test::Unit::TestCase
|
||||
def test_palindrome_ok
|
||||
assert(palindrome? "aba")
|
||||
end
|
||||
|
||||
def test_palindrome_nok
|
||||
assert_equal(false, palindrome?("ab"))
|
||||
end
|
||||
|
||||
def test_object_without_reverse
|
||||
assert_raise(NoMethodError) {palindrome? 42}
|
||||
end
|
||||
|
||||
def test_wrong_number_args
|
||||
assert_raise(ArgumentError) {palindrome? "a", "b"}
|
||||
end
|
||||
|
||||
def test_show_failing_test
|
||||
assert(palindrome?("ab"), "this test case fails on purpose")
|
||||
end
|
||||
end
|
||||
28
Task/Test-a-function/Ruby/test-a-function-2.rb
Normal file
28
Task/Test-a-function/Ruby/test-a-function-2.rb
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
# palindrome.rb
|
||||
def palindrome?(s)
|
||||
s == s.reverse
|
||||
end
|
||||
|
||||
require 'minitest/spec'
|
||||
require 'minitest/autorun'
|
||||
describe "palindrome? function" do
|
||||
it "returns true if arg is a palindrome" do
|
||||
(palindrome? "aba").must_equal true
|
||||
end
|
||||
|
||||
it "returns false if arg is not a palindrome" do
|
||||
palindrome?("ab").must_equal false
|
||||
end
|
||||
|
||||
it "raises NoMethodError if arg is without #reverse" do
|
||||
proc { palindrome? 42 }.must_raise NoMethodError
|
||||
end
|
||||
|
||||
it "raises ArgumentError if wrong number of args" do
|
||||
proc { palindrome? "a", "b" }.must_raise ArgumentError
|
||||
end
|
||||
|
||||
it "passes a failing test" do
|
||||
palindrome?("ab").must_equal true, "this test case fails on purpose"
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue