Hello all,
I just want to announce a small library that provides tests for your data structure implementations.
Right now it’s just Dict
, but I’d like to extend it to other data structures.
What CommonTests.isDict
will check and how it works underneath is comparison to elm/core
Dict behaviour. We run the same actions on your Dict implementation and on the core Dict, and then check they arrived at the same results. (a.k.a. model based testing.)
The Dict API is conceptually separated into three categories:
-
Creation:
empty
,singleton
,fromList
-
Updates: anything that takes a Dict and returns a Dict.
insert
,map
,union
, etc. -
Queries: anything that returns a non-Dict.
size
,member
,get
,foldl
,keys
,toList
, etc.
All of which are randomized and tested.
I’ve built on top of @miniBill’s work regarding categorizing the various Dict implementations, and went on to test them with this package. Here are the results:
Library | Module | Behaves like elm/core Dict? |
---|---|---|
edkelly303/elm-any-type-collections | Any.Dict | |
edkv/elm-generic-dict | GenericDict | |
matzko/elm-opaque-dict | OpaqueDict |
update is buggy [1]
|
owanturist/elm-avl-dict | AVL.Dict | |
pzp1997/assoc-list | AssocList | Uses insertion order [2] |
timo-weike/generic-collections | AutoDict | |
timo-weike/generic-collections | ManualDict | |
turboMaCk/any-dict | Dict.Any |
Future work
The test results above seem to say, we’re doing pretty good!
But again, these test results check conformance to elm/core
Dict behaviour. We should check it as well! Some unit tests do exist already, but we could write some property based tests to perhaps help uncover some more bugs. (Indeed there are some[3].)
If anybody feels compelled to work on that Dict test suite with me (might be a nice intro to property based tests), send me a message somewhere! We can brainstorm the properties together and then implement them.[4]
-
More specifically, the paths
Just -> Nothing
andNothing -> Just
don’t remove and insert elements respectively. Tracked in a GitHub issue. ↩︎ -
This is not necessarily a bug, but it’s a difference from elm/core Dict. It might be unexpected behaviour for those depending on Dicts being sorted by keys. ↩︎
-
Not that this one in particular could be caught by an unit/property-based test suite: it only shows up with
--optimize
! ↩︎ -
I can’t promise PRs to
elm/core
being merged, of course ↩︎