| |
| """COMPUTATION module for openScale (a body-weight / health tracker). |
| |
| CORE FUNCTION: input -> output. This lane is the sole owner of jump_kind="value". |
| openScale's core transform is: you enter a Weight (and the user's Height/Gender/ |
| age/activity from the profile), and the app DERIVES a set of values: |
| |
| BMI = weight / (height/100)^2 -> shown on the Overview card AND Statistics |
| BMR (Mifflin-St Jeor) -> Statistics card, "kcal" |
| TDEE = BMR * activity multiplier -> Statistics card, "kcal" |
| Weight echo -> Overview card AND Statistics ("kg") |
| |
| Every EXPECTED string below was OBSERVED on the RUNNING ORIGINAL (a user with |
| Height 180, Male, born 2008 (age ~18), Sedentary; one measurement), never computed |
| from a formula or read from source: |
| |
| weight 80 -> BMI "24.7" weight 60 -> "18.5" weight 100 -> "30.9" |
| BMR "1840 kcal" TDEE "2208 kcal" |
| weight echo "80 kg" Statistics Min/Max/Avg == the single value |
| height 200 + weight 80 -> BMI "20" (whole-number BMI renders without ".0") |
| |
| RELIABLE OBSERVATION POINT: on the Edit-Measurement DETAIL screen BMI does NOT |
| reliably recompute live from a dialog edit, so we always SAVE -> read on |
| Overview / Statistics. The one in-page value transition we assert directly is the |
| NumberInputDialog stepper effect on the EditText string (Weight step +0.1). |
| |
| DROPPED: WHR / WHtR. On this build the derived WHR/WHtR rows render "-" on the |
| detail screen even after waist+hips are entered and saved (observed WHR="-", |
| WHtR="-"), so no value is reproducibly observable — recon permits dropping these. |
| |
| Run: |
| python3 test_android_computation.py <PACKAGE> <RESULTS_DIR> |
| """ |
| import os |
| import sys |
|
|
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) |
| from android_testgen_kit import * |
|
|
|
|
| |
| |
| |
| |
| |
|
|
| def and_enter_user_form(): |
| """From the Overview 'No User Active' surface, open the Add-User form.""" |
| n = find_node_ci(ui(), "Add User") |
| if n is None or not tap_node(n): |
| return False |
| settle("launch") |
| and_enter("user_form") |
| return True |
|
|
|
|
| def and_enter_new_measurement(): |
| """From the Overview, open the New Measurement screen (empty-state 'Add |
| Measurement' button, or the top-bar cd='Add new measurement').""" |
| n = (find_node_ci(ui(), "Add Measurement") |
| or find_node(ui(), content_desc="Add new measurement")) |
| if n is None or not tap_node(n): |
| return False |
| settle("launch") |
| and_enter("new_measurement") |
| return True |
|
|
|
|
| def and_enter_weight_dialog(): |
| """From the New/Edit Measurement screen, open the Edit Weight |
| NumberInputDialog (cd='Edit Weight').""" |
| n = find_node(ui(), content_desc="Edit Weight") |
| if n is None or not tap_node(n): |
| return False |
| settle("tap") |
| and_enter("weight_dialog") |
| return True |
|
|
|
|
| def and_reach_statistics(): |
| """From the Overview, reach the Statistics screen, PROVING the jump. |
| |
| 'before' MUST be snapshotted while the Overview is showing — the 'Statistics' |
| title is genuinely absent there, so tapping through the drawer makes it newly |
| APPEAR (and_reach). Opening the drawer FIRST would place the 'Statistics' |
| drawer item into 'before' and defeat the appeared-check (this was the bug in |
| the first run). Counts one surface via and_enter. |
| """ |
| before = and_showing() |
| menu = find_node(ui(), content_desc="Open menu") |
| if menu is None or not tap_node(menu): |
| return False |
| settle("launch") |
| dest = (find_node(ui(), content_desc="Statistics") |
| or find_node_ci(ui(), "Statistics")) |
| if dest is None or not tap_node(dest): |
| return False |
| settle("launch") |
| after = and_showing() |
| ok = and_reach(before, after, "Statistics") |
| if ok: |
| and_enter("statistics") |
| return ok |
|
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| def set_dialog_value(val): |
| c = find_node_ci(ui(), "Clear") |
| if c: |
| tap_node(c) |
| settle("keyboard") |
| ets = find_by_class(ui(), "EditText") |
| if not ets: |
| return "" |
| et = ets[0] |
| tap_node(et) |
| settle("keyboard") |
| settle("keyboard") |
| for ch in str(val): |
| adb_shell("input", "text", ch) |
| settle("text") |
| settle("text") |
| ets = find_by_class(ui(), "EditText") |
| return ets[0].get("text", "") if ets else "" |
|
|
|
|
| def _tap_dialog_ok(): |
| ok_btn = find_node_ci(ui(), "OK") |
| if ok_btn: |
| tap_node(ok_btn) |
| settle("tap") |
|
|
|
|
| def create_user(height="180", name="TestUser"): |
| """clear_data() -> launch -> fill Name+Height -> tap the top-right Save button |
| DIRECTLY (no hide_keyboard(); its BACK fallback would discard the form). |
| Returns True once the 'No User Active' state is gone.""" |
| clear_data() |
| launch_app() |
| wait_for_foreground() |
| settle("launch") |
| if not and_enter_user_form(): |
| return False |
| ets = sorted(find_by_class(ui(), "EditText"), |
| key=lambda e: e.get("_bounds", (0, 0, 0, 0))[1]) |
| if len(ets) < 2: |
| return False |
| type_text(ets[0], name) |
| settle("text") |
| ets = sorted(find_by_class(ui(), "EditText"), |
| key=lambda e: e.get("_bounds", (0, 0, 0, 0))[1]) |
| type_text(ets[1], height) |
| settle("text") |
| btns = [n for n in ui() |
| if n.get("class", "").endswith("Button") |
| and n.get("clickable") == "true" |
| and n.get("_bounds", (0, 0, 0, 0))[0] > 800] |
| if not btns: |
| return False |
| tap_node(btns[0]) |
| settle("launch") |
| return find_node_ci(ui(), "No User Active") is None |
|
|
|
|
| def add_weight_measurement(weight): |
| """From the Overview (user must already exist): open New Measurement, set |
| Weight via the proven recipe, OK, Save measurement. Returns the field string |
| the dialog actually held (caller verifies == str(weight)).""" |
| if not and_enter_new_measurement(): |
| return None |
| if not and_enter_weight_dialog(): |
| return None |
| got = set_dialog_value(weight) |
| _tap_dialog_ok() |
| sm = find_node(ui(), content_desc="Save measurement") |
| if sm: |
| tap_node(sm) |
| settle("launch") |
| return got |
|
|
|
|
| def user_with_weight(weight, height="180"): |
| """End-to-end fixture: clean user + one saved weight measurement, left on the |
| Overview. Returns (ok, dialog_field_string).""" |
| if not create_user(height=height): |
| return False, "" |
| got = add_weight_measurement(weight) |
| return (got == str(weight)), (got or "") |
|
|
|
|
| |
|
|
| def _norm(s): |
| """Normalise a numeric display for comparison: drop spaces & thousands |
| separators, lowercase the unit.""" |
| return s.replace(",", "").replace(" ", "").strip().lower() |
|
|
|
|
| def overview_card_texts(): |
| """Every text on the Overview that carries a digit (date, '80 kg', '24.7').""" |
| return [n.get("text", "").strip() for n in ui() |
| if n.get("text", "").strip() and any(c.isdigit() for c in n.get("text", ""))] |
|
|
|
|
| def stat_value(metric_label, kind): |
| """On the Statistics screen, the 'Min:'/'Max:'/'Avg:' value for a metric card. |
| |
| Each metric card is a TIGHT vertical cluster whose 'Kind:' rows straddle the |
| label (OBSERVED geometry: 'Min: 80 kg' y=360, 'Weight' y=389, 'Max: 80 kg' |
| y=402, 'Avg: 80 kg' y=444 — the label sits BETWEEN Min and Max, and the next |
| card is ~500px away). So the right row is the 'Kind:' row whose y is CLOSEST |
| to the label's y (not merely the first one below it — that reads the NEXT |
| card). `kind` in {'Min','Max','Avg'}. Returns the value part, or "". |
| """ |
| nodes = ui() |
| prefix = f"{kind}:" |
| lab = None |
| for n in nodes: |
| if n.get("text", "").strip() == metric_label: |
| lab = n |
| break |
| if lab is None: |
| return "" |
| ly = lab.get("_bounds", (0, 0, 0, 0))[1] |
| cands = [n for n in nodes if n.get("text", "").strip().startswith(prefix)] |
| if not cands: |
| return "" |
| |
| |
| nearest = min(cands, key=lambda n: abs(n.get("_bounds", (0, 0, 0, 0))[1] - ly)) |
| if abs(nearest.get("_bounds", (0, 0, 0, 0))[1] - ly) > 120: |
| return "" |
| return nearest.get("text", "").split(":", 1)[1].strip() |
|
|
|
|
| def dialog_field_value(): |
| ets = find_by_class(ui(), "EditText") |
| return ets[0].get("text", "") if ets else "" |
|
|
|
|
| |
| |
| |
| @and_test(expects=("computation_bmi_80_overview", |
| "computation_overview_chart_vlm")) |
| def test_bmi_80_overview(): |
| ok_setup, got = user_with_weight("80") |
| if not ok_setup: |
| record("computation_bmi_80_overview", False, |
| f"setup_failed: could not enter weight 80 (dialog held {got!r})", |
| depth=1, jump_kind="value", expect="24.7") |
| record("computation_overview_chart_vlm", False, |
| "setup_failed: no saved measurement to chart", |
| depth=1, jump_kind="value", tag="position") |
| return |
| texts = overview_card_texts() |
| present = any(_norm(t) == "24.7" for t in texts) |
| record("computation_bmi_80_overview", present, |
| "" if present else f"behavior_wrong: Overview BMI not '24.7'; saw {texts!r}", |
| depth=1, jump_kind="value", expect="24.7") |
| |
| |
| |
| vlm_assert("computation_overview_chart", |
| "In the upper area of this screen, is there a small colored dot " |
| "plotted in a graph/plot region, with a date label (such as a day " |
| "and month) shown along the horizontal axis below it?", |
| RESULTS_DIR, depth=1, jump_kind="value", tag="position") |
|
|
|
|
| |
| |
| |
| @and_test(expects=("computation_bmi_60_overview",)) |
| def test_bmi_60_overview(): |
| ok_setup, got = user_with_weight("60") |
| if not ok_setup: |
| record("computation_bmi_60_overview", False, |
| f"setup_failed: could not enter weight 60 (dialog held {got!r})", |
| depth=1, jump_kind="value", expect="18.5") |
| return |
| texts = overview_card_texts() |
| present = any(_norm(t) == "18.5" for t in texts) |
| |
| wrong = any(_norm(t) == "24.7" for t in texts) |
| ok = present and not wrong |
| record("computation_bmi_60_overview", ok, |
| "" if ok else f"behavior_wrong: Overview BMI not '18.5'; saw {texts!r}", |
| depth=1, jump_kind="value", expect="18.5") |
|
|
|
|
| |
| |
| |
| @and_test(expects=("computation_bmi_100_overview",)) |
| def test_bmi_100_overview(): |
| ok_setup, got = user_with_weight("100") |
| if not ok_setup: |
| record("computation_bmi_100_overview", False, |
| f"setup_failed: could not enter weight 100 (dialog held {got!r})", |
| depth=1, jump_kind="value", expect="30.9") |
| return |
| texts = overview_card_texts() |
| present = any(_norm(t) == "30.9" for t in texts) |
| record("computation_bmi_100_overview", present, |
| "" if present else f"behavior_wrong: Overview BMI not '30.9'; saw {texts!r}", |
| depth=1, jump_kind="value", expect="30.9") |
|
|
|
|
| |
| |
| |
| @and_test(expects=("computation_weight_echo_overview",)) |
| def test_weight_echo_overview(): |
| ok_setup, got = user_with_weight("80") |
| if not ok_setup: |
| record("computation_weight_echo_overview", False, |
| f"setup_failed: could not enter weight 80 (dialog held {got!r})", |
| depth=1, jump_kind="value", expect="80 kg") |
| return |
| texts = overview_card_texts() |
| present = any(_norm(t) == _norm("80 kg") for t in texts) |
| record("computation_weight_echo_overview", present, |
| "" if present else f"behavior_wrong: card weight not '80 kg'; saw {texts!r}", |
| depth=1, jump_kind="value", expect="80 kg") |
|
|
|
|
| |
| |
| |
| @and_test(expects=("computation_stats_bmi_min",)) |
| def test_stats_bmi_min(): |
| ok_setup, got = user_with_weight("80") |
| if not ok_setup: |
| record("computation_stats_bmi_min", False, |
| f"setup_failed: could not enter weight 80 (dialog held {got!r})", |
| depth=2, jump_kind="value", expect="24.7") |
| return |
| if not and_reach_statistics(): |
| record("computation_stats_bmi_min", False, |
| "setup_failed: could not reach the Statistics screen", |
| depth=2, jump_kind="value", expect="24.7") |
| return |
| val = stat_value("BMI", "Min") |
| ok = _norm(val) == "24.7" |
| record("computation_stats_bmi_min", ok, |
| "" if ok else f"behavior_wrong: Statistics BMI Min not '24.7'; saw {val!r}", |
| depth=2, jump_kind="value", expect="24.7") |
|
|
|
|
| |
| |
| |
| @and_test(expects=("computation_stats_bmi_max",)) |
| def test_stats_bmi_max(): |
| ok_setup, got = user_with_weight("80") |
| if not ok_setup: |
| record("computation_stats_bmi_max", False, |
| f"setup_failed: could not enter weight 80 (dialog held {got!r})", |
| depth=2, jump_kind="value", expect="24.7") |
| return |
| if not and_reach_statistics(): |
| record("computation_stats_bmi_max", False, |
| "setup_failed: could not reach the Statistics screen", |
| depth=2, jump_kind="value", expect="24.7") |
| return |
| val = stat_value("BMI", "Max") |
| ok = _norm(val) == "24.7" |
| record("computation_stats_bmi_max", ok, |
| "" if ok else f"behavior_wrong: Statistics BMI Max not '24.7'; saw {val!r}", |
| depth=2, jump_kind="value", expect="24.7") |
|
|
|
|
| |
| |
| |
| @and_test(expects=("computation_stats_bmi_avg",)) |
| def test_stats_bmi_avg(): |
| ok_setup, got = user_with_weight("80") |
| if not ok_setup: |
| record("computation_stats_bmi_avg", False, |
| f"setup_failed: could not enter weight 80 (dialog held {got!r})", |
| depth=2, jump_kind="value", expect="24.7") |
| return |
| if not and_reach_statistics(): |
| record("computation_stats_bmi_avg", False, |
| "setup_failed: could not reach the Statistics screen", |
| depth=2, jump_kind="value", expect="24.7") |
| return |
| val = stat_value("BMI", "Avg") |
| ok = _norm(val) == "24.7" |
| record("computation_stats_bmi_avg", ok, |
| "" if ok else f"behavior_wrong: Statistics BMI Avg not '24.7'; saw {val!r}", |
| depth=2, jump_kind="value", expect="24.7") |
|
|
|
|
| |
| |
| |
| @and_test(expects=("computation_stats_bmr_min",)) |
| def test_stats_bmr_min(): |
| ok_setup, got = user_with_weight("80") |
| if not ok_setup: |
| record("computation_stats_bmr_min", False, |
| f"setup_failed: could not enter weight 80 (dialog held {got!r})", |
| depth=2, jump_kind="value", expect="1840 kcal") |
| return |
| if not and_reach_statistics(): |
| record("computation_stats_bmr_min", False, |
| "setup_failed: could not reach the Statistics screen", |
| depth=2, jump_kind="value", expect="1840 kcal") |
| return |
| val = stat_value("BMR", "Min") |
| ok = _norm(val) == _norm("1840 kcal") |
| record("computation_stats_bmr_min", ok, |
| "" if ok else f"behavior_wrong: Statistics BMR Min not '1840 kcal'; saw {val!r}", |
| depth=2, jump_kind="value", expect="1840 kcal") |
|
|
|
|
| |
| |
| |
| @and_test(expects=("computation_stats_bmr_avg",)) |
| def test_stats_bmr_avg(): |
| ok_setup, got = user_with_weight("80") |
| if not ok_setup: |
| record("computation_stats_bmr_avg", False, |
| f"setup_failed: could not enter weight 80 (dialog held {got!r})", |
| depth=2, jump_kind="value", expect="1840 kcal") |
| return |
| if not and_reach_statistics(): |
| record("computation_stats_bmr_avg", False, |
| "setup_failed: could not reach the Statistics screen", |
| depth=2, jump_kind="value", expect="1840 kcal") |
| return |
| val = stat_value("BMR", "Avg") |
| ok = _norm(val) == _norm("1840 kcal") |
| record("computation_stats_bmr_avg", ok, |
| "" if ok else f"behavior_wrong: Statistics BMR Avg not '1840 kcal'; saw {val!r}", |
| depth=2, jump_kind="value", expect="1840 kcal") |
|
|
|
|
| |
| |
| |
| @and_test(expects=("computation_stats_tdee_min",)) |
| def test_stats_tdee_min(): |
| ok_setup, got = user_with_weight("80") |
| if not ok_setup: |
| record("computation_stats_tdee_min", False, |
| f"setup_failed: could not enter weight 80 (dialog held {got!r})", |
| depth=2, jump_kind="value", expect="2208 kcal") |
| return |
| if not and_reach_statistics(): |
| record("computation_stats_tdee_min", False, |
| "setup_failed: could not reach the Statistics screen", |
| depth=2, jump_kind="value", expect="2208 kcal") |
| return |
| val = stat_value("TDEE", "Min") |
| ok = _norm(val) == _norm("2208 kcal") |
| record("computation_stats_tdee_min", ok, |
| "" if ok else f"behavior_wrong: Statistics TDEE Min not '2208 kcal'; saw {val!r}", |
| depth=2, jump_kind="value", expect="2208 kcal") |
|
|
|
|
| |
| |
| |
| @and_test(expects=("computation_stats_tdee_avg",)) |
| def test_stats_tdee_avg(): |
| ok_setup, got = user_with_weight("80") |
| if not ok_setup: |
| record("computation_stats_tdee_avg", False, |
| f"setup_failed: could not enter weight 80 (dialog held {got!r})", |
| depth=2, jump_kind="value", expect="2208 kcal") |
| return |
| if not and_reach_statistics(): |
| record("computation_stats_tdee_avg", False, |
| "setup_failed: could not reach the Statistics screen", |
| depth=2, jump_kind="value", expect="2208 kcal") |
| return |
| val = stat_value("TDEE", "Avg") |
| ok = _norm(val) == _norm("2208 kcal") |
| record("computation_stats_tdee_avg", ok, |
| "" if ok else f"behavior_wrong: Statistics TDEE Avg not '2208 kcal'; saw {val!r}", |
| depth=2, jump_kind="value", expect="2208 kcal") |
|
|
|
|
| |
| |
| |
| @and_test(expects=("computation_stats_weight_min",)) |
| def test_stats_weight_min(): |
| ok_setup, got = user_with_weight("80") |
| if not ok_setup: |
| record("computation_stats_weight_min", False, |
| f"setup_failed: could not enter weight 80 (dialog held {got!r})", |
| depth=2, jump_kind="value", expect="80 kg") |
| return |
| if not and_reach_statistics(): |
| record("computation_stats_weight_min", False, |
| "setup_failed: could not reach the Statistics screen", |
| depth=2, jump_kind="value", expect="80 kg") |
| return |
| val = stat_value("Weight", "Min") |
| ok = _norm(val) == _norm("80 kg") |
| record("computation_stats_weight_min", ok, |
| "" if ok else f"behavior_wrong: Statistics Weight Min not '80 kg'; saw {val!r}", |
| depth=2, jump_kind="value", expect="80 kg") |
|
|
|
|
| |
| |
| |
| @and_test(expects=("computation_stats_weight_avg",)) |
| def test_stats_weight_avg(): |
| ok_setup, got = user_with_weight("80") |
| if not ok_setup: |
| record("computation_stats_weight_avg", False, |
| f"setup_failed: could not enter weight 80 (dialog held {got!r})", |
| depth=2, jump_kind="value", expect="80 kg") |
| return |
| if not and_reach_statistics(): |
| record("computation_stats_weight_avg", False, |
| "setup_failed: could not reach the Statistics screen", |
| depth=2, jump_kind="value", expect="80 kg") |
| return |
| val = stat_value("Weight", "Avg") |
| ok = _norm(val) == _norm("80 kg") |
| record("computation_stats_weight_avg", ok, |
| "" if ok else f"behavior_wrong: Statistics Weight Avg not '80 kg'; saw {val!r}", |
| depth=2, jump_kind="value", expect="80 kg") |
|
|
|
|
| |
| |
| |
| |
| @and_test(expects=("computation_stats_bmi_60",)) |
| def test_stats_bmi_60(): |
| ok_setup, got = user_with_weight("60") |
| if not ok_setup: |
| record("computation_stats_bmi_60", False, |
| f"setup_failed: could not enter weight 60 (dialog held {got!r})", |
| depth=2, jump_kind="value", expect="18.5") |
| return |
| if not and_reach_statistics(): |
| record("computation_stats_bmi_60", False, |
| "setup_failed: could not reach the Statistics screen", |
| depth=2, jump_kind="value", expect="18.5") |
| return |
| val = stat_value("BMI", "Avg") |
| ok = _norm(val) == "18.5" |
| record("computation_stats_bmi_60", ok, |
| "" if ok else f"behavior_wrong: Statistics BMI Avg not '18.5' for weight 60; saw {val!r}", |
| depth=2, jump_kind="value", expect="18.5") |
|
|
|
|
| |
| |
| |
| |
| |
| @and_test(expects=("computation_stepper_increase",)) |
| def test_stepper_increase(): |
| if not create_user(): |
| record("computation_stepper_increase", False, |
| "setup_failed: could not create the prerequisite user", |
| depth=2, jump_kind="value", expect="80.1") |
| return |
| if not and_enter_new_measurement(): |
| record("computation_stepper_increase", False, |
| "setup_failed: could not open New Measurement", |
| depth=2, jump_kind="value", expect="80.1") |
| return |
| if not and_enter_weight_dialog(): |
| record("computation_stepper_increase", False, |
| "setup_failed: could not open the Edit Weight dialog", |
| depth=2, jump_kind="value", expect="80.1") |
| return |
| before = set_dialog_value("80") |
| if before != "80": |
| record("computation_stepper_increase", False, |
| f"setup_failed: dialog field did not hold '80' before stepping (held {before!r})", |
| depth=2, jump_kind="value", expect="80.1") |
| return |
| inc = find_node_ci(ui(), "Increase") |
| if inc is None or not tap_node(inc): |
| record("computation_stepper_increase", False, |
| "feature_missing: no 'Increase' stepper in the dialog", |
| depth=2, jump_kind="value", expect="80.1") |
| return |
| settle("tap") |
| after = dialog_field_value() |
| ok = _norm(after) == "80.1" |
| record("computation_stepper_increase", ok, |
| "" if ok else f"behavior_wrong: Increase did not step 80 -> 80.1; field now {after!r}", |
| depth=2, jump_kind="value", expect="80.1") |
|
|
|
|
| |
| |
| |
| |
| |
| @and_test(expects=("computation_stepper_decrease",)) |
| def test_stepper_decrease(): |
| if not create_user(): |
| record("computation_stepper_decrease", False, |
| "setup_failed: could not create the prerequisite user", |
| depth=2, jump_kind="value", expect="79.9") |
| return |
| if not and_enter_new_measurement(): |
| record("computation_stepper_decrease", False, |
| "setup_failed: could not open New Measurement", |
| depth=2, jump_kind="value", expect="79.9") |
| return |
| if not and_enter_weight_dialog(): |
| record("computation_stepper_decrease", False, |
| "setup_failed: could not open the Edit Weight dialog", |
| depth=2, jump_kind="value", expect="79.9") |
| return |
| before = set_dialog_value("80") |
| if before != "80": |
| record("computation_stepper_decrease", False, |
| f"setup_failed: dialog field did not hold '80' before stepping (held {before!r})", |
| depth=2, jump_kind="value", expect="79.9") |
| return |
| dec = find_node_ci(ui(), "Decrease") |
| if dec is None or not tap_node(dec): |
| record("computation_stepper_decrease", False, |
| "feature_missing: no 'Decrease' stepper in the dialog", |
| depth=2, jump_kind="value", expect="79.9") |
| return |
| settle("tap") |
| after = dialog_field_value() |
| ok = _norm(after) == "79.9" |
| record("computation_stepper_decrease", ok, |
| "" if ok else f"behavior_wrong: Decrease did not step 80 -> 79.9; field now {after!r}", |
| depth=2, jump_kind="value", expect="79.9") |
|
|
|
|
| |
| |
| |
| |
| @and_test(expects=("computation_input_roundtrip_100",)) |
| def test_input_roundtrip_100(): |
| if not create_user(): |
| record("computation_input_roundtrip_100", False, |
| "setup_failed: could not create the prerequisite user", |
| depth=2, jump_kind="value", expect="100") |
| return |
| if not and_enter_new_measurement(): |
| record("computation_input_roundtrip_100", False, |
| "setup_failed: could not open New Measurement", |
| depth=2, jump_kind="value", expect="100") |
| return |
| if not and_enter_weight_dialog(): |
| record("computation_input_roundtrip_100", False, |
| "setup_failed: could not open the Edit Weight dialog", |
| depth=2, jump_kind="value", expect="100") |
| return |
| got = set_dialog_value("100") |
| ok = got == "100" |
| record("computation_input_roundtrip_100", ok, |
| "" if ok else f"behavior_wrong: entering '100' left the field {got!r}", |
| depth=2, jump_kind="value", expect="100") |
|
|
|
|
| |
| |
| |
| |
| @and_test(expects=("computation_weight_unit_kg",)) |
| def test_weight_unit_kg(): |
| if not create_user(): |
| record("computation_weight_unit_kg", False, |
| "setup_failed: could not create the prerequisite user", |
| depth=2, jump_kind="value", expect="kg") |
| return |
| if not and_enter_new_measurement(): |
| record("computation_weight_unit_kg", False, |
| "setup_failed: could not open New Measurement", |
| depth=2, jump_kind="value", expect="kg") |
| return |
| if not and_enter_weight_dialog(): |
| record("computation_weight_unit_kg", False, |
| "setup_failed: could not open the Edit Weight dialog", |
| depth=2, jump_kind="value", expect="kg") |
| return |
| has_kg = find_node(ui(), text="kg") is not None |
| record("computation_weight_unit_kg", has_kg, |
| "" if has_kg else "behavior_wrong: Weight dialog does not show the 'kg' unit label", |
| depth=2, jump_kind="value", expect="kg") |
|
|
|
|
| |
| |
| |
| |
| |
| @and_test(expects=("computation_bmi_absent_then_present",)) |
| def test_bmi_absent_then_present(): |
| if not create_user(): |
| record("computation_bmi_absent_then_present", False, |
| "setup_failed: could not create the prerequisite user", |
| depth=1, jump_kind="value", expect="24.7 absent-then-present") |
| return |
| |
| before_texts = [n.get("text", "").strip() for n in ui()] |
| bmi_before = any(_norm(t) == "24.7" for t in before_texts) |
| got = add_weight_measurement("80") |
| if got != "80": |
| record("computation_bmi_absent_then_present", False, |
| f"setup_failed: could not enter weight 80 (dialog held {got!r})", |
| depth=1, jump_kind="value", expect="24.7 absent-then-present") |
| return |
| after_texts = overview_card_texts() |
| bmi_after = any(_norm(t) == "24.7" for t in after_texts) |
| ok = (not bmi_before) and bmi_after |
| record("computation_bmi_absent_then_present", ok, |
| "" if ok else (f"behavior_wrong: BMI '24.7' before={bmi_before} after={bmi_after} " |
| f"(expected absent then present)"), |
| depth=1, jump_kind="value", expect="24.7 absent-then-present") |
|
|
|
|
| |
| |
| |
| |
| |
| @and_test(expects=("computation_bmi_height_200",)) |
| def test_bmi_height_200(): |
| ok_setup, got = user_with_weight("80", height="200") |
| if not ok_setup: |
| record("computation_bmi_height_200", False, |
| f"setup_failed: could not create user h=200 / weight 80 (dialog held {got!r})", |
| depth=1, jump_kind="value", expect="20") |
| return |
| texts = overview_card_texts() |
| |
| present = any(_norm(t) == "20" for t in texts) |
| |
| wrong = any(_norm(t) == "24.7" for t in texts) |
| ok = present and not wrong |
| record("computation_bmi_height_200", ok, |
| "" if ok else f"behavior_wrong: BMI for h=200,w=80 not '20'; saw {texts!r}", |
| depth=1, jump_kind="value", expect="20") |
|
|
|
|
| TESTS = [ |
| test_bmi_80_overview, |
| test_bmi_60_overview, |
| test_bmi_100_overview, |
| test_weight_echo_overview, |
| test_stats_bmi_min, |
| test_stats_bmi_max, |
| test_stats_bmi_avg, |
| test_stats_bmr_min, |
| test_stats_bmr_avg, |
| test_stats_tdee_min, |
| test_stats_tdee_avg, |
| test_stats_weight_min, |
| test_stats_weight_avg, |
| test_stats_bmi_60, |
| test_stepper_increase, |
| test_stepper_decrease, |
| test_input_roundtrip_100, |
| test_weight_unit_kg, |
| test_bmi_absent_then_present, |
| test_bmi_height_200, |
| ] |
|
|
| if __name__ == "__main__": |
| run_suite(TESTS, "computation") |
|
|