Skip to content
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

Merged
merged 4 commits into from Oct 21, 2013
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 52 additions & 0 deletions Parsimmon/ExampleTests/ParsimmonTaggerTests.m
@@ -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
4 changes: 4 additions & 0 deletions Parsimmon/Parsimmon.xcodeproj/project.pbxproj
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
3A57BA891811D1BD003F0163 /* ParsimmonTaggerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A57BA881811D1BD003F0163 /* ParsimmonTaggerTests.m */; };
3AE5AFCC180DE015002241FE /* ParsimmonTokenizerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3AE5AFCB180DE015002241FE /* ParsimmonTokenizerTests.m */; };
3AE5AFCD180DE163002241FE /* ParsimmonTokenizer.m in Sources */ = {isa = PBXBuildFile; fileRef = B67005AF1807D80E00CFF860 /* ParsimmonTokenizer.m */; };
3AE5AFCE180DE163002241FE /* ParsimmonTagger.m in Sources */ = {isa = PBXBuildFile; fileRef = B67005BA1809CD5600CFF860 /* ParsimmonTagger.m */; };
Expand Down Expand Up @@ -50,6 +51,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
3A57BA881811D1BD003F0163 /* ParsimmonTaggerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ParsimmonTaggerTests.m; sourceTree = "<group>"; };
3AE5AFCB180DE015002241FE /* ParsimmonTokenizerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ParsimmonTokenizerTests.m; sourceTree = "<group>"; };
B67005771807D79500CFF860 /* Parsimmon.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Parsimmon.app; sourceTree = BUILT_PRODUCTS_DIR; };
B670057A1807D79500CFF860 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -173,6 +175,7 @@
isa = PBXGroup;
children = (
3AE5AFCB180DE015002241FE /* ParsimmonTokenizerTests.m */,
3A57BA881811D1BD003F0163 /* ParsimmonTaggerTests.m */,
B67005A51807D79500CFF860 /* ExampleTests.m */,
B67005A01807D79500CFF860 /* Supporting Files */,
);
Expand Down Expand Up @@ -344,6 +347,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
3A57BA891811D1BD003F0163 /* ParsimmonTaggerTests.m in Sources */,
3AE5AFCD180DE163002241FE /* ParsimmonTokenizer.m in Sources */,
3AE5AFCE180DE163002241FE /* ParsimmonTagger.m in Sources */,
3AE5AFCF180DE163002241FE /* ParsimmonLemmatizer.m in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions Parsimmon/Parsimmon/ParsimmonTaggedToken.h
Expand Up @@ -36,4 +36,6 @@
- (instancetype)initWithToken:(NSString *)token tag:(NSString *)tag;
- (id) init __unavailable;

- (BOOL)isEqualToTaggedToken:(ParsimmonTaggedToken *)taggedToken;

@end
29 changes: 29 additions & 0 deletions Parsimmon/Parsimmon/ParsimmonTaggedToken.m
Expand Up @@ -39,6 +39,35 @@ - (instancetype)initWithToken:(NSString *)token tag:(NSString *)tag
return self;
}

- (NSUInteger)hash
Copy link
Owner

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

#pragma mark - NSObject

for some organization 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

{
NSUInteger hash = self.token.hash ^ self.tag.hash;

return hash;
}

- (BOOL)isEqual:(id)object
{
BOOL isEqual = NO;

if ([object isKindOfClass:[self class]])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if ([object isKindOfClass:[self class]]) {

K&R style :octocat:

{
isEqual = [self isEqualToTaggedToken:object];
}
return isEqual;
}

- (BOOL)isEqualToTaggedToken:(ParsimmonTaggedToken *)taggedToken
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just

return [self.token isEqualToString:taggedToken.token] && [self.tag isEqualToString:taggedToken.tag];

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.
Let me know if you still prefer the shorter form.

Copy link
Owner

Choose a reason for hiding this comment

The 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?

{
BOOL isEqualToTaggedToken;

isEqualToTaggedToken = ([self.token isEqualToString:taggedToken.token] &&
[self.tag isEqualToString:taggedToken.tag]);

return isEqualToTaggedToken;
}


- (NSString *)description
{
return [NSString stringWithFormat:@"('%@', %@)", self.token, self.tag];
Expand Down