aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/spec/compositor/generation/primitive.lux
blob: 63568fbcebf65b81082d2475b0d59e03663cc08f (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
(.module:
  [lux #*
   ["_" test (#+ Test)]
   [abstract
    [monad (#+ do)]]
   [control
    [pipe (#+ case>)]]
   [data
    ["." error]
    ["." bit ("#@." equivalence)]
    [number
     ["." frac]]
    ["." text ("#@." equivalence)
     format]]
   [math
    ["r" random]]
   [tool
    [compiler
     ["." synthesis]]]]
  [///
   [common (#+ Runner)]])

(def: (f/=' reference subject)
  (-> Frac Frac Bit)
  (or (f/= reference subject)
      (and (frac.not-a-number? reference)
           (frac.not-a-number? subject))))

(def: #export (spec run)
  (-> Runner Test)
  (`` ($_ _.and
          (~~ (template [<evaluation-name> <synthesis> <gen> <test>]
                [(do r.monad
                   [expected <gen>]
                   (_.test (%name (name-of <synthesis>))
                           (|> (run <evaluation-name> (<synthesis> expected))
                               (case> (#error.Success actual)
                                      (<test> expected (:assume actual))

                                      (#error.Failure error)
                                      false))))]

                ["bit" synthesis.bit  r.bit  bit@=]
                ["i64" synthesis.i64  r.i64  "lux i64 ="]
                ["f64" synthesis.f64  r.frac  f/=']
                ["text" synthesis.text (r.ascii 5) text@=]
                ))
          )))