mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Seperate test file for samples
This commit is contained in:
2
Rakefile
2
Rakefile
@@ -16,7 +16,7 @@ end
|
||||
|
||||
CLOBBER.include 'lib/linguist/samples.yml'
|
||||
|
||||
task :classifier => [:clobber, 'lib/linguist/samples.yml']
|
||||
task :samples => [:clobber, 'lib/linguist/samples.yml']
|
||||
|
||||
namespace :classifier do
|
||||
LIMIT = 1_000
|
||||
|
||||
@@ -16,13 +16,6 @@ class TestClassifier < Test::Unit::TestCase
|
||||
File.read(File.join(samples_path, name))
|
||||
end
|
||||
|
||||
def test_instance_freshness
|
||||
# Just warn, it shouldn't scare people off by breaking the build.
|
||||
if Samples::DATA['md5'] != Samples.data['md5']
|
||||
warn "Classifier database is out of date. Run `bundle exec rake classifier`."
|
||||
end
|
||||
end
|
||||
|
||||
def test_classify
|
||||
db = {}
|
||||
Classifier.train! db, "Ruby", fixture("ruby/foo.rb")
|
||||
@@ -59,14 +52,6 @@ class TestClassifier < Test::Unit::TestCase
|
||||
assert_equal [], Classifier.classify(Samples::DATA, nil)
|
||||
end
|
||||
|
||||
def test_verify
|
||||
data = Samples::DATA
|
||||
|
||||
assert_equal data['languages_total'], data['languages'].inject(0) { |n, (_, c)| n += c }
|
||||
assert_equal data['tokens_total'], data['language_tokens'].inject(0) { |n, (_, c)| n += c }
|
||||
assert_equal data['tokens_total'], data['tokens'].inject(0) { |n, (_, ts)| n += ts.inject(0) { |m, (_, c)| m += c } }
|
||||
end
|
||||
|
||||
def test_classify_ambiguous_languages
|
||||
Samples.each do |sample|
|
||||
language = Linguist::Language.find_by_alias(sample[:language])
|
||||
|
||||
25
test/test_samples.rb
Normal file
25
test/test_samples.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
require 'linguist/samples'
|
||||
|
||||
require 'test/unit'
|
||||
|
||||
class TestSamples < Test::Unit::TestCase
|
||||
include Linguist
|
||||
|
||||
def test_up_to_date
|
||||
assert serialized = Samples::DATA
|
||||
assert latest = Samples.data
|
||||
|
||||
# Just warn, it shouldn't scare people off by breaking the build.
|
||||
if serialized['md5'] != latest['md5']
|
||||
warn "Samples database is out of date. Run `bundle exec rake samples`."
|
||||
end
|
||||
end
|
||||
|
||||
def test_verify
|
||||
assert data = Samples::DATA
|
||||
|
||||
assert_equal data['languages_total'], data['languages'].inject(0) { |n, (_, c)| n += c }
|
||||
assert_equal data['tokens_total'], data['language_tokens'].inject(0) { |n, (_, c)| n += c }
|
||||
assert_equal data['tokens_total'], data['tokens'].inject(0) { |n, (_, ts)| n += ts.inject(0) { |m, (_, c)| m += c } }
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user