File: backend_common_tests.rb

package info (click to toggle)
ruby-classifier-reborn 2.2.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,424 kB
  • sloc: ruby: 2,021; makefile: 7
file content (70 lines) | stat: -rw-r--r-- 2,558 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# encoding: utf-8

module BackendCommonTests
  def test_initial_values
    assert @backend.total_words.zero?
    assert @backend.total_trainings.zero?
    assert @backend.category_keys.empty?
  end

  def test_total_words
    @backend.update_total_words(10)
    assert_equal 10, @backend.total_words
    @backend.update_total_words(-7)
    assert_equal 3, @backend.total_words
  end

  def test_total_trainings
    @backend.update_total_trainings(10)
    assert_equal 10, @backend.total_trainings
    @backend.update_total_trainings(-7)
    assert_equal 3, @backend.total_trainings
  end

  def test_category_training
    refute @backend.category_has_trainings?(:Interesting)
    @backend.update_category_training_count(:Interesting, 10)
    assert @backend.category_has_trainings?(:Interesting)
    assert_equal 10, @backend.category_training_count(:Interesting)
    @backend.update_category_training_count(:Interesting, -7)
    assert_equal 3, @backend.category_training_count(:Interesting)
  end

  def test_category_word
    @backend.update_category_word_count(:Interesting, 10)
    assert_equal 10, @backend.category_word_count(:Interesting)
    @backend.update_category_word_count(:Interesting, -7)
    assert_equal 3, @backend.category_word_count(:Interesting)
  end

  def test_category
    @backend.add_category(:Interesting)
    @backend.add_category(:"Not so interesting")
    assert_equal [:Interesting, :"Not so interesting"].sort, @backend.category_keys.sort
  end

  def test_category_word_frequency
    @backend.add_category(:Interesting)
    refute @backend.word_in_category?(:Interesting, "foo")
    assert_equal 0, @backend.category_word_frequency(:Interesting, "foo")
    @backend.update_category_word_frequency(:Interesting, "foo", 10)
    assert @backend.word_in_category?(:Interesting, "foo")
    assert_equal 10, @backend.category_word_frequency(:Interesting, "foo")
    @backend.update_category_word_frequency(:Interesting, "foo", -7)
    assert_equal 3, @backend.category_word_frequency(:Interesting, "foo")
    @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