aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/specification/compositor/generation/reference.lux
blob: ce0d00d1aab10568344d3a72b74273c5af313b8c (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
61
62
63
64
(.require
 [library
  [lux (.except symbol)
   [abstract
    [monad (.only do)]]
   [control
    ["[0]" pipe]
    ["[0]" try]]
   [data
    [number
     ["n" nat]
     ["f" frac]]]
   [meta
    [compiler
     ["[0]" reference]
     ["[0]" synthesis]]]
   [math
    ["r" random (.only Random)]]
   [test
    ["_" property (.only Test)]]]]
 [///
  [common (.only Runner Definer)]])

(def symbol
  (Random Symbol)
  (let [symbol_part (r.upper_case_alpha 5)]
    [(r.and symbol_part symbol_part)]))

(def (definition define)
  (-> Definer Test)
  (do r.monad
    [name ..symbol
     expected r.safe_frac]
    (_.test "Definitions."
      (|> (define name (synthesis.f64 expected))
          (pipe.when
            {try.#Success actual}
            (f.= expected (as Frac actual))

            {try.#Failure _}
            false)))))

(def (variable run)
  (-> Runner Test)
  (do [! r.monad]
    [register (|> r.nat (at ! each (n.% 100)))
     expected r.safe_frac]
    (_.test "Local variables."
      (|> (synthesis.branch/let [(synthesis.f64 expected)
                                 register
                                 (synthesis.variable/local register)])
          (run "variable")
          (pipe.when
            {try.#Success actual}
            (f.= expected (as Frac actual))

            {try.#Failure _}
            false)))))

(def .public (spec runner definer)
  (-> Runner Definer Test)
  (all _.and
       (..definition definer)
       (..variable runner)))