Releases: NicMcPhee/Machine-shop-simulator
Add property-based tests
I wanted to try property-based testing, and decided to give junit-quickcheck a try. To simplify incorporating the necessary libraries and dependencies, I converted the project to use Gradle and then added junit-quickcheck as a dependency.
I started out by writing some properties for LinkedQueue because I thought that would be easier since I "understood" what the queue code was doing better than I feel I understand the simulator. In doing so I came to understand that you need to implement both doShrink() and magnitude if you want junit-quickcheck to do the nifty bit of shrinking test cases to try to find a small(er) test case that raises an error. This is a great feature because it makes it a lot easier to understand what's happening when tests fail and I really wanted see that in action. It turns out that making smaller instances of a LinkedQueue was kind of a pain because there was no way to walk through a LinkedQueue without removing all the items in the process, which then made a mess of error reporting later. So I had to remove everything from the original queue, put them all back, and then use them to build a smaller queue. Kinda ugly, to be honest.
I then implemented several different properties for the simulator. Most of that went pretty well once I understood how to use junit-quickcheck. Again the biggest challenge was doShrink(); I implemented two ways of shrinking a SimulationSpecification: Remove a random machine, or remove a random job. Removing a job turned out to be pretty straightforward; I just needed to decrement the number of jobs and remove the task list for that job. Removing a random machine was kind of a pain because I had to loop through all the task lists and remove any occurrences of that machine (which indirectly shrunk the size of the task lists, which was nice) and remember to decrement the machine number for any machine with a higher number. (E.g., if we're deleting machine 3, we have to change all machine 4 references to machine 3, 5 to 4, 6 to 5, etc.).
All the tests pass, and if I deliberately "break" the simulator junit-quickcheck is typically able to give me an input with 1 machine and 1 job that exposes the problem, which is cool. The test coverage is also at or very near 100% across all the simulator classes.
Convert to gradle
Add gradle config info so we can use it to manage builds and (importantly next) dependencies.
Extracted all the I/O from the simulator to simplify testing
This extracts all the I/O out of the simulator and into some I/O helper classes. The simulator can now be restructured so that it takes an input object and returns an output object, which should make testing a lot simpler.