aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/spec/compositor/generation/reference.lux
blob: 8c53db6c67b9a61ef1e2595d7ad0e24989bc038e (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
54
55
56
57
58
59
60
(.module:
  [lux #*
   ["_" test (#+ Test)]
   [abstract
    [monad (#+ do)]]
   [control
    [pipe (#+ case>)]
    ["." try]]
   [data
    [number
     ["n" nat]
     ["f" frac]]]
   [tool
    [compiler
     ["." reference]
     ["." synthesis]]]
   [math
    ["r" random (#+ Random)]]]
  [///
   [common (#+ Runner Definer)]])

(def: name
  (Random Name)
  (let [name-part (r.ascii/upper-alpha 5)]
    [(r.and name-part name-part)]))

(def: (definition define)
  (-> Definer Test)
  (do r.monad
    [name ..name
     expected r.safe-frac]
    (_.test "Definitions."
            (|> (define name (synthesis.f64 expected))
                (case> (#try.Success actual)
                       (f.= expected (:coerce Frac actual))

                       (#try.Failure _)
                       false)))))

(def: (variable run)
  (-> Runner Test)
  (do {@ r.monad}
    [register (|> r.nat (:: @ map (n.% 100)))
     expected r.safe-frac]
    (_.test "Local variables."
            (|> (synthesis.branch/let [(synthesis.f64 expected)
                                       register
                                       (synthesis.variable/local register)])
                (run "variable")
                (case> (#try.Success actual)
                       (f.= expected (:coerce Frac actual))

                       (#try.Failure _)
                       false)))))

(def: #export (spec runner definer)
  (-> Runner Definer Test)
  ($_ _.and
      (..definition definer)
      (..variable runner)))