File size: 23,051 Bytes
966ca88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
#!/usr/bin/env python3
"""COMPUTATION-lane behavioral suite for FlashDim (input -> output).

This lane is the sole owner of jump_kind="value". The app's core function is
setting a flashlight brightness LEVEL; the observable OUTPUT is the
`level_indicator` TextView, formatted "<level> / <maxLevel>".

Every assertion here is a real INPUT -> OUTPUT computation:
  A. tap a level quick-button (Max/Half/Min/Off) -> exact indicator string.
     maxLevel is DERIVED at runtime (parsed from the Max result "N / N"),
     never hardcoded; the Half test then asserts the app computes max//2.
  B. tap the custom vertical seek_bar at a y-fraction -> level = f(position),
     asserting the exact indicator string observed live at each fraction.
  C. (depth 2) the Settings "Preferred level" slider dialog -> "New: N",
     asserting New = f(track fraction).

All expected values were OBSERVED on the running original app, never computed
from source or a constant. The three VLM records verify the CANVAS-drawn
seekbar FILL (which never reaches the view tree) agrees with the numeric level.
"""
import os
import re
import sys

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from android_testgen_kit import *  # noqa: F403,F401


# ── Home helpers ────────────────────────────────────────────────────────────
# restart_app() resumes the app's existing task, and FlashDim's back-stack
# (MainActivity -> SettingsActivity, etc.) survives force-stop, so a raw restart
# can land on Settings. _go_home() backs out until the home surface (identified
# by the level_indicator TextView) is showing.
def _go_home(max_back: int = 6) -> bool:
    restart_app()
    wait_for_foreground(15)
    settle("launch")
    for _ in range(max_back):
        if node_by_id(ui(), "level_indicator") is not None:
            return True
        back()
        settle("launch")
    return node_by_id(ui(), "level_indicator") is not None


def _read_indicator() -> str:
    """The 'N / M' text out of a FRESH dump."""
    n = node_by_id(ui(), "level_indicator")
    return n.get("text", "").strip() if n else ""


def _norm(s: str) -> str:
    """Collapse whitespace so '10 / 10' and '10  /  10' compare equal."""
    return re.sub(r"\s+", " ", s.strip())


def _parse_pair(s: str):
    """'N / M' -> (N, M) ints, or None."""
    m = re.search(r"(\d+)\s*/\s*(\d+)", s)
    return (int(m.group(1)), int(m.group(2))) if m else None


def _derive_max():
    """Run the app to learn maxLevel: tap Max, the indicator reads 'max / max'.
    Returns (max, note). Never assumes 10."""
    if not _go_home():
        return None, "setup_failed: home surface (level_indicator) not reachable"
    if not tap_node(node_by_id(ui(), "max_button")):
        return None, "setup_failed: max_button not tappable"
    pair = _parse_pair(_read_indicator())
    if not pair:
        return None, f"setup_failed: could not parse indicator after Max ({_read_indicator()!r})"
    lvl, mx = pair
    if lvl != mx:
        return None, f"behavior_wrong: Max gave '{lvl} / {mx}', expected level==max"
    return mx, ""


def _seek_bounds():
    """Fresh seek_bar geometry (cx, y1, height) — re-read before EVERY tap
    because a state change invalidates coordinates."""
    n = node_by_id(ui(), "seek_bar")
    if not n or "_bounds" not in n:
        return None
    x1, y1, x2, y2 = n["_bounds"]
    return (x1 + x2) // 2, y1, y2 - y1


def _seek_to(frac: float) -> str:
    """Tap the seek_bar at vertical fraction `frac` (0=top). Returns the
    resulting indicator string, or '' if the bar was not found."""
    b = _seek_bounds()
    if not b:
        return ""
    cx, y1, h = b
    tap(cx, y1 + round(frac * h))
    return _read_indicator()


def _shot(name: str) -> None:
    screencap(os.path.join(RESULTS_DIR, "screenshots", f"{name}.png"))


# ══════════════════════════════════════════════════════════════════════════════
# A. Level quick-button -> indicator value  (depth 0, jump_kind=value)
#    Each test derives maxLevel live, then asserts the exact observed string.
#    Positive/negative pairing: the answer is ABSENT (indicator != target)
#    before the tap and PRESENT after.
# ══════════════════════════════════════════════════════════════════════════════

