빈 목록을 소요하고 그냥 반환하는 함수,테스트가 같은 작동하는지 테스트하는 테스트 코드를 사용하여 나는 목록을 취하는 간단한 함수에 대한 단위 테스트를 작성하기 위해 노력하고있어
func :: [a] -> [a]
func x = x
emptyListTest :: Test
emptyListTest = TestCase $ assertEqual "for (func [])," [] $ func []
main :: IO Counts
main = runTestTT $ TestList [emptyListTest]
는 그러나, 나는 비어 리와 오류를
No instance for (Show a0) arising from a use of `assertEqual'
The type variable `a0' is ambiguous
Possible fix: add a type signature that fixes these type variable(s)
Note: there are several potential instances:
instance Show Double -- Defined in `GHC.Float'
instance Show Float -- Defined in `GHC.Float'
instance (Integral a, Show a) => Show (GHC.Real.Ratio a)
-- Defined in `GHC.Real'
...plus 28 others
In the expression: assertEqual "for (func [])," []
In the second argument of `($)', namely
`assertEqual "for (func [])," [] $ func []'
In the expression:
TestCase $ assertEqual "for (func [])," [] $ func []
다른 테스트를 얻을 빈리스트에게 주어진 때 예상 sts 잘 작동하고 ghci
func []
호출하여 수동으로 테스트 할 때 함수를 잘 작동합니다.
더미 유형을 작성하고 해당 유형의 요소를 가져 오는 목록을 작성한 경우 (올바르게 말하면 올바른 방법 일 경우) 테스트에 통과 한 것처럼 보이고 테스트 합격자 :
data Dummy = Dummy
deriving(Eq, Show)
emptyList :: [Dummy]
emptyList = []
emptyListTest :: Test
emptyListTest = TestCase $ assertEqual "for (func [])," [] $ func emptyList
왜인가요? 더미 타입 라우트를 다운시키지 않고 빈리스트를 가지고 함수를 테스트 할 수있는 방법이 있습니까?
가 왜 인터프리터에서 오류가없는 함수 작업 난 그냥'[]을 통과 않는'유형이없는? –
@Michal Charemza GHCI에는 특별한 추론 규칙이 있습니다. – alternative
보다 정확한 ghci가 디폴트로'(Eq a, Show a)'제약 조건은'assertEqual' 제약 조건에서'()'로 발생합니다. 이것은 Haskell의 디폴트 규칙의 확장입니다. 자세한 내용은 [여기] (https://www.haskell.org/ghc/docs/latest/html/users_guide/interactive-evaluation.html#extended-default-rules)를 참조하십시오! – yatima2975