hspec-hashable-0.1.0.0: Initial project template from stack

Copyright(c) Plow Technologies 2016
LicenseBSD3
Maintainermchaver@gmail.com
StabilityBeta
Safe HaskellNone
LanguageHaskell2010

Test.Hspec.Hashable

Contents

Description

 

Synopsis

Introduction

For every Hashable instance of a type, each unique value of that type should have a unique hash. Generally, a Generic Hashable instance of a type should create a unique hash, and ideally these match the rules of type's Eq instance. Any values for that type that are equal should have the same hash and any values that are not equal should have unique hashes. There might still be cases where a Generic Hashable instance breaks those expectations. There are also cases where you might implement Hashable by hand. This testing library assumes that you expect the uniqueness of a type matches in Eq and Hashable.

Main functions

 

testHashableUniqueness :: forall a. (Arbitrary a, Eq a, Hashable a, Show a, Typeable a) => Int -> Proxy a -> Spec Source #

the main testing function, give it a sampleSize larger than zero (or it will fail) and it will produce arbitrary elements to test the uniqueness of the created hash for a particular type. Should use a large sample size to help find hash collisions.

testHashableUniquenessWithoutTypeable :: forall a. (Arbitrary a, Eq a, Hashable a, Show a) => Int -> String -> Proxy a -> Spec Source #

same as testHashableUniqueness but it does not require an instance of typeable and you should pass the type name as a string so it appears in the error message.

testSelfEquality :: forall a. (Arbitrary a, Eq a, Hashable a, Show a) => Int -> String -> Proxy a -> Spec Source #

test whether or not the Eq instances is defined such that any value equals itself. If it does not, then the testHashableCollision testing function might not work as expected.

testHashableCollision :: forall a. (Arbitrary a, Eq a, Hashable a, Show a) => Int -> String -> Proxy a -> Spec Source #

test whether or not there is are hash collisions between unique values. if there are you need to fix your definition of Hashable.

Internal help functions

 

dupsByMatchingSnd :: Eq b => [(a, b)] -> [(a, b)] -> [(a, b)] Source #

filter a list by collecting all duplications of the second item of the tuple and return both elements of the tuple.