Added assertions to check conditions for exiting while loop

in _raisePermanenceToThreshold method

fixes #1322 
@rhyolight Should we have NuPIC issue numbers in comments? Thanks.