souplesse

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

PointTest.elm (1871B)


      1 module PointTest exposing (specs)
      2 
      3 import Point exposing (Point, downsample, subseq)
      4 import Pos exposing (Pos)
      5 import Test exposing (..)
      6 import Expect exposing (Expectation)
      7 
      8 newPoint i = Point
      9              (1731437067 + (toFloat i)*1.2)
     10              (Pos 52 1 (Just 10))
     11              (Just (round(sin((toFloat i)/10)*10))) (Just i) Nothing
     12 
     13 
     14 points n = List.map newPoint (List.range 0 n)
     15 
     16 maybe default val =
     17     case val of
     18         Just v -> v
     19         Nothing -> default
     20 
     21 specs: Test
     22 specs =
     23     describe "Point"
     24         [ describe "downsample"
     25               [ test "it returns no more points than requested" <|
     26                     \_ ->
     27                     let orig = (points 10)
     28                         sampled = Point.downsample 5 orig
     29                     in Expect.equal 5 (List.length sampled)
     30               , test "it drops points which are too close together" <|
     31                   \_ ->
     32                       let orig = List.map newPoint [ 0, 1, 2, 3, 4, 10, 500, 1000 ]
     33                           sampled = Point.downsample 10 orig
     34                           idx p = maybe 0 p.power
     35                       in Expect.equalLists [0, 500, 1000] (List.map idx sampled)
     36               ]
     37         , describe "subseq"
     38             [ test "chooses only points in the time range" <|
     39                   \_ ->
     40                   let orig = (points 50)
     41                       s = 1731437087
     42                       d = 40
     43                       subs = subseq orig s d
     44                   in Expect.equal True
     45                       (List.all (\ p -> p.time >= s && p.time <= s + d) subs)
     46             , test "is empty if no points" <|
     47                   \_ ->
     48                       Expect.equalLists [] (subseq [] 10 10)
     49             , test "is empty if no time" <|
     50                   \_ ->
     51                       Expect.equalLists (subseq (points 50) 1731437067 0) []
     52             ]
     53         ]