assert
Create a function assert \ _equal that takes two arguments and outputs whether they have the same value. Similarly, create a function assert \ _not \ _equal that outputs whether they have different values.
assert.rb
require 'colorize'
def puts_vals(expected, result)
puts "expected :: #{expected}"
puts "result :: #{result}"
end
def assert_not_equal(expected, result)
puts_vals(expected, result)
if expected != result
print "succeeded in #{__method__}.\n".green
else
print "failed in #{__method__}.\n".red
end
end
def assert_equal(expected, result)
puts_vals(expected, result)
if expected == result
print "succeeded in #{__method__}.\n".green
else
print "failed in #{__method__}.\n".red
end
end
if $PROGRAM_NAME == __FILE__
assert_equal(1, 1)
assert_equal(1, 2)
assert_not_equal(1, 2)
assert_not_equal(1, 1)
end
require_assert.rb
require './assert'
assert_equal(4, 2 * 2)
assert_not_equal('Muku', 'Miku')
Chart type ruby-IV (assert \ _equal)
Recommended Posts