[Haskell-beginners] Quickcheck: pushing element onto stack increases stack size

PATRICK BROWNE patrick.browne at dit.ie
Thu May 11 19:38:59 UTC 2017


Hi,
I am trying to use Quickcheck to check that pushing an element increases
the size of a stack.
Something like:
prop_size2 x s = (size (Push x s)) > (size s)

Is this possible? Below is my effort using an empty stack.
Thanks in advance,
Pat


module Stack (empty, push, pop, top, isEmpty) where
import Test.QuickCheck

data Stack a = Empty | Push a (Stack a) deriving  Show

empty :: Stack a
empty = Empty

push :: a -> Stack a -> Stack a
push x ss = Push x ss

pop :: Stack a -> Stack a
pop Empty = error "pop emptyStack"
pop (Push x ss) = ss

top :: Stack a -> a
top Empty = error "top emptyStack"
top (Push x ss) = x

isEmpty :: Stack a -> Bool
isEmpty Empty = True
isEmpty (Push x ss) = False


size :: (Stack a) -> Int
size Empty = 0
size (Push x ss) = succ (size ss)


prop_size x  = (size (Push x Empty)) > (size Empty)

-- 


This email originated from DIT. If you received this email in error, please 
delete it from your system. Please note that if you are not the named 
addressee, disclosing, copying, distributing or taking any action based on 
the contents of this email or attachments is prohibited. www.dit.ie

Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí 
earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an 
seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon 
dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa 
ríomhphost nó sna hiatáin seo. www.dit.ie

Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to 
Grangegorman <http://www.dit.ie/grangegorman>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20170511/64f3d46e/attachment.html>


More information about the Beginners mailing list