Unit testing IO Int and similar in Haskell

Of the Ninety-nine Haskell issues :

Question 23 : Extract a certain number of randomly selected items from the list.

This is a partial solution. For simplicity, this code simply selects one item from the list.

import System.Random (randomRIO)

randItem :: [a] -> IO a
randItem xs = do
    i <- randomRIO (0,length xs - 1)
    return $ xs !! i

therefore it randItem [1..10]will return IO Intthat matches (but is not equal to) some Int from 1 to 10.

So far so good. But what tests can I write for my randItem function? What is the connection - if there is - can I confirm entry and exit?

I can use the same logic as the above function to create m Bool, but I cannot figure out how to test for m Bool. Thank.

+4
source share
1

, . QuickCheck, :

  • .
  • .

, Haskell Random , ( Haskell-) . , randomRIO, randomR randomRs. RandomGen unit test ( QuickCheck). .

+4

Source: https://habr.com/ru/post/1687644/


All Articles