imSimReal: The latest

I’ve pretty much finished IMSRGravity class for now. It really does nothing but wrap an NSDictionary with some meaningful names. The NSDictionary is initialized from a property list, Gravity.plist. The plist contains the names of celestial bodies (Earth, Moon, Jupiter) as keys, and their gravity accelerations at the surface as the values. Gravity is in meters per second per second.

The test case for initializing IMSRGravity works.

The second imSimReal class in IMSRPointObject. This class represents a point mass for purposes of dealing with translational kinematics. It contains an NSMutableDictionary which contains the position, velocity and acceleration applied to the object in three dimensions (X, Y and Z). Currently I am trying to write tests and test the condition where nine values are 0.0 in the initialized state. I am having an interesting time with an NSNumber when initialized with double.

The IMSRPointObject initializer code:

- (id)initWithPositionX: (double)positionX positionY: (double)positionY positionZ: (double)positionZ
			  velocityX: (double)velocityX velocityY: (double)velocityY velocityZ: (double)velocityZ
		  accelerationX: (double)accelerationX accelerationY: (double)accelerationY accelerationZ: (double)accelerationZ
	if (![super init])
		return nil;
	NSArray *keys = [[NSArray alloc] initWithObjects: @"positionX", @"positionY", @"positionZ",
					 @"velocityX", @"velocityY", @"velocityZ", 
					 @"accelerationX", @"accelerationY", @"accelerationZ", nil];
	NSArray *values	= [[NSArray alloc] initWithObjects: [NSNumber numberWithDouble: positionX],
					   [NSNumber numberWithDouble: positionY], [NSNumber numberWithDouble: positionZ],
					   [NSNumber numberWithDouble: velocityX], [NSNumber numberWithDouble: velocityY],
					   [NSNumber numberWithDouble: velocityZ], [NSNumber numberWithDouble: accelerationX],
					   [NSNumber numberWithDouble: accelerationY], [NSNumber numberWithDouble: accelerationZ]];
	pointObject	= [NSMutableDictionary dictionaryWithObjects: values forKeys: keys];
	return self;

And the code for testing this initializer:

- (void)testInitPointObjectWithPositionVelocityAndAcceleration
	IMSRPointObject *point1	= [[IMSRPointObject alloc] initWithPositionX: 0.0
			   									       positionY: 0.0
			   									       positionZ: 0.0
			   									       velocityX: 0.0
			   									       velocityY: 0.0
			   									       velocityZ: 0.0								    			        accelerationX: 0.0
		    										   accelerationY: 0.0								    				   accelerationZ: 0.0];
	STAssertNotNil(point1, @"Could not construct point with all zero values");
	NSMutableDictionary *state1	= [point1 pointObject];
	STAssertNotNil(state1, @"state dictionary not available");
	NSNumber *count		= [NSNumber numberWithInt: [state1 count]];
	NSNumber *expCount	= [NSNumber numberWithInt: 9];
	STAssertTrue([count isEqualToNumber: expCount], 
				 @"Incorrect number of values. Have %d, should be %d", count, expCount); 
	[count release];
	[expCount release]; 
	NSNumber *expectedValue	= [NSNumber numberWithDouble: 0.0];
	for (id key in state1)
		NSNumber *value	= [state1 objectForKey: key];
		STAssertTrue([value isEqualToNumber: expectedValue], 
					 @"Number for %@ is %@. Should be %d", key, value, expectedValue);
		[value release];

	[expectedValue release];
	[state1 release];
	[point1 release];

Note that the test passes up to the

STAssertTrue([count isEqualToNumber: expCount], ...

the test works. After that, things go awry. The line:

NSNumber *expectedValue = [NSNumber numberWithDouble: 0.0]; 

causes the test to throw an uncaught exception and fail. I can’t figure out what’s wrong with that line… Time to take a break and see what I can figure out tomorrow.

Technorati Tags:
, ,

This entry was posted in imSimReal, iPhone, Macintosh, OS X, Software Development. Bookmark the permalink.

Comments are closed.