Class: TestBase

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/test/unit/base_test.rb

Instance Method Summary collapse

Instance Method Details

#setupObject



4
5
6
# File 'lib/test/unit/base_test.rb', line 4

def setup
  @bayes = OmniCat::Classifiers::Bayes.new
end

#test_add_categoriesObject



8
9
10
11
12
13
14
15
# File 'lib/test/unit/base_test.rb', line 8

def test_add_categories
  @bayes.add_categories ["neutral", "positive", "negative"]
  assert_not_nil(@bayes.categories["neutral"])
  assert_equal(
    ["neutral", "positive", "negative"],
    @bayes.categories.keys
  )
end

#test_classify_batchObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/test/unit/base_test.rb', line 27

def test_classify_batch
  @bayes.add_category "positive"
  @bayes.add_category "negative"
  @bayes.train_batch "positive", ["good job ever", "valid syntax",
    "best moments of my life"]
  @bayes.train_batch("negative", ["bad work", "awfull day", "never liked it"])
  results = @bayes.classify_batch(
    ["good sytanx research", "bad words"]
  )

  assert_equal(2, results.count)

  assert_equal(
    "positive",
    results[0].category[:name]
  )
  assert_equal(
    "negative",
    results[1].category[:name]
  )

end

#test_train_batchObject



17
18
19
20
21
22
23
24
25
# File 'lib/test/unit/base_test.rb', line 17

def test_train_batch
  @bayes.add_category "positive"
  @bayes.train_batch "positive", ["good job ever", "valid syntax",
    "best moments of my life"]
  assert_equal(
    3,
    @bayes.categories["positive"].doc_count
  )
end