Adds constitutionScore and constitutionModifier to Monster.

Adds tests for constitutionScore and constitutionModifier.
This commit is contained in:
2020-09-13 03:29:01 -07:00
parent 58ce77e4df
commit aca029955e
2 changed files with 28 additions and 2 deletions

View File

@@ -85,6 +85,10 @@
if (tempNumber != nil && [tempNumber isKindOfClass:[NSNumber class]]) { if (tempNumber != nil && [tempNumber isKindOfClass:[NSNumber class]]) {
self.dexterityScore = tempNumber.intValue; self.dexterityScore = tempNumber.intValue;
} }
tempNumber = [jsonRoot objectForKey:@"conPoints"];
if (tempNumber != nil && [tempNumber isKindOfClass:[NSNumber class]]) {
self.constitutionScore = tempNumber.intValue;
}
return self; return self;
} }
@@ -136,7 +140,7 @@
} }
-(int)constitutionModifier { -(int)constitutionModifier {
@throw [[NSException alloc] initWithName:@"unimplemented" reason:@"Method not implemented." userInfo:nil]; return [Monster abilityModifierForScore:self.constitutionScore];
} }
-(int)intelligenceModifier { -(int)intelligenceModifier {
@@ -350,6 +354,7 @@
self.alignment = monster.alignment; self.alignment = monster.alignment;
self.strengthScore = monster.strengthScore; self.strengthScore = monster.strengthScore;
self.dexterityScore = monster.dexterityScore; self.dexterityScore = monster.dexterityScore;
self.constitutionScore = monster.constitutionScore;
} }
@end @end

View File

@@ -25,7 +25,7 @@
- (void)setUp { - (void)setUp {
_context = nil; _context = nil;
_monster = [[Monster alloc] initWithContext:_context]; _monster = [[Monster alloc] initWithContext:_context];
_jsonString = @"{\"name\":\"Acolyte\",\"size\":\"medium\",\"type\":\"humanoid\",\"tag\":\"any race\",\"alignment\":\"any alignment\",\"strPoints\":8,\"dexPoints\":10}"; _jsonString = @"{\"name\":\"Acolyte\",\"size\":\"medium\",\"type\":\"humanoid\",\"tag\":\"any race\",\"alignment\":\"any alignment\",\"strPoints\":8,\"dexPoints\":10,\"conPoints\":12}";
_jsonData = [_jsonString dataUsingEncoding:NSUTF8StringEncoding]; _jsonData = [_jsonString dataUsingEncoding:NSUTF8StringEncoding];
} }
@@ -42,6 +42,7 @@
XCTAssertEqualObjects(@"", _monster.alignment); XCTAssertEqualObjects(@"", _monster.alignment);
XCTAssertEqual(0, _monster.strengthScore); XCTAssertEqual(0, _monster.strengthScore);
XCTAssertEqual(0, _monster.dexterityScore); XCTAssertEqual(0, _monster.dexterityScore);
XCTAssertEqual(0, _monster.constitutionScore);
} }
- (void)testInitWithJSONString { - (void)testInitWithJSONString {
@@ -55,6 +56,7 @@
XCTAssertEqualObjects(@"any alignment", _monster.alignment); XCTAssertEqualObjects(@"any alignment", _monster.alignment);
XCTAssertEqual(8, _monster.strengthScore); XCTAssertEqual(8, _monster.strengthScore);
XCTAssertEqual(10, _monster.dexterityScore); XCTAssertEqual(10, _monster.dexterityScore);
XCTAssertEqual(12, _monster.constitutionScore);
} }
- (void)testInitWithEmptyJSONString { - (void)testInitWithEmptyJSONString {
@@ -68,6 +70,7 @@
XCTAssertEqualObjects(@"", _monster.alignment); XCTAssertEqualObjects(@"", _monster.alignment);
XCTAssertEqual(0, _monster.strengthScore); XCTAssertEqual(0, _monster.strengthScore);
XCTAssertEqual(0, _monster.dexterityScore); XCTAssertEqual(0, _monster.dexterityScore);
XCTAssertEqual(0, _monster.constitutionScore);
} }
- (void)testInitWithJSONData { - (void)testInitWithJSONData {
_monster = [[Monster alloc] initWithJSONData:_jsonData andContext:_context]; _monster = [[Monster alloc] initWithJSONData:_jsonData andContext:_context];
@@ -80,6 +83,7 @@
XCTAssertEqualObjects(@"any alignment", _monster.alignment); XCTAssertEqualObjects(@"any alignment", _monster.alignment);
XCTAssertEqual(8, _monster.strengthScore); XCTAssertEqual(8, _monster.strengthScore);
XCTAssertEqual(10, _monster.dexterityScore); XCTAssertEqual(10, _monster.dexterityScore);
XCTAssertEqual(12, _monster.constitutionScore);
} }
- (void)testNameGetterAndSetter { - (void)testNameGetterAndSetter {
@@ -123,6 +127,7 @@
XCTAssertEqualObjects(@"any alignment", _monster.alignment); XCTAssertEqualObjects(@"any alignment", _monster.alignment);
XCTAssertEqual(8, _monster.strengthScore); XCTAssertEqual(8, _monster.strengthScore);
XCTAssertEqual(10, _monster.dexterityScore); XCTAssertEqual(10, _monster.dexterityScore);
XCTAssertEqual(12, _monster.constitutionScore);
} }
- (void)testMetaWithNoFieldsSet { - (void)testMetaWithNoFieldsSet {
@@ -273,4 +278,20 @@
XCTAssertEqual(1, _monster.dexterityModifier); XCTAssertEqual(1, _monster.dexterityModifier);
} }
- (void)testConstitutionScoreGetterAndSetter {
_monster.constitutionScore = 11;
XCTAssertEqual(11, _monster.constitutionScore);
}
- (void)testConstitutionModifier {
_monster.constitutionScore = 9;
XCTAssertEqual(-1, _monster.constitutionModifier);
_monster.constitutionScore = 10;
XCTAssertEqual(0, _monster.constitutionModifier);
_monster.constitutionScore = 12;
XCTAssertEqual(1, _monster.constitutionModifier);
}
@end @end