Download presentation
Presentation is loading. Please wait.
Published byFlorence Griffith Modified over 9 years ago
1
Assignment: Unit Testing
2
Wall-follower applied to a simple maze
3
Perfect Maze A perfect maze is defined as a maze which has one and only one path from any point in the maze to any other point no inaccessible sections no circular paths no open areas
4
“Pefect Maze” xSxxxxxxxxxxxxxxxx x x x x x xx x xxx x xxx x x x x x x xx x xxxxxx xxxxxx xx x x x x x xx xxx x x xx x x xxx xxxx xxxx x x x x xxxxxxxxxxxxxxxxEx
5
* Denotes a node xSxxxxxxxxxxxxxxxx X* x x x x xx x xxx x xxx x x x x x * x xx x xxxxxx xxxxxx xx x x x* x * x xx * xxx x x xx x x xxx *xxxx xxxx x x x * x XxxxxxxxxxxxxxxxEx
6
E S
7
“Pefect Maze” xSxxxxxxxxxxxxxxxx x x x x x xx x xxx x xxx x x xE x x x xx x xxxxxx xxxxxx xx x x x x x xx xxx x x xx x x xxx xxxx xxxx x x x x xxxxxxxxxxxxxxxxxx
8
E S
9
Pseudo-code in its simplest form InitPositionInitDirection done = FALSE; While (!done) if IsOpenForward if IsOpenForward { MoveForward MoveForward if IsEndNode if IsEndNode done = TRUE done = TRUE else if IsOpenToRight else if IsOpenToRight TurnRight TurnRight } else else TurnLeft; TurnLeft;
10
“Units” ► Read a grid ► Clean the grid ► Find start position ► Find start direction ► Test forward cell ► Test right cell ► Test end of maze ► Turn left ► Turn right ► Move forward ► Record cell entering data Direction ► Report(s): Cells visited Count of visits to cell Directions from which cell was entered
11
For testing, try using: ► ‘ ‘ will denote an open cell ► ‘x’ will denote a wall ► ‘s’ is start ► ‘e’ is end ► Make your application adaptable for these values
12
Simple Moving and Direction ► movements: ► east: dx=1, dy=0 ► south: dx=0, dy=-1 ► west: dx=-1, dy=0 ► north: dx=0, dy=1 ► To turn, increment or decrement through directions
13
Test Grid You don’t need an actual “maze” to test but you do need a grid. Example:xxxxxx123xx456xx789xXxxxx By using these types of known inputs, it becomes easy to test your units. In this case, each non- wall cell has a unique value.
14
Example Test Grid Cases ► Edges not closed Generate a warning ► Not all chars in same case ► No ‘end’ cell ► No ‘start’ cell ► ‘extra’ cells around maze
15
Maze Assignment Full Reveal: Week 1 Feb 25 ► BMP as input ► This assignment is not about mazes ► This assignment IS about unit testing and test-driven development ► use Java or C# for the entire assignment Purpose: use JUnit (or csUnit) build indicated units write tests for units ► Points off for obvious cases that you did not consider
16
Maze Assignment Full Reveal: Week 2 March 4 ► Maze defined by BMP ► solve mazes ► Continue to use JUnit or csUnit ► report non-perfect mazes inaccessible sections circular paths open areas ► report node locations ► Employ A* ► Report path and cost of path
17
Maze Assignment Full Reveal: Week 3 March 11 ► Create a GUI ► test mazes minimum: report problems better: highlight offending part of maze, step through all problems detected ideal: automatically repair problems when possible ► edit mazes interactively ► design mazes automatically
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.