Skip to content

Commit

Permalink
Add support to reset trained classifiers to their initial state (#143)
Browse files Browse the repository at this point in the history
* Fixed test failutres if redis is not running

* Remove warnings of uninitialized instances of test teardown

* Checking right conditiones for the test teardown

* Added reset methods in Bayes, LSI, and Bayes backends

* Corrected teardown conditionals

* Added tests for reset functionality

* Corrected typo in documentation

* Added tests for reset method in backends

* Utilize Redis backend reset method in test teardown
  • Loading branch information
ibnesayeed authored and Ch4s3 committed Feb 8, 2017
1 parent 4b68fd9 commit 67be2f5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
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

0 comments on commit 67be2f5

Please sign in to comment.