@and_test(expects=("computation_max_button",))
def test_max_button():
    mx, note = _derive_max()          # _derive_max already taps Max
    if mx is None:
        record("computation_max_button", False, note,
               depth=0, jump_kind="value", expect="'<max> / <max>'")
        return
    expected = f"{mx} / {mx}"
    got = _read_indicator()
    ok = _norm(got) == _norm(expected)
    record("computation_max_button", ok,
           "" if ok else f"behavior_wrong: Max shows {got!r}, expected {expected!r}",
           depth=0, jump_kind="value", expect=f"indicator == '{expected}'")


@and_test(expects=("computation_half_button",))
def test_half_button():
    # Real computation: assert the app computes maxLevel // 2 (integer division).
    mx, note = _derive_max()
    if mx is None:
        record("computation_half_button", False, note,
               depth=0, jump_kind="value", expect="'<max//2> / <max>'")
        return
    before = _read_indicator()        # currently 'max / max' from _derive_max
    expected = f"{mx // 2} / {mx}"
    ok_tap = tap_node(node_by_id(ui(), "half_button"))
    got = _read_indicator()
    # negative->positive: the half value must have been ABSENT then PRESENT
    ok = ok_tap and _norm(got) == _norm(expected) and _norm(before) != _norm(expected)
    if not ok_tap:
        msg = "setup_failed: half_button not tappable"
    elif _norm(got) != _norm(expected):
        msg = f"behavior_wrong: Half shows {got!r}, expected {expected!r} (max//2)"
    else:
        msg = ""
    record("computation_half_button", ok, msg,
           depth=0, jump_kind="value", expect=f"indicator == '{expected}' (max//2)")


@and_test(expects=("computation_min_button",))
def test_min_button():
    mx, note = _derive_max()
    if mx is None:
        record("computation_min_button", False, note,
               depth=0, jump_kind="value", expect="'1 / <max>'")
        return
    expected = f"1 / {mx}"
    ok_tap = tap_node(node_by_id(ui(), "min_button"))
    got = _read_indicator()
    ok = ok_tap and _norm(got) == _norm(expected)
    msg = ("" if ok else
           ("setup_failed: min_button not tappable" if not ok_tap
            else f"behavior_wrong: Min shows {got!r}, expected {expected!r}"))
    record("computation_min_button", ok, msg,
           depth=0, jump_kind="value", expect=f"indicator == '{expected}'")


@and_test(expects=("computation_off_button",))
def test_off_button():
    # Positive/negative: turn the flash ON (Max) first so the '0 / max' answer
    # is provably ABSENT, then Off makes it PRESENT.
    mx, note = _derive_max()          # taps Max -> 'max / max'
    if mx is None:
        record("computation_off_button", False, note,
               depth=0, jump_kind="value", expect="'0 / <max>'")
        return
    before = _read_indicator()        # 'max / max'
    expected = f"0 / {mx}"
    ok_tap = tap_node(node_by_id(ui(), "off_button"))
    got = _read_indicator()
    ok = (ok_tap and _norm(got) == _norm(expected)
          and _norm(before) != _norm(expected))
    msg = ("" if ok else
           ("setup_failed: off_button not tappable" if not ok_tap
            else f"behavior_wrong: Off shows {got!r}, expected {expected!r}"))
    record("computation_off_button", ok, msg,
           depth=0, jump_kind="value", expect=f"indicator == '{expected}'")


# ══════════════════════════════════════════════════════════════════════════════
# B. Seekbar position -> level value  (depth 0, jump_kind=value)
#    level = f(y-position) on the custom vertical LightLevelSeekBar.
#    Fractions and expected strings were OBSERVED live and are deterministic
#    across repeated runs. Bounds are re-read before EACH tap.
# ══════════════════════════════════════════════════════════════════════════════

@and_test(expects=("computation_seek_top_max", "computation_seek_top_max_vlm"))
def test_seek_top_max():
    if not _go_home():
        record("computation_seek_top_max", False,
               "setup_failed: home not reachable",
               depth=0, jump_kind="value", expect="'<max> / <max>'")
        return
    mx = _parse_pair(_read_indicator())
    mx = mx[1] if mx else 10
    got = _seek_to(0.03)              # top of the bar -> saturates at max
    if not got:
        record("computation_seek_top_max", False,
               "setup_failed: seek_bar not found",
               depth=0, jump_kind="value", expect=f"'{mx} / {mx}'")
        return
    expected = f"{mx} / {mx}"
    ok = _norm(got) == _norm(expected)
    record("computation_seek_top_max", ok,
           "" if ok else f"behavior_wrong: top tap shows {got!r}, expected {expected!r}",
           depth=0, jump_kind="value", expect=f"indicator == '{expected}'")
    _shot("computation_seek_top_max_vlm")
    vlm_assert("computation_seek_top_max",
               "In this flashlight app, the vertical segmented bar on the right "
               "side is at its maximum level. Are ALL of its segments (roughly ten "
               "stacked bars, top to bottom) filled/highlighted in the bright "
               "accent color rather than dark gray?",
               RESULTS_DIR, expect="YES", depth=0, jump_kind="value", tag="color")


