aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/data/number/frac.lux
blob: 544ab858c0dca83795fb0b7d1a6d702210d2e8e7 (plain)
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
(.module:
  [lux #*
   data/text/format
   ["_" test (#+ Test)]
   [abstract
    [monad (#+ do)]
    {[0 #test]
     [/
      ["$." equivalence]
      ["$." order]
      ["$." number]
      ["$." monoid]
      ["$." codec]]}]
   [math
    ["r" random]]]
  {1
   ["." /
    //]})

(def: #export test
  Test
  (let [gen-frac (:: r.monad map (|>> (i/% +100) .int-to-frac) r.int)]
    (<| (_.context (%name (name-of /._)))
        (`` ($_ _.and
                ($equivalence.spec /.equivalence gen-frac)
                ($order.spec /.order gen-frac)
                ($number.spec /.order /.number gen-frac)
                (~~ (template [<monoid>]
                      [(<| (_.context (%name (name-of <monoid>)))
                           ($monoid.spec /.equivalence <monoid> gen-frac))]

                      [/.addition] [/.multiplication] [/.minimum] [/.maximum]
                      ))
                ## TODO: Uncomment ASAP
                ## (~~ (template [<codec>]
                ##     [(<| (_.context (%name (name-of /.binary)))
                ##          ($codec.spec /.equivalence <codec> gen-frac))]

                ##     [/.binary] [/.octal] [/.decimal] [/.hex]
                ##     ))
                
                (_.test "Alternate notations."
                        (and (f/= (bin "+1100.1001")
                                  (bin "+11,00.10,01"))
                             (f/= (oct "-6152.43")
                                  (oct "-615,2.43"))
                             (f/= (hex "+deadBE.EF")
                                  (hex "+dead,BE.EF"))))
                (do r.monad
                  [sample gen-frac]
                  (_.test (format (%name (name-of /.frac-to-bits)) " " (%name (name-of /.bits-to-frac)))
                          (|> sample /.frac-to-bits /.bits-to-frac (f/= sample))))
                )))))