2020-01-12 20:58:09 +13:00
|
|
|
defmodule WaferDLLTest do
|
|
|
|
use ExUnit.Case, async: true
|
|
|
|
alias Wafer.DLL.{Rx, Tx}
|
|
|
|
|
|
|
|
test "synchronised transmission" do
|
|
|
|
value = {:marty, "McFly"}
|
|
|
|
|
|
|
|
tx = Tx.init(value)
|
|
|
|
rx = Rx.init()
|
|
|
|
|
|
|
|
{tx, rx} = transmit(tx, rx)
|
|
|
|
|
|
|
|
assert Tx.complete?(tx)
|
|
|
|
assert Rx.complete?(rx)
|
2021-12-09 20:10:07 +13:00
|
|
|
assert {:ok, ^value} = Rx.value(rx)
|
2020-01-12 20:58:09 +13:00
|
|
|
end
|
|
|
|
|
|
|
|
def transmit(%Tx{} = tx, %Rx{} = rx) do
|
|
|
|
case Tx.tx(tx) do
|
2020-01-17 12:19:17 +13:00
|
|
|
{:done, tx} ->
|
|
|
|
{tx, rx}
|
|
|
|
|
2020-01-12 20:58:09 +13:00
|
|
|
{byte, tx} ->
|
|
|
|
rx = Rx.rx(rx, byte)
|
|
|
|
transmit(tx, rx)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|