File: 22dumpers.t

package info (click to toggle)
libmath-symbolic-perl 0.613-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,268 kB
  • sloc: perl: 12,638; makefile: 9
file content (38 lines) | stat: -rw-r--r-- 844 bytes parent folder | download | duplicates (6)
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
#!perl
use strict;
use warnings;
use Carp qw/croak/;
use Test::More tests => 1+4*7;
BEGIN {
    use_ok('Math::Symbolic');
}
use Math::Symbolic qw/:all/;
use Math::Symbolic::Derivative qw/partial_derivative/;

if ($ENV{TEST_YAPP_PARSER}) {
	require Math::Symbolic::Parser::Yapp;
	$Math::Symbolic::Parser = Math::Symbolic::Parser::Yapp->new();
}


my @f = (
        q{-a+b*x},
        q{a+b*x+c*x^2},
        q{b+2*c*x},
        q{a+x+}.join('+', map {"x^$_"} 2..10),
        '1+'.join('+', map {"$_*x^".($_-1)} 2..10),
        q{sin(2*x)*cos(3*x)},
        q{2*cos(2*x)*cos(3*x)-3*sin(3*x)*sin(2*x)},
);

foreach (@f) {
    my $f = parse_from_string($_);
    my ($code) = $f->to_code();
    ok(defined $code);
    my ($sub) = $f->to_sub();
    ok(defined $sub);
    ok(ref($sub) eq 'CODE');

    ok($f->test_num_equiv($sub), "to_sub works");
}