File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change 313
313
})
314
314
_val
315
315
}))
316
+
317
+ ###
318
+ # @brief Check if a condition is verified for all elements of a list
319
+ # @param a the list to work on
320
+ # @param f the conditon
321
+ # =begin
322
+ # (let a [1 2 3 4])
323
+ # (let f (fun(e)(< e 5)))
324
+ # (print (list:forAll a f)) # true
325
+ # =end
326
+ # @author https://github.com/Gryfenfer97
327
+ ##
328
+ (let list:forAll (fun (a f) {
329
+ (mut verified true)
330
+ (mut index 0)
331
+ (while (and verified (< index (len a))) {
332
+ (if (not (f (@ a index)))
333
+ (set verified false)
334
+ )
335
+ (set index (+ 1 index))
336
+ })
337
+ verified
338
+ }))
339
+
340
+ ###
341
+ # @brief Check if a condition if verified for one or more elements of a list
342
+ # @param a the list to work on
343
+ # @param f the conditon
344
+ # =begin
345
+ # (let a [1 2 3 4])
346
+ # (let f (fun(e)(< e 3)))
347
+ # (print (list:any a f)) # true
348
+ # =end
349
+ # @author https://github.com/Gryfenfer97
350
+ ##
351
+ (let list:any (fun (a f) {
352
+ (mut verified false)
353
+ (mut index 0)
354
+ (while (and (not verified) (< index (len a))) {
355
+ (if (f (@ a index))
356
+ (set verified true)
357
+ )
358
+ (set index (+ 1 index))
359
+ })
360
+ verified
361
+ }))
Original file line number Diff line number Diff line change 64
64
(set tests (assert-eq a [1 2 3] "unmodified list" tests))
65
65
(set tests (assert-eq b [4 5 6] "unmodified list" tests))
66
66
67
+ (set tests (assert-eq (list:forAll a (fun (e) (< e 4))) true "list:forAll" tests))
68
+ (set tests (assert-eq (list:forAll a (fun (e) (< e 2))) false "list:forAll" tests))
69
+ (set tests (assert-eq (list:forAll [] (fun (e) (= e 2))) true "list:forAll" tests))
70
+ (set tests (assert-eq (list:any a (fun (e) (< e 2))) true "list:any" tests))
71
+ (set tests (assert-eq (list:any a (fun (e) (> e 8))) false "list:any" tests))
72
+ (set tests (assert-eq (list:any [] (fun (e) (= e 8))) false "list:any" tests))
73
+
67
74
(recap "List tests passed" tests (- (time) start-time))
68
75
69
76
tests
You can’t perform that action at this time.
0 commit comments