Test sparse diff
Fix logic error in sparse diff

Fixes #5853
Merge pull request #5855 from tkelman/sparse-diff

Fix logic error in sparse diff