(require '[clojure.test.check.generators :as gen])
(def ACTIONS
{:create-new-user #{}
:edit-user #{:create-new-user}
:create-new-board #{:create-new-user}
:edit-board #{:create-new-board}
:create-new-anonymous-comment #{:create-new-board}
:create-new-signed-comment #{:create-new-board}
:edit-comment-text #{:create-new-anonymous-comment :create-new-signed-comment}
:edit-comment-text-and-flip-anonymity #{:create-new-anonymous-comment :create-new-signed-comment}
:flip-anonymity #{:create-new-anonymous-comment :create-new-signed-comment}
:vote-comment-up #{:create-new-anonymous-comment :create-new-signed-comment}
:vote-comment-down #{:create-new-anonymous-comment :create-new-signed-comment}})
(def actions (-> ACTIONS keys vec gen/elements gen/vector))
(defn filter-actions-into-logical-order [as]
(let [seen (atom #{})]
(filter
(fn [v]
(let [required (get ACTIONS v)
valid? (or (some? (some required @seen))
(and (empty? @seen) (= v :create-new-user)))]
(when valid?
(swap! seen conj v)
true)))
as)))
(def ordered-actions (gen/fmap #(-> % filter-actions-into-logical-order vec) actions))
:제한된 순서로 일련의 동작에 대한 test.check 생성기를 만드는 방법은 무엇입니까? 두 발생기의 예로서
# (last (gen/sample actions 100))
[:edit-user :vote-comment-down :flip-anonymity :vote-comment-down :vote-comment-down :vote-comment-up :edit-user :create-new-anonymous-comment :edit-board :create-new-signed-comment :vote-comment-up :edit-comment-text-and-flip-anonymity :edit-user :create-new-signed-comment :edit-user :edit-user :vote-comment-down :edit-user :vote-comment-down :create-new-user :vote-comment-down :create-new-user :create-new-user :edit-comment-text-and-flip-anonymity :create-new-user :edit-comment-text-and-flip-anonymity :create-new-anonymous-comment :edit-comment-text :create-new-board :vote-comment-down :flip-anonymity :create-new-signed-comment :vote-comment-up :create-new-user :create-new-signed-comment :edit-user :create-new-user :create-new-board :vote-comment-down :create-new-board :create-new-board :create-new-board :edit-board :edit-comment-text-and-flip-anonymity :edit-user :edit-comment-text :create-new-signed-comment :vote-comment-up :edit-comment-text-and-flip-anonymity :flip-anonymity :create-new-anonymous-comment :create-new-anonymous-comment :edit-board :create-new-signed-comment :edit-comment-text-and-flip-anonymity :edit-board :vote-comment-up :edit-comment-text :create-new-board :edit-comment-text-and-flip-anonymity :create-new-board :vote-comment-down :edit-comment-text-and-flip-anonymity :vote-comment-up :create-new-user :vote-comment-up :edit-comment-text :edit-board :edit-comment-text-and-flip-anonymity :flip-anonymity :edit-board :create-new-anonymous-comment :flip-anonymity :create-new-signed-comment :edit-user :edit-comment-text-and-flip-anonymity :edit-comment-text :edit-comment-text :create-new-user :flip-anonymity :edit-user :vote-comment-up :edit-user :create-new-user :edit-comment-text :edit-comment-text :flip-anonymity :edit-comment-text :edit-board :flip-anonymity :edit-board :edit-comment-text :edit-user :create-new-user :flip-anonymity]
# (last (gen/sample ordered-actions 100))
[:create-new-user :edit-user :edit-user :create-new-board :edit-board :edit-user :create-new-anonymous-comment :edit-comment-text :edit-board :edit-user :edit-user :vote-comment-up :edit-comment-text :create-new-signed-comment :edit-comment-text :create-new-board :edit-comment-text :edit-comment-text :edit-comment-text :vote-comment-up :vote-comment-up :edit-board :edit-comment-text-and-flip-anonymity :create-new-signed-comment :create-new-anonymous-comment :create-new-signed-comment :edit-user :create-new-anonymous-comment :edit-board :create-new-board :create-new-anonymous-comment :create-new-board :flip-anonymity :create-new-anonymous-comment :edit-board :vote-comment-up :vote-comment-down :edit-board :edit-comment-text :edit-user :edit-comment-text :flip-anonymity :create-new-signed-comment :vote-comment-up :edit-comment-text-and-flip-anonymity :vote-comment-up :create-new-signed-comment :edit-comment-text :create-new-signed-comment :create-new-anonymous-comment :edit-board :create-new-anonymous-comment]
ACTIONS
키 액션의 이름 맵이며,이 값은 그 동작에 대한 (OR 기반) 의존성이다. 예를 들어, 무엇이든 할 수 있으려면 먼저 :create-new-user
을 입력해야하며, :edit-board
이되기 전에 :create-new-board
을 입력해야하고 :edit-comment-text
이되기 전에 적어도 하나는 :create-new-*-comment
이어야합니다.
위의 코드는 작동하는 것처럼 보이지만 추악합니다. 1) filter-actions-into-logical-order
코드에서 :create-new-user
에 대한 특정 예외를 지정하는 방법이 마음에 들지 않습니다. 2) 나는 기본적으로 임의의 동작 목록을 취하고 작업이 순서대로 이해할 때까지 필터링하는 것을 좋아하지 않습니다.
다른 사람들이 test.check를 사용하여 이러한 일련의 동작을 어떻게 생성하는지 궁금합니다. 확실하게 발전기 만 사용하는 방법이 있어야합니까?
아마도이 질문을 http://codereview.stackexchange.com/ –