--
-- Matcher
--

assertEqual "nat's o"
  (match 0 as nat with
    | o -> True
    | _ -> False)
  True

assertEqual "nat's o"
  (match 1 as nat with
    | o -> True
    | _ -> False)
  False

assertEqual "nat's s"
  (match 10 as nat with
    | s $n -> n)
  9

assertEqual "nat's s"
  (match 0 as nat with
    | s o -> True
    | _ -> False)
  False

--
-- Sequences
--

assertEqual "nats" (take 10 nats) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

assertEqual "nats0" (take 10 nats0) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

assertEqual "odds" (take 10 odds) [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]

assertEqual "evens" (take 10 evens) [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]

assertEqual "primes" (take 10 primes) [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]

--
-- Natural numbers
--

assertEqual "divisor" (divisor 10 5) True

assertEqual "findFactor" (findFactor 1) 1
assertEqual "findFactor" (findFactor 35) 5
assertEqual "findFactor" (findFactor 100) 2

assertEqual "pF" (pF 1) []
assertEqual "pF" (pF 3) [3]
assertEqual "pF" (pF 100) [2, 2, 5, 5]

assertEqual "isOdd" (isOdd 3) True
assertEqual "isOdd" (isOdd 4) False

assertEqual "isEven" (isEven 4) True
assertEqual "isEven" (isEven 5) False

assertEqual "isPrime" (isPrime 17) True
assertEqual "isPrime" (isPrime 18) False

assertEqual "perm" (perm 5 2) 20

assertEqual "comb" (comb 5 2) 10

assertEqual "nAdic" (nAdic 10 123) [1, 2, 3]
assertEqual "nAdic" (nAdic 2 10) [1, 0, 1, 0]

assertEqual "rtod"
  (2#(%1, take 10 %2) (rtod (6 / 35)))
  (0, [1, 7, 1, 4, 2, 8, 5, 7, 1, 4])

assertEqual "rtod'" (rtod' (6 / 35)) (0, [1], [7, 1, 4, 2, 8, 5])

assertEqual "showDecimal" (showDecimal 10 (6 / 35)) "0.1714285714"
assertEqual "showDecimal'" (showDecimal' (6 / 35)) "0.1 714285 ..."

assertEqual
  "regular-continued-fraction sqrt of 2"
  (rtof
     (regularContinuedFraction
        1
        [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]))
  1.4142135623730951

assertEqual "regular-continued-fraction pi"
  (rtof
     (regularContinuedFraction
        3
        [7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, 2, 2, 1, 84, 2,
         1, 1, 15, 3, 13]))
  3.141592653589793

assertEqual "continued-fraction pi"
  (rtof
     (continuedFraction
        3
        [7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2, 2, 2, 1, 84, 2,
         1, 1, 15, 3, 13]
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
         1, 1, 1]))
  3.141592653589793

assertEqual
  "regularContinuedFractionOfSqrt case 1"
  (2#(%1, take 10 %2) (regularContinuedFractionOfSqrt 2))
  (1, [2, 2, 2, 2, 2, 2, 2, 2, 2, 2])

assertEqual
  "regularContinuedFractionOfSqrt case 2"
  (rtof
     (regularContinuedFraction
        (2#(%1, take 100 %2) (regularContinuedFractionOfSqrt 2))))
  1.4142135623730951
