Skip to content

Instantly share code, notes, and snippets.

@jaz303
Created August 3, 2010 14:08
Show Gist options
  • Save jaz303/506426 to your computer and use it in GitHub Desktop.
Save jaz303/506426 to your computer and use it in GitHub Desktop.
# constructor = lambda { build_valid_user }
# truth_table = [
# [ :account_admin=, :can_upload=, :"account.public_uploads_allowed=", :can_upload_files?, :can_upload_public_files?],
# [ false, false, false, false, false],
# [ true, false, false, true, true],
# [ false, true, false, true, false],
# [ true, true, false, true, true],
# [ false, false, true, false, false],
# [ true, false, true, true, true],
# [ false, true, true, true, true],
# [ true, true, true, true, true]
# ]
#
# assert_truth_table(constructor, truth_table)
#
def assert_truth_table(constructor, matrix)
field_list = matrix.shift.map(&:to_s)
matrix.each do |row|
instance = constructor.call
field_list.each_with_index do |fields,index|
next unless fields =~ /=$/
chain = fields.split('.')
method, tmp = chain.pop, instance
chain.each { |m| tmp = tmp.send(m) }
tmp.send(method, row[index])
end
field_list.each_with_index do |fields,index|
next if fields =~ /=$/
chain = fields.split('.')
method, tmp = chain.pop, instance
chain.each { |m| tmp = tmp.send(m) }
assert_equal(row[index], tmp.send(method))
end
end
end
@thaiviet1994
Copy link

Creating a “truth table” is not hard, you can use an useful tool (CKod, at http://ckod.sourceforge.net/_/) to make a “truth table”.

  1. CKod homepage: http://ckod.sourceforge.net/
  2. CKod online: http://ckod.sourceforge.net/_/
  3. CKod forum: http://ckod.sourceforge.net/~/

Good luck to you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment