-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More Unit Tests #3
Changes from all commits
fc17db7
fda15f5
680152b
b23682f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// ParsimmonTaggedTokenTests.m | ||
// Parsimmon | ||
// | ||
// Created by Hector Zarate on 10/18/13. | ||
// | ||
// | ||
|
||
#import <XCTest/XCTest.h> | ||
#import "ParsimmonTaggedToken.h" | ||
#import "ParsimmonTagger.h" | ||
|
||
@interface ParsimmonTaggerTests : XCTestCase | ||
|
||
@end | ||
|
||
@implementation ParsimmonTaggerTests | ||
|
||
- (void)setUp | ||
{ | ||
[super setUp]; | ||
// Put setup code here; it will be run once, before the first test case. | ||
} | ||
|
||
- (void)tearDown | ||
{ | ||
// Put teardown code here; it will be run once, after the last test case. | ||
[super tearDown]; | ||
} | ||
|
||
- (void)testTagWordsInText | ||
{ | ||
NSArray *expectedTaggedTokens = @[[[ParsimmonTaggedToken alloc] initWithToken:@"The" tag:@"Determiner"], | ||
[[ParsimmonTaggedToken alloc] initWithToken:@"quick" tag:@"Adjective"], | ||
[[ParsimmonTaggedToken alloc] initWithToken:@"brown" tag:@"Adjective"], | ||
[[ParsimmonTaggedToken alloc] initWithToken:@"fox" tag:@"Noun"], | ||
[[ParsimmonTaggedToken alloc] initWithToken:@"jumps" tag:@"Noun"], | ||
[[ParsimmonTaggedToken alloc] initWithToken:@"over" tag:@"Preposition"], | ||
[[ParsimmonTaggedToken alloc] initWithToken:@"the" tag:@"Determiner"], | ||
[[ParsimmonTaggedToken alloc] initWithToken:@"lazy" tag:@"Adjective"], | ||
[[ParsimmonTaggedToken alloc] initWithToken:@"dog" tag:@"Noun"]]; | ||
|
||
NSString *testStringOne = @"The quick brown fox jumps over the lazy dog"; | ||
|
||
ParsimmonTagger *tagger = [[ParsimmonTagger alloc] init]; | ||
|
||
NSArray *taggedTokens = [tagger tagWordsInText:testStringOne]; | ||
|
||
XCTAssertEqualObjects(taggedTokens, expectedTaggedTokens, @"Failed to tagged words in text"); | ||
} | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,9 +39,36 @@ - (instancetype)initWithToken:(NSString *)token tag:(NSString *)tag | |
return self; | ||
} | ||
|
||
|
||
#pragma mark - NSObject | ||
|
||
|
||
- (NSString *)description | ||
{ | ||
return [NSString stringWithFormat:@"('%@', %@)", self.token, self.tag]; | ||
} | ||
|
||
- (NSUInteger)hash | ||
{ | ||
NSUInteger hash = self.token.hash ^ self.tag.hash; | ||
|
||
return hash; | ||
} | ||
|
||
- (BOOL)isEqual:(id)object | ||
{ | ||
BOOL isEqual = NO; | ||
|
||
if ([object isKindOfClass:[self class]]){ | ||
isEqual = [self isEqualToTaggedToken:object]; | ||
} | ||
return isEqual; | ||
} | ||
|
||
- (BOOL)isEqualToTaggedToken:(ParsimmonTaggedToken *)taggedToken | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about just
? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've found that this shorter form of returns makes debugging more difficult. Hence the verbose form. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, interesting. Is it because it's easier to see the value of the evaluated expression when using a debugger? |
||
{ | ||
return ([self.token isEqualToString:taggedToken.token] && | ||
[self.tag isEqualToString:taggedToken.tag]); | ||
} | ||
|
||
@end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move hash and isEqual: to the end with description and add
for some organization 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good!