File: backend_memory_test.rb

package info (click to toggle)
ruby-classifier-reborn 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,420 kB
  • sloc: ruby: 2,021; makefile: 5
file content (31 lines) | stat: -rw-r--r-- 1,194 bytes parent folder | download | duplicates (3)
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