[RUBY] Special Lecture on Multiscale Simulation: 8th (assert)

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

Use assert from other source code

require_assert.rb


require './assert'

assert_equal(4, 2 * 2)
assert_not_equal('Muku', 'Miku')

References

Chart type ruby-IV (assert \ _equal)


Recommended Posts

Special Lecture on Multiscale Simulation: 8th (assert)
Special Lecture on Multi-Scale Simulation: 11th (class)
Special Lecture on Multiscale Simulation: 10th (Recursive)
Special Lecture on Multi-Scale Simulation: I tried to summarize the 5th
Special Lecture on Multi-Scale Simulation: I tried to summarize the 7th
Multiscale simulation 11
10th class: Recursion
5th class: Output
7th class: if, else
6th class: Variables, method
5th
6th
6th
Rake
9th
7th
11th
9th
7th
11th
10th
10th
Anonymous class (anonymous class)
Special Lecture on Multi-Scale Simulation: 11th (class)
Class method
ObjectMapper class
ArrayList class
10th class: Recursion
8th class: rake
5th class: Output
7th class: if, else
6th class: Variables, method
5th
ruby exercise memo VI (hello class)
6th
6th
9th
7th
11th
9th
7th
11th
10th
10th
Special Lecture on Multi-Scale Simulation: 11th (class)