Per my comment above, these tests have a lot of ground to cover. Should this code be split up into two functions that work independently? It could also work to have those two separate functions and one function to delegate between them.