Skip to content

Commit

Permalink
Add RangeImpl unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
baldimir committed Oct 17, 2024
1 parent 4687dfa commit 677d502
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ public Boolean includes(Object param) {
} else {
if (highEndPoint == null && isUpperBoundaryValueUndefined) {
return posInfRangeIncludes(param);
} else {
} else if (highEndPoint != null) {
return finiteRangeIncludes(param);
} else {
return false;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ void getHighBoundary() {
assertThat(rangeImpl.getHighBoundary()).isEqualTo(highBoundary);
}

@Test
void isLowerBoundaryValueUndefined() {
final boolean isLowerBoundaryValueUndefined = true;
final RangeImpl rangeImpl = new RangeImpl(Range.RangeBoundary.OPEN, 10, 15, Range.RangeBoundary.OPEN, isLowerBoundaryValueUndefined, false);
assertThat(rangeImpl.isLowerBoundaryValueUndefined()).isEqualTo(isLowerBoundaryValueUndefined);
}

@Test
void isUpperBoundaryValueUndefined() {
final boolean isUpperBoundaryValueUndefined = true;
final RangeImpl rangeImpl = new RangeImpl(Range.RangeBoundary.OPEN, 10, 15, Range.RangeBoundary.OPEN, false, true);
assertThat(rangeImpl.isUpperBoundaryValueUndefined()).isEqualTo(isUpperBoundaryValueUndefined);
}

@Test
void includes() {
RangeImpl rangeImpl = new RangeImpl(Range.RangeBoundary.OPEN, 10, 15, Range.RangeBoundary.OPEN, false, false);
Expand All @@ -77,6 +91,31 @@ void includes() {
assertThat(rangeImpl.includes(10)).isTrue();
assertThat(rangeImpl.includes(12)).isTrue();
assertThat(rangeImpl.includes(15)).isTrue();

rangeImpl = new RangeImpl(Range.RangeBoundary.CLOSED, null, 15, Range.RangeBoundary.CLOSED, true, false);
assertThat(rangeImpl.includes(-1456)).isTrue();
assertThat(rangeImpl.includes(20)).isFalse();
assertThat(rangeImpl.includes(null)).isNull();

rangeImpl = new RangeImpl(Range.RangeBoundary.CLOSED, 15, null, Range.RangeBoundary.CLOSED, false, true);
assertThat(rangeImpl.includes(-1456)).isFalse();
assertThat(rangeImpl.includes(20)).isTrue();
assertThat(rangeImpl.includes(null)).isNull();

rangeImpl = new RangeImpl(Range.RangeBoundary.CLOSED, null, null, Range.RangeBoundary.CLOSED, false, true);
assertThat(rangeImpl.includes(-1456)).isNull();
assertThat(rangeImpl.includes(20)).isNull();
assertThat(rangeImpl.includes(null)).isNull();

rangeImpl = new RangeImpl(Range.RangeBoundary.CLOSED, null, 15, Range.RangeBoundary.CLOSED, false, true);
assertThat(rangeImpl.includes(-1456)).isFalse();
assertThat(rangeImpl.includes(20)).isFalse();
assertThat(rangeImpl.includes(null)).isNull();

rangeImpl = new RangeImpl(Range.RangeBoundary.CLOSED, 15, null, Range.RangeBoundary.CLOSED, true, false);
assertThat(rangeImpl.includes(-1456)).isFalse();
assertThat(rangeImpl.includes(20)).isFalse();
assertThat(rangeImpl.includes(null)).isNull();
}

@Test
Expand All @@ -98,6 +137,13 @@ void equals() {
rangeImpl2 = new RangeImpl(Range.RangeBoundary.CLOSED, 12, 17, Range.RangeBoundary.CLOSED, false, false);
assertThat(rangeImpl2).isNotEqualTo(rangeImpl);

rangeImpl2 = new RangeImpl(Range.RangeBoundary.OPEN, 10, 15, Range.RangeBoundary.OPEN, true, false);
assertThat(rangeImpl2).isNotEqualTo(rangeImpl);
rangeImpl2 = new RangeImpl(Range.RangeBoundary.OPEN, 10, 15, Range.RangeBoundary.OPEN, true, true);
assertThat(rangeImpl2).isNotEqualTo(rangeImpl);
rangeImpl2 = new RangeImpl(Range.RangeBoundary.OPEN, 10, 15, Range.RangeBoundary.OPEN, false, true);
assertThat(rangeImpl2).isNotEqualTo(rangeImpl);

rangeImpl = new RangeImpl();
assertThat(rangeImpl).isEqualTo(rangeImpl);
}
Expand All @@ -120,5 +166,12 @@ void hashCodeTest() {
assertThat(rangeImpl2).doesNotHaveSameHashCodeAs(rangeImpl);
rangeImpl2 = new RangeImpl(Range.RangeBoundary.CLOSED, 12, 17, Range.RangeBoundary.CLOSED, false, false);
assertThat(rangeImpl2).doesNotHaveSameHashCodeAs(rangeImpl);

rangeImpl2 = new RangeImpl(Range.RangeBoundary.OPEN, 10, 15, Range.RangeBoundary.OPEN, true, false);
assertThat(rangeImpl2).doesNotHaveSameHashCodeAs(rangeImpl);
rangeImpl2 = new RangeImpl(Range.RangeBoundary.OPEN, 10, 15, Range.RangeBoundary.OPEN, true, true);
assertThat(rangeImpl2).doesNotHaveSameHashCodeAs(rangeImpl);
rangeImpl2 = new RangeImpl(Range.RangeBoundary.OPEN, 10, 15, Range.RangeBoundary.OPEN, false, true);
assertThat(rangeImpl2).doesNotHaveSameHashCodeAs(rangeImpl);
}
}

0 comments on commit 677d502

Please sign in to comment.