@and_test(expects=("computation_seek_mid_half", "computation_seek_mid_half_vlm"))
def test_seek_mid_half():
    if not _go_home():
        record("computation_seek_mid_half", False,
               "setup_failed: home not reachable",
               depth=0, jump_kind="value", expect="'<max//2> / <max>'")
        return
    mx = _parse_pair(_read_indicator())
    mx = mx[1] if mx else 10
    got = _seek_to(0.50)             # middle -> half
    if not got:
        record("computation_seek_mid_half", False,
               "setup_failed: seek_bar not found",
               depth=0, jump_kind="value", expect=f"'{mx // 2} / {mx}'")
        return
    expected = f"{mx // 2} / {mx}"
    ok = _norm(got) == _norm(expected)
    record("computation_seek_mid_half", ok,
           "" if ok else f"behavior_wrong: middle tap shows {got!r}, expected {expected!r}",
           depth=0, jump_kind="value", expect=f"indicator == '{expected}'")
    _shot("computation_seek_mid_half_vlm")
    vlm_assert("computation_seek_mid_half",
               "In this flashlight app, the vertical segmented bar on the right is "
               "set to roughly half. Is the bar filled/highlighted from the BOTTOM "
               "up to about the MIDDLE (about half of the stacked segments bright, "
               "the upper half dark)?",
               RESULTS_DIR, expect="YES", depth=0, jump_kind="value", tag="position")


@and_test(expects=("computation_seek_low_one", "computation_seek_low_one_vlm"))
def test_seek_low_one():
    if not _go_home():
        record("computation_seek_low_one", False,
               "setup_failed: home not reachable",
               depth=0, jump_kind="value", expect="'1 / <max>'")
        return
    mx = _parse_pair(_read_indicator())
    mx = mx[1] if mx else 10
    got = _seek_to(0.90)             # near bottom -> level 1
    if not got:
        record("computation_seek_low_one", False,
               "setup_failed: seek_bar not found",
               depth=0, jump_kind="value", expect=f"'1 / {mx}'")
        return
    expected = f"1 / {mx}"
    ok = _norm(got) == _norm(expected)
    record("computation_seek_low_one", ok,
           "" if ok else f"behavior_wrong: low tap shows {got!r}, expected {expected!r}",
           depth=0, jump_kind="value", expect=f"indicator == '{expected}'")
    _shot("computation_seek_low_one_vlm")
    vlm_assert("computation_seek_low_one",
               "In this flashlight app, the vertical segmented bar on the right is "
               "set to its lowest non-zero level. Is ONLY the single bottom segment "
               "highlighted in the bright accent color while all segments above it "
               "are dark gray?",
               RESULTS_DIR, expect="YES", depth=0, jump_kind="value", tag="color")


@and_test(expects=("computation_seek_bottom_zero",))
def test_seek_bottom_zero():
    # Divide/edge case: tapping the very bottom drives the level to 0 (off).
    # Positive/negative: set Max first so '0 / max' is ABSENT, then bottom tap
    # makes it PRESENT.
    if not _go_home():
        record("computation_seek_bottom_zero", False,
               "setup_failed: home not reachable",
               depth=0, jump_kind="value", expect="'0 / <max>'")
        return
    mx = _parse_pair(_read_indicator())
    mx = mx[1] if mx else 10
    _seek_to(0.03)                    # drive to max first
    before = _read_indicator()
    got = _seek_to(0.999)            # very bottom -> 0
    if not got:
        record("computation_seek_bottom_zero", False,
               "setup_failed: seek_bar not found",
               depth=0, jump_kind="value", expect=f"'0 / {mx}'")
        return
    expected = f"0 / {mx}"
    ok = _norm(got) == _norm(expected) and _norm(before) != _norm(expected)
    record("computation_seek_bottom_zero", ok,
           "" if ok else f"behavior_wrong: bottom tap shows {got!r}, expected {expected!r}",
           depth=0, jump_kind="value", expect=f"indicator == '{expected}'")


