5
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Ruby(assert_equal)

Posted at

assert_equal

assert equalとはequalかどうかを確かめる(assert)関数です.assert_equal(引数,引数)が同じ値かを判定するコードを示します.

def assert_equal(expected, result)
  return expected == result
end

p assert_equal(1, 1)

expectedとresultが同じ値のためtrueと帰ってきます.

colorize-出色の継承-

次に出力に色を付けます.trueのときは緑,falseのときは赤で表示させます.

require 'colorize'

def assert_equal(expected, result)
  if expected == result
    puts 'true'.green
  else
    puts 'false'.red
  end
end

assert_equal(1, 1)

trueのため緑で表示されます.

colorizeというgem libraryがないと怒られた場合は

> gem install colorize

でinstallしてください.gemというのはrubyのlibraryを管理するシステムです.


  • source ~/grad_members_20f/members/Kazufumi0823/c4_assert_equal.org
5
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?