mirror of
				https://github.com/KevinMidboe/linguist.git
				synced 2025-10-29 17:50:22 +00:00 
			
		
		
		
	Add simple classifier
This commit is contained in:
		
							
								
								
									
										26
									
								
								test/test_classifier.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								test/test_classifier.rb
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | ||||
| require 'linguist/classifier' | ||||
| require 'linguist/language' | ||||
|  | ||||
| require 'test/unit' | ||||
|  | ||||
| class TestClassifier < Test::Unit::TestCase | ||||
|   include Linguist | ||||
|  | ||||
|   def fixtures_path | ||||
|     File.expand_path("../fixtures", __FILE__) | ||||
|   end | ||||
|  | ||||
|   def fixture(name) | ||||
|     File.read(File.join(fixtures_path, name)) | ||||
|   end | ||||
|  | ||||
|   def test_truth | ||||
|     classifier = Classifier.new | ||||
|     classifier.train Language["Ruby"], fixture("ruby/foo.rb") | ||||
|     classifier.train Language["Objective-C"], fixture("objective-c/Foo.h") | ||||
|     classifier.train Language["Objective-C"], fixture("objective-c/Foo.m") | ||||
|  | ||||
|     results = classifier.classify(fixture("objective-c/hello.m")) | ||||
|     assert_equal Language["Objective-C"], results.first[0] | ||||
|   end | ||||
| end | ||||
		Reference in New Issue
	
	Block a user