Fix inverted condition and add tests.