Adds intelligenceScore and intelligenceModifier to Monster.

Adds tests for intelligenceScore and intelligenceModifier.
This commit is contained in:
2020-09-13 03:31:21 -07:00
parent 26f92e43f6
commit 05b3ad1280
2 changed files with 28 additions and 2 deletions

View File

@@ -89,6 +89,10 @@
if (tempNumber != nil && [tempNumber isKindOfClass:[NSNumber class]]) { if (tempNumber != nil && [tempNumber isKindOfClass:[NSNumber class]]) {
self.constitutionScore = tempNumber.intValue; self.constitutionScore = tempNumber.intValue;
} }
tempNumber = [jsonRoot objectForKey:@"intPoints"];
if (tempNumber != nil && [tempNumber isKindOfClass:[NSNumber class]]) {
self.intelligenceScore = tempNumber.intValue;
}
return self; return self;
} }
@@ -144,7 +148,7 @@
} }
-(int)intelligenceModifier { -(int)intelligenceModifier {
@throw [[NSException alloc] initWithName:@"unimplemented" reason:@"Method not implemented." userInfo:nil]; return [Monster abilityModifierForScore:self.intelligenceScore];
} }
-(int)wisdomModifier { -(int)wisdomModifier {
@@ -355,6 +359,7 @@
self.strengthScore = monster.strengthScore; self.strengthScore = monster.strengthScore;
self.dexterityScore = monster.dexterityScore; self.dexterityScore = monster.dexterityScore;
self.constitutionScore = monster.constitutionScore; self.constitutionScore = monster.constitutionScore;
self.intelligenceScore = monster.intelligenceScore;
} }
@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,\"conPoints\":12}"; _jsonString = @"{\"name\":\"Acolyte\",\"size\":\"medium\",\"type\":\"humanoid\",\"tag\":\"any race\",\"alignment\":\"any alignment\",\"strPoints\":8,\"dexPoints\":10,\"conPoints\":12,\"intPoints\":14}";
_jsonData = [_jsonString dataUsingEncoding:NSUTF8StringEncoding]; _jsonData = [_jsonString dataUsingEncoding:NSUTF8StringEncoding];
} }
@@ -43,6 +43,7 @@
XCTAssertEqual(0, _monster.strengthScore); XCTAssertEqual(0, _monster.strengthScore);
XCTAssertEqual(0, _monster.dexterityScore); XCTAssertEqual(0, _monster.dexterityScore);
XCTAssertEqual(0, _monster.constitutionScore); XCTAssertEqual(0, _monster.constitutionScore);
XCTAssertEqual(0, _monster.intelligenceScore);
} }
- (void)testInitWithJSONString { - (void)testInitWithJSONString {
@@ -57,6 +58,7 @@
XCTAssertEqual(8, _monster.strengthScore); XCTAssertEqual(8, _monster.strengthScore);
XCTAssertEqual(10, _monster.dexterityScore); XCTAssertEqual(10, _monster.dexterityScore);
XCTAssertEqual(12, _monster.constitutionScore); XCTAssertEqual(12, _monster.constitutionScore);
XCTAssertEqual(14, _monster.intelligenceScore);
} }
- (void)testInitWithEmptyJSONString { - (void)testInitWithEmptyJSONString {
@@ -71,6 +73,7 @@
XCTAssertEqual(0, _monster.strengthScore); XCTAssertEqual(0, _monster.strengthScore);
XCTAssertEqual(0, _monster.dexterityScore); XCTAssertEqual(0, _monster.dexterityScore);
XCTAssertEqual(0, _monster.constitutionScore); XCTAssertEqual(0, _monster.constitutionScore);
XCTAssertEqual(0, _monster.intelligenceScore);
} }
- (void)testInitWithJSONData { - (void)testInitWithJSONData {
_monster = [[Monster alloc] initWithJSONData:_jsonData andContext:_context]; _monster = [[Monster alloc] initWithJSONData:_jsonData andContext:_context];
@@ -84,6 +87,7 @@
XCTAssertEqual(8, _monster.strengthScore); XCTAssertEqual(8, _monster.strengthScore);
XCTAssertEqual(10, _monster.dexterityScore); XCTAssertEqual(10, _monster.dexterityScore);
XCTAssertEqual(12, _monster.constitutionScore); XCTAssertEqual(12, _monster.constitutionScore);
XCTAssertEqual(14, _monster.intelligenceScore);
} }
- (void)testNameGetterAndSetter { - (void)testNameGetterAndSetter {
@@ -128,6 +132,7 @@
XCTAssertEqual(8, _monster.strengthScore); XCTAssertEqual(8, _monster.strengthScore);
XCTAssertEqual(10, _monster.dexterityScore); XCTAssertEqual(10, _monster.dexterityScore);
XCTAssertEqual(12, _monster.constitutionScore); XCTAssertEqual(12, _monster.constitutionScore);
XCTAssertEqual(14, _monster.intelligenceScore);
} }
- (void)testMetaWithNoFieldsSet { - (void)testMetaWithNoFieldsSet {
@@ -294,4 +299,20 @@
XCTAssertEqual(1, _monster.constitutionModifier); XCTAssertEqual(1, _monster.constitutionModifier);
} }
- (void)testIntelligenceScoreGetterAndSetter {
_monster.intelligenceScore = 11;
XCTAssertEqual(11, _monster.intelligenceScore);
}
- (void)testIntelligenceModifier {
_monster.intelligenceScore = 9;
XCTAssertEqual(-1, _monster.intelligenceModifier);
_monster.intelligenceScore = 10;
XCTAssertEqual(0, _monster.intelligenceModifier);
_monster.intelligenceScore = 12;
XCTAssertEqual(1, _monster.intelligenceModifier);
}
@end @end