File: 01-basic-operation.t

package info (click to toggle)
libcolor-spectrum-multi-perl 0.02-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid
  • size: 84 kB
  • sloc: perl: 72; makefile: 2
file content (48 lines) | stat: -rwxr-xr-x 1,424 bytes parent folder | download
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!perl -T

use strict;
use Color::Spectrum::Multi;
use Test::More;

# Tests to perform.  Each consists of a set of parameters to pass, and a list of
# colours we expect to receive.
my @tests = (
    [
        [ 5, '#FF0000', '#00FF00' ],
        [ split /\s+/, '#FF0000 #E85500 #AAAA00 #55E800 #00FF00' ],
    ],
    [
        [7, '#FF0000', '#00FF00', '#0000FF'],
        [ split /\s+/, '#FF0000 #AAAA00 #00FF00 #00E855 #00AAAA #0055E8 #0000FF' ],
    ],
);

# Declare the number of tests we expect to run.  For each set of test data, we
# will run a set of 4 tests, twice.
plan tests => ( 2 * 4 ) * @tests;


# For each test, call the module both ways, and check the result looks as we
# expect (overkill, but doesn't hurt):
for my $test (@tests) {
    # Do this test procedurally:
    my @result = Color::Spectrum::Multi::generate(@{ $test->[0] });
    _check_result(\@result, $test->[1]);

    # And now OO-style:
    my $spectrum = Color::Spectrum::Multi->new;
    @result = $spectrum->generate(@{ $test->[0] });
    _check_result(\@result, $test->[1]);
}


# Ensure the result of a test looks good.
sub _check_result {
    my ($result, $test_expects) = @_;
    ok(ref $result eq 'ARRAY', "Got an array from this test");
    ok(@$result > 2, "Array contains at least two colours");
    is(@$result, @$test_expects, "Correct number of colours");
    is_deeply($result, $test_expects, "Got the colours we expected");
}