Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ynzingakempter committed Sep 12, 2023
1 parent 4564227 commit d7208b3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
9 changes: 1 addition & 8 deletions src/main/java/org/repozoo/commons/range/RangeSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,7 @@ default Stream<T> streamValues() {
}

default void forEachValue(Consumer<T> valueConsumer) {
streamRanges().forEach(r -> {
Value<T> max = r.maxValue();
Value<T> current = r.minValue();
while (current.compareTo(max) <= 0) {
valueConsumer.accept(current.value());
current = current.next();
}
});
streamValues().forEach(valueConsumer::accept);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.repozoo.commons.range.factories.LocalDateRange;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -20,11 +21,25 @@ void streamValues_givesExpectedElements() {
Range<LocalDate> vacationBayern = LocalDateRange.between(LocalDate.parse("2024-07-29"), LocalDate.parse("2024-09-09"));
RangeSet<LocalDate> intersection = vacationBerlin.intersection(vacationBayern);

List<String> list = intersection.streamValues().map(LocalDate::toString).toList();
List<LocalDate> list = intersection.streamValues().toList();

assertThat(list).hasSize(33);
assertThat(list).first().isEqualTo("2024-07-29");
assertThat(list).last().isEqualTo("2024-08-30");
assertThat(list).first().isEqualTo(LocalDate.parse("2024-07-29"));
assertThat(list).last().isEqualTo(LocalDate.parse("2024-08-30"));
}

@Test
void forEachValue_givesExpectedElements() {
Range<LocalDate> vacationBerlin = LocalDateRange.between(LocalDate.parse("2024-07-18"), LocalDate.parse("2024-08-30"));
Range<LocalDate> vacationBayern = LocalDateRange.between(LocalDate.parse("2024-07-29"), LocalDate.parse("2024-09-09"));
RangeSet<LocalDate> intersection = vacationBerlin.intersection(vacationBayern);
List<LocalDate> list = new ArrayList<>();

intersection.forEachValue(list::add);

assertThat(list).hasSize(33);
assertThat(list).first().isEqualTo(LocalDate.parse("2024-07-29"));
assertThat(list).last().isEqualTo(LocalDate.parse("2024-08-30"));
}

@Test
Expand Down

0 comments on commit d7208b3

Please sign in to comment.