From 4dfee69397e5f016f77b040442ebcad41ed816e0 Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Sun, 21 May 2017 15:36:20 +0200 Subject: [PATCH] Add tests for empty Set(|Hash).pick handling --- S02-types/set.t | 18 +++++++++++++++++- S02-types/sethash.t | 18 +++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/S02-types/set.t b/S02-types/set.t index cd4a58f52e..1334f0e9d5 100644 --- a/S02-types/set.t +++ b/S02-types/set.t @@ -1,7 +1,7 @@ use v6; use Test; -plan 189; +plan 197; sub showset($s) { $s.keys.sort.join(' ') } @@ -283,6 +283,22 @@ dies-ok { set(1, 2) «+» set(3, 4) }, 'Set «+» Set is illegal'; is $s.total, 3, '.pick should not change Set'; } +# empty set handling of .pick +{ + is-deeply set().pick, Nil, 'empty set.pick -> Nil'; + for + 1, '1', + *-1, '*-1', + *, '*', + Inf, 'Inf', + -1, '-1', + -Inf, '-Inf' + -> $p, $t { + is-deeply set().pick($p), ().Seq, "empty set.rpick($t) -> ().Seq" + } + dies-ok { set().pick(NaN) }, 'empty set.pick(NaN) should die'; +} + # L { diff --git a/S02-types/sethash.t b/S02-types/sethash.t index ac5ad66b01..44a68314b0 100644 --- a/S02-types/sethash.t +++ b/S02-types/sethash.t @@ -1,7 +1,7 @@ use v6; use Test; -plan 229; +plan 237; # L @@ -296,6 +296,22 @@ sub showset($s) { $s.keys.sort.join(' ') } is $s.elems, 3, '.pick should not change the SetHash'; } +# empty SetHash handling of .pick +{ + is-deeply ().SetHash.pick, Nil, '().SetHash.pick -> Nil'; + for + 1, '1', + *-1, '*-1', + *, '*', + Inf, 'Inf', + -1, '-1', + -Inf, '-Inf' + -> $p, $t { + is-deeply ().SetHash.pick($p), ().Seq, "().SetHash.pick($t) -> ().Seq" + } + dies-ok { ().SetHash.pick(NaN) }, '().SetHash.pick(NaN) should die'; +} + # L {