// SPDX-License-Identifier: Apache-2.0
; specs/widgets/tc-five-in-a-byte.t27 -- lesson 14 of the course "The ternary machine" (specs/course/ternary-computing.t27)
; Source of truth for public/widgets/tc-five-in-a-byte/ (gHashTag/trinity): scripts/widget-pages-from-spec.mjs compiles this
; file, checks its constants, evaluates the tests below and writes the page; the page hands every constant to
; tool.js as window.T27_WIDGET. tool.js draws through ../ternary-kit.js and computes nothing: every number comes
; from public/widgets/tc-five-in-a-byte/logic.js, the fn bodies of the gHashTag/t27 spec in logic.t27, compiled to wasm.
; ASCII only (L3), English only (LANG-EN).
; phi^2 + 1/phi^2 = 3 | TRINITY

module widget_tc_five_in_a_byte;

pub const KIND : str = "widget-tool";
pub const ID : str = "tc-five-in-a-byte";
pub const TITLE : str = "Five trits in one byte: 243 of 256 codes";
pub const DESCRIPTION : str = "3^5 = 243 fits under 2^8 = 256. Press the trits to pack them, or drag the byte to unpack it; bytes from 243 up hold nothing.";
pub const IMAGE_ALT : str = "Five trits in a byte card: the trits + - 0 + - packed into one byte, its eight bits lit. 243 of the 256 byte values are used: 99.06 percent of the information, against 79 percent for two bits per trit.";
pub const HOOK : str = "Five trits fit one byte with 13 codes to spare: 99 percent of the bits carry information.";
pub const CATEGORY : str = "compiler";
pub const DATA_SOURCES : [1]str = ["gHashTag/t27 specs/ternary/trits.t27 (t27#8979): every value on the page is its fn bodies, compiled to wasm (logic.js), with 18 tests and 4108 runtime asserts"];
pub const READS_LOCAL_FILES : bool = false;
pub const SENDS_NOTHING : bool = true;

pub const K_CARD_WIDTH : u16 = 1200;
pub const K_CARD_HEIGHT : u16 = 630;

pub const SAY_LOADING : str = "Loading";
pub const K_PACK5_CODES : u32 = 243;
pub const SAY_TRITS5 : str = "Five trits, t0 at the left";
pub const SAY_TRIT_N : str = "trit {0}: {1}";
pub const SAY_BYTE : str = "Byte 0-255";
pub const SAY_PACKED : str = "packed into byte {0}";
pub const SAY_INVALID : str = "byte {0} is not a five-trit code: only 0 to {1} - 1 are";
pub const SAY_USE : str = "five trits per byte: {0}% of the bits carry information";
pub const SAY_USE2 : str = "two bits per trit: {0}%";
pub const SAY_SOURCE : str = "Logic: t27 spec ternary/trits.t27, compiled";

test the_card_is_the_share_size {
    assert K_CARD_WIDTH == 1200;
    assert K_CARD_HEIGHT == 630;
    assert K_CARD_WIDTH * 21 == K_CARD_HEIGHT * 40;
}

test the_widget_starts_where_its_card_says {
    assert K_PACK5_CODES == 243;
}
