Add output diagram writing. Add output tests.
Add input tests.