-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBallTest.m
80 lines (62 loc) · 2.36 KB
/
BallTest.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#import "BallTest.h"
#import "Ball.h"
#import "UIAcceleration+Settable.h"
@implementation BallTest
- (void) testBallExists {
Ball* ball = [[Ball alloc] init];
STAssertNotNil(ball, @"");
}
- (void) testInitialVelocity {
Ball* ball = [[Ball alloc] init];
STAssertEquals(0.0f, ball.xVelocity, nil);
STAssertEquals(0.0f, ball.yVelocity, nil);
STAssertEquals(0.0f, ball.zVelocity, nil);
}
-(void) testInitialPosition {
Ball* ball = [[Ball alloc] init];
STAssertEquals(50.0f, ball.xPos, nil);
STAssertEquals(50.0f, ball.yPos, nil);
}
-(void) testChangeXVelocity {
Ball* ball = [[Ball alloc] init];
UIAcceleration* acceleration;
acceleration = [[UIAcceleration alloc] initWithX: 1.0f withY: 0.0 andZ: 0.0f];
//v = a * t
UIAccelerometer *accelerometer = [[UIAccelerometer alloc] init];
[ball accelerometer: accelerometer didAccelerate: acceleration];
STAssertEquals(1.0f * ball.accelerationCoefficient, ball.xVelocity, nil);
STAssertEquals(50.0f + (1/60.0f * ball.accelerationCoefficient), ball.xPos, nil);
}
-(void) testMoveOneTick {
Ball* ball = [[Ball alloc] init];
[ball setXVelocity:60.0f];
UIAcceleration* acceleration;
acceleration = [[UIAcceleration alloc] initWithX: 0.0f withY: 0.0 andZ: 0.0f];
//v = a * t
UIAccelerometer *accelerometer = [[UIAccelerometer alloc] init];
[ball accelerometer: accelerometer didAccelerate: acceleration];
STAssertEquals(60.0f, ball.xVelocity, nil);
STAssertEquals(51.0f, ball.xPos, nil);
//velocity is pixels / second
}
-(void) testChangeYVelocity {
Ball* ball = [[Ball alloc] init];
UIAcceleration* acceleration;
acceleration = [[UIAcceleration alloc] initWithX: 0.0f withY: 1.0f andZ: 0.0f];
UIAccelerometer *accelerometer = [[UIAccelerometer alloc] init];
[ball accelerometer: accelerometer didAccelerate: acceleration];
STAssertEquals(1.0f * ball.accelerationCoefficient, ball.yVelocity, nil);
STAssertEquals(50.0f + (1/60.0f * ball.accelerationCoefficient), ball.yPos, nil);
}
-(void) testMoveOneTickY {
Ball* ball = [[Ball alloc] init];
[ball setYVelocity:60.0f];
UIAcceleration* acceleration;
acceleration = [[UIAcceleration alloc] initWithX: 0.0f withY: 0.0 andZ: 0.0f];
//v = a * t
UIAccelerometer *accelerometer = [[UIAccelerometer alloc] init];
[ball accelerometer: accelerometer didAccelerate: acceleration];
STAssertEquals(60.0f, ball.yVelocity, nil);
STAssertEquals(51.0f, ball.yPos, nil);
}
@end