"""EV-69: a close value an ended phase change tried stays the add-on's own, so the charger taking it late is never read as another writer (no false CHARGER_OTHER, the peak cut never blocked). `python3 -B test_ev69.py` Rows T1-T20, T23-T25 and the Never rules N1-N9 of reports/EV-69-test-plan.md (T21 is test_ev69_fuzz.py, T14 and T22 are the existing suites CI runs). Every check's label starts with its id. Writer level, `tools/ev69_kit.py`: a `SolarWriter` / `ManualWriter` on a stub driver, a stub tracker and a stub reading; time is a 1 s step counter on the model clock. `Base69` is de733f4's behaviour (the carry switched off): the red side of a row, and the equal side of T17 (i). "S1" is the EV-22 review repro (round 2): own 3 -> 1 select taken (window from 122), clamp 16 up to 134 and 8 from 135, close tries 12 A at 132, 8 A at 137 and 142 (all refused), a press at 138, MAX_TRIES ends the change at 142, the 12 A shown at 140. "S1-np": no press. "S1-nt": no take at 140. "CE": the EV-60 cap end (cut_fails 2, close 1 refused, cap 6 A, close 2 = 6 A refused, then the cap end E). "MW": the Manual shape. Mutating a module this file grades? Read MUTATION.md first (purge __pycache__). """ import os import sys HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, os.path.join(HERE, "tools")) from app import carmode as CM # noqa: E402 from named_absence import nth, present # noqa: E402 from ev69_kit import (Base69, BaseM69, Drv, LOG, LOOP, Rd, Run, CLOCK, # noqa: E402,F401 REC, cap, check, done, evs, n_other, n_some, near, nev, press, set_cap, show, swriter, LAST) # ------------------------------------------------------------------ worlds def mk_s1(cls=None, take=None): w = swriter(0.0, ph=3, cls=cls) w.plan.a, w.plan.n = 12.0, 1 drv = Drv(0.0, take or (lambda a, d: False), ph=1) w.seq = {"stage": "settle", "t0": 119.0, "t1": 122.0, "n": 1, "tries": 0, "prev": None, "from": 3, "own": [0.0], "sel": True} w.last_done = 122.0 w._own_n = 3 w._select_try(1, True) return w, drv def clamp_s1(t): return 16.0 if t < 135 else 8.0 def s1(until=400, ev=(), press_at=138, show_at=140, take=None, cls=None, cur=None, stale=None, gone=None, writing=None): w, drv = mk_s1(cls, take) pairs = list(ev) if press_at is not None: pairs.append((press_at, press)) if show_at is not None: pairs.append((show_at, lambda w_, d, s: setattr( d, "cur", d.calls[0][1]))) r = Run(w, drv) return r.go(123, until, ev=evs(*pairs), clamp=clamp_s1, cur=cur, stale=stale, gone=gone, writing=writing) def mk_ce(cls=None, take=None, cut_fails=2, plan_a=8.0): w = swriter(plan_a, ph=1, cls=cls) w.cut_key, w.cut_fails, w.cut_fail_at = 0, cut_fails, -100.0 w.plan._set(plan_a, 130.0, 3) drv = Drv(plan_a, take or (lambda a, d: a == 0.0), ph=1) return w, drv def ce(until=960, cls=None, hook=None, ev=(), plan_a=8.0, take=None, press_after_close2=False): """Close 1 refused, the cap comes in the step after it, close 2 (a cut try, 6 A) refused, then the cap end E.""" w, drv = mk_ce(cls, take, plan_a=plan_a) st = {"cap": False} def h(t, w_, d, s): nz = [1 for tt, a in d.calls if a > 0] if nz and not s["cap"]: s["cap"] = True set_cap(w_, 6.0) if press_after_close2 and len(nz) == 2 and not s.get("pr"): s["pr"] = True w_.user_changed() if hook: hook(t, w_, d, s) r = Run(w, drv, st=st) return r.go(130, until, ev=evs(*ev), hook=h) def close_times(r): return [int(t) for t, a in r.drv.calls if a > 0] def mw(until, user=False, hook2=None, cls=None): """Manual at 12 A on 1 phase; the user picks 3 phases at 100. Every current write but the 0 A is refused. Close 1 = 12 A, then the clamp falls to 8 (or the user lowers the current to 8) before try 2.""" w = (cls or CM.ManualWriter)() drv = Drv(12.0, lambda a, d: a == 0.0, ph=1) st = {"a": 12.0, "n": 1, "rev": 1, "clamp": 16.0} r = Run(w, drv, kind="manual", st=st) def hook(t, w_, d, s): if t == 100: w_.user_changed() s["rev"] += 1 s["n"] = 3 nzc = [1 for tt, a in d.calls if a > 0] if len(nzc) == 1 and not s.get("low"): s["low"] = True if user: w_.user_changed() s["rev"] += 1 s["a"] = 8.0 else: s["clamp"] = 8.0 if hook2: hook2(t, w_, d, s) return r.go(0, until, hook=hook) # =========================================================================== # print("S1 (the reviewer's clamp shape), Solar") # =========================================================================== # cut150 = (150, cap(6.0)) base = s1(400, ev=[cut150], cls=Base69) check(f"T1 [red on base]: S1 on de733f4 (the carry off): mismatch " f"{base.first_ms(140)}, hold {base.first_hold()}, no peak cut write " f"({base.calls_from(143, 400, True)[:3]})", near(base.first_ms(140), 143, 144) and near(base.first_hold(), 173, 174) and 6.0 not in [a for _, a in base.calls_from(143, 200)]) r = s1(400, ev=[cut150]) cut_w = [x for x in r.calls_from(150, 152) if x[1] == 6.0] check(f"T1: S1 (12 A shown at 140), the cut due at 150: 140-400 no mismatch, " f"hold, CHARGER_OTHER or 'Something else' line ({r.first_ms(140)}, " f"{n_other()}, {n_some()}), the 6 A peak cut write " f"at 150-151 ({cut_w}), gave_up never True", r.clean(140, 400) and n_other() == 0 and n_some() == 0 and cut_w and not any(r.gu[t] for t in range(140, 401))) nev("T1", r) r = s1(400) check("T2: S1 to 400, no cut: no mismatch, hold or CHARGER_OTHER 140-400", r.clean(140, 400) and n_other() == 0 and n_some() == 0) w8 = [x for x in r.calls_from(190, 215) if x[1] == 8.0] check(f"T2: the 8 A retry goes out at about 202 and is refused ({w8}); 12 A " f"stays own after that write: prior_a = was = 12 " f"({r.prior[205]}, {r.att[205]})", len(w8) == 1 and near(w8[0][0], 202, 203) and r.prior[205] == 12.0 and r.att[205] == 8.0 and r.carry[205] == []) nev("T2", r) # T3 (changed, GUR): H2 and the reset of fails / gave_up rb = s1(400, press_at=None, ev=[cut150], cls=Base69) rc = s1(400, press_at=None, ev=[cut150]) cw = [x for x in rc.calls_from(150, 152) if x[1] == 6.0] check(f"T3: S1-np, the cut from 150: the 6 A cut write at 150-151 ({cw}), no " f"mismatch, hold or CHARGER_OTHER 140-400 ({n_other()})", cw and rc.clean(140, 400) and n_other() == 0) nev("T3", rc) rp = s1(400, press_at=None) check(f"T3: H2, the press is not needed: S1-np on de733f4 gives mismatch " f"{rb.first_ms(140)}, hold {rb.first_hold()}, gave_up {rb.gu[142]}, " f"and no cut write ({rb.calls_from(143, 200, True)[:2]}) (B1)", near(rb.first_ms(140), 143, 144) and rb.first_hold() is not None and rb.gu[142] is True and 6.0 not in [a for _, a in rb.calls_from(143, 200)]) check(f"T3: S1-np, no cut: no mismatch, hold or CHARGER_OTHER 140-400 " f"({n_other()})", rp.clean(140, 400) and n_other() == 0) check(f"T3 (GUR): the carried 12 A take resets fails/gave_up only: gave_up " f"True at 142 ({rp.gu[142]}), False and fails 0 from 143 " f"({rp.gu[143]}, {rp.fl[143]}); the clamp value 8 A is re-sent at the " f"next retry ({rp.calls_from(190, 215)}). EV-69 GUR: a carried take " f"resets fails/gave_up only", rp.gu[142] is True and not any(rp.gu[t] for t in range(143, 202)) and all(rp.fl[t] == 0 for t in range(143, 202)) and rp.calls_from(190, 215) == [(202, 8.0)]) # T23 (GUR): a carried take is not an adopt check(f"T23: S1-np, the carried 12 A take: taken stays False, last_a None, " f"sent_a 8 A unchanged 143-201 " f"({set(rp.taken[t] for t in range(143, 202))}, " f"{set(rp.last_a[t] for t in range(143, 202))}, " f"{set(rp.sent_a[t] for t in range(143, 202))}); the 8 A goes out at " f"the next RETRY_S step ({rp.calls_from(143, 400)[:1]})", all(rp.taken[t] is False for t in range(143, 202)) and all(rp.last_a[t] is None for t in range(143, 202)) and all(rp.sent_a[t] == 8.0 for t in range(143, 202)) and (142 + int(CM.RETRY_S), 8.0) in rp.calls_from(143, 400)) # T4: a late take after the end for tk in (150, 143, 170, 199): ev = [(tk, show(12.0))] rb = s1(400, show_at=None, ev=ev, cls=Base69) r = s1(400, show_at=None, ev=ev) check(f"T4: S1-nt, 12 A from {tk}: no mismatch 142-400 (the standing 0 A " f"is no take and does not end the carry) ({r.first_ms(142)}); " f"base: {rb.first_ms(142)}", r.clean(142, 400) and n_other() == 0 and rb.first_ms(142) is not None) # T6 (c): a foreign value after the end is still counted and held r = s1(400, ev=[(160, show(16.0))]) check(f"T6 (i): S1 then foreign 16 A at 160: mismatch at 160-161 " f"({r.first_ms(150)}), hold at +30 ({r.first_hold()}) and not +29, " f"exactly 1 CHARGER_OTHER ({n_other()}), nothing non-zero written 160-" f"400 ({r.calls_from(160, 400, True)})", near(r.first_ms(150), 160, 161) and near(r.first_hold(), 190, 191) and r.first_hold() - r.first_ms(150) == 30 and n_other() == 1 and not r.calls_from(160, 400, True) and not r.viol) nev("T6 (i)", r) r = s1(400, show_at=None, ev=[(150, show(5.0))]) check(f"T6 (iii): S1-nt, foreign 5 A at 150: mismatch at 150-151 " f"({r.first_ms(142)}), hold 30 s later ({r.first_hold()}), 1 " f"CHARGER_OTHER ({n_other()}), nothing non-zero written after " f"({r.calls_from(150, 400, True)})", near(r.first_ms(142), 150, 151) and r.first_hold() - r.first_ms(142) == 30 and n_other() == 1 and not r.calls_from(150, 400, True)) nev("T6 (iii)", r) # T7: OQ3, the known limit and its edge r = s1(400, show_at=None, ev=[(150, show(12.0))]) check(f"T7 (i): S1-nt, a foreign value exactly 12 A at 150: no mismatch " f"150-200 (the accepted OQ3 limit, EV-67 class) ({r.first_ms(150)})", r.clean(150, 200)) r = s1(400, show_at=None, ev=[(230, show(12.0))], take=lambda a, d: a == 8.0 and d.now >= 200) check(f"T7 (ii): the 8 A retry taken at 202 (an own take ends the bound), " f"foreign 12 A at 230: mismatch at 230 ({r.first_ms(203)}), hold at " f"260 ({r.first_hold()}), 1 CHARGER_OTHER ({n_other()})", near(r.first_ms(203), 230, 231) and near(r.first_hold(), 260, 261) and n_other() == 1) # T10-T13: the bound r = s1(400, show_at=None, ev=[(150, show(8.0)), (160, show(12.0))]) check(f"T10: S1-nt, the charger takes 8 A (sent_a, an adopt) at 150, then " f"shows 12 A at 160: mismatch at 160 ({r.first_ms(150)}), hold at 190 " f"({r.first_hold()}), 1 CHARGER_OTHER ({n_other()}), nothing non-zero " f"written 160-400 ({r.calls_from(160, 400, True)})", near(r.first_ms(150), 160, 161) and near(r.first_hold(), 190, 191) and n_other() == 1 and not r.calls_from(160, 400, True) and r.carry[151] == []) nev("T10", r) r = s1(400, show_at=None, ev=[(210, show(12.0))]) check(f"T11: S1-nt, the 8 A retry at about 202 refused on 0 A (prior_a 0), " f"12 A at 210: mismatch at 210 ({r.first_ms(150)}), hold at 240 " f"({r.first_hold()}), 1 CHARGER_OTHER ({n_other()})", near(r.first_ms(150), 210, 211) and near(r.first_hold(), 240, 241) and n_other() == 1 and r.prior[205] == 0.0) r = s1(400, show_at=None, ev=[(190, cap(6.0)), (210, show(12.0))]) check(f"T11 variant: the new write is a cut try (cap 6 at 190): 12 A at 210: " f"mismatch ({r.first_ms(150)}), hold ({r.first_hold()}), 1 " f"CHARGER_OTHER ({n_other()}), cut written " f"({r.calls_from(190, 195, True)})", near(r.first_ms(150), 210, 211) and near(r.first_hold(), 240, 241) and n_other() == 1 and (190, 6.0) in r.calls_from(190, 192, True)) r = s1(400, show_at=None, ev=[(145, press), (150, show(12.0))]) check(f"T12: S1-nt, a press at 145 (no hold: the carry ends), 12 A at 150: " f"mismatch at 150 ({r.first_ms(146)}), hold at 180 ({r.first_hold()}), " f"1 CHARGER_OTHER ({n_other()}), no write at or above 12 A " f"({[x for x in r.calls_from(145) if x[1] >= 12.0]})", near(r.first_ms(146), 150, 151) and near(r.first_hold(), 180, 181) and n_other() == 1 and not [x for x in r.calls_from(145) if x[1] >= 12.0]) nev("T12", r) # The press's own retry write ends the carry too, so the row above cannot see # the press end it. Here no step after the press is fresh (no write): the # press alone ends the carry. Nothing is own after it (no judging, the EV-22 # start-state blind spot), so the row grades the state: the carry is gone. r = s1(400, show_at=None, ev=[(145, press), (146, show(12.0))], stale=lambda t: 145 <= t <= 149) check(f"T12 (press alone): S1-nt, a press at 145, no fresh read and no write " f"until 150: the carry ended with the press ({r.carry[144]}, " f"{r.carry[145]}), 12 A is no own value ({r.own[149]})", r.carry[144] != [] and all(r.carry[t] == [] for t in range(145, 150)) and 12.0 not in r.own[149] and not r.calls_from(145, 149)) r = s1(400, show_at=None, ev=[(145, show(16.0)), (200, show(12.0))]) check(f"T13: S1-nt, foreign 16 A at 145 (hold at 175), the writer then sets " f"12 A at 200: the hold stands 175-400 (no lift by match on an old " f"value) ({r.first_hold()}, {all(r.hold[t] for t in range(176, 401))}), " f"1 CHARGER_OTHER ({n_other()}), nothing written 145-400 " f"({r.calls_from(145, 400)})", near(r.first_hold(), 175, 176) and all(r.hold[t] for t in range(177, 401)) and n_other() == 1 and not r.calls_from(145, 400, True) and r.carry[176] == []) nev("T13", r) # T15: unknown read-backs r = s1(400, show_at=None, ev=[(151, show(12.0))], cur=lambda t, d: None if 143 <= t <= 150 else d.cur) check(f"T15 (i): S1-nt, an unknown read-back 143-150 and 12 A at 151: no " f"mismatch 143-400 ({r.first_ms(140)}), no hold, no CHARGER_OTHER " f"({n_other()})", r.clean(143, 400) and n_other() == 0) r = s1(400, show_at=None, ev=[(145, show(16.0))], cur=lambda t, d: None if 150 <= t <= 160 else d.cur) check(f"T15 (ii): foreign 16 A at 145, unknown 150-160, 16 A again from 161: " f"mismatch from 145 ({r.first_ms(140)}), the count stands through " f"None ({all(r.ms[t] is not None for t in range(146, 175))}), hold at " f"175 ({r.first_hold()})", near(r.first_ms(140), 145, 146) and all(r.ms[t] is not None for t in range(146, 175)) and near(r.first_hold(), 175, 176) and n_other() == 1) # T16: stale reads r = s1(400, show_at=None, ev=[(143, show(12.0))], stale=lambda t: 143 <= t <= 147) check(f"T16 (i): S1-nt, 12 A shown from 143 but stale for 143-147: those " f"steps decide nothing, 148-400 no mismatch ({r.first_ms(140)}), no " f"CHARGER_OTHER ({n_other()}); the carry stands through them " f"({r.carry[147]})", r.clean(143, 400) and n_other() == 0 and r.carry[147] != []) r = s1(400, show_at=None, ev=[(145, show(16.0))]) check(f"T16 (ii): a frozen foreign read is a mismatch, then a hold, as " f"before ({r.first_ms(140)}, {r.first_hold()})", near(r.first_ms(140), 145, 146) and near(r.first_hold(), 175, 176)) # T17: restart and return rn = s1(400, show_at=None, cur=lambda t, d: 12.0 if t >= 156 else d.cur, gone=lambda t: 145 <= t <= 155) rbs = s1(400, show_at=None, cur=lambda t, d: 12.0 if t >= 156 else d.cur, gone=lambda t: 145 <= t <= 155, cls=Base69) same = all((rn.ms[t], rn.hold[t], rn.ncalls[t]) == (rbs.ms[t], rbs.hold[t], rbs.ncalls[t]) for t in range(156, 401)) check(f"T17 (i): the charger gone 145-155, back showing 12 A: from 156 every " f"cycle's writes, mismatch and hold equal de733f4 on the same run " f"({same}); the carry stands while it is gone ({rn.carry[155]}) and is " f"gone with the return ({rn.carry[156]})", same and rn.carry[156] == [] and rn.carry[155] != []) src = open(os.path.join(HERE, "app", "carmode.py")).read() others = [f for f in os.listdir(os.path.join(HERE, "app")) if f.endswith(".py") and f != "carmode.py" and "_carry" in open(os.path.join(HERE, "app", f)).read()] w2, m2 = CM.SolarWriter(), CM.ManualWriter() check(f"T17 (ii): a new writer (a process restart) carries nothing " f"({w2._carry}, {m2._carry}); the carry is in no other module (no state " f"file key) ({others})", w2._carry == [] and m2._carry == [] and not others) # T18: a raised try is carried for lab, val in (("(i) try 2 (8 A) raising", 8.0), ("(ii) try 1 (12 A) raising", 12.0)): take = (lambda v: lambda a, d: "raise" if a == v else False)(val) rb = s1(400, show_at=None, ev=[(150, show(12.0))], take=take, cls=Base69, press_at=None) r = s1(400, show_at=None, ev=[(150, show(12.0))], take=take, press_at=None) errs = [t for t, lv, m in r.log if lv == "ERROR" and m == REC] check(f"T18 {lab}: 12 A shown at 150: no mismatch 150-400 " f"({r.first_ms(150)}), the raised value counted as a try, one " f"ERROR record per value ({len(errs)}); base: {rb.first_ms(150)}", r.clean(150, 400) and n_other() == 0 and len(errs) == 1 and rb.first_ms(150) is not None) # T20: Stop / the 0 A rule t0 = lambda a, d: a == 0.0 and d.now >= 158 # noqa: E731 r = s1(400, show_at=140, take=t0, writing=lambda t: t < 160) z = [x for x in r.calls_from(160) if x[1] == 0.0] check(f"T20 (i): S1 (12 A own), Stop at 160: the way-out 0 A at 160 ({z[:1]}), " f"no mismatch at 160 ({r.ms[160]}), no hold, no CHARGER_OTHER " f"({n_other()})", z and near(z[0][0], 160, 161) and r.ms[160] is None and not any(r.hold.values()) and n_other() == 0) r = s1(400, take=t0, ev=[(160, show(16.0))], writing=lambda t: t < 170) z = [x for x in r.calls_from(160) if x[1] == 0.0] check(f"T20 (ii): T6 (i) with Stop at 170 (the count running since 160): the " f"0 A goes out in the count ({z[:2]}), no hold after it " f"({r.first_hold()}), no CHARGER_OTHER ({n_other()})", z and near(z[0][0], 170, 171) and r.first_hold() is None and n_other() == 0) r = s1(400, take=t0, ev=[(160, show(16.0))], writing=lambda t: t < 200) check(f"T20 (iii): T6 (i) with Stop at 200 (the hold stands): nothing " f"written 160-400 ({r.calls_from(160, 400)}), the hold stands " f"({r.hold[300]}), 1 CHARGER_OTHER ({n_other()})", not r.calls_from(160, 400) and r.hold[300] and n_other() == 1) # =========================================================================== # print("CE (the EV-60 cap end), Solar") # =========================================================================== # r = ce(960) ct = close_times(r) E = nth(ct, 1) + 5 check(f"T5 setup: close 1 (8 A) at {nth(ct, 0)}, the cap, close 2 (6 A) at " f"{nth(ct, 1)}, the cap end at {E} with no write ({r.ended})", present(E) and len(ct) >= 2 and r.drv.calls[0][1] == 0.0 and [a for t, a in r.drv.calls if a > 0][:2] == [8.0, 6.0] and r.ended == E) for lab, at_ in (("at E+8", E + 8), ("between close 2 and E", E - 2)): rb = ce(960, ev=[(at_, show(8.0))], cls=Base69) r = ce(960, ev=[(at_, show(8.0))]) k1 = [x for x in r.calls_from(E + 1, 959) if x[1] > 0] check(f"T5: CE, the charger shows 8 A (close 1) {lab}: no mismatch, hold " f"or CHARGER_OTHER E..960 ({r.first_ms(E)}, {n_other()}), no write " f"in key 0 after E, the 6 A cut try at the key roll 900-901 " f"({k1[:2]}), cut_fails never above 3", r.clean(E, 960) and n_other() == 0 and not [x for x in k1 if x[0] < 900] and [x for x in k1 if 900 <= x[0] <= 901 and x[1] == 6.0] and not r.viol) check(f"T5 [red on base] {lab}: base mismatch ({rb.first_ms(E)}), hold " f"({rb.first_hold()}), no cut try at 900 " f"({[x for x in rb.calls_from(E + 1, 959) if x[1] > 0][:2]})", rb.first_ms(E) is not None and rb.first_hold() is not None and not [x for x in rb.calls_from(900, 905) if x[1] > 0]) nev("T5", r) r = ce(960, ev=[(E + 20, show(10.0))]) check(f"T6 (ii): CE, foreign 10 A at E+20: mismatch at the change " f"({r.first_ms(E)}), hold at +30 ({r.first_hold()}), 1 CHARGER_OTHER " f"({n_other()}), nothing non-zero written from the change to 960 " f"({r.calls_from(E + 20, 960, True)})", near(r.first_ms(E), E + 20, E + 21) and r.first_hold() - r.first_ms(E) == 30 and n_other() == 1 and not r.calls_from(E + 20, 960, True)) nev("T6 (ii)", r) # T19: the quarter boundary rb = ce(960, ev=[(900, show(8.0))], cls=Base69) r = ce(960, ev=[(900, show(8.0))]) check(f"T19: CE, the cap standing to 960, the charger shows 8 A at the step " f"of 900: no mismatch 900-960, the key-1 cut try at 900-901 " f"({r.calls_from(899, 905)}), its refusal keeps 8 A own " f"(prior_a {r.prior[902]})", r.clean(900, 960) and n_other() == 0 and [x for x in r.calls_from(900, 901) if x[1] == 6.0] and r.prior[902] == 8.0) check(f"T19 [red on base]: mismatch at 900 ({rb.first_ms(895)})", rb.first_ms(895) is not None) # T24 (formal Dev note 1): the 0 A is carried r = ce(500, press_after_close2=True) E = close_times(r)[1] + 5 r = ce(500, press_after_close2=True, ev=[(E + 3, show(0.0))]) check(f"T24: cap end with a press inside the sequence (prior_a cleared), the " f"charger then shows its own 0 A: no mismatch_since, no hold " f"({r.first_ms(E)}, {r.first_hold()}); the carry holds the 0 A " f"({r.carry[E + 4]})", r.ended == E and r.clean(E, 500) and 0.0 in r.carry[E + 4] and r.prior[E - 1] is None) # T25 (formal Dev note 2): no carry when the end's own value is taken def ce25(): w, drv = mk_ce(plan_a=12.0) st = {"cap": False} def hook(t, w_, d, s): nz = [(tt, a) for tt, a in d.calls if a > 0] if nz and not s["cap"]: s["cap"] = True set_cap(w_, 6.0) if len(nz) >= 2 and t == nz[1][0] + 5: d.cur = 6.0 # close 2 taken late, read at E if len(nz) >= 2 and t == nz[1][0] + 5 + 10: d.cur = 12.0 # an earlier close value return Run(w, drv, st=st).go(130, 600, hook=hook) r = ce25() E = close_times(r)[1] + 5 check(f"T25: CE, the read at E adopts sent_a (6 A taken late) before the cap " f"end: nothing is carried ({r.carry[E]}, {r.carry[E + 10]}), the 12 A " f"(an earlier close value) is no own value when it shows at E+10 " f"({r.own[E + 10]}), 6 A stays taken (taken {r.taken[E]}, sent_a " f"{r.sent_a[E + 10]}); no write in key 0 after E " f"({r.calls_from(E, 899)})", r.ended == E and all(r.carry[t] == [] for t in range(E, 601)) and 12.0 not in r.own[E + 10] and r.taken[E] is True and r.sent_a[E + 10] == 6.0 and not r.calls_from(E, 899)) # The test plan reads T25 as "a mismatch, a hold at +30". It cannot, by the # code: the cap end sets last_a None (F5) and the adopt cleared attempted_a / # prior_a, so no own value is left at all and `_watch` judges nothing (the # EV-22 start-state blind spot, not EV-69's). The row asserts the rule itself: # nothing carried (red under carryAfterTake, which carries 0, 12 and 6). # =========================================================================== # print("MW (Manual, OQ2)") # =========================================================================== # r = mw(300) nzc = [int(t) for t, a in r.drv.calls if a > 0] E = nth(nzc, -1) check(f"T8 setup: Manual closes 12 A, the clamp falls, tries 2 and 3 are 8 A " f"({[(int(t), a) for t, a in r.drv.calls]}), the :589 end at {r.ended}", present(E) and [a for t, a in r.drv.calls if a > 0] == [12.0, 8.0, 8.0] and r.ended == E and r.gu[E] is True) for lab, kw in (("the clamp falls", dict()), ("the user lowers car_current 12 -> 8", dict(user=True))): r0 = mw(300, **kw) E = r0.ended rb = mw(E + 300, cls=BaseM69, hook2=lambda t, w, d, s, E=E: setattr( d, "cur", 12.0) if t == E + 3 else None, **kw) r = mw(E + 300, hook2=lambda t, w, d, s, E=E: setattr( d, "cur", 12.0) if t == E + 3 else None, **kw) check(f"T8: Manual, {lab}, the charger shows 12 A at E+3: no mismatch, " f"hold or 'Something else changes the charger' line E..E+300 " f"({r.first_ms(E)}, {n_some()}); the EV-59 count is unchanged " f"(gave_up {r.gu[E + 4]}); base: hold at {rb.first_hold(E)}", r.clean(E, E + 300) and n_some() == 0 and r.gu[E + 4] is (not kw) # clamp: EV-59 gave up; user: the # count restarted, it asks again and rb.first_hold(E) is not None and near( rb.first_hold(E), E + 33, E + 34)) nev(f"T8 ({lab})", r) r0 = mw(300) E = r0.ended r = mw(E + 300, hook2=lambda t, w, d, s: setattr(d, "cur", 16.0) if t == E + 5 else None) check(f"T9: Manual, foreign 16 A at E+5: mismatch at E+5 ({r.first_ms(E)}), " f"hold at E+35 ({r.first_hold(E)}), 1 INFO line ({n_some()}), no write " f"over 16 A to E+300 ({r.calls_from(E + 1, 10 ** 9, True)})", near(r.first_ms(E), E + 5, E + 6) and near(r.first_hold(E), E + 35, E + 36) and n_some() == 1 and not r.calls_from(E + 1, 10 ** 9, True)) # =========================================================================== # print("Rules the code keeps (Dev notes)") # =========================================================================== # check("T1 [Dev note 1]: one helper `_carry_end` serves both ends and both " "writers (ManualWriter defines it, SolarWriter does not redefine it)", "_carry_end" in vars(CM.ManualWriter) and "_carry_end" not in vars(CM.SolarWriter) and src.count("self._carry_end(q)") == 2) check("T1 [Dev note 6]: `_put` keeps `stopped and not cut_try` (the cut never " "waits on gave_up)", "(stopped and not cut_try)" in src) done()