utahplt / chorex

Choreographic programming in Elixir
https://hex.pm/packages/chorex
MIT License
14 stars 0 forks source link

Not finding behaviour dependencies inside `if` tests #2

Closed ashton314 closed 1 month ago

ashton314 commented 1 month ago

Failure to implement get_budget() doesn't get caught by the behaviour generation code:

  defmodule TestChor2 do
    defchor [Buyer1, Buyer2, Seller1] do
      Buyer1.get_book_title() ~> Seller1.b
      Seller1.get_price("book:" <> b) ~> Buyer1.p
      Seller1.get_price("book:" <> b) ~> Buyer2.p
      # Buyer2.(p / 2) ~> Buyer1.contrib
      Buyer2.compute_contrib(p) ~> Buyer1.contrib

      if Buyer1.(p - contrib < get_budget()) do
        Buyer1[L] ~> Seller1
        Buyer1.get_address() ~> Seller1.addr
        Seller1.get_delivery_date(b, addr) ~> Buyer1.d_date
        return(Buyer1.d_date)
      else
        Buyer1[R] ~> Seller1
        return(Buyer1.(nil))
      end
    end
  end

  defmodule MySeller1 do
    use TestChor2.Chorex, :seller1

    def get_delivery_date(book, addr) do
      IO.inspect({book, addr}, label: "getting delivery date for")
      ~D[2024-05-13]
    end

    def get_price("book:Das Glasperlenspiel"), do: 42
    def get_price("book:Zen and the Art of Motorcycle Maintenance"), do: 13
  end

  defmodule MyBuyer1 do
    use TestChor2.Chorex, :buyer1

    def get_book_title(), do: "Zen and the Art of Motorcycle Maintenance"
    def get_address(), do: "Maple Street"
  end

  defmodule MyBuyer2 do
    use TestChor2.Chorex, :buyer2

    def compute_contrib(price) do
      IO.inspect(price, label: "Buyer 2 computing contribution of")
      price / 2
    end
  end