Generalized getNodesToSwap(), additional testing code