Sha256: 79130f3a26929025536101ad412ef9eeaca78fe2f6a6b800ed6ce0e786929524

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

require 'test/unit'
require_relative '../lib/unsupervised-language-detection/naive-bayes-classifier'

class NaiveBayesEmTests < Test::Unit::TestCase
  def setup
    number_examples = [%w(one two three), %w(two three four five six), %w(seven three one four five eight nine), %w(ten one two six three seven), %w(one five six seven two eight ten nine)]
    color_examples = [%w(red blue green), %w(red blue yellow purple red), %w(brown green purple red blue black white)]
    @two = NaiveBayesClassifier.train_em(20, number_examples + color_examples)
  end
  
  def test_classify
    color_classifications = [%w(red rainbow green grass), %w(one red blue green), %w(brown cow)].map do |example|
      @two.classify(example)
    end    
    number_classifications = [%w(one hundred two three red), %w(one nine one one eight), %w(three cows)].map do |example|      
      @two.classify(example)
    end
    
    assert_equal 1, color_classifications.uniq.size
    assert_equal 1, number_classifications.uniq.size
    assert_not_equal color_classifications.first, number_classifications.first
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
unsupervised-language-detection-0.0.6 test/test_naive_bayes_em.rb
unsupervised-language-detection-0.0.5 test/test_naive_bayes_em.rb