-
Notifications
You must be signed in to change notification settings - Fork 0
/
Testing.java
74 lines (58 loc) · 2.5 KB
/
Testing.java
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
import core.Vector;
/**
* Basic class to test various classes of this package
*
* @author Oskar Kirmis <[email protected]>
*/
public class Testing {
/**
* Run the program. JavaVM has to be started using "-ea" argument to enable assertions.
*/
public static void main(String[] args) {
testMathUtils();
testActionLocker();
}
/**
* Test MathUtils class. This class does basic operations on vectors.
*/
public static void testMathUtils()
{
// Test MathUtils.angleFromVector()
assert cmp( MathUtils.angleFromVector( new Vector(1, 1) ), Math.PI / 4.0 ) : "MathUtils failed.";
assert cmp( MathUtils.angleFromVector( new Vector(1,-1) ), -Math.PI / 4.0 ) : "MathUtils failed.";
assert cmp( MathUtils.angleFromVector( new Vector(0, 1) ), Math.PI / 2 ) : "MathUtils failed.";
assert cmp( MathUtils.angleFromVector( new Vector(0,-1) ), -Math.PI / 2 ) : "MathUtils failed.";
// Test MathUtils.angleOnCircle()
assert cmp( MathUtils.angleOnCircle(5, 2.5), Math.PI / 4 ) : "MathUtils failed.";
assert cmp( MathUtils.angleOnCircle(0, 2.5), Math.PI / 2 ) : "MathUtils failed.";
// Test MathUtils.isVectorParallel()
assert MathUtils.isVectorParallel( new Vector( 1,1 ), new Vector( 1, 1 ) ) : "MathUtils failed.";
assert MathUtils.isVectorParallel( new Vector( 1,1 ), new Vector( 1, 0.8f ) ) : "MathUtils failed.";
assert !MathUtils.isVectorParallel( new Vector( 1,1 ), new Vector( 1, 0 ) ) : "MathUtils failed.";
System.out.println( "MathUtils test passed." );
}
/**
* Test ActionLocker class. This class is used to time events in the game.
*/
public static void testActionLocker()
{
ActionLocker locker = new ActionLocker();
locker.initialize( 10 );
// Test actionlocker isLocked/initialize()
assert !locker.isLocked( ActionLocker.ACTION_THROW_BOTTLE ) : "ActionLocker failed";
assert !locker.isLocked( ActionLocker.ACTION_HIT_POT ) : "ActionLocker failed";
assert !locker.isLocked( ActionLocker.ACTION_THROW_BOTTLE ) : "ActionLocker failed";
assert !locker.isLocked( ActionLocker.ACTION_OWNED_FLAGS + 9 ) : "ActionLocker failed";
// Test lock
locker.lock( ActionLocker.ACTION_THROW_BOTTLE , 1 );
assert locker.isLocked( ActionLocker.ACTION_THROW_BOTTLE ) : "ActionLocker failed";
// Test tick
locker.tick();
assert !locker.isLocked( ActionLocker.ACTION_THROW_BOTTLE ) : "ActionLocker failed";
System.out.println( "ActionLocker test passed." );
}
private static boolean cmp( double a, double b )
{
return Math.abs( a - b ) < Math.pow( 10 , -6 );
}
}