Commit Graph

18 Commits

Author SHA1 Message Date
Jan Hrcek
bf2710effb Various typo fixes 2021-08-17 13:46:15 +02:00
Willem Van Onsem
ddeb2fcb13
use fmap for Main tests 2021-03-15 21:19:22 +01:00
Jonathan Daugherty
dd7b6c3c7f tests: remove now-defunct prop_findByNonDecreasing List test 2020-12-23 11:14:10 -08:00
Jonathan Daugherty
5c1596db00
Merge pull request #230 from frasertweedale/test/list-initial-selection
Add test for List initial selection
2019-05-04 09:07:24 -07:00
Fraser Tweedale
39884263b2 add test for List initial selection
We do not have a test to confirm that the initial selection for a
list is always 'Just 0' (or 'Nothing' when the list is empty).  Add
a test for this contract.
2019-05-04 19:26:01 +10:00
Fraser Tweedale
3324049c90 refactor many applications of 'view listElementsL'
List / GenericList derives Foldable, which means that in many cases
where 'length (l ^. listElementsL)' was written, we can instead
write 'length l'.  Likewise for 'null'.  Avoid these unnecessary
applications.
2019-05-04 19:10:07 +10:00
Fraser Tweedale
bba4320f35 List: add "move to next" function
A common use case is to seek to the next occurrence in the list of
an element matching some predicate (e.g. next unread email).  Add
the 'listFindBy' function to satisfy this use case.

'listFindBy' is lazy.  Also redefine 'listMoveToElement' in terms of
'listFindBy', making it lazy.  This changes the constraints from
(Traversable t) to (Foldable t, Splittable t), which is reasonable.
2018-12-14 08:41:08 +10:00
Fraser Tweedale
cd4fed802a List: make listMoveBy lazy
'listMoveBy' was evaluating the whole container, making it (and the
many functions that use it) unusable for applications needing lazy
loading.  Fix the function and add a regression test.
2018-12-08 21:52:32 +10:00
Fraser Tweedale
f715cb62f3 List: add class Reversible
Add the 'Reversible' type class and generalise 'listReverse' over
it.  Add instances and QuickCheck properties for Vector and Seq.
2018-12-08 18:34:10 +10:00
Fraser Tweedale
f23b6b1dba List: add instance Splittable Seq
Add an instance of Splittable for Data.Sequence.Seq, and QuickCheck
properties for it.

Add lower bound containers >= 0.5.7, being the version at which the
Semigroup instance was introduced.
2018-12-08 18:33:11 +10:00
Fraser Tweedale
8db170a02b List: abstract container type
Introduce 'GenericList' which abstracts list behaviour over the
container type.  This allows the use of types other than Vector, if
it would suit a particular application (e.g. lazy loading of list
contents).

'List' is retained as a type synonym for backwards compatibility.
For a container type to be usable with 'List', it must have
instances of 'Traversable' and a new type class 'Splittable' which
allows splitting the container at a given index.

Some operations impose additional constraints on the container type:

- listInsert: 'Applicative' and 'Semigroup'
- listRemove: 'Semigroup'
- listClear: 'Monoid'

Fixes: https://github.com/jtdaugherty/brick/issues/201
2018-12-08 18:32:57 +10:00
Fraser Tweedale
dc84681bdb List: fix listMoveBy behaviour when no selection
Add QuickCheck properties for the behaviour described in the
'listMoveBy' haddock, particularly for when there is no current
selection.  Then fix 'listMoveBy' to make the tests pass.
2018-12-08 08:26:27 +10:00
Fraser Tweedale
eafa41a13a List: fix listReplace behaviour on invalid index
Add QuickCheck properties for the behaviour described in the
'listReplace' haddock.  Then fix 'listReplace' to make the tests
pass.
2018-12-08 08:26:27 +10:00
Fraser Tweedale
040f3dadb7 tests: add List properties
Add some property tests for List behaviour.  Among other things,
check that the "selected element" bookkeeping maintains a valid
selection at all times (as long as you're using the provided
functions and not manipulating the underlying Vector directly).
2018-12-07 08:56:21 +10:00
Fraser Tweedale
f46ac63c97 tests: exit with nonzero status when tests fail
The current 'main' has type 'IO Bool' but a return value of 'False'
does not cause the program to exit with nonzero status.  Witnessed
by the following:

  ftweedal% cat foo.hs
  main :: IO Bool
  main = putStrLn "goodbye world" *> pure False

  ftweedal% runhaskell foo.hs
  goodbye world

  ftweedal% echo $?
  0

This causes the cabal test suite to pass, even when there are
errors.  Unless you inspect the QuickCheck output carefully, you
might not notice that a test is failing.  Update 'main' to ensure
that we exit nonzero when quickCheckAll returns 'False'.
2018-12-05 21:20:15 +10:00
Daniel Wagner
11b7be5616 delete unused extension to fix tests on GHC 7.10 2018-03-25 22:32:52 -04:00
Daniel Wagner
ba69f6846a make test suite more obviously correct 2018-03-25 18:04:15 -04:00
Daniel Wagner
5dd5bc4100 add a way to join neighboring borders 2018-03-25 18:04:15 -04:00