mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-26 23:04:15 +00:00
library/array.m:
Make array.map_corresponding_foldl/6 throw an exception if the input
arrays differ in size. This brings its behaviour into line with that of
the other "corresponding" predicates. It also avoids the unsafe behaviour
that can currently result when the second input array has fewer elements
than the first.
Add some additional modes to array.map_corresponding_foldl/6.
Replace calls to error/1 with calls to unexpected/2 throughout this
module.
NEWS:
Announce the above change.
tests/hard_coded/ho_array_ops.{m,exp}:
Extend this test to cover map_corresponding_foldl/6.
58 lines
1.3 KiB
Plaintext
58 lines
1.3 KiB
Plaintext
TESTING: foldl_corresponding (ok)
|
|
1 - 2
|
|
2 - 4
|
|
3 - 6
|
|
4 - 8
|
|
5 - 10
|
|
RESULT: OK
|
|
FINISHED TESTING: foldl_corresponding (ok)
|
|
|
|
TESTING: foldl_corresponding (empty)
|
|
RESULT: OK
|
|
FINISHED TESTING: foldl_corresponding (empty)
|
|
|
|
TESTING: foldl_corresponding (mismatch)
|
|
RESULT: EXCEPTION: software_error("predicate `array.foldl_corresponding\'/5: Unexpected: mismatched array sizes")
|
|
FINISHED TESTING: foldl_corresponding (mismatch)
|
|
|
|
TESTING: foldl2_corresponding (ok)
|
|
1 - 2
|
|
2 - 4
|
|
3 - 6
|
|
4 - 8
|
|
5 - 10
|
|
Sum is 45.
|
|
RESULT: OK
|
|
FINISHED TESTING: foldl2_corresponding (ok)
|
|
|
|
TESTING: foldl2_corresponding (empty)
|
|
Sum is 0.
|
|
RESULT: OK
|
|
FINISHED TESTING: foldl2_corresponding (empty)
|
|
|
|
TESTING: foldl2_corresponding (mismatch)
|
|
RESULT: EXCEPTION: software_error("predicate `array.foldl2_corresponding\'/7: Unexpected: mismatched array sizes")
|
|
FINISHED TESTING: foldl2_corresponding (mismatch)
|
|
|
|
TESTING: map_corresponding_foldl (ok)
|
|
1 + 2 = 3
|
|
2 + 4 = 6
|
|
3 + 6 = 9
|
|
4 + 8 = 12
|
|
5 + 10 = 15
|
|
array([3, 6, 9, 12, 15])
|
|
|
|
RESULT: OK
|
|
FINISHED TESTING: map_corresponding_foldl (ok)
|
|
|
|
TESTING: map_corresponding_foldl (empty)
|
|
array([])
|
|
|
|
RESULT: OK
|
|
FINISHED TESTING: map_corresponding_foldl (empty)
|
|
|
|
TESTING: map_corresponding_foldl (mismatch)
|
|
RESULT: EXCEPTION: software_error("predicate `array.map_corresponding_foldl\'/6: Unexpected: mismatched array sizes")
|
|
FINISHED TESTING: map_corresponding_foldl (mismatch)
|
|
|