Last active
August 29, 2015 14:24
-
-
Save dav/599d7b4299c0de109cc3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
describe(@"cardinalityPhraseWithNumber:singularPhrase:pluralPhrase:", ^{ | |
it(@"should pluralize 0", ^{ | |
NSString *phrase = [NSString cardinalityPhraseWithInteger:0 singularPhrase:@"bug" pluralPhrase:@"bugs"]; | |
[[phrase should] equal:@"0 bugs"]; | |
}); | |
it(@"should singularize 1", ^{ | |
NSString *phrase = [NSString cardinalityPhraseWithInteger:1 singularPhrase:@"bug" pluralPhrase:@"bugs"]; | |
[[phrase should] equal:@"1 bug"]; | |
}); | |
it(@"should pluralize -1", ^{ | |
NSString *phrase = [NSString cardinalityPhraseWithInteger:-1 singularPhrase:@"bug" pluralPhrase:@"bugs"]; | |
[[phrase should] equal:@"-1 bugs"]; | |
}); | |
it(@"should pluralize 2", ^{ | |
NSString *phrase = [NSString cardinalityPhraseWithInteger:2 singularPhrase:@"bug" pluralPhrase:@"bugs"]; | |
[[phrase should] equal:@"2 bugs"]; | |
}); | |
}); | |
---------------- | |
+ (NSString *)cardinalityPhraseWithInteger:(NSInteger)number singularPhrase:(NSString *)singularPhrase pluralPhrase:(NSString *)pluralPhrase | |
{ | |
return [NSString stringWithFormat:@"%ld %@", (long)number, number == 1 ? singularPhrase : pluralPhrase]; | |
} | |
+ (NSString *)cardinalityPhraseRelativeToInteger:(NSInteger)number singularPhrase:(NSString *)singularPhrase pluralPhrase:(NSString *)pluralPhrase | |
{ | |
return [NSString stringWithFormat:@"%@", number == 1 ? singularPhrase : pluralPhrase]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment