-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic test for ParsimmonNaiveBayesClassifier.
- Loading branch information
1 parent
17b77c8
commit 4998fbb
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
Parsimmon/ParsimmonTests/ParsimmonNaiveBayesClassifierTests.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// ParsimmonNaiveBayesClassifierTests.m | ||
// Parsimmon | ||
// | ||
// Created by Ayaka Nonaka on 6/20/14. | ||
// | ||
// | ||
|
||
#import <XCTest/XCTest.h> | ||
#import "ParsimmonNaiveBayesClassifier.h" | ||
|
||
@interface ParsimmonNaiveBayesClassifierTests : XCTestCase | ||
@end | ||
|
||
@implementation ParsimmonNaiveBayesClassifierTests | ||
|
||
- (void)testBasicExample | ||
{ | ||
ParsimmonNaiveBayesClassifier *classifier = [[ParsimmonNaiveBayesClassifier alloc] init]; | ||
|
||
// Train the classifier with some ham examples. | ||
[classifier trainWithText:@"nom nom ham" category:@"ham"]; | ||
[classifier trainWithText:@"make sure to get the ham" category:@"ham"]; | ||
[classifier trainWithText:@"please put the eggs in the fridge" category:@"ham"]; | ||
|
||
// Train the classifier with some spam examples. | ||
[classifier trainWithText:@"spammy spam spam" category:@"spam"]; | ||
[classifier trainWithText:@"what does the fox say?" category:@"spam"]; | ||
[classifier trainWithText:@"and fish go blub" category:@"spam"]; | ||
|
||
// Classify some new text. Is it ham or spam? | ||
// In practice, you'd want to train with more examples first. | ||
NSString *firstExample = @"use the eggs in the fridge."; | ||
NSString *secondExample = @"what does the fish say?"; | ||
|
||
XCTAssertEqual([classifier classify:firstExample], @"ham"); | ||
XCTAssertEqual([classifier classify:secondExample], @"spam"); | ||
} | ||
|
||
@end |