aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/aedifex/project.lux
blob: 18c307ae023329841387de8b56a0ed526406420b (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

(.require
 [library
  [lux (.except)
   [abstract
    [monad (.only do)]
    ["[0]" equivalence
     ["[1]T" \\test]]
    ["[0]" monoid
     ["[1]T" \\test]]]
   [control
    ["[0]" try (.use "[1]#[0]" functor)]
    ["[0]" exception]]
   [data
    ["[0]" product]
    ["[0]" text (.use "[1]#[0]" equivalence)]]
   [math
    ["[0]" random (.only Random) (.use "[1]#[0]" monad)]
    [number
     ["n" nat]]]
   [test
    ["_" property (.only Test)]]]]
 [//
  ["@[0]" profile]]
 [\\program
  ["[0]" / (.only)
   ["/[1]" //
    ["[1]" profile]]]])

(def profile
  (Random [//.Name //.Profile])
  (|> @profile.random
      (random#each (has //.#parents (list)))
      (random.and (random.alphabetic 1))))

(def .public random
  (Random /.Project)
  (do random.monad
    [[name profile] ..profile]
    (in (/.project name profile))))

(def .public test
  Test
  (<| (_.covering /._)
      (_.for [/.Project /.project]
             (all _.and
                  (_.for [/.equivalence]
                         (equivalenceT.spec /.equivalence ..random))
                  (_.for [/.monoid]
                         (monoidT.spec /.equivalence /.monoid ..random))

                  (_.coverage [/.file]
                    (|> /.file
                        (text#= "")
                        not))
                  (do random.monad
                    [[super_name super_profile] ..profile
                     [dummy_name dummy_profile] (random.only (|>> product.left (text#= super_name) not)
                                                             ..profile)
                     [sub_name sub_profile] (random.only (function (_ [name profile])
                                                           (and (not (text#= super_name name))
                                                                (not (text#= dummy_name name))))
                                                         ..profile)
                     fake_name (random.only (function (_ name)
                                              (and (not (text#= super_name name))
                                                   (not (text#= dummy_name name))
                                                   (not (text#= sub_name name))))
                                            (random.alphabetic 1))
                     .let [project (all (of /.monoid composite)
                                        (/.project super_name super_profile)
                                        (/.project dummy_name dummy_profile)
                                        (/.project sub_name (has //.#parents (list super_name) sub_profile)))
                           circular (all (of /.monoid composite)
                                         (/.project super_name (has //.#parents (list sub_name) super_profile))
                                         (/.project dummy_name dummy_profile)
                                         (/.project sub_name (has //.#parents (list super_name) sub_profile)))]]
                    (all _.and
                         (_.coverage [/.profile]
                           (and (|> (/.profile project super_name)
                                    (try#each (of //.equivalence = super_profile))
                                    (try.else false))
                                (|> (/.profile project dummy_name)
                                    (try#each (of //.equivalence = dummy_profile))
                                    (try.else false))
                                (|> (/.profile project sub_name)
                                    (try#each (of //.equivalence = (of //.monoid composite sub_profile super_profile)))
                                    (try.else false))))
                         (_.coverage [/.unknown_profile]
                           (when (/.profile project fake_name)
                             {try.#Success _}
                             false

                             {try.#Failure error}
                             (exception.match? /.unknown_profile error)))
                         (_.coverage [/.circular_dependency]
                           (when (/.profile circular sub_name)
                             {try.#Success _}
                             false

                             {try.#Failure error}
                             (exception.match? /.circular_dependency error)))
                         ))
                  ))))