File: UtilsTest.hs

package info (click to toggle)
haskell-tidal 1.7.10-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 776 kB
  • sloc: haskell: 9,594; lisp: 413; makefile: 5
file content (56 lines) | stat: -rw-r--r-- 1,801 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
{-# LANGUAGE OverloadedStrings #-}

module Sound.Tidal.UtilsTest where

import Test.Microspec

import Prelude hiding ((<*), (*>))

import Sound.Tidal.Utils

run :: Microspec ()
run =
  describe "Sound.Tidal.Utils" $ do
    describe "delta" $ do
      it "subtracts the second element of a tuple from the first" $ do
        property $ delta (3,10) === (7 :: Int)
   
    describe "applies function to both elements of tuple" $ do
       let res = mapBoth (+1) (2,5) 
       property $ ((3,6) :: (Int, Int)) === res

    describe "apply function to first element of tuple" $ do
       let res = mapFst (+1) (2, 5) 
       property $ ((3, 5) :: (Int, Int)) === res

    describe "apply function to second element of tuple" $ do
       let res = mapSnd (+1) (2, 5)
       property $ ((2, 6) :: (Int, Int)) === res
     
    describe "return midpoint between first and second tuple value" $ do
       let res = mid (2, 5)
       property $ (3.5 :: Double) === res

    describe "return of two lists, with unique values to each list" $ do
       let res = removeCommon [1,2,5,7,12,16] [2,3,4,5,15,16]
       property $ (([1,7,12],[3,4,15]) :: ([Int], [Int])) === res

    describe "wrap around indexing" $ do
       let res = (!!!) [1..5] 7
       property $ (3 :: Int) === res

    describe "safe list indexing" $ do 
       let res = nth 2 ([] :: [Int])
       property $ Nothing === res

    describe "list accumulation with given list elements" $ do
       let res = accumulate ([1..5] :: [Int])
       property $ [1,3,6,10,15] === res 

    describe "index elements in list" $ do
       let res = enumerate ['a', 'b', 'c']
       property $ [(0,'a'),(1,'b'),(2,'c')] === res

    describe "split list by given pred" $ do 
       let res = wordsBy (== ':') "bd:3"
       property $ ["bd", "3"] === res