// SPDX-License-Identifier: Apache-2.0
; specs/widgets/golden-split-optimality.t27 -- the infographic of lesson 4 of the GoldenFloat course (specs/course/goldenfloat.t27)
; Source of truth for public/widgets/golden-split-optimality/ (gHashTag/trinity): scripts/widget-pages-from-spec.mjs compiles
; this file, checks its constants, evaluates the tests below and writes the page. tool.js is one import of
; ../infographic.js, which draws SAY_TABLE_* as a real <table> and SAY_FLOW_* as an SVG diagram with a
; <title>, black and white, and holds no words of its own. ASCII only (L3), English only (LANG-EN).
; The lesson spec it illustrates: public/t27/files/specs/math/phi_split_optimality.t27.
; phi^2 + 1/phi^2 = 3 | TRINITY

module widget_golden_split_optimality;

pub const KIND : str = "widget-tool";
pub const ID : str = "golden-split-optimality";
pub const TITLE : str = "GoldenFloat 4: why the split is phi";
pub const DESCRIPTION : str = "Two arguments for the phi split, and one that gives an equal split instead, read from phi_split_optimality.t27. Lesson 4 of the GoldenFloat course.";
pub const IMAGE_ALT : str = "A black and white table, Two arguments for the split, and one that gives another answer: Self-similarity, E / M = M / (E + M), Theorem 1; Its solution, r = 1 / phi, about 0.618, r^2 + r - 1 = 0; Maximise E * M, E = M, 7 and 7 for 14, AM-GM, not phi; Rounding, round((N - 1) / phi^2), Theorem 2; Formats matched, 7 of 7, verify_7_7_match.";
pub const HOOK : str = "Self-similarity gives 1 / phi; maximising E * M gives an equal split. The spec says which is which.";
pub const CATEGORY : str = "compiler";
pub const DATA_SOURCES : [2]str = ["The lesson spec public/t27/files/specs/math/phi_split_optimality.t27, read when the course was authored; every number in the table is a constant, a test value or arithmetic of that file", "Nothing on this page was measured on hardware or timed; a value written into a test is said to be written in, not computed"];
pub const READS_LOCAL_FILES : bool = false;
pub const SENDS_NOTHING : bool = true;

; --- The table -----------------------------------------------------------------------------
pub const SAY_TABLE_CAPTION : str = "Two arguments for the split, and one that gives another answer";
pub const SAY_TABLE_HEAD : [3]str = ["Argument", "What it gives", "In the spec"];
pub const SAY_TABLE_CELLS : [15]str = ["Self-similarity", "E / M = M / (E + M)", "Theorem 1", "Its solution", "r = 1 / phi, about 0.618", "r^2 + r - 1 = 0", "Maximise E * M", "E = M, 7 and 7 for 14", "AM-GM, not phi", "Rounding", "round((N - 1) / phi^2)", "Theorem 2", "Formats matched", "7 of 7", "verify_7_7_match"];
pub const K_TABLE_COLS : u8 = 3;
pub const K_TABLE_ROWS : u8 = 5;
pub const K_TABLE_CELLS : u16 = 15;

; --- The diagram and the note ----------------------------------------------------------------
pub const SAY_FLOW_TITLE : str = "From self-similarity to 1 / phi";
pub const SAY_FLOW_STEPS : [3]str = ["Ask E / M = M / (E + M)", "r = 1 / (r + 1)", "r = (sqrt(5) - 1) / 2"];
pub const K_FLOW_STEPS : u8 = 3;
pub const SAY_NOTE : str = "The spec states that self-similarity is a defining property of phi, not the result of an optimisation.";

test the_cells_fill_whole_rows {
    assert K_TABLE_ROWS * K_TABLE_COLS == K_TABLE_CELLS;
}

test the_table_has_a_body {
    assert K_TABLE_ROWS > 0;
    assert K_TABLE_COLS > 0;
}

test the_diagram_has_every_step {
    assert K_FLOW_STEPS == 3;
    assert K_FLOW_STEPS > 1;
}
