aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/locale/territory.lux
blob: 5548c3a6ea866c5c83e85fa27314352c72dee274 (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
(.using
 [library
  [lux "*"
   ["_" test {"+" Test}]
   [abstract
    [monad {"+" do}]
    [hash {"+" Hash}]
    [\\specification
     ["$[0]" hash]]]
   [control
    ["[0]" maybe]]
   [data
    ["[0]" text]
    [collection
     ["[0]" set {"+" Set}]
     ["[0]" list ("[1]#[0]" functor mix)]]]
   [macro
    ["[0]" template]]
   [math
    ["[0]" random {"+" Random}]
    [number
     ["n" nat]]]]]
 [\\library
  ["[0]" /]])

(type: Bundle
  (Record
   [#amount Nat
    #names (Set Text)
    #shorts (Set Text)
    #longs (Set Text)
    #numbers (Set Nat)
    #territories (Set /.Territory)
    #test Test]))

(template [<bundle> <territories>]
  [(def: <bundle>
     Bundle
     (let [amount (template.amount <territories>)
           territories (`` (list (~~ (template.spliced <territories>))))]
       [#amount amount
        #names (|> territories (list#each /.name) (set.of_list text.hash))
        #shorts (|> territories (list#each /.short_code) (set.of_list text.hash))
        #longs (|> territories (list#each /.long_code) (set.of_list text.hash))
        #numbers (|> territories (list#each /.numeric_code) (set.of_list n.hash))
        #territories (|> territories (set.of_list /.hash))
        #test (_.coverage <territories>
                true)]))]

  [territories/a [/.afghanistan /.aland_islands /.albania /.algeria /.american_samoa
                  /.andorra /.angola /.anguilla /.antarctica /.antigua
                  /.argentina /.armenia /.aruba /.australia /.austria
                  /.azerbaijan]]
  [territories/b [/.the_bahamas /.bahrain /.bangladesh /.barbados /.belarus
                  /.belgium /.belize /.benin /.bermuda /.bhutan
                  /.bolivia /.bonaire /.bosnia /.botswana /.bouvet_island
                  /.brazil /.british_indian_ocean_territory /.brunei_darussalam /.bulgaria /.burkina_faso
                  /.burundi]]
  [territories/c [/.cape_verde /.cambodia /.cameroon /.canada /.cayman_islands
                  /.central_african_republic /.chad /.chile /.china /.christmas_island
                  /.cocos_islands /.colombia /.comoros /.congo /.democratic_republic_of_the_congo
                  /.cook_islands /.costa_rica /.ivory_coast /.croatia /.cuba
                  /.curacao /.cyprus /.czech_republic]]
  [territories/d [/.denmark /.djibouti /.dominica /.dominican_republic]]
  [territories/e [/.ecuador /.egypt /.el_salvador /.equatorial_guinea /.eritrea
                  /.estonia /.eswatini /.ethiopia]]
  [territories/f [/.falkland_islands /.faroe_islands /.fiji /.finland /.france
                  /.french_guiana /.french_polynesia /.french_southern_territories]]
  [territories/g [/.gabon /.the_gambia /.georgia /.germany /.ghana
                  /.gibraltar /.greece /.greenland /.grenada /.guadeloupe
                  /.guam /.guatemala /.guernsey /.guinea /.guinea_bissau
                  /.guyana]]
  [territories/h [/.haiti /.heard_island /.honduras /.hong_kong
                  /.hungary]]
  [territories/i [/.iceland /.india /.indonesia /.iran /.iraq
                  /.ireland /.isle_of_man /.israel /.italy]]
  [territories/j [/.jamaica /.japan /.jersey /.jordan]]
  [territories/k [/.kazakhstan /.kenya /.kiribati /.north_korea /.south_korea
                  /.kuwait /.kyrgyzstan]]
  [territories/l [/.laos /.latvia /.lebanon /.lesotho /.liberia
                  /.libya /.liechtenstein /.lithuania /.luxembourg]]
  [territories/m [/.macau /.macedonia /.madagascar /.malawi /.malaysia
                  /.maldives /.mali /.malta /.marshall_islands /.martinique
                  /.mauritania /.mauritius /.mayotte /.mexico /.micronesia
                  /.moldova /.monaco /.mongolia /.montenegro /.montserrat
                  /.morocco /.mozambique /.myanmar]]
  [territories/n [/.namibia /.nauru /.nepal /.netherlands /.new_caledonia
                  /.new_zealand /.nicaragua /.niger /.nigeria /.niue
                  /.norfolk_island /.northern_mariana_islands /.norway]]
  [territories/o [/.oman]]
  [territories/p [/.pakistan /.palau /.palestine /.panama /.papua_new_guinea
                  /.paraguay /.peru /.philippines /.pitcairn_islands /.poland
                  /.portugal /.puerto_rico]]
  [territories/q [/.qatar]]
  [territories/r [/.reunion /.romania /.russia /.rwanda]]
  [territories/s [/.saint_barthelemy /.saint_helena /.saint_kitts /.saint_lucia /.saint_martin
                  /.saint_pierre /.saint_vincent /.samoa /.san_marino /.sao_tome
                  /.saudi_arabia /.senegal /.serbia /.seychelles /.sierra_leone
                  /.singapore /.sint_maarten /.slovakia /.slovenia /.solomon_islands
                  /.somalia /.south_africa /.south_georgia /.south_sudan /.spain
                  /.sri_lanka /.sudan /.suriname /.svalbard /.sweden
                  /.switzerland /.syria]]
  [territories/t [/.taiwan /.tajikistan /.tanzania /.thailand /.east_timor
                  /.togo /.tokelau /.tonga /.trinidad /.tunisia
                  /.turkey /.turkmenistan /.turks /.tuvalu]]
  [territories/u [/.uganda /.ukraine /.united_arab_emirates /.united_kingdom /.united_states_of_america
                  /.united_states_minor_outlying_islands /.uruguay /.uzbekistan]]
  [territories/v [/.vanuatu /.vatican_city /.venezuela /.vietnam /.british_virgin_islands /.united_states_virgin_islands]]
  [territories/w [/.wallis /.western_sahara]]
  [territories/y [/.yemen]]
  [territories/z [/.zambia /.zimbabwe]]
  )

(def: territories
  (List Bundle)
  (list ..territories/a
        ..territories/b
        ..territories/c
        ..territories/d
        ..territories/e
        ..territories/f
        ..territories/g
        ..territories/h
        ..territories/i
        ..territories/j
        ..territories/k
        ..territories/l
        ..territories/m
        ..territories/n
        ..territories/o
        ..territories/p
        ..territories/q
        ..territories/r
        ..territories/s
        ..territories/t
        ..territories/u
        ..territories/v
        ..territories/w
        ..territories/y
        ..territories/z))

(def: (aggregate lens hash territories)
  (All (_ a) (-> (-> Bundle (Set a))
                 (Hash a)
                 (List Bundle)
                 [Nat (Set a)]))
  (list#mix (function (_ bundle [amount set])
              [(n.+ amount (the #amount bundle))
               (set.union set (lens bundle))])
            [0 (set.empty hash)]
            territories))

(def: territories_test
  Test
  (|> ..territories
      list.reversed
      (list#each (the #test))
      (list#mix _.and
                (`` (all _.and
                         (~~ (template [<lens> <tag> <hash>]
                               [(let [[amount set] (..aggregate (the <tag>) <hash> ..territories)]
                                  (_.coverage [<lens>]
                                    (n.= amount (set.size set))))]

                               [/.name #names text.hash]
                               [/.short_code #shorts text.hash]
                               [/.long_code #longs text.hash]
                               [/.numeric_code #numbers n.hash]
                               [/.equivalence #territories /.hash]
                               ))
                         )))))

(template: (!aliases <reference> <aliases>)
  [(_.coverage <aliases>
     (list.every? (# /.equivalence = <reference>)
                  (`` (list (~~ (template.spliced <aliases>))))))])

(def: aliases_test
  Test
  (all _.and
       ... A
       (!aliases /.antigua [/.barbuda])
       ... B
       (!aliases /.bonaire [/.sint_eustatius /.saba])
       (!aliases /.bosnia [/.herzegovina])
       ... H
       (!aliases /.heard_island [/.mcdonald_islands])
       ... S
       (!aliases /.saint_helena [/.ascension /.tristan_da_cunha])
       (!aliases /.saint_kitts [/.nevis])
       (!aliases /.saint_pierre [/.miquelon])
       (!aliases /.saint_vincent [/.the_grenadines])
       (!aliases /.sao_tome [/.principe])
       (!aliases /.south_georgia [/.south_sandwich_islands])
       (!aliases /.svalbard [/.jan_mayen])
       ... T
       (!aliases /.trinidad [/.tobago])
       (!aliases /.turks [/.caicos_islands])
       ... U
       (!aliases /.united_kingdom [/.northern_ireland])
       ... W
       (!aliases /.wallis [/.futuna])
       ))

(def: .public random
  (Random /.Territory)
  (let [options (|> ..territories
                    (list#each (|>> (the #territories) set.list))
                    list.together)]
    (do [! random.monad]
      [choice (# ! each (n.% (list.size options))
                 random.nat)]
      (in (maybe.trusted (list.item choice options))))))

(def: .public test
  Test
  (<| (_.covering /._)
      (_.for [/.Territory])
      (all _.and
           (_.for [/.hash]
                  ($hash.spec /.hash ..random))
           
           ..territories_test
           ..aliases_test
           )))