phase: 20.49 COMPLETE; 20.50 Flow+String minimal reps; 20.51 selfhost v0/v1 minimal (Option A/B); hv1-inline binop/unop/copy; docs + run_all + CURRENT_TASK -> 21.0
This commit is contained in:
61
local_tests/test_p2p_basic.hako
Normal file
61
local_tests/test_p2p_basic.hako
Normal file
@ -0,0 +1,61 @@
|
||||
// 🧪 P2PBox基本機能テスト
|
||||
// IntentBoxとP2PBoxの基本的な動作を検証
|
||||
|
||||
print("=== P2PBox Basic Test ===")
|
||||
|
||||
// 1. IntentBoxの作成
|
||||
print("\n1. Creating IntentBox...")
|
||||
local world
|
||||
world = new IntentBox()
|
||||
print("✅ IntentBox created: " + world.type())
|
||||
|
||||
// 2. P2PBoxノードの作成
|
||||
print("\n2. Creating P2PBox nodes...")
|
||||
local alice
|
||||
local bob
|
||||
local charlie
|
||||
|
||||
alice = new P2PBox("alice", world)
|
||||
bob = new P2PBox("bob", world)
|
||||
charlie = new P2PBox("charlie", world)
|
||||
|
||||
print("✅ Alice created: " + alice.getNodeId())
|
||||
print("✅ Bob created: " + bob.getNodeId())
|
||||
print("✅ Charlie created: " + charlie.getNodeId())
|
||||
|
||||
// 3. リスナー登録テスト
|
||||
print("\n3. Testing listener registration...")
|
||||
bob.on("greeting", "bob_greeting_handler")
|
||||
charlie.on("greeting", "charlie_greeting_handler")
|
||||
print("✅ Listeners registered")
|
||||
|
||||
// 4. 直接送信テスト
|
||||
print("\n4. Testing direct send...")
|
||||
alice.send("greeting", "Hello Bob!", "bob")
|
||||
alice.send("greeting", "Hello Charlie!", "charlie")
|
||||
print("✅ Messages sent")
|
||||
|
||||
// 5. ブロードキャストテスト
|
||||
print("\n5. Testing broadcast...")
|
||||
alice.broadcast("announcement", "Hello everyone!")
|
||||
print("✅ Broadcast sent")
|
||||
|
||||
// 6. リスナー解除テスト
|
||||
print("\n6. Testing listener removal...")
|
||||
local result
|
||||
result = bob.off("greeting")
|
||||
print("✅ Bob's listener removed: " + result)
|
||||
|
||||
// 7. 解除後の送信テスト
|
||||
print("\n7. Testing send after listener removal...")
|
||||
alice.send("greeting", "Hello again Bob!", "bob")
|
||||
print("✅ Message sent (Bob should not receive)")
|
||||
|
||||
// 8. 複数リスナーテスト
|
||||
print("\n8. Testing multiple listeners...")
|
||||
charlie.on("data", "charlie_data_handler1")
|
||||
charlie.on("data", "charlie_data_handler2")
|
||||
alice.send("data", "Test data", "charlie")
|
||||
print("✅ Multiple listeners tested")
|
||||
|
||||
print("\n=== Test Complete ===")
|
||||
Reference in New Issue
Block a user