wip(0.S2): migrate - a var nothing writes becomes a let; a state is keyed by its module, directory or program, so every program's plan agrees; paths normalized; program states named SceneDemoState / scene_demo_st; the LSP reads state, mut and entry/handler parameters
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3eda72e8c2
commit
5ffe50ed02
463 changed files with 72045 additions and 67421 deletions
|
|
@ -5,140 +5,138 @@ import "ludic.tracks"
|
|||
import "ludic.base"
|
||||
program TracksTest {
|
||||
numbers float
|
||||
state TrackstestState {
|
||||
now: float = 0.0
|
||||
skill: int = 1
|
||||
placed_n: int = 0
|
||||
placed_last: int = -1
|
||||
}
|
||||
var now: float = 0.0
|
||||
var skill: int = 1
|
||||
var placed_n: int = 0
|
||||
var placed_last: int = -1
|
||||
|
||||
function fake_now(trackstest_st: TrackstestState) -> float { return trackstest_st.now }
|
||||
function fake_skill(trackstest_st: TrackstestState) -> int { return trackstest_st.skill }
|
||||
function fake_now() -> float { return now }
|
||||
function fake_skill() -> int { return skill }
|
||||
function fake_bearing(yaw: float) -> string {
|
||||
if yaw > 0.0 { return "east" }
|
||||
return "west"
|
||||
}
|
||||
function fake_placed(trackstest_st: mut TrackstestState, kind: int, i: int) -> void {
|
||||
trackstest_st.placed_n += 1
|
||||
trackstest_st.placed_last = i
|
||||
function fake_placed(kind: int, i: int) -> void {
|
||||
placed_n += 1
|
||||
placed_last = i
|
||||
}
|
||||
|
||||
bind TracksWorld { now: fn fake_now, skill: fn fake_skill, bearing: fn fake_bearing, placed: fn fake_placed }
|
||||
|
||||
function fresh(base_st: mut BaseState, tracks_st: mut TracksState, trackstest_st: mut TrackstestState) -> void {
|
||||
trackstest_st.now = 10.0
|
||||
trackstest_st.skill = 1
|
||||
trackstest_st.placed_n = 0
|
||||
trackstest_st.placed_last = -1
|
||||
tracks_config(tracks_st, 3, 4)
|
||||
tracks_config_reading(tracks_st, 1, 0.5, 2.5)
|
||||
tracks_reset(base_st, tracks_st)
|
||||
function fresh() -> void {
|
||||
now = 10.0
|
||||
skill = 1
|
||||
placed_n = 0
|
||||
placed_last = -1
|
||||
tracks_config(3, 4)
|
||||
tracks_config_reading(1, 0.5, 2.5)
|
||||
tracks_reset()
|
||||
}
|
||||
|
||||
function reads(base_st: mut BaseState, tracks_st: mut TracksState) -> []TrackRead { return q_drain(base_st, tracks_reads(base_st, tracks_st)) }
|
||||
function reads() -> []TrackRead { return q_drain(tracks_reads()) }
|
||||
|
||||
test "a print goes into its kind's ring and is drawn" (base_st: mut BaseState, tracks_st: mut TracksState, trackstest_st: mut TrackstestState) {
|
||||
fresh(base_st, tracks_st, trackstest_st)
|
||||
let i = tracks_leave(tracks_st, 1, 5.0, 6.0, 1.0, 7, false)
|
||||
test "a print goes into its kind's ring and is drawn" {
|
||||
fresh()
|
||||
let i = tracks_leave(1, 5.0, 6.0, 1.0, 7, false)
|
||||
expect_eq(i, 0)
|
||||
expect_eq(tracks_count(tracks_st, 1), 1)
|
||||
expect_eq(tracks_count(tracks_st, 0), 0)
|
||||
expect_eq(trackstest_st.placed_n, 1)
|
||||
let s = tracks_slot(tracks_st, 1, 0)
|
||||
expect(tracks_x(tracks_st, s) == 5.0 and tracks_z(tracks_st, s) == 6.0)
|
||||
expect_eq(tracks_sp(tracks_st, s), 7)
|
||||
expect_eq(tracks_count(1), 1)
|
||||
expect_eq(tracks_count(0), 0)
|
||||
expect_eq(placed_n, 1)
|
||||
let s = tracks_slot(1, 0)
|
||||
expect(tracks_x(s) == 5.0 and tracks_z(s) == 6.0)
|
||||
expect_eq(tracks_sp(s), 7)
|
||||
}
|
||||
|
||||
test "a full ring writes over its oldest print" (base_st: mut BaseState, tracks_st: mut TracksState, trackstest_st: mut TrackstestState) {
|
||||
fresh(base_st, tracks_st, trackstest_st)
|
||||
for n in 0 .. 5 { tracks_leave(tracks_st, 2, float(n), 0.0, 0.0, n, false) }
|
||||
expect_eq(tracks_count(tracks_st, 2), 4)
|
||||
expect_eq(trackstest_st.placed_last, 0)
|
||||
expect_eq(tracks_sp(tracks_st, tracks_slot(tracks_st, 2, 0)), 4)
|
||||
test "a full ring writes over its oldest print" {
|
||||
fresh()
|
||||
for n in 0 .. 5 { tracks_leave(2, float(n), 0.0, 0.0, n, false) }
|
||||
expect_eq(tracks_count(2), 4)
|
||||
expect_eq(placed_last, 0)
|
||||
expect_eq(tracks_sp(tracks_slot(2, 0)), 4)
|
||||
}
|
||||
|
||||
test "a print ages on the world's clock" (base_st: mut BaseState, tracks_st: mut TracksState, trackstest_st: mut TrackstestState) {
|
||||
fresh(base_st, tracks_st, trackstest_st)
|
||||
tracks_leave(tracks_st, 1, 0.0, 0.0, 0.0, 1, false)
|
||||
trackstest_st.now = 13.0
|
||||
let s = tracks_slot(tracks_st, 1, 0)
|
||||
expect(tracks_age(tracks_st, s) == 3.0)
|
||||
expect_eq(tracks_fresh_of(tracks_st, tracks_age(tracks_st, s)), TRACK_OLD)
|
||||
expect_eq(tracks_fresh_of(tracks_st, 0.2), TRACK_FRESH)
|
||||
expect_eq(tracks_fresh_of(tracks_st, 1.0), TRACK_RECENT)
|
||||
test "a print ages on the world's clock" {
|
||||
fresh()
|
||||
tracks_leave(1, 0.0, 0.0, 0.0, 1, false)
|
||||
now = 13.0
|
||||
let s = tracks_slot(1, 0)
|
||||
expect(tracks_age(s) == 3.0)
|
||||
expect_eq(tracks_fresh_of(tracks_age(s)), TRACK_OLD)
|
||||
expect_eq(tracks_fresh_of(0.2), TRACK_FRESH)
|
||||
expect_eq(tracks_fresh_of(1.0), TRACK_RECENT)
|
||||
}
|
||||
|
||||
test "the nearest print within reach, or none" (base_st: mut BaseState, tracks_st: mut TracksState, trackstest_st: mut TrackstestState) {
|
||||
fresh(base_st, tracks_st, trackstest_st)
|
||||
tracks_leave(tracks_st, 1, 10.0, 0.0, 0.0, 1, false)
|
||||
tracks_leave(tracks_st, 2, 1.0, 1.0, 0.0, 2, false)
|
||||
expect_eq(tracks_nearest(tracks_st, 0.0, 0.0, 2.0), tracks_slot(tracks_st, 2, 0))
|
||||
expect_eq(tracks_nearest(tracks_st, 50.0, 50.0, 2.0), -1)
|
||||
test "the nearest print within reach, or none" {
|
||||
fresh()
|
||||
tracks_leave(1, 10.0, 0.0, 0.0, 1, false)
|
||||
tracks_leave(2, 1.0, 1.0, 0.0, 2, false)
|
||||
expect_eq(tracks_nearest(0.0, 0.0, 2.0), tracks_slot(2, 0))
|
||||
expect_eq(tracks_nearest(50.0, 50.0, 2.0), -1)
|
||||
}
|
||||
|
||||
test "a print read twice is two facts and one count" (base_st: mut BaseState, tracks_st: mut TracksState, trackstest_st: mut TrackstestState) {
|
||||
fresh(base_st, tracks_st, trackstest_st)
|
||||
tracks_leave(tracks_st, 1, 0.0, 0.0, 1.0, 3, true)
|
||||
let s = tracks_nearest(tracks_st, 0.0, 0.0, 2.0)
|
||||
tracks_read(base_st, tracks_st, s)
|
||||
tracks_read(base_st, tracks_st, s)
|
||||
let rs = reads(base_st, tracks_st)
|
||||
test "a print read twice is two facts and one count" {
|
||||
fresh()
|
||||
tracks_leave(1, 0.0, 0.0, 1.0, 3, true)
|
||||
let s = tracks_nearest(0.0, 0.0, 2.0)
|
||||
tracks_read(s)
|
||||
tracks_read(s)
|
||||
let rs = reads()
|
||||
expect_eq(len(rs), 2)
|
||||
expect(rs[0].first and not rs[1].first)
|
||||
expect_eq(rs[0].source, TRACK_PRINT)
|
||||
expect_eq(rs[0].kind, 1)
|
||||
expect(rs[0].legend)
|
||||
expect(rs[0].bearing == "east")
|
||||
expect_eq(tracks_read_count(tracks_st), 1)
|
||||
expect(tracks_has_bearing(tracks_st) and tracks_last_yaw(tracks_st) == 1.0)
|
||||
expect_eq(tracks_read_count(), 1)
|
||||
expect(tracks_has_bearing() and tracks_last_yaw() == 1.0)
|
||||
}
|
||||
|
||||
test "a reader without the skill cannot name the animal" (base_st: mut BaseState, tracks_st: mut TracksState, trackstest_st: mut TrackstestState) {
|
||||
fresh(base_st, tracks_st, trackstest_st)
|
||||
trackstest_st.skill = 0
|
||||
tracks_leave(tracks_st, 1, 0.0, 0.0, 0.0, 3, false)
|
||||
tracks_read(base_st, tracks_st, tracks_slot(tracks_st, 1, 0))
|
||||
expect(not reads(base_st, tracks_st)[0].named)
|
||||
test "a reader without the skill cannot name the animal" {
|
||||
fresh()
|
||||
skill = 0
|
||||
tracks_leave(1, 0.0, 0.0, 0.0, 3, false)
|
||||
tracks_read(tracks_slot(1, 0))
|
||||
expect(not reads()[0].named)
|
||||
}
|
||||
|
||||
test "a sign that is not a print is told, and counts when it is the first" (base_st: mut BaseState, tracks_st: mut TracksState, trackstest_st: mut TrackstestState) {
|
||||
fresh(base_st, tracks_st, trackstest_st)
|
||||
tracks_note(base_st, tracks_st, 4, TRACK_SCAT, false, -1.0, true)
|
||||
tracks_note(base_st, tracks_st, 4, TRACK_SCAT, false, -1.0, false)
|
||||
let rs = reads(base_st, tracks_st)
|
||||
test "a sign that is not a print is told, and counts when it is the first" {
|
||||
fresh()
|
||||
tracks_note(4, TRACK_SCAT, false, -1.0, true)
|
||||
tracks_note(4, TRACK_SCAT, false, -1.0, false)
|
||||
let rs = reads()
|
||||
expect_eq(len(rs), 2)
|
||||
expect_eq(rs[0].source, TRACK_SCAT)
|
||||
expect_eq(tracks_read_count(tracks_st), 1)
|
||||
expect_eq(tracks_read_count(), 1)
|
||||
}
|
||||
|
||||
test "a written-over slot is a new, unread print" (base_st: mut BaseState, tracks_st: mut TracksState, trackstest_st: mut TrackstestState) {
|
||||
fresh(base_st, tracks_st, trackstest_st)
|
||||
tracks_leave(tracks_st, 0, 0.0, 0.0, 0.0, 1, false)
|
||||
tracks_read(base_st, tracks_st, tracks_slot(tracks_st, 0, 0))
|
||||
for n in 0 .. 4 { tracks_leave(tracks_st, 0, 0.0, 0.0, 0.0, 2, false) }
|
||||
expect(not tracks_was_read(tracks_st, tracks_slot(tracks_st, 0, 0)))
|
||||
test "a written-over slot is a new, unread print" {
|
||||
fresh()
|
||||
tracks_leave(0, 0.0, 0.0, 0.0, 1, false)
|
||||
tracks_read(tracks_slot(0, 0))
|
||||
for n in 0 .. 4 { tracks_leave(0, 0.0, 0.0, 0.0, 2, false) }
|
||||
expect(not tracks_was_read(tracks_slot(0, 0)))
|
||||
}
|
||||
|
||||
test "clearing the ground forgets the prints, not the reader" (base_st: mut BaseState, tracks_st: mut TracksState, trackstest_st: mut TrackstestState) {
|
||||
fresh(base_st, tracks_st, trackstest_st)
|
||||
tracks_leave(tracks_st, 1, 0.0, 0.0, 0.0, 1, false)
|
||||
tracks_read(base_st, tracks_st, tracks_slot(tracks_st, 1, 0))
|
||||
tracks_clear(tracks_st)
|
||||
expect_eq(tracks_count(tracks_st, 1), 0)
|
||||
expect_eq(tracks_read_count(tracks_st), 1)
|
||||
test "clearing the ground forgets the prints, not the reader" {
|
||||
fresh()
|
||||
tracks_leave(1, 0.0, 0.0, 0.0, 1, false)
|
||||
tracks_read(tracks_slot(1, 0))
|
||||
tracks_clear()
|
||||
expect_eq(tracks_count(1), 0)
|
||||
expect_eq(tracks_read_count(), 1)
|
||||
}
|
||||
|
||||
test "a save section reads back the same reader" (base_st: mut BaseState, tracks_st: mut TracksState, trackstest_st: mut TrackstestState) {
|
||||
fresh(base_st, tracks_st, trackstest_st)
|
||||
tracks_note(base_st, tracks_st, 1, TRACK_SIGN, true, 0.0, true)
|
||||
tracks_note_bearing(tracks_st, 2.5)
|
||||
test "a save section reads back the same reader" {
|
||||
fresh()
|
||||
tracks_note(1, TRACK_SIGN, true, 0.0, true)
|
||||
tracks_note_bearing(2.5)
|
||||
let root = save_tree()
|
||||
save_section(root, "tracks", 1, tracks_save(tracks_st))
|
||||
save_section(root, "tracks", 1, tracks_save())
|
||||
let text = save_encode(root)
|
||||
tracks_reset(base_st, tracks_st)
|
||||
tracks_reset()
|
||||
let n = load_section(save_decode(text), "tracks")
|
||||
tracks_load(base_st, tracks_st, n.data, n.version)
|
||||
expect_eq(tracks_read_count(tracks_st), 1)
|
||||
expect(tracks_has_bearing(tracks_st) and tracks_last_yaw(tracks_st) == 2.5)
|
||||
tracks_load(n.data, n.version)
|
||||
expect_eq(tracks_read_count(), 1)
|
||||
expect(tracks_has_bearing() and tracks_last_yaw() == 2.5)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue