THINK FIRST·CODE LATER

← All labs

Post lifecycle: state-transition testing

Problem

A StudyBuddy post has the states DRAFT, PUBLISHED, HIDDEN, DELETED. The valid transitions are:

From Event To
DRAFT publish PUBLISHED
DRAFT delete DELETED
PUBLISHED hide HIDDEN
PUBLISHED delete DELETED
HIDDEN restore PUBLISHED
HIDDEN delete DELETED

Input: several test sequences. Each line is one sequence of events for a new post (which starts in DRAFT), e.g. publish hide restore. For each line print the path, marking rejected events: a rejected event leaves the state unchanged.

Exact format: start with the initial state; for each event append -event-> STATE if valid, or (event rejected) if not.

Finally print transition coverage: Transitions covered: c/6 and Not covered: ... listing uncovered valid transitions as FROM-event in the table order, separated by , , or Not covered: none.

Input:

publish hide restore
delete publish

Output:

DRAFT -publish-> PUBLISHED -hide-> HIDDEN -restore-> PUBLISHED
DRAFT -delete-> DELETED (publish rejected)
Transitions covered: 4/6
Not covered: PUBLISHED-delete, HIDDEN-delete

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

s8-4-data-1.txt

publish hide restore
delete publish
What your program must print for s8-4-data-1.txt
DRAFT -publish-> PUBLISHED -hide-> HIDDEN -restore-> PUBLISHED
DRAFT -delete-> DELETED (publish rejected)
Transitions covered: 4/6
Not covered: PUBLISHED-delete, HIDDEN-delete

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < s8-4-data-1.txt

Windows PowerShell does not understand <:

Get-Content s8-4-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.