Skip to content

Commit

Permalink
Merge pull request #3 from Hecktorzr/unitTest
Browse files Browse the repository at this point in the history
More Unit Tests
  • Loading branch information
ayanonagon committed Oct 21, 2013
2 parents 737c6d0 + b23682f commit 56ff72b
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
52 changes: 52 additions & 0 deletions Parsimmon/ExampleTests/ParsimmonTaggerTests.m
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
4 changes: 4 additions & 0 deletions Parsimmon/Parsimmon.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@
- (instancetype)initWithToken:(NSString *)token tag:(NSString *)tag;
- (id) init __unavailable;

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

@end
27 changes: 27 additions & 0 deletions Parsimmon/Parsimmon/ParsimmonTaggedToken.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
return ([self.token isEqualToString:taggedToken.token] &&
[self.tag isEqualToString:taggedToken.tag]);
}

@end

0 comments on commit 56ff72b

Please sign in to comment.