以下数据结构作为我的小型餐厅应用程序的状态:
{:orders {:e4d55743-c964-48e8-9cd1-cb1cf9075617 [#:helloworld.restaurant{:name "chilly parotta", :quantity 3} #:helloworld.restaurant{:name "masal dosa", :quantity 2}]}, :menu {:kothu-parotta #:helloworld.restaurant{:name "Kothu Parotta", :price 9.5, :quantity 50}, :butter-naan #:helloworld.restaurant{:name "Butter Naan", :price 3, :quantity 50}, :paneer-butter-masala #:helloworld.restaurant{:name "Paneer Butter Masala", :price 9.5, :quantity 50}}}
我有一个函数用于更新与订单中每个订单项目对应的菜单项,以减去订单数量从库存中,并返回新的菜单。我想验证以下内容:
- 订单项目中的项目,应该存在于菜单中
- 库存中的项目数量应该大于订单数量
我有以下规范(注意:目前我没有验证2)。当我运行此函数调用更新菜单项时,update-menu-item-for-order-item 函数未验证1中的谓词。我在 fdef 规范中犯了什么错误?
(s/def ::name string?)
(s/def ::price number?)
(s/def ::quantity number?)
(s/def ::order-item (s/keys :req [::name ::quantity]))
(s/def ::order-items (s/coll-of ::order-item))
(s/def ::menu-item (s/keys :req [::name ::price ::quantity]))
(s/def ::menu-item-id keyword?)
(s/def ::menu (s/map-of ::menu-item-id ::menu-item))
(s/fdef restaurant-save-menu :args (s/cat :menu-items (s/coll-of ::menu-item)))
(s/fdef update-menu-item-for-order-item
:args (s/and (s/cat :menu ::menu :order-item ::order-item)
#(contains? (:menu %) (keyword (slugify (::name (:order-item %))))))
:ret ::menu)
(stest/instrument `update-menu-item-for-order-item)
(stest/instrument `restaurant-save-menu)