Skip to content

Commit

Permalink
test: dicey-spec:random-from-array was flaky
Browse files Browse the repository at this point in the history
Becaus the last member in $dicey-spec:array-of-sequences
is an empty sequence which was sometimes
selected this lead to the comparison
`() = (1, 2, 3, 4,5,6)`
This will obviously evaluate to false().
Now array:fold-left is used to check each
sequence. Actually the sums of those sequences as `()=()` evaluates to
false as well.
  • Loading branch information
line-o committed Jan 24, 2023
1 parent bc7edda commit 8f8e520
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/test/dicey-spec.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ declare
%test:assertTrue
function dicey-spec:random-from-array () {
let $n := dicey:pick($dicey-spec:array-of-sequences, random-number-generator())?_item
return $n = $dicey-spec:array-of-sequences?*
let $sum-n := sum($n)
return array:fold-left(
$dicey-spec:array-of-sequences, false(),
function ($r, $s) { $r or $sum-n = sum($s) }
)
};

declare
Expand Down

0 comments on commit 8f8e520

Please sign in to comment.