M1c: Gleichschritt im Netz #9

Merged
steven merged 20 commits from m1c-gleichschritt-im-netz into main 2026-10-02 06:41:02 +00:00
2 changed files with 5 additions and 8 deletions
Showing only changes of commit 6c7c5bffc2 - Show all commits
+2 -5
View File
@@ -229,7 +229,6 @@ impl Driver {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use std::panic;
#[test] #[test]
fn a_host_saves_and_records_its_world() { fn a_host_saves_and_records_its_world() {
@@ -254,12 +253,10 @@ mod tests {
#[test] #[test]
fn a_panic_breaks_the_session_for_good() { fn a_panic_breaks_the_session_for_good() {
// Keep the expected panic from printing a message into the output. // The test harness keeps the message of this expected panic to itself
let previous = panic::take_hook(); // and shows it only if the test fails.
panic::set_hook(Box::new(|_| {}));
let mut driver = Driver::host(World::new(1)); let mut driver = Driver::host(World::new(1));
let result = driver.guarded(|_| -> u32 { panic!("an internal error") }); let result = driver.guarded(|_| -> u32 { panic!("an internal error") });
panic::set_hook(previous);
assert_eq!(result, None); assert_eq!(result, None);
assert!(driver.is_broken()); assert!(driver.is_broken());
+3 -3
View File
@@ -172,7 +172,7 @@ func _host_and_guest() -> Array[GwSession]:
_carry(host, guest) _carry(host, guest)
host.step() host.step()
_carry(host, guest) _carry(host, guest)
while guest.pending_ticks() > 0: for i in guest.pending_ticks():
guest.step() guest.step()
return [host, guest] return [host, guest]
@@ -191,7 +191,7 @@ func test_a_guest_follows_its_host_through_the_bridge() -> void:
host.step() host.step()
_carry(host, guest) _carry(host, guest)
check_eq(guest.pending_ticks(), 25, "the ticks wait until the guest runs them") check_eq(guest.pending_ticks(), 25, "the ticks wait until the guest runs them")
while guest.pending_ticks() > 0: for i in guest.pending_ticks():
guest.step() guest.step()
check_eq(guest.state_hash_hex(), host.state_hash_hex(), "both worlds are the same") check_eq(guest.state_hash_hex(), host.state_hash_hex(), "both worlds are the same")
check_eq(guest.local_player(), 1, "the guest is player 1") check_eq(guest.local_player(), 1, "the guest is player 1")
@@ -213,7 +213,7 @@ func test_the_hit_of_a_guest_becomes_a_message_to_the_host() -> void:
host.step() host.step()
_carry(host, guest) _carry(host, guest)
var events: Array[Dictionary] = [] var events: Array[Dictionary] = []
while guest.pending_ticks() > 0: for i in guest.pending_ticks():
events.append_array(guest.step()) events.append_array(guest.step())
check_eq(events.map(func(event: Dictionary) -> String: return event["type"]), ["tile_hit"], "the guest sees its hit") check_eq(events.map(func(event: Dictionary) -> String: return event["type"]), ["tile_hit"], "the guest sees its hit")
check_eq(host.damage_codes()[rock.y * host.map_width() + rock.x], 1, "and so does the host") check_eq(host.damage_codes()[rock.y * host.map_width() + rock.x], 1, "and so does the host")