Skip to content

Commit

Permalink
MAINT: include null in equality operators
Browse files Browse the repository at this point in the history
Signed-off-by: Chen <[email protected]>
  • Loading branch information
chenqi0805 committed Feb 24, 2022
1 parent cc492ea commit d175a29
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public Integer getSymbol() {
@Override
public Boolean eval(Object... args) {
checkArgument(args.length == 2, "Operands length needs to be 2.");
if ((args[0] == null) || (args[1] == null)) {
return args[0] == null && args[1] == null;
}
return args[0].equals(args[1]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public Integer getSymbol() {
@Override
public Boolean eval(Object... args) {
checkArgument(args.length == 2, "Operands length needs to be 2.");
if ((args[0] == null) || (args[1] == null)) {
return args[0] != null || args[1] != null;
}
return !args[0].equals(args[1]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ void testEvalValidArgs() {
final TestObject testObject3 = new TestObject("2");
assertThat(objectUnderTest.eval(testObject1, testObject2), is(true));
assertThat(objectUnderTest.eval(testObject1, testObject3), is(false));
assertThat(objectUnderTest.eval(null, testObject1), is(false));
assertThat(objectUnderTest.eval(testObject1, null), is(false));
assertThat(objectUnderTest.eval(null, null), is(true));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ void testEvalValidArgs() {
final TestObject testObject3 = new TestObject("2");
assertThat(objectUnderTest.eval(testObject1, testObject2), is(false));
assertThat(objectUnderTest.eval(testObject1, testObject3), is(true));
assertThat(objectUnderTest.eval(null, testObject1), is(true));
assertThat(objectUnderTest.eval(testObject1, null), is(true));
assertThat(objectUnderTest.eval(null, null), is(false));
}

@Test
Expand Down

0 comments on commit d175a29

Please sign in to comment.