subttle / regular

Finite Automata and Regular Expressions for Regular Languages in Haskell
BSD 3-Clause "New" or "Revised" License
10 stars 1 forks source link

Explicit testing of generated sequences which can be checked using external resource #14

Closed subttle closed 3 years ago

subttle commented 3 years ago

There are many numerical sequences generated throughout this library, it would be nice to organize the testing of said sequences (in a dedicated scope label, perhaps Sequences.* or something) against some trusted third party sources (e.g. OEIS®) For example:

-- Fibonacci numbers (as a non-empty list)
-- http://oeis.org/A000045
fibonacci ∷ NonEmpty ℕ
fibonacci = fix ((⊲) 0 . NE.scanl (+) 1)

Could easily be checked to have the same initial segment that is listed under OEIS®:

testFibInit ∷ Test ()
testFibInit = expect (((==) `on` NE.take 40) expected fibonacci)
  where
    -- http://oeis.org/A000045
    expected ∷ NonEmpty ℕ
    expected = 0
       NE.:| [ 1
             , 1
             , 2
             , 3
             , 5
             , 8
             , 13
             , 21
             , 34
             , 55
             , 89
             , 144
             , 233
             , 377
             , 610
             , 987
             , 1597
             , 2584
             , 4181
             , 6765
             , 10946
             , 17711
             , 28657
             , 46368
             , 75025
             , 121393
             , 196418
             , 317811
             , 514229
             , 832040
             , 1346269
             , 2178309
             , 3524578
             , 5702887
             , 9227465
             , 14930352
             , 24157817
             , 39088169
             , 63245986
             , 102334155
             ]

And have a scoped test added to the main run suite, e.g.:

              , scope "Sequences.Fib"        testFibInit

Not exactly a substitute for a proof of correctness but then again that is the nature of testing :D