Skip to content

Instantly share code, notes, and snippets.

@SpacyRicochet
Created August 27, 2011 18:11
Show Gist options
  • Save SpacyRicochet/1175685 to your computer and use it in GitHub Desktop.
Save SpacyRicochet/1175685 to your computer and use it in GitHub Desktop.
Unit test that goes odd
@import "../MBMonster.j"
@implementation MBMonsterTest : OJTestCase
{
MBMonster testMonster;
}
- (void)setUp
{
// Use MBMonster's default initialization.
testMonster = [[MBMonster alloc] init];
}
- (void)tearDown
{
}
- (void)testSetSpeeds
{
// Check whether adding a larger amount of speeds works.
// Taken directly from setSetKeywords in MBEntity.j, since we're testing the CPMutableArray functionality.
var toBeAdded = [CPMutableArray arrayWithObjects:@"Natural", @"Beast", @"Immortal", nil];
[testMonster setSpeeds:toBeAdded];
[self assert:toBeAdded equals:[testMonster speeds] message:@"Keyword array not changed properly"];
[self assertTrue:[[[testMonster speeds] objectAtIndex:0] isEqual:@"Natural"] message:@"First keyword not set properly."];
[self assertTrue:[[[testMonster speeds] objectAtIndex:1] isEqual:@"Beast"] message:@"Second keyword not set properly."];
[self assertTrue:[[[testMonster speeds] objectAtIndex:2] isEqual:@"Immortal"] message:@"Third keyword not set properly."];
// Check to see if the bounds of the array is still correct.
[self assertThrows:function(){ [[testMonster speeds] objectAtIndex:3];}];
}
- (void)testAddSpeed
{
var testSpeed1 = [MBSpeed speedWithType:@"Fly (hover)" andSpeed:6];
var testSpeed2 = [MBSpeed speedWithType:@"Climb" andSpeed:8];
[self assertTrue:[testMonster addSpeed:testSpeed1] message:@"Speed not added succesfully."];
CPLog.warn(@"%@", [[testMonster speeds] count]);
CPLog.warn(@"%@", [[testMonster speeds] description]);
[self assertTrue:[[testMonster speeds] count] == 1 message:@"Speed array not one."];
}
/*
Output of the CPLogs:
2011-08-27 15:15:38.754 objj [warn]: 4
2011-08-27 15:15:38.756 objj [warn]: (
Natural,
Beast,
Immortal,
<MBSpeed 0x0004c3>
)
2011-08-27 15:15:38.758 objj [warn]: addFailure test=[MBMonsterTest testAddSpeed] failure=AssertionFailedError: Speed array not one.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment