Music-NeoRiemannianTonnetz
view release on metacpan or search on metacpan
t/Music-NeoRiemannianTonnetz.t view on Meta::CPAN
#!perl
use strict;
use warnings;
use Test::More; # plan is down at bottom
use Test::Exception;
eval 'use Test::Differences'; # display convenience
my $deeply = $@ ? \&is_deeply : \&eq_or_diff;
BEGIN { use_ok('Music::NeoRiemannianTonnetz') }
my $Nrt = Music::NeoRiemannianTonnetz->new;
isa_ok( $Nrt, 'Music::NeoRiemannianTonnetz' );
taskify_tokens();
techno();
transform_3_11();
transform_4_27();
sub taskify_tokens {
my $tasks = $Nrt->taskify_tokens('P');
is( scalar @$tasks, 1, 'single step task count' );
ok( ref $tasks->[0][1] eq 'CODE', 'task is code ref' );
$tasks = $Nrt->taskify_tokens('N'); # should expand to RLP
is( scalar @$tasks, 3, 'three step task count' );
is( scalar( grep { ref $_->[1] eq 'CODE' ? 1 : () } @$tasks ),
3, 'three little code refs' );
}
sub techno {
my @techno = (qw/tonn tz/) x 8;
my @even_more_techno = (qw/tonn tz/) x 32;
$deeply->( [ $Nrt->techno ], \@techno, 'tonn tz' );
$deeply->( [ $Nrt->techno(4) ], \@even_more_techno, 'even more tonn tz' );
}
sub transform_3_11 {
# flip minor|major traids
my $pset = $Nrt->transform( 'P', [ 60, 63, 67 ] );
$deeply->( $pset, [ 60, 64, 67 ], 'P - minor triad to major' );
$pset = $Nrt->transform( 'P', $pset );
$deeply->( $pset, [ 60, 63, 67 ], 'P - major triad to minor' );
# should be a no-op, repeated P just toggle the 3rd back and forth
$deeply->(
$Nrt->transform( 'PPPP', [ 57, 60, 64 ] ),
[ 57, 60, 64 ],
'PPPP toggle'
);
# unsupported pitch set (for now)
dies_ok( sub { $Nrt->transform( 'P', [ 0, 1, 2 ] ) } );
$deeply->(
$Nrt->transform( 'R', [ 57, 60, 64 ] ),
[ 55, 60, 64 ],
'R - A minor to C major'
);
$deeply->(
$Nrt->transform( 'R', [ 60, 64, 67 ] ),
[ 60, 64, 69 ],
'R - C major to A minor'
);
$deeply->(
( run in 0.958 second using v1.01-cache-2.11-cpan-007c89162af )