Adds strengthScore and strengthModifier to Monster.
Adds tests for strengthScore and strengthModifier.
This commit is contained in:
@@ -70,12 +70,17 @@
|
||||
self = [self initWithContext:context];
|
||||
|
||||
NSDictionary *jsonRoot = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
|
||||
NSNumber *tempNumber;
|
||||
|
||||
self.name = [jsonRoot objectForKey:@"name"] ?: @"";
|
||||
self.size = [jsonRoot objectForKey:@"size"] ?: @"";
|
||||
self.type = [jsonRoot objectForKey:@"type"] ?: @"";
|
||||
self.subtype = [jsonRoot objectForKey:@"tag"] ?: @"";
|
||||
self.alignment = [jsonRoot objectForKey:@"alignment"] ?: @"";
|
||||
tempNumber = [jsonRoot objectForKey:@"strPoints"];
|
||||
if (tempNumber != nil && [tempNumber isKindOfClass:[NSNumber class]]) {
|
||||
self.strengthScore = tempNumber.intValue;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
@@ -120,7 +125,7 @@
|
||||
}
|
||||
|
||||
-(int)strengthModifier {
|
||||
@throw [[NSException alloc] initWithName:@"unimplemented" reason:@"Method not implemented." userInfo:nil];
|
||||
return [Monster abilityModifierForScore:self.strengthScore];
|
||||
}
|
||||
|
||||
-(int)dexterityModifier {
|
||||
@@ -340,6 +345,7 @@
|
||||
self.type = monster.type;
|
||||
self.subtype = monster.subtype;
|
||||
self.alignment = monster.alignment;
|
||||
self.strengthScore = monster.strengthScore;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
- (void)setUp {
|
||||
_context = nil;
|
||||
_monster = [[Monster alloc] initWithContext:_context];
|
||||
_jsonString = @"{\"name\":\"Acolyte\",\"size\":\"medium\",\"type\":\"humanoid\",\"tag\":\"any race\",\"alignment\":\"any alignment\"}";
|
||||
_jsonString = @"{\"name\":\"Acolyte\",\"size\":\"medium\",\"type\":\"humanoid\",\"tag\":\"any race\",\"alignment\":\"any alignment\",\"strPoints\":8}";
|
||||
_jsonData = [_jsonString dataUsingEncoding:NSUTF8StringEncoding];
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
XCTAssertEqualObjects(@"", _monster.type);
|
||||
XCTAssertEqualObjects(@"", _monster.subtype);
|
||||
XCTAssertEqualObjects(@"", _monster.alignment);
|
||||
XCTAssertEqual(0, _monster.strengthScore);
|
||||
}
|
||||
|
||||
- (void)testInitWithJSONString {
|
||||
@@ -51,6 +52,7 @@
|
||||
XCTAssertEqualObjects(@"humanoid", _monster.type);
|
||||
XCTAssertEqualObjects(@"any race", _monster.subtype);
|
||||
XCTAssertEqualObjects(@"any alignment", _monster.alignment);
|
||||
XCTAssertEqual(8, _monster.strengthScore);
|
||||
}
|
||||
|
||||
- (void)testInitWithEmptyJSONString {
|
||||
@@ -62,6 +64,7 @@
|
||||
XCTAssertEqualObjects(@"", _monster.type);
|
||||
XCTAssertEqualObjects(@"", _monster.subtype);
|
||||
XCTAssertEqualObjects(@"", _monster.alignment);
|
||||
XCTAssertEqual(0, _monster.strengthScore);
|
||||
}
|
||||
- (void)testInitWithJSONData {
|
||||
_monster = [[Monster alloc] initWithJSONData:_jsonData andContext:_context];
|
||||
@@ -72,6 +75,7 @@
|
||||
XCTAssertEqualObjects(@"humanoid", _monster.type);
|
||||
XCTAssertEqualObjects(@"any race", _monster.subtype);
|
||||
XCTAssertEqualObjects(@"any alignment", _monster.alignment);
|
||||
XCTAssertEqual(8, _monster.strengthScore);
|
||||
}
|
||||
|
||||
- (void)testNameGetterAndSetter {
|
||||
@@ -113,6 +117,7 @@
|
||||
XCTAssertEqualObjects(@"humanoid", _monster.type);
|
||||
XCTAssertEqualObjects(@"any race", _monster.subtype);
|
||||
XCTAssertEqualObjects(@"any alignment", _monster.alignment);
|
||||
XCTAssertEqual(8, _monster.strengthScore);
|
||||
}
|
||||
|
||||
- (void)testMetaWithNoFieldsSet {
|
||||
@@ -231,4 +236,20 @@
|
||||
XCTAssertEqual(5, [Monster abilityModifierForScore:20]);
|
||||
}
|
||||
|
||||
- (void)testStrengthScoreGetterAndSetter {
|
||||
_monster.strengthScore = 11;
|
||||
XCTAssertEqual(11, _monster.strengthScore);
|
||||
}
|
||||
|
||||
- (void)testStrengthModifier {
|
||||
_monster.strengthScore = 9;
|
||||
XCTAssertEqual(-1, _monster.strengthModifier);
|
||||
|
||||
_monster.strengthScore = 10;
|
||||
XCTAssertEqual(0, _monster.strengthModifier);
|
||||
|
||||
_monster.strengthScore = 12;
|
||||
XCTAssertEqual(1, _monster.strengthModifier);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user