The refactoring is now published as Slice on sammancoaching.org: https://sammancoaching.org/refactorings/slice.html - git mv ideas/split-loop-with-lambda -> ideas/slice-with-lambda - rename learning-hour file and update frontmatter name - update paths in tools/rehearse scripts and report title - update prose: 'Split Loop with Lambda' -> 'Slice with Lambda' in learning hour, exercise READMEs, storyboard, solution comments - link the published Slice refactoring from the pattern draft
104 lines
5.4 KiB
Diff
104 lines
5.4 KiB
Diff
Only in /tmp/rehearsal/runs/B/workspace: AGENTS.md
|
|
diff -ru '--exclude=target' /tmp/rehearsal/pristine/src/main/java/codingdojo/LongRangeForecasts.java /tmp/rehearsal/runs/B/workspace/src/main/java/codingdojo/LongRangeForecasts.java
|
|
--- /tmp/rehearsal/pristine/src/main/java/codingdojo/LongRangeForecasts.java 2026-09-27 14:39:01.304467310 +0000
|
|
+++ /tmp/rehearsal/runs/B/workspace/src/main/java/codingdojo/LongRangeForecasts.java 2026-09-27 14:53:31.157357707 +0000
|
|
@@ -3,36 +3,25 @@
|
|
import java.time.Instant;
|
|
import java.time.temporal.ChronoUnit;
|
|
import java.util.*;
|
|
+import java.util.function.LongFunction;
|
|
|
|
public class LongRangeForecasts {
|
|
|
|
private final Scorer scorer = new Scorer();
|
|
|
|
- public Map<IceCream, Integer> longRangeForecast(String quarter) {
|
|
+ public Map<IceCream, Integer> longRangeForecast() {
|
|
+ return longRangeForecast(daysForward -> {
|
|
+ scorer.updateSelection();
|
|
+ return scorer.lookupWeather(daysForward);
|
|
+ });
|
|
+ }
|
|
|
|
+ public Map<IceCream, Integer> longRangeForecast(LongFunction<Boolean> dayOffsetToWeather) {
|
|
var result = new HashMap<IceCream, Integer>();
|
|
- if (Objects.equals(quarter, "Q1") || Objects.equals(quarter, "Q4")) {
|
|
- for (IceCream flavour : IceCream.values()) {
|
|
- result.put(flavour, 5);
|
|
- }
|
|
- }
|
|
for (IceCream flavour : IceCream.values()) {
|
|
result.put(flavour, 0);
|
|
}
|
|
- List<Instant> interestingDates = List.of(
|
|
- Instant.parse("2023-05-01T14:00:00.000-07:00"),
|
|
- Instant.parse("2023-05-18T14:00:00.000-07:00"),
|
|
- Instant.parse("2023-06-05T14:00:00.000-07:00"),
|
|
- Instant.parse("2023-06-23T14:00:00.000-07:00")
|
|
- );
|
|
- List<Boolean> expectedWeather = new ArrayList<>();
|
|
- for (Instant interestingDate : interestingDates) {
|
|
- scorer.updateSelection();
|
|
- var forecastDate = Instant.parse("2023-04-26T14:00:00.000-07:00");
|
|
- long daysForward = ChronoUnit.DAYS.between(forecastDate, interestingDate);
|
|
- Boolean lookupWeather = scorer.lookupWeather(daysForward);
|
|
- expectedWeather.add(lookupWeather);
|
|
- }
|
|
+ List<Boolean> expectedWeather = collectExpectedWeather(dayOffsetToWeather);
|
|
|
|
for (IceCream flavour : result.keySet()) {
|
|
result.put(flavour, result.get(flavour) + 10);
|
|
@@ -46,4 +35,21 @@
|
|
}
|
|
return result;
|
|
}
|
|
+
|
|
+ private List<Boolean> collectExpectedWeather(LongFunction<Boolean> dayOffsetToWeather) {
|
|
+ List<Instant> interestingDates = List.of(
|
|
+ Instant.parse("2023-05-01T14:00:00.000-07:00"),
|
|
+ Instant.parse("2023-05-18T14:00:00.000-07:00"),
|
|
+ Instant.parse("2023-06-05T14:00:00.000-07:00"),
|
|
+ Instant.parse("2023-06-23T14:00:00.000-07:00")
|
|
+ );
|
|
+ List<Boolean> expectedWeather = new ArrayList<>();
|
|
+ for (Instant interestingDate : interestingDates) {
|
|
+ var forecastDate = Instant.parse("2023-04-26T14:00:00.000-07:00");
|
|
+ long daysForward = ChronoUnit.DAYS.between(forecastDate, interestingDate);
|
|
+ Boolean lookupWeather = dayOffsetToWeather.apply(daysForward);
|
|
+ expectedWeather.add(lookupWeather);
|
|
+ }
|
|
+ return expectedWeather;
|
|
+ }
|
|
}
|
|
diff -ru '--exclude=target' /tmp/rehearsal/pristine/src/test/java/codingdojo/DailyForecastsTest.salesForecast.received.txt /tmp/rehearsal/runs/B/workspace/src/test/java/codingdojo/DailyForecastsTest.salesForecast.received.txt
|
|
--- /tmp/rehearsal/pristine/src/test/java/codingdojo/DailyForecastsTest.salesForecast.received.txt 2026-09-27 14:39:03.626410227 +0000
|
|
+++ /tmp/rehearsal/runs/B/workspace/src/test/java/codingdojo/DailyForecastsTest.salesForecast.received.txt 2026-09-27 14:53:35.478277153 +0000
|
|
@@ -1,4 +1,4 @@
|
|
Forecast at: 2026-09-27
|
|
Steve score: 9
|
|
-Julie score: 9
|
|
-Francis score: 9
|
|
+Julie score: 3
|
|
+Francis score: 11
|
|
diff -ru '--exclude=target' /tmp/rehearsal/pristine/src/test/java/codingdojo/LongRangeForecastsTest.java /tmp/rehearsal/runs/B/workspace/src/test/java/codingdojo/LongRangeForecastsTest.java
|
|
--- /tmp/rehearsal/pristine/src/test/java/codingdojo/LongRangeForecastsTest.java 2026-09-27 14:39:01.304467310 +0000
|
|
+++ /tmp/rehearsal/runs/B/workspace/src/test/java/codingdojo/LongRangeForecastsTest.java 2026-09-27 14:53:33.005323250 +0000
|
|
@@ -13,8 +13,7 @@
|
|
|
|
@Test
|
|
void longRangeForecast() {
|
|
- var quarter = "Q3";
|
|
- var actual = new LongRangeForecasts().longRangeForecast(quarter);
|
|
+ var actual = new LongRangeForecasts().longRangeForecast();
|
|
StringBuilder printedResult = printIceCreamForecast(actual);
|
|
|
|
Approvals.verify(printedResult);
|
|
diff -ru '--exclude=target' /tmp/rehearsal/pristine/src/test/java/codingdojo/LongRangeForecastsTest.longRangeForecast.received.txt /tmp/rehearsal/runs/B/workspace/src/test/java/codingdojo/LongRangeForecastsTest.longRangeForecast.received.txt
|
|
--- /tmp/rehearsal/pristine/src/test/java/codingdojo/LongRangeForecastsTest.longRangeForecast.received.txt 2026-09-27 14:39:03.582411308 +0000
|
|
+++ /tmp/rehearsal/runs/B/workspace/src/test/java/codingdojo/LongRangeForecastsTest.longRangeForecast.received.txt 2026-09-27 14:53:35.437277917 +0000
|
|
@@ -1 +1 @@
|
|
-{Strawberry:12, Chocolate:12, Vanilla:12, }
|
|
\ No newline at end of file
|
|
+{Strawberry:12, Chocolate:12, Vanilla:17, }
|
|
\ No newline at end of file
|