Retoor software development Projects Research SearchXNG
Register Sign In

10 lines
196 B
Plaintext
Raw Normal View History

feat: add forall method to Sequence class for testing all elements pass predicate Implement a `forall` method on the Sequence class that takes a predicate function and returns true only if every element in the sequence satisfies the predicate. The method iterates through all elements, returning false immediately upon encountering any element where the predicate does not return exactly true. Includes core library documentation and a test file verifying behavior with numeric comparisons and non-boolean predicate returns.
2015-01-14 08:47:01 +01:00
var a = [1, 2, 3]
var b = a.forall {|x| x > 1 }
IO.print(b) // expect: false
var d = a.forall {|x| x > 0 }
IO.print(d) // expect: true
test: add forall test for empty list and non-bool/non-function args Add test case verifying that `forall` returns true for an empty list regardless of predicate, and add two new test files covering runtime errors when `forall` receives a non-boolean-returning function or a non-function argument. Also refactor the `forall` implementation to use logical negation (`!`) instead of explicit `!= true` comparison.
2015-01-15 07:42:15 +01:00
var e = [].forall {|x| false }
IO.print(e) // expect: true
Reference in New Issue Copy Permalink
cb1703409c
wren/test/list/forall.wren
Response time: 39ms
Mail Licenses API