Skip to content

Commit 84f30f4

Browse files
author
Arun Prasaad
committed
Verify key command for undoing the last move
1 parent ae2dee6 commit 84f30f4

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

.cascade

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ avoid_unnecessary_getters = true
1010
# Method ordering: helper methods after their callers
1111
# Test names should be propositional (e.g., "returns_true_when_condition_met")
1212
propositional_test_names = true
13+
# Test descriptions should be propositional (e.g., "returns_initial_position_after_undo")
14+
propositional_test_descriptions = true
1315
helper_methods_after_caller = true
1416

1517
[editing]

src/test/java/ihm/SokobanWindowTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,39 @@ void handles_restart_action() {
256256
then(controller.getWorker().getColumn()).isEqualTo(initialColumn);
257257
}
258258

259+
@Test
260+
void can_undo_the_last_move() {
261+
// given - make a move
262+
int initialLine = controller.getWorker().getLine();
263+
int initialColumn = controller.getWorker().getColumn();
264+
265+
// Move right
266+
KeyEvent rightKey = new KeyEvent(window,
267+
KeyEvent.KEY_PRESSED,
268+
System.currentTimeMillis(),
269+
0,
270+
KeyEvent.VK_RIGHT,
271+
KeyEvent.CHAR_UNDEFINED);
272+
window.keyPressed(rightKey);
273+
274+
// when - press space to step back
275+
KeyEvent spaceKey = new KeyEvent(window,
276+
KeyEvent.KEY_PRESSED,
277+
System.currentTimeMillis(),
278+
0,
279+
KeyEvent.VK_SPACE,
280+
KeyEvent.CHAR_UNDEFINED);
281+
window.keyPressed(spaceKey);
282+
283+
// then - worker should be back at initial position
284+
then(controller.getWorker().getLine())
285+
.as("line position is restored when undoing last move")
286+
.isEqualTo(initialLine);
287+
then(controller.getWorker().getColumn())
288+
.as("column position is restored when undoing last move")
289+
.isEqualTo(initialColumn);
290+
}
291+
259292
@Test
260293
void completing_a_custom_level_disposes_window_and_shows_home_window() {
261294
// given - create a test window with the simplified level that only needs one push

0 commit comments

Comments
 (0)