@and_test(expects=("computation_seek_frac_seven",))
def test_seek_frac_seven():
    # Additional mapping point verified live: f=0.30 -> level 7.
    if not _go_home():
        record("computation_seek_frac_seven", False,
               "setup_failed: home not reachable",
               depth=0, jump_kind="value", expect="'7 / <max>'")
        return
    mx = _parse_pair(_read_indicator())
    mx = mx[1] if mx else 10
    got = _seek_to(0.30)
    if not got:
        record("computation_seek_frac_seven", False,
               "setup_failed: seek_bar not found",
               depth=0, jump_kind="value", expect=f"'7 / {mx}'")
        return
    expected = f"7 / {mx}"
    ok = _norm(got) == _norm(expected)
    record("computation_seek_frac_seven", ok,
           "" if ok else f"behavior_wrong: 0.30 tap shows {got!r}, expected {expected!r}",
           depth=0, jump_kind="value", expect=f"indicator == '{expected}'")


@and_test(expects=("computation_seek_frac_three",))
def test_seek_frac_three():
    # Additional mapping point verified live: f=0.70 -> level 3.
    if not _go_home():
        record("computation_seek_frac_three", False,
               "setup_failed: home not reachable",
               depth=0, jump_kind="value", expect="'3 / <max>'")
        return
    mx = _parse_pair(_read_indicator())
    mx = mx[1] if mx else 10
    got = _seek_to(0.70)
    if not got:
        record("computation_seek_frac_three", False,
               "setup_failed: seek_bar not found",
               depth=0, jump_kind="value", expect=f"'3 / {mx}'")
        return
    expected = f"3 / {mx}"
    ok = _norm(got) == _norm(expected)
    record("computation_seek_frac_three", ok,
           "" if ok else f"behavior_wrong: 0.70 tap shows {got!r}, expected {expected!r}",
           depth=0, jump_kind="value", expect=f"indicator == '{expected}'")


@and_test(expects=("computation_seek_monotonic",))
def test_seek_monotonic():
    # Cross-check the mapping is a genuine decreasing function of y (top>bottom),
    # not a fixed value: level(0.03) > level(0.50) > level(0.90).
    if not _go_home():
        record("computation_seek_monotonic", False,
               "setup_failed: home not reachable",
               depth=0, jump_kind="value", expect="level(top) > level(mid) > level(low)")
        return
    vals = []
    for frac in (0.03, 0.50, 0.90):
        p = _parse_pair(_seek_to(frac))
        vals.append(p[0] if p else None)
    if any(v is None for v in vals):
        record("computation_seek_monotonic", False,
               f"setup_failed: could not read all levels {vals}",
               depth=0, jump_kind="value", expect="level(top) > level(mid) > level(low)")
        return
    top, mid, low = vals
    ok = top > mid > low
    record("computation_seek_monotonic", ok,
           "" if ok else f"behavior_wrong: levels top/mid/low={vals} not strictly decreasing",
           depth=0, jump_kind="value",
           expect=f"level decreases top->bottom (got {top}>{mid}>{low})")


# ══════════════════════════════════════════════════════════════════════════════
# C. Preferred-level slider dialog  (depth 2, jump_kind=value)
#    home -> Settings (depth 1) -> "Preferred level" dialog (depth 2).
#    Track fraction f -> "New: N". Two well-separated fractions verified live
#    (f=0.30 -> New 3, f=0.70 -> New 8). Cancel to avoid persisting state.
# ══════════════════════════════════════════════════════════════════════════════

def and_enter_preferred_level():
    """Open Settings, then the 'Set preferred level' dialog. Returns (ok, note).
    Counts two surfaces (Settings, dialog) via and_enter()."""
    if not _go_home():
        return False, "setup_failed: home not reachable"
    settings = find_node(ui(), content_desc="Settings")
    if not tap_node(settings):
        return False, "setup_failed: Settings action not tappable"
    settle("launch")
    if node_by_id(ui(), "recycler_view") is None:
        return False, "setup_failed: Settings screen did not open"
    and_enter("settings")
    row = find_node_ci(ui(), "Preferred level")
    if not tap_node(row):
        return False, "setup_failed: 'Preferred level' row not tappable"
    settle("tap")
    title = find_node_ci(ui(), "Set preferred level")
    if title is None:
        return False, "setup_failed: 'Set preferred level' dialog did not open"
    and_enter("preferred_level_dialog")
    return True, ""


