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.

No.8, ruby_4th(assert_equal)

Last updated at Posted at 2020-11-18

学習内容

  • 継承
  • テスト開発用プログラム

colorize

  • ref: https://github.com/fazibear/colorize

  • 文字の色や背景色などを変更可能

  • String クラスを拡張、または ColorizeString クラスを追加することで実装

疑似変数 `__FILE__`

  • 現在のソースファイル名を出力

  • 使用例: テスト用プログラム

    • ファイル名とプログラム名が一致するなら if 内を実行(require で呼び出すなどで、ソースファイル名と実行ファイル名が異なるなら実行しない。)
    if $PROGRAM_NAME == __FILE__
      assert_equal(1, 1)
      assert_equal(1, 2)
      assert_not_equal(1, 2)
      assert_not_equal(1, 1)
    end
    

Code

require 'colorize'

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

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

assert_equal(1, 2)
assert_not_equal(1, 1)

参考

  • 講義ページ

https://qiita.com/daddygongon/items/f6cea87314ee26e130ea#%E3%81%8A%E9%A1%8Cassert_equal

  • プロを目指す人のための Ruby 入門

https://www.amazon.co.jp/%E3%83%97%E3%83%AD%E3%82%92%E7%9B%AE%E6%8C%87%E3%81%99%E4%BA%BA%E3%81%AE%E3%81%9F%E3%82%81%E3%81%AERuby%E5%85%A5%E9%96%80-%E8%A8%80%E8%AA%9E%E4%BB%95%E6%A7%98%E3%81%8B%E3%82%89%E3%83%86%E3%82%B9%E3%83%88%E9%A7%86%E5%8B%95%E9%96%8B%E7%99%BA%E3%83%BB%E3%83%87%E3%83%90%E3%83%83%E3%82%B0%E6%8A%80%E6%B3%95%E3%81%BE%E3%81%A7-Software-Design-plus-ebook/dp/B077Q8BXHC/ref=sr_1_1?__mk_ja_JP=%E3%82%AB%E3%82%BF%E3%82%AB%E3%83%8A&dchild=1&keywords=ruby&qid=1605077175&sr=8-1


  • source ~/classes/muli_scale/grad_members_20f/members/keita_k7/memo/../memo/c8.org
5
0
1

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?