Skip to content
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

Add support to reset trained classifiers to their initial state #143

Merged
merged 12 commits into from
Feb 8, 2017
18 changes: 15 additions & 3 deletions test/backends/backend_common_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

module BackendCommonTests
def test_initial_values
assert_equal 0, @backend.total_words
assert_equal 0, @backend.total_trainings
assert_equal [], @backend.category_keys
assert @backend.total_words.zero?
assert @backend.total_trainings.zero?
assert @backend.category_keys.empty?
end

def test_total_words
Expand Down Expand Up @@ -55,4 +55,16 @@ def test_category_word_frequency
@backend.delete_category_word(:Interesting, "foo")
refute @backend.word_in_category?(:Interesting, "foo")
end

def test_reset
@backend.update_total_words(10)
@backend.update_total_trainings(10)
@backend.add_category(:Interesting)
@backend.update_category_training_count(:Interesting, 10)
@backend.update_category_word_count(:Interesting, 10)
@backend.reset
assert @backend.total_words.zero?
assert @backend.total_trainings.zero?
assert @backend.category_keys.empty?
end
end
2 changes: 1 addition & 1 deletion test/backends/backend_redis_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ def setup
end

def teardown
@backend.instance_variable_get(:@redis).flushdb if defined? @backend
@backend.reset if defined? @backend
end
end
2 changes: 1 addition & 1 deletion test/bayes/bayesian_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def setup
end

def teardown
@redis_backend.instance_variable_get(:@redis).flushdb unless @redis_backend.nil?
@redis_backend.reset unless @redis_backend.nil?
end

def test_equality_of_backends
Expand Down
2 changes: 1 addition & 1 deletion test/bayes/bayesian_redis_benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def setup
def teardown
if defined? @classifiers
self.class.bench_range.each do |n|
@classifiers[n].instance_variable_get(:@backend).instance_variable_get(:@redis).flushdb
@classifiers[n].reset
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/bayes/bayesian_redis_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def setup
def teardown
Hasher::STOPWORDS['en'] = @old_stopwords
if defined? @backend
@backend.instance_variable_get(:@redis).flushdb
@alternate_backend.instance_variable_get(:@redis).flushdb
@backend.reset
@alternate_backend.reset
end
end
end