csys testing: helpers for sending and receiving complex messages
This commit is contained in:
parent
f9e6d664d5
commit
37920f3b98
4 changed files with 22 additions and 8 deletions
|
|
@ -18,10 +18,11 @@ defmodule Scopes.CSys.Program do
|
|||
|
||||
# processors
|
||||
|
||||
def basic_active({head, _info}, scope) do
|
||||
def basic_active(msg = {head, _info}, scope) do
|
||||
case head do
|
||||
[:csys, :create, :parent | _rest] -> create_parent(scope)
|
||||
[:csys, :create, :child | _rest] -> create_child(scope)
|
||||
_ -> forward(msg, scope) || notify(msg, scope)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -2,4 +2,8 @@ defmodule Scopes.Shape do
|
|||
def create(head, info \\ []) do
|
||||
{head, info}
|
||||
end
|
||||
|
||||
def head(rec), do: elem(rec, 0)
|
||||
def info(rec), do: elem(rec, 1)
|
||||
def data(rec), do: info(rec)[:data]
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,6 +6,17 @@ defmodule Scopes.CSysTest do
|
|||
alias Scopes.CSys
|
||||
alias Scopes.CSys.Environ
|
||||
alias Scopes.CSys.Program
|
||||
alias Scopes.Shape
|
||||
|
||||
def send_value(rcvr, val) do
|
||||
msg = Shape.create([:csys, :data], data: %{value: val})
|
||||
Actor.send(rcvr, msg)
|
||||
end
|
||||
|
||||
def receive_head(head) do
|
||||
assert_receive {^head, info}
|
||||
{head, info}
|
||||
end
|
||||
|
||||
describe "basic:" do
|
||||
test "minimal-neural-net" do
|
||||
|
|
@ -13,10 +24,9 @@ defmodule Scopes.CSysTest do
|
|||
Environ.put_prog(env, :basic, Program.basic_prog())
|
||||
proc = Environ.get_stage(env, :basic, :initial)
|
||||
zero = CSys.neuron({[], proc, [], env})
|
||||
Actor.send(zero, "Hello Zero!")
|
||||
# msg = Message.create([:csys, :data], data: %{value: "Hello Zero!"})
|
||||
# Actor.send(zero, msg)
|
||||
assert_receive "Hello Zero!"
|
||||
#Actor.send(zero, "Hello Zero!")
|
||||
send_value(zero, "Hello Zero!")
|
||||
assert "Hello Zero!" = Shape.data(receive_head([:csys, :data])).value
|
||||
Actor.send(zero, {[:csys, :create, :parent], nil})
|
||||
assert_receive {:created, new1}
|
||||
Actor.send(new1, {[:csys, :create, :child], nil})
|
||||
|
|
|
|||
|
|
@ -5,9 +5,8 @@ defmodule Scopes.ShapeTest do
|
|||
|
||||
describe "shape:" do
|
||||
test "basic" do
|
||||
obj = Shape.create([:dom, :data], data: %{value: 42})
|
||||
{_head, info} = obj
|
||||
assert 42 = info[:data].value
|
||||
rec = Shape.create([:dom, :data], data: %{value: 42})
|
||||
assert 42 = Shape.data(rec).value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue