1#!/usr/bin/perl
2#
3# $Id: 01basic.t,v 1.1 2004/03/05 14:59:36 nik Exp $
4
5use strict;
6use warnings;
7use Test::More tests => 13;
8
9if(eval "require Test::Differences") {
10  no warnings 'redefine';
11  *is_deeply = \&Test::Differences::eq_or_diff;
12}
13
14BEGIN {
15  use_ok('List::PowerSet', qw(powerset powerset_lazy));
16}
17
18my $ps = powerset(qw(1 2 3));
19
20is(ref $ps, 'ARRAY', 'powerset() returned an array ref');
21is(scalar @$ps, 8, '  with the right number of elements');
22
23my $expected = [ [1, 2, 3], [2, 3], [1, 3], [3], [1, 2], [2], [1], [] ];
24
25is_deeply($ps, $expected, '  and they\'re the expected elements');
26
27$ps = powerset_lazy(1..3);
28
29is(ref $ps, 'CODE', 'powerset_lazy() returned a code ref');
30
31# Make sure that the results from powerset_lazy() match up with the
32# expected results
33my $i = 0;
34while(my $set = $ps->()) {
35  is_deeply($set, $expected->[$i], "  element $i matches");
36  $i++;
37}
38