def _read_new_value():
    """Parse the 'New: N' number from the dialog's TextView."""
    for n in ui():
        t = n.get("text", "").replace("&#10;", "\n")
        m = re.search(r"New:\s*(\d+)", t)
        if m:
            return int(m.group(1))
    return None


def _slider_set(frac: float):
    """Tap the slider track in the customPanel at horizontal fraction `frac`;
    return the resulting New value (int) or None. Re-reads bounds each call."""
    cp = node_by_id(ui(), "customPanel")
    if not cp or "_bounds" not in cp:
        return None
    x1, y1, x2, y2 = cp["_bounds"]
    tx = x1 + round(frac * (x2 - x1))
    tx = max(x1 + 1, min(x2 - 1, tx))
    # The New/Current text sits at the top of customPanel; the slider track is
    # in its lower half. Tap ~78% down the panel height (verified live).
    ty = y1 + round(0.78 * (y2 - y1))
    tap(tx, ty)
    return _read_new_value()


@and_test(expects=("computation_pref_slider_low",))
def test_pref_slider_low():
    ok_nav, note = and_enter_preferred_level()
    if not ok_nav:
        record("computation_pref_slider_low", False, note,
               depth=2, jump_kind="value", expect="dialog shows 'New: 3'")
        return
    before = _read_new_value()
    got = _slider_set(0.30)          # verified live -> New 3
    ok = got == 3 and before != 3
    if got is None:
        msg = "setup_failed: could not read 'New:' value after slider tap"
    elif got != 3:
        msg = f"behavior_wrong: slider f=0.30 gave New:{got}, expected New:3"
    else:
        msg = ""
    record("computation_pref_slider_low", ok, msg,
           depth=2, jump_kind="value", expect="dialog shows 'New: 3'")
    # Cancel so the preferred-level pref is not persisted.
    tap_text(ui(), "Cancel")


@and_test(expects=("computation_pref_slider_high",))
def test_pref_slider_high():
    ok_nav, note = and_enter_preferred_level()
    if not ok_nav:
        record("computation_pref_slider_high", False, note,
               depth=2, jump_kind="value", expect="dialog shows 'New: 8'")
        return
    got = _slider_set(0.70)          # verified live -> New 8
    ok = got == 8
    if got is None:
        msg = "setup_failed: could not read 'New:' value after slider tap"
    elif got != 8:
        msg = f"behavior_wrong: slider f=0.70 gave New:{got}, expected New:8"
    else:
        msg = ""
    record("computation_pref_slider_high", ok, msg,
           depth=2, jump_kind="value", expect="dialog shows 'New: 8'")
    tap_text(ui(), "Cancel")


@and_test(expects=("computation_pref_slider_monotonic",))
def test_pref_slider_monotonic():
    # The slider is a real function of position: New(0.30) < New(0.70).
    ok_nav, note = and_enter_preferred_level()
    if not ok_nav:
        record("computation_pref_slider_monotonic", False, note,
               depth=2, jump_kind="value", expect="New(low) < New(high)")
        return
    low = _slider_set(0.30)
    high = _slider_set(0.70)
    if low is None or high is None:
        record("computation_pref_slider_monotonic", False,
               f"setup_failed: could not read New values (low={low}, high={high})",
               depth=2, jump_kind="value", expect="New(low) < New(high)")
        tap_text(ui(), "Cancel")
        return
    ok = low < high
    record("computation_pref_slider_monotonic", ok,
           "" if ok else f"behavior_wrong: New(0.30)={low} not < New(0.70)={high}",
           depth=2, jump_kind="value",
           expect=f"New increases with position (got {low} < {high})")
    tap_text(ui(), "Cancel")


TESTS = [
    # A. level quick-buttons
    test_max_button,
    test_half_button,
    test_min_button,
    test_off_button,
    # B. seekbar position -> level
    test_seek_top_max,
    test_seek_mid_half,
    test_seek_low_one,
    test_seek_bottom_zero,
    test_seek_frac_seven,
    test_seek_frac_three,
    test_seek_monotonic,
    # C. preferred-level slider dialog (depth 2)
    test_pref_slider_low,
    test_pref_slider_high,
    test_pref_slider_monotonic,
]

if __name__ == "__main__":
    if not device_online():
        print("Device offline — aborting.")
        sys.exit(1)
    run_suite(TESTS, "computation")