test/classifiers/one_r_test.rb in ai4r-1.2 vs test/classifiers/one_r_test.rb in ai4r-1.3

- old
+ new

@@ -4,10 +4,11 @@ require File.dirname(__FILE__) + '/../../lib/ai4r/classifiers/one_r' class OneRTest < Test::Unit::TestCase include Ai4r::Classifiers + include Ai4r::Data @@data_examples = [ ['New York', '<30', 'M', 'Y'], ['Chicago', '<30', 'M', 'Y'], ['New York', '<30', 'M', 'Y'], ['New York', '[30-50)', 'F', 'N'], @@ -17,45 +18,46 @@ ] @@data_labels = [ 'city', 'age_range', 'gender', 'marketing_target' ] def test_build - assert_raise(ArgumentError) { OneR.new.build(nil) } - assert_raise(ArgumentError) { OneR.new.build([]) } - classifier = OneR.new.build(@@data_examples) - assert_not_nil(classifier.data_labels) + assert_raise(ArgumentError) { OneR.new.build(DataSet.new) } + classifier = OneR.new.build(DataSet.new(:data_items => @@data_examples)) + assert_not_nil(classifier.data_set.data_labels) assert_not_nil(classifier.rule) - assert_equal("attribute_1", classifier.data_labels.first) - assert_equal("class_value", classifier.data_labels.last) - classifier = OneR.new.build(@@data_examples, @@data_labels) - assert_not_nil(classifier.data_labels) + assert_equal("attribute_1", classifier.data_set.data_labels.first) + assert_equal("class_value", classifier.data_set.data_labels.last) + classifier = OneR.new.build(DataSet.new(:data_items => @@data_examples, + :data_labels => @@data_labels)) + assert_not_nil(classifier.data_set.data_labels) assert_not_nil(classifier.rule) - assert_equal("city", classifier.data_labels.first) - assert_equal("marketing_target", classifier.data_labels.last) + assert_equal("city", classifier.data_set.data_labels.first) + assert_equal("marketing_target", classifier.data_set.data_labels.last) assert_equal(1, classifier.rule[:attr_index]) end def test_eval - classifier = OneR.new.build(@@data_examples) + classifier = OneR.new.build(DataSet.new(:data_items => @@data_examples)) assert_equal("Y", classifier.eval(['New York', '<30', 'M'])) assert_equal("N", classifier.eval(['New York', '[30-50)', 'M'])) assert_equal("N", classifier.eval(['Chicago', '[50-80]', 'M'])) end - def test_to_s - classifier = OneR.new.build(@@data_examples, @@data_labels) + def test_get_rules + classifier = OneR.new.build(DataSet.new(:data_items => @@data_examples, + :data_labels => @@data_labels)) marketing_target = nil age_range = nil - eval(classifier.to_s) + eval(classifier.get_rules) assert_nil(marketing_target) age_range = '<30' - eval(classifier.to_s) + eval(classifier.get_rules) assert_equal("Y", marketing_target) age_range = '[30-50)' - eval(classifier.to_s) + eval(classifier.get_rules) assert_equal("N", marketing_target) age_range = '[50-80]' - eval(classifier.to_s) + eval(classifier.get_rules) assert_equal("N", marketing_target) end end