# Copyright (c) 2006 Surendra K. Singhi # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA require File.join(File.dirname(__FILE__), 'abstract_unit') class ClassifiableTest < Test::Unit::TestCase fixtures :comments def test_instance_train_untrain_no_identifier_1 @comment = comments(:hello) assert_not_nil @comment @comment.train(:good) @comment.train(:evil) assert_not_nil ClassifierModel.find_by_classifiable_type(Comment.to_s) @comment.untrain(:good) @comment.untrain(:evil) assert_not_nil ClassifierModel.find_by_classifiable_type(Comment.to_s) end def test_instance_train_untrain_no_identifier_2 @comment = comments(:hello) assert_not_nil @comment @comment.train_good @comment.train_evil assert_not_nil ClassifierModel.find_by_classifiable_type(Comment.to_s) @comment.untrain_good @comment.untrain_evil assert_not_nil ClassifierModel.find_by_classifiable_type(Comment.to_s) end def test_instance_train_untrain_identifier_1 @comment = comments(:hello) assert_not_nil @comment @comment.train(:good,1) @comment.train(:evil,1) assert_not_nil ClassifierModel.find_by_identifier(1) @comment.untrain(:good,1) @comment.untrain(:evil,1) assert_not_nil ClassifierModel.find_by_identifier(1) end def test_instance_train_untrain_identifier_2 @comment = comments(:hello) assert_not_nil @comment @comment.train_good 1 @comment.train_evil 1 assert_not_nil ClassifierModel.find_by_identifier(1) @comment.untrain_good 1 @comment.untrain_evil 1 end def test_instance_classify_no_identifier @comment = comments(:hello) assert_not_nil @comment @comment.train_good @comment.train_evil assert_not_nil ClassifierModel.find_by_classifiable_type(Comment.to_s) @comment.classifications @comment.classify end def test_instance_train_classify_identifier_1 @comment = comments(:hello) assert_not_nil @comment @comment.train(:good,1) @comment.train(:evil,1) assert_not_nil ClassifierModel.find_by_identifier(1) @comment.classifications @comment.classify end def test_instance_group_no_identifier Comment.train [:good, :evil], [comments(:hello), comments(:bye)] assert_not_nil ClassifierModel.find_by_classifiable_type(Comment.to_s) comments(:hello).classifications comments(:hello).classify Comment.untrain [:good, :evil], [comments(:hello), comments(:bye)] comments(:hello).classifications comments(:hello).classify end def test_instance_group_identifier_1 Comment.train [:good, :evil], [comments(:hello), comments(:bye)], 10 assert_not_nil ClassifierModel.find_by_classifiable_type(Comment.to_s) assert_equal 10, ClassifierModel.find_by_classifiable_type(Comment.to_s).identifier comments(:hello).classifications 10 comments(:hello).classify 10 Comment.untrain [:good, :evil], [comments(:hello), comments(:bye)], 10 assert_equal 2, Comment.classifications([comments(:hello), comments(:bye)], 10).size assert_equal 2, Comment.classify([comments(:hello), comments(:bye)], 10).size end end