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

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.