Files
learning-hour-maker/ideas/split-loop-with-lambda/exercise/rehearsal-runs/A+Q/pi-stdout.txt
T
Your Name b993f25c53 Add agent rehearsal harness, findings, and per-run evidence for split-loop-with-lambda
Six scripted pi sub-agent runs (3 tool regimes × 2 models) rehearsed the
exercise; deterministic gate = solution test + approved file. Key results:
mandated CLI triples cost on the strong model (4:06 vs 0:39, PASS both);
weak model fails only under the mandate (A+Q), passes when free or optional.
Drift documented with code: scorer.updateSelection left inside the extracted
method (A+Q, C+Q). Harness in tools/rehearse; summary in
rehearsal-findings.md; per-run evidence in rehearsal-runs/; cheat sheet in
rehearse-with-agent.md corrected (lambda-typed parameters unsupported).
2026-09-27 17:36:19 +00:00

75 lines
2.8 KiB
Plaintext

## Refactoring Complete — Final Diff
Here's the summary of all changes made to `LongRangeForecasts.java`:
### Summary of Changes
| Step | What was done |
|------|---------------|
| **1** | Introduced `dayOffsetToWeather` lambda (`LongFunction<Boolean>`) at top of method; replaced `scorer.lookupWeather(daysForward)` with `dayOffsetToWeather.apply(daysForward)` |
| **2** | Extracted weather-collection loop into new private method `collectExpectedWeather(List<Instant>, LongFunction<Boolean>)` |
| **3** | Removed `String quarter` parameter, added no-arg overload `longRangeForecast()` that wraps `scorer` in a lambda and delegates to `longRangeForecast(LongFunction<Boolean>)` |
### Final Diff
```diff
@@ -3,36 +3,27 @@
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(dayOffset -> scorer.lookupWeather(dayOffset));
+ }
+
+ 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(...);
- List<Boolean> expectedWeather = new ArrayList<>();
- for (...) {
- scorer.updateSelection();
- ...
- Boolean lookupWeather = scorer.lookupWeather(daysForward);
- expectedWeather.add(lookupWeather);
- }
+ List<Boolean> expectedWeather = collectExpectedWeather(interestingDates, dayOffsetToWeather);
@@ -46,4 +37,16 @@
}
return result;
}
+
+ private List<Boolean> collectExpectedWeather(List<Instant> interestingDates,
+ LongFunction<Boolean> dayOffsetToWeather) {
+ List<Boolean> result = 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);
+ result.add(dayOffsetToWeather.apply(daysForward));
+ }
+ return result;
+ }
}
```
The code **compiles cleanly**. The test fails because the old `longRangeForecast(String)` signature no longer exists — which is expected per the task instructions.