假设我有以下自定义数据类型:
data Animal = Characteristics [Char] (Set.Set [Char])
和一些功能
checkAnimalType :: [Char] -> Animal -> [Animal]
现在我正在尝试为此编写 hspec 测试,如下所示:
describe "checkAnimalType" $ do
it "returns a list of animals" $ do
(checkAnimalType ["foo", "coo", "doo", "bar", "moo"](Characteristics "foo" $ Set.fromList(["foo", "coo"]))) $ `shouldBe` [(Characteristics "foo" $ Set.fromList(["cockadoodledoo"]))]
这失败了:
No instance for (Eq Animal) arising from a use of ‘shouldBe’
我的问题是,是否可以在测试范围内临时实现 Eq 类型类Animal
?还是有更好的方法来做到这一点?