aboutsummaryrefslogtreecommitdiff
path: root/challenge-252/e-choroba/perl/ch-2.pl
blob: 321c4500cc8f2aa5853870672a677fa12fcc4be2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/perl
use warnings;
use strict;
use experimental qw( signatures );

sub unique_sum_zero($n) {
    return [(0) x ($n % 2), map { $_, -$_ } 1 .. $n / 2]
}

use Test::More tests => 7;
use List::Util qw{ sum uniq };

subtest "n=$_" => sub {
    plan tests => 3;
    my $output = unique_sum_zero($_);
    is scalar @$output, $_, 'length';
    my @u = uniq(@$output);
    is scalar @u, $_, 'uniq';
    is sum(@$output), 0, 'sum 0';
} for 1 .. 7;