Verify classifer counts

This commit is contained in:
Joshua Peek
2012-06-20 15:48:46 -05:00
parent 7bcf90c527
commit 516a220d9f
2 changed files with 13 additions and 0 deletions

View File

@@ -68,6 +68,15 @@ module Linguist
nil
end
# Public: Verify internal counts are consistent.
#
# Returns Boolean.
def verify
@languages.inject(0) { |n, (l, c)| n += c } == @languages_total &&
@language_tokens.inject(0) { |n, (l, c)| n += c } == @tokens_total &&
@tokens.inject(0) { |n, (l, ts)| n += ts.inject(0) { |m, (t, c)| m += c } } == @tokens_total
end
# Public: Prune infrequent tokens.
#
# Returns receiver Classifier instance.

View File

@@ -55,6 +55,10 @@ class TestClassifier < Test::Unit::TestCase
assert results.first[1] < 0.5, results.first.inspect
end
def test_verify
assert Classifier.instance.verify
end
def test_gc
Classifier.instance.gc
end