Created
April 17, 2016 10:10
-
-
Save esehara/4647fb60952fa50a51e4a04397e37327 to your computer and use it in GitHub Desktop.
MiniTestで一つのファイルにテストを混ぜてしまおう ref: http://qiita.com/esehara@github/items/40a74251b0a67b5b6520
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# もっといい方法があるが、サンプルのために、このままにする | |
def exchange_node x, coin | |
return 1 if x == 0 | |
return 1 if x < 5 | |
return 0 if x < 0 | |
sum_coin = 0 | |
case coin | |
when 10 | |
sum_coin += exchange_node(x - 5, 5) | |
end | |
sum_coin += exchange_node(x - coin, coin) + 1 | |
return sum_coin | |
end | |
# --------------------TestCase | |
require 'minitest/unit' | |
require 'minitest/autorun' | |
class TestExchange < MiniTest::Unit::TestCase | |
def test_exchange_node_5 | |
assert_equal 3, exchange_node(10, 5) | |
end | |
def test_exchange_node_10 | |
assert_equal 4, exchange_node(10, 10) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
esehara@esehara-CF-N9JCCCPS:~/Code/Ruby/ExchangeProblem$ ruby exchange.rb | |
Run options: --seed 4701 | |
# Running tests: | |
.. | |
Finished tests in 0.016379s, 305.2619 tests/s, 305.2619 assertions/s. | |
2 tests, 2 assertions, 0 failures, 0 errors, 0 skips |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irb(main):001:0> require './exchange.rb' | |
=> true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment