Class: TestQM
- Inherits:
-
Object
- Object
- TestQM
- Defined in:
- lib/logic_tools/test_logic_tools.rb
Overview
Class for testing the implementation Quine Mc Cluskey algorithm.
Instance Method Summary collapse
-
#initialize(seed = 0) ⇒ TestQM
constructor
Creates the tester with a
seedfor random generation. -
#test_qm(tree, generator) ⇒ Object
Tests Quine Mac Cluskey on a given
tree. -
#test_qm_all(test = nil) ⇒ Object
Tests the implementation of the espresso algorithm on each possible 1-cube cover of 4 variables.
Constructor Details
#initialize(seed = 0) ⇒ TestQM
Creates the tester with a seed for random generation.
212 213 214 215 216 |
# File 'lib/logic_tools/test_logic_tools.rb', line 212 def initialize(seed = 0) # Ensures QM is used. load "logic_tools/logicsimplify_qm.rb" @seed = seed end |
Instance Method Details
#test_qm(tree, generator) ⇒ Object
Tests Quine Mac Cluskey on a given tree.
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/logic_tools/test_logic_tools.rb', line 219 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) ⇒ Object
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.
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/logic_tools/test_logic_tools.rb', line 243 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 |