File: Catmandu-Fix-sum.t

package info (click to toggle)
libcatmandu-perl 1.2024-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,552 kB
  • sloc: perl: 17,037; makefile: 24; sh: 1
file content (32 lines) | stat: -rw-r--r-- 730 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env perl

use strict;
use warnings;
use Test::More;
use Test::Exception;

my $pkg;

BEGIN {
    $pkg = 'Catmandu::Fix::sum';
    use_ok $pkg;
}

require_ok $pkg;

lives_ok {$pkg->new('numbers')->fix({numbers => [1, 2]})};

is_deeply $pkg->new('numbers')->fix({numbers => [1, 2]}), {numbers => 3},
    "Simple sum ok";

# Fibonacci sequence now!
is_deeply $pkg->new('numbers')->fix({numbers => [1, 1, 2, 3, 5, 8, 13, 21]}),
    {numbers => 54}, "Fibbonaci sum ok";

is_deeply $pkg->new('numbers')->fix({numbers => [1.234, 4.653, 4.5]}),
    {numbers => 10.387}, "Float sum ok";

is_deeply $pkg->new('numbers')->fix({numbers => [1, 'hello']}),
    {numbers => [1, 'hello']}, "Members must all be numbers";

done_testing;