Skip to content

Refactoring of backend tests to move duplicate login in the common file #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions test/bayes/bayesian_common_tests.rb
Original file line number Diff line number Diff line change
@@ -178,4 +178,42 @@ def test_custom_file_stopwords
assert_equal Float::INFINITY, classifier.classify_with_score('These stopwords')[1]
refute_equal Float::INFINITY, classifier.classify_with_score('To be or not to be')[1]
end

private

def another_classifier
ClassifierReborn::Bayes.new %w(Interesting Uninteresting), backend: @alternate_backend
end

def auto_categorize_classifier
ClassifierReborn::Bayes.new 'Interesting', 'Uninteresting', auto_categorize: true, backend: @alternate_backend
end

def threshold_classifier(category)
ClassifierReborn::Bayes.new category, backend: @alternate_backend
end

def empty_classifier
ClassifierReborn::Bayes.new backend: @alternate_backend
end

def useless_classifier
ClassifierReborn::Bayes.new auto_categorize: false, backend: @alternate_backend
end

def empty_string_stopwords_classifier
ClassifierReborn::Bayes.new stopwords: "", backend: @alternate_backend
end

def empty_array_stopwords_classifier
ClassifierReborn::Bayes.new stopwords: [], backend: @alternate_backend
end

def array_stopwords_classifier
ClassifierReborn::Bayes.new stopwords: ["these", "are", "custom", "stopwords"], backend: @alternate_backend
end

def file_stopwords_classifier
ClassifierReborn::Bayes.new stopwords: File.dirname(__FILE__) + '/../data/stopwords/en', backend: @alternate_backend
end
end
37 changes: 1 addition & 36 deletions test/bayes/bayesian_memory_test.rb
Original file line number Diff line number Diff line change
@@ -7,47 +7,12 @@ class BayesianMemoryTest < Minitest::Test
include BayesianCommonTests

def setup
@alternate_backend = ClassifierReborn::BayesMemoryBackend.new
@classifier = ClassifierReborn::Bayes.new 'Interesting', 'Uninteresting'
@old_stopwords = Hasher::STOPWORDS['en']
end

def teardown
Hasher::STOPWORDS['en'] = @old_stopwords
end

def another_classifier
ClassifierReborn::Bayes.new %w(Interesting Uninteresting)
end

def auto_categorize_classifier
ClassifierReborn::Bayes.new 'Interesting', 'Uninteresting', auto_categorize: true
end

def threshold_classifier(category)
ClassifierReborn::Bayes.new category
end

def empty_classifier
ClassifierReborn::Bayes.new
end

def useless_classifier
ClassifierReborn::Bayes.new auto_categorize: false
end

def empty_string_stopwords_classifier
ClassifierReborn::Bayes.new stopwords: ""
end

def empty_array_stopwords_classifier
ClassifierReborn::Bayes.new stopwords: []
end

def array_stopwords_classifier
ClassifierReborn::Bayes.new stopwords: ["these", "are", "custom", "stopwords"]
end

def file_stopwords_classifier
ClassifierReborn::Bayes.new stopwords: File.dirname(__FILE__) + '/../data/stopwords/en'
end
end
48 changes: 6 additions & 42 deletions test/bayes/bayesian_redis_test.rb
Original file line number Diff line number Diff line change
@@ -8,10 +8,10 @@ class BayesianRedisTest < Minitest::Test

def setup
begin
@redis_backend = ClassifierReborn::BayesRedisBackend.new
@redis_backend.instance_variable_get(:@redis).config(:set, "save", "")
@alternate_redis_backend = ClassifierReborn::BayesRedisBackend.new(db: 1)
@classifier = ClassifierReborn::Bayes.new 'Interesting', 'Uninteresting', backend: @redis_backend
@backend = ClassifierReborn::BayesRedisBackend.new
@backend.instance_variable_get(:@redis).config(:set, "save", "")
@alternate_backend = ClassifierReborn::BayesRedisBackend.new(db: 1)
@classifier = ClassifierReborn::Bayes.new 'Interesting', 'Uninteresting', backend: @backend
@old_stopwords = Hasher::STOPWORDS['en']
rescue Redis::CannotConnectError => e
skip(e)
@@ -20,43 +20,7 @@ def setup

def teardown
Hasher::STOPWORDS['en'] = @old_stopwords
@redis_backend.instance_variable_get(:@redis).flushdb
@alternate_redis_backend.instance_variable_get(:@redis).flushdb
end

def another_classifier
ClassifierReborn::Bayes.new %w(Interesting Uninteresting), backend: @alternate_redis_backend
end

def auto_categorize_classifier
ClassifierReborn::Bayes.new 'Interesting', 'Uninteresting', auto_categorize: true, backend: @alternate_redis_backend
end

def threshold_classifier(category)
ClassifierReborn::Bayes.new category, backend: @alternate_redis_backend
end

def empty_classifier
ClassifierReborn::Bayes.new backend: @alternate_redis_backend
end

def useless_classifier
ClassifierReborn::Bayes.new auto_categorize: false, backend: @alternate_redis_backend
end

def empty_string_stopwords_classifier
ClassifierReborn::Bayes.new stopwords: "", backend: @alternate_redis_backend
end

def empty_array_stopwords_classifier
ClassifierReborn::Bayes.new stopwords: [], backend: @alternate_redis_backend
end

def array_stopwords_classifier
ClassifierReborn::Bayes.new stopwords: ["these", "are", "custom", "stopwords"], backend: @alternate_redis_backend
end

def file_stopwords_classifier
ClassifierReborn::Bayes.new stopwords: File.dirname(__FILE__) + '/../data/stopwords/en', backend: @alternate_redis_backend
@backend.instance_variable_get(:@redis).flushdb
@alternate_backend.instance_variable_get(:@redis).flushdb
end
end