forked from john-bai/DesignPatterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMementoTest.java
More file actions
76 lines (65 loc) · 1.71 KB
/
Copy pathMementoTest.java
File metadata and controls
76 lines (65 loc) · 1.71 KB
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
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package designpatterns;
import java.awt.Point;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author jtherrell
*/
public class MementoTest {
public MementoTest() {
}
// TODO add test methods here.
// The methods must be annotated with annotation @Test. For example:
//
@Test
public void testMoveExecuteOnce() {
Point delta = new Point(5,5);
Graphix g = new Graphix(new Point(100,100));
MoveCommand move = new MoveCommand(g);
move.execute(delta);
Point expResult = new Point(105,105);
Point result = g.position();
assertEquals(expResult, result);
}
@Test
public void testMoveExecuteMany() {
Point delta = new Point(5,5);
Graphix g = new Graphix(new Point(100,100));
MoveCommand move = new MoveCommand(g);
for(int i = 0; i < 10; i++)
move.execute(delta);
Point expResult = new Point(150,150);
Point result = g.position();
assertEquals(expResult, result);
}
@Test
public void testMoveUndoOnce() {
Point delta = new Point(5,5);
Graphix g = new Graphix(new Point(100,100));
MoveCommand move = new MoveCommand(g);
move.execute(delta);
move.unexecute();
Point expResult = new Point(100,100);
Point result = g.position();
assertEquals(expResult, result);
}
@Test
public void testMoveUndoMany() {
Point delta = new Point(5,5);
Graphix g = new Graphix(new Point(100,100));
MoveCommand move = new MoveCommand(g);
for(int i = 0; i < 10; i++)
move.execute(delta);
for(int i = 0; i < 10; i++) {
move.unexecute();
}
Point expResult = new Point(100,100);
Point result = g.position();
assertEquals(expResult, result);
}
}