-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueryTests-enumerate.rkt
302 lines (229 loc) · 14 KB
/
queryTests-enumerate.rkt
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#lang rosette
(require "./interp-enumerate.rkt")
; Need the following sets of features:
; 1. Ability to get a different solution if this one does not work
; 2. Ability to deal with reals properly
; 4. Add a solution to: solution: unrecognized solver output: (error line 7404 column 10: model is not available)
; 5. Need to extend to more columns
; 6. Fix division by zero problem with simple-multiply2
; 8. if then else wont work if we have multiple conditions (case statement for a whole set of conds
(define-symbolic i1 integer?)
(define-symbolic i2 integer?)
(define-symbolic i3 integer?)
(define-symbolic i4 integer?)
(define-symbolic i5 integer?)
(define-symbolic i6 integer?)
(define-symbolic s1 string?)
(define-symbolic s2 string?)
(define-symbolic r1 real?)
(define-symbolic r2 real?)
(define mult234
(custom
(lambda (p pos)
(send p basic-math pos
(send p basic-math (cons 1 pos)
(send p in-v pos 2 number?)
(send p in-v pos 3 number?))
(send p in-v pos 4 number?)))))
(define extra-m234 (hash 'number (list mult234)))
(define mult23x
(custom
(lambda (p pos v)
(send p basic-math pos
(send p basic-math (cons 1 pos)
(send p in-v pos 2 number?)
(send p in-v pos 3 number?))
v))
do-all-int))
(define extra-m23x (hash 'number (list mult23x)))
; test selection of a certain column (Col2) based on value in a different column (Col1)
(define (simple-selection1)
(test analyze '(if) '() '(index-of) 7 '(5 0) (list s1 i1) '(("A" 5)("B" 5))))
(define (simple-remainder1)
(test analyze '() '() '(index-of) 7 '(2 0 3) (list i1 i2) '((18 4) (10 5) (17 7))))
(define (simple-symbolic1)
(test analyze '(if) '() '() 7 '(5 0) (list s1 i1) (list (list "A" i2) (list "B" 5))))
(define (simple-symbolic2)
(test analyze '(if) '() '() 7 (list i2 0) (list s1 i1) (list (list "A" i2) (list "B" 5))))
(define (simple-symbolic3)
(test analyze '() '() '() 7 (list s2 "B") (list s1 i1) (list (list s2 1) (list "B" 5))))
; test selection of a certain column based on its string
(define (simple-selection2)
(test analyze '() '() '() 7 '(1050 0) (list s1 i1) '(("Committed" 1050) ("Custom" 1050))))
; test multiplication of 2 columns based on string in the first column - return Col 2 * Col 3 if Col1 = "Committed"
(define (simple-selection3)
(test analyze '() '() '() 10 '(50000 0 1000) (list s1 i1 i2) '(("Committed" 1000 50) ("Custom" 1000 10) ("Committed" 100 10))))
(define math345
(custom
(lambda (p pos)
(send p basic-math pos
(send p in-v pos 3 number?)
(send p basic-math (cons 1 pos)
(send p in-v pos 4 number?)
(send p in-v pos 5 number?))))))
(define committed-if
(custom
(lambda (p pos yes no)
(send p if-then-else
(send p logic-op (cons 3 pos)
(send p compare-to-str (cons 4 pos)
(send p in-v (cons 5 pos) 1 string?)
(send p symbolic (cons 6 pos) string?))
(send p is-null? (cons 7 pos)))
yes no))
do-all-int do-all-int))
(define committed
(custom
(lambda (p pos)
(send p logic-op (cons 3 pos)
(send p compare-to-str (cons 4 pos)
(send p in-v (cons 5 pos) 1 string?)
(send p symbolic (cons 6 pos) string?))
(send p is-null? (cons 7 pos))))))
(define extra-selection4 (hash 'boolean (list committed) 'number (list math345)))
; test selection of a certain column (Col2) based on value in a different column (Col1)
(define (simple-selection1b)
(test analyze '(if) '() '() 7 '(1050 0) (list s1 i1) '(("Committed" 1050)("Custom" 1050))))
; test a simple multiply - need to handle reals properly because of precision issues
(define (simple-multiply1)
(test analyze '() '() '() 3 '(2.4 2.469) (list r1 r2) '((4 .6)(8.23 .3))))
; test simple boolean expression - Return expression Col2 < Col3
(define (simple-boolean1)
(test analyze '(>) '() '() 5 '(#t #f #f #t) (list s1 i1 i2) '(("A" 5 7)("B" 7 5)("C" 5 5)("D" 1 2))))
; test simple boolean expression - Return expression Col3 > Col2 and Col1 == "A"
(define (simple-boolean2)
(test analyze '(==) '() '(index-of substring) 9 '(#t #f #f #f) (list s1 i1 i2) '(("A" 5 7)("A" 7 5)("C" 7 5)("C" 5 7))))
; define (col1 + col2) / col3
(define (simple-math1)
(test analyze '() '() '() 6 '(2 4 5) (list i1 i2 i3) '((1 1 1)(9 7 4)(4 6 2))))
; if col1="A" then take col2 else 0
(define (simple-eq1)
(test analyze '(if ==) '() '(index-of length) 9 '(5 0 13) (list s1 i1) '(("A" 5)("AAA" 7)("A" 13))))
; and (col1 > col2, col3 = "A")
(define (simple-compare1)
(test analyze '(==) '() '(index-of substring) 9 '(#t #f #f #f) (list i1 i2 s1) '((5 3 "A")(3 5 "A")(5 3 "B")(5 5 "A"))))
; test if col1 > .33
(define (simple-test5)
(test analyze '() '() '() 7 '(#t #t #f) (list r1) '((.44)(.34)(.33))))
; test a simple multiply - by a constant
(define (simple-multiply2)
(test analyze '() '() '() 5 '(.008 .016) (list i1 i2) '((4)(8))))
; test string equal
(define (simple-compare2)
(test analyze '(==) '() '(index-of substring abs) 10 '(9 0 15) (list i1 i2 s1) '((4 3 "A") (4 3 "B") (5 5 "A"))))
; if col1="" then take col3 else col2
(define (simple-test2)
(test analyze '(==) '() '(abs index-of length) 7 '(5 0) (list s1 i1) '(("A" 5)("" 5))))
; define (col1 + col2) / col3
(define (simple-test3)
(test analyze '() '() '() 6 '(3.55 3.85) (list r1 r2 i1) '((4.3 2.8 2)(3.5 4.2 2))))
; and (col1 > col2, col3 = "A")
(define (simple-test4)
(test analyze '(and) '() '(substring) 9 '(#t #f #f #f) (list i1 i2 s1) '((5 3 "A")(3 5 "A")(5 3 "B")(5 5 "A"))))
; test if (col1 > col2) and (col2 < col3) and (col4 = "C" or col4 = "D")
(define (simple-test6)
(test analyze '() '() '(index-of) 9 '(#t #f #f #t #f) (list i1 i2 i3 s1) '((5 2 4 "C")(5 2 1 "C")(1 2 4 "C")(8 1 5 "D")(5 2 4 "M"))))
; test if Col1 is "Committed" AND Col2 is not blank, then max(0, Col3 - (Col4 * Col5))
(define (simple-selection4)
(test analyze '() '() '(substring) 10 '(5000 0 0) (list s1 i1 i2 i3 i4) '(("Committed" 25 10000 100 50) ("Committed" () 10000 100 50) ("Custom" 25 10000 100 50))))
; something wrong with strings...
(define (simple-selection1c)
(test analyze '() '() '(index-of) 5 '("5" "0") (list s1 s2) '(("A" "5")("B" "5"))))
; test combination of ANDs, NOTs, and arithmetic operations
(define (simple-test1)
(test analyze '(*) '() '() 10 '(2.6 0 0) (list s1 s2 i1 i2 r1) '(("A" "FOO" 5 4 .6)("A" "G" 10 9.7 1.3)("B" "G" 4 1.23 .3))))
(define v #(i1 i2 i3 i4 i5 i6))
; add a second to date
(define (simple-date-add1)
(test analyze '() '() '() 10 (list #(0 0 0 29 2 2000) #(23 59 23 28 2 2000) #(0 46 23 28 2 1999)) (list v) (list (list #(59 59 23 28 2 2000)) (list #(22 59 23 28 2 2000)) (list #(59 45 23 28 2 1999)))))
; add a minute to date
(define (simple-date-add2)
(test analyze '() '() '() 10 (list #(59 0 0 1 3 2001) #(22 23 23 28 2 2000) #(59 0 0 1 1 2000)) (list v) (list (list #(59 59 23 28 2 2001)) (list #(22 22 23 28 2 2000)) (list #(59 59 23 31 12 1999)))))
; add hour to date
(define (simple-date-add3)
(test analyze '() '() '() 10 (list #(59 59 0 1 3 2001) #(22 22 0 29 2 2000) #(59 59 0 1 1 2000)) (list v) (list (list #(59 59 23 28 2 2001)) (list #(22 22 23 28 2 2000)) (list #(59 59 23 31 12 1999)))))
; add days to date
(define (simple-date-add4)
(test analyze '() '() '() 10 (list #(59 59 23 2 3 2001) #(22 22 23 27 2 2000) #(59 59 23 2 1 2000)) (list v) (list (list #(59 59 23 28 2 2001)) (list #(22 22 23 25 2 2000)) (list #(59 59 23 31 12 1999)))))
; add months to date
(define (simple-date-add5)
(test analyze '() '() '() 10 (list #(59 59 23 28 2 2001) #(22 22 23 25 3 2000) #(59 59 23 31 1 2000)) (list v) (list (list #(59 59 23 30 1 2001)) (list #(22 22 23 25 2 2000)) (list #(59 59 23 31 12 1999)))))
; add years to date
(define (simple-date-add6)
(test analyze '() '() '() 10 (list #(59 59 23 30 1 2016) #(22 22 23 25 2 2015) #(59 59 23 31 12 2014)) (list v) (list (list #(59 59 23 30 1 2001)) (list #(22 22 23 25 2 2000)) (list #(59 59 23 31 12 1999)))))
; subtract seconds from date
(define (simple-date-subtract1)
(test analyze '() '() '() 10 (list #(59 59 23 31 12 2000) #(21 22 23 25 2 2000) #(58 59 23 31 12 1999)) (list v) (list (list #(0 0 0 1 1 2001)) (list #(22 22 23 25 2 2000)) (list #(59 59 23 31 12 1999)))))
; subtract 1 minute from date
(define (simple-date-subtract2)
(test analyze '() '() '() 10 (list #(0 59 23 31 12 2000) #(22 21 23 25 2 2000) #(59 58 23 31 12 1999)) (list v) (list (list #(0 0 0 1 1 2001)) (list #(22 22 23 25 2 2000)) (list #(59 59 23 31 12 1999)))))
; subtract 1 hour from date
(define (simple-date-subtract3)
(test analyze '() '() '() 10 (list #(0 0 23 31 12 2000) #(22 22 22 25 2 2000) #(59 59 22 31 12 1999)) (list v) (list (list #(0 0 0 1 1 2001)) (list #(22 22 23 25 2 2000)) (list #(59 59 23 31 12 1999)))))
; subtract 1 day from date
(define (simple-date-subtract4)
(test analyze '() '() '() 10 (list #(0 0 0 31 12 2000) #(22 22 23 24 2 2000) #(59 59 23 30 12 1999)) (list v) (list (list #(0 0 0 1 1 2001)) (list #(22 22 23 25 2 2000)) (list #(59 59 23 31 12 1999)))))
; subtract 1 month from date
(define (simple-date-subtract5)
(test analyze '() '() '() 10 (list #(0 0 0 1 3 2001) #(59 59 23 30 11 1999)) (list v) (list (list #(0 0 0 1 4 2001)) (list #(59 59 23 31 12 1999)))))
; subtract 10 years from date
(define (simple-date-subtract6)
(test analyze '() '() '() 10 (list #(0 0 0 1 1 1991) #(22 22 23 31 3 1990) #(59 59 23 31 12 1989)) (list v) (list (list #(0 0 0 1 1 2001)) (list #(22 22 23 31 3 2000)) (list #(59 59 23 31 12 1999)))))
; epoch to date
(define (epoch-to-date-test1)
(test analyze '() '() '() 10 (list #(28 26 18 4 10 2017) #(0 24 8 4 10 2016) #(0 0 2 1 1 2016)) (list v) (list (list 1507141588) (list 1475569440) (list 1451613600))))
; epoch to date + add 1 s
(define (epoch-to-date-test2)
(test analyze '() '() '() 10 (list #(29 26 18 4 10 2017) #(1 24 8 4 10 2016) #(1 0 2 1 1 2016)) (list v) (list (list 1507141588) (list 1475569440) (list 1451613600))))
; date extract
(define (date-extract1)
(test analyze '() '() '() 5 (list 59 22 59 59 59) (list v) (list (list #(59 59 23 28 2 2000)) (list #(22 59 23 28 2 2000))(list #(59 45 23 28 2 2000))(list #(59 45 23 28 2 1999))(list #(59 45 23 28 2 1990)))))
(define (date-extract2)
(test analyze '() '() '() 5 (list 59 59 45) (list v) (list (list #(59 59 23 28 2 2000)) (list #(22 59 23 28 2 2000))(list #(59 45 23 28 2 2000)))))
(define (date-extract3)
(test analyze '() '() '() 5 (list 22 23 21) (list v) (list (list #(59 59 22 28 2 2000)) (list #(22 59 23 28 2 2000))(list #(59 45 21 28 2 2000)))))
(define (date-extract4)
(test analyze '() '() '() 5 (list 28 22 1) (list v) (list (list #(59 59 22 28 2 2000)) (list #(22 59 23 22 2 2000))(list #(59 45 21 1 2 2000)))))
(define (date-extract5)
(test analyze '() '() '() 5 (list 1 12 8) (list v) (list (list #(59 59 22 28 1 2000)) (list #(22 59 23 22 12 2000))(list #(59 45 21 1 8 2000)))))
(define (date-extract6)
(test analyze '() '() '() 5 (list 2001 2004 2008) (list v) (list (list #(59 59 22 28 1 2001)) (list #(22 59 23 22 12 2004))(list #(59 45 21 1 8 2008)))))
; diff dates - only works for days as defined by the function
(define (date-diff-test)
(test analyze '() '() '() 5 (list 1 4 8) (list v) (list (list #(59 59 22 28 1 2000) #(59 59 22 27 1 2000)) (list #(22 59 23 22 12 2000) #(22 59 23 18 12 2000))(list #(59 45 21 10 8 2000) #(59 45 21 2 8 2000)))))
; filter dates that are >= 2000
(define (simple-date-filter1)
(test analyze '() '() '() 5 (list #t #t #t #f #f) (list v) (list (list #(59 59 23 28 2 2000)) (list #(22 59 23 28 2 2000))(list #(59 45 23 28 2 2000))(list #(59 45 23 28 2 1999))(list #(59 45 23 28 2 1990)))))
; filter dates that are == 2000
(define (simple-date-filter2)
(test analyze '() '() '() 5 (list #t #t #t #f #f) (list v) (list (list #(59 59 23 28 2 2000)) (list #(22 59 23 28 2 2000))(list #(59 45 23 28 2 2000))(list #(59 45 23 28 2 2002))(list #(59 45 23 28 2 2001)))))
; date to epoch
(define (date-to-epoch-test1)
(test analyze '() '() '() 10 (list 1507141588 1475569440 1451613600) (list v) (list (list #(28 26 18 4 10 2017)) (list #(0 24 8 4 10 2016)) (list #(0 0 2 1 1 2016)))))
; compose add years + add seconds
; add years to date
(define (simple-date-add7)
(test analyze '() '() '() 10 (list #(0 0 0 31 1 2016) #(23 22 23 25 2 2015) #(0 0 0 1 1 2015)) (list v) (list (list #(59 59 23 30 1 2001)) (list #(22 22 23 25 2 2000)) (list #(59 59 23 31 12 1999)))))
; do a like test, assuming the like pattern is in a column (so pattern is a constant)
(define (simple-like)
(test analyze '() '() '() 3 (list #t #t #f) (list s1 s2) '(("A%" "Apple")("B%" "Brtist")("A%" "Junk"))))
; do a like test, assuming the like pattern is in a column (so pattern is a constant)
(define (simple-like1)
(test analyze '() '() '() 3 (list #t #t #f) (list s1 s2) '(("Apple" "A%")("Brtist" "B%")("Junk" "A%"))))
; do a like test, assuming the like pattern is in a column (so pattern is a constant)
(define (simple-like1a)
(test analyze '() '() '() 6 (list #t #t #f #f) (list s1 s2) '(("Apple" "XA%")("Brtist" "XB%")("Junk" "XA%")("Garbage" "XB%"))))
; do a like test, assuming the like pattern is in a column (so pattern is a constant)
(define (simple-like1b)
(test analyze '() '() '() 6 (list #t #t #f #f) (list s1 s2) '(("XA%" "Apple") ("XB%" "Brtist")("XA%" "Junk")("XB%" "Garbage"))))
; do a like test where we 'find' the pattern
(define (simple-like2)
(test analyze '() '() '() 7 (list #t #f #t #f) (list s1) '(("abcBronx")("abBadly")("aBrown")("Apple"))))
; do a simple trim test
(define (simple-trim1)
(test analyze '() '() '() 5 (list "Apple" "Boy: and dog." "Dot") (list s1) '((" Apple")("Boy: and dog. ")("Dot"))))
(define (simple-trim2)
(test analyze '() '() '() 5 (list "Apple's Tim Cook?" "Boy walking home" "Dot234") (list s1) '(("Apple's Tim Cook? ")(" Boy walking home ")(" Dot234"))))
; do a simple digits test
(define (simple-digits)
(test analyze '() '() '() 5 (list "123" "325" "425") (list s1) '(("Apple123Boy")("Boy325Apple")("Dot425"))))