나는 Clojure에서 연습을하고 있는데 (질문인지, 대문자 등으로 쓰여진 것에 따라 입력에 대답) 작동하는 동안 내 코드가 nil
모든 정답과 함께 반환 되기 때문에 필요한 테스트를 통과 할 수 없습니다 . 어떻게 피할 수 있습니까?
(ns bob
(:use [clojure.string :only [upper-case blank?]]))
(defn- silence? [question]
(blank? question))
(defn- yell? [question]
(and (re-find #".*!$" question) (= question (upper-case question))))
(defn- ask? [question]
(re-find #".*\?$" question))
(defn response-for [question]
(if (silence? "Fine, be that way.")
(case ((juxt yell? ask?) question)
[true true] "Calm down, I know what I'm doing!"
[true false] "Woah, chill out!"
[false true] "Sure."
"Whatever.")))
테스트의 예 :
FAIL in (responds-to-forceful-talking) (bob_test.clj:25)
expected: (= "Whatever." (bob/response-for "Let's go make out behind the gym!"))
actual: (not (= "Whatever." nil))
미리 감사드립니다!
John이 귀하의 문제가 if 에 있다고 언급했듯이 몇 가지 조정에 따라 문제를 해결하십시오.
(defn response-for [question]
(if (silence? question)
"Fine, be that way."
(case ((juxt yell? ask?) question)
[true true] "Calm down, I know what I'm doing!"
[true false] "Woah, chill out!"
[false true] "Sure."
"Whatever.")))
(= "Whatever." (bob/response-for "Let's go make out behind the gym!"))
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다