class TestQM
Class for testing the implementation Quine Mc Cluskey algorithm.
Public Class Methods
new(seed = 0)
click to toggle source
Creates the tester with a seed
for random generation.
# File lib/logic_tools/test_logic_tools.rb, line 236 def initialize(seed = 0) # Ensures QM is used. load "logic_tools/logicsimplify_qm.rb" @seed = seed end
Public Instance Methods
test_qm(tree,generator)
click to toggle source
Tests Quine Mac Cluskey on a given tree
.
# File lib/logic_tools/test_logic_tools.rb, line 243 def test_qm(tree,generator) print "Quine Mc Cluskey algorithm on expression=[#{tree}]...\n" simple = tree.simplify() print "result: [#{simple}]\n" cover = tree.to_cover(*generator.each_variable) # print "cover=#{cover}\n" simple_cover = simple.to_cover(*generator.each_variable) # print "simple_cover=#{simple_cover}\n" check0 = (cover + simple_cover.complement).is_tautology? # check0 = same_truth_table?(cover,simple) # assert_equal(true,check0) print "check 0 = #{check0}\n" raise "Test failure" unless check0 check1 = (cover.complement + simple_cover).is_tautology? # assert_equal(true,check1) print "check 1 = #{check1}\n" raise "Test failure" unless check1 return true end
test_qm_all(test = nil)
click to toggle source
Tests the implementation of the espresso algorithm on each possible 1-cube cover of 4 variables.
Test only on cover if a test
number is given.
# File lib/logic_tools/test_logic_tools.rb, line 267 def test_qm_all(test = nil) generator = Generator.new("a","b","c","d") generator.seed = @seed if test then test = test.to_i print "Test #{test}: " return test_qm(generator.make_std_conj(test),generator) else generator.each_std_conj.with_index do |tree,i| print "Test #{i}: " return false unless test_qm(tree,generator) end return true end end