[General boards] [Winter 2019 courses] [Fall 2018 courses] [Summer 2018 courses] [Older or newer terms]

Testing Seaweed Length


Since we are not given a setCurrentLength method I assume we cannot implement one hoping the autograder uses it. In that case to test seaweed being eaten I put fish right next to it and set its direction appropriately, however due to a random variable it may move up or down in the single step it takes to get to the seaweed and thus the expected length of the seaweed may vary. Is there a way for mockito to force a certain value in fish ie so it doesn’t move up or down or should I check for all possible lengths, which doesn’t seem very specific for catching bugs.


You can always do the confidence interval thing, where you run the test 1000 times and expect the length to be (not moving up / down length) about 90% of the time

Alternatively, you can put the “eat seaweed” logic in Seaweed’s update method, and just check the cells in y-1 to y-length contain a fish, and trim your own length to where the fish was found (this is what I would do if I were you…), then mock a fish intersecting a seaweed, call “update()” on the seaweed, and ensure it’s shrunk.