1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
# encoding: utf-8
require File.dirname(__FILE__) + '/../test_helper'
require_relative './backend_common_tests'
class BackendMemoryTest < Minitest::Test
include BackendCommonTests
def setup
@backend = ClassifierReborn::BayesMemoryBackend.new
end
def test_persistence
@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.update_category_word_frequency(:Interesting, 'foo', 10)
binary = Marshal.dump(@backend)
loaded_backend = Marshal.load(binary)
assert_equal @backend.total_words, loaded_backend.total_words
assert_equal @backend.total_trainings, loaded_backend.total_trainings
assert_equal @backend.category_training_count(:Interesting), loaded_backend.category_training_count(:Interesting)
assert_equal @backend.category_word_count(:Interesting), loaded_backend.category_word_count(:Interesting)
assert_equal @backend.category_word_frequency(:Interesting, 'foo'),
loaded_backend.category_word_frequency(:Interesting, 'foo')
end
end
|