File: test.pl

package info (click to toggle)
libmath-calculus-differentiate-perl 0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, lenny, squeeze, stretch, wheezy
  • size: 72 kB
  • ctags: 7
  • sloc: perl: 650; makefile: 41
file content (89 lines) | stat: -rw-r--r-- 1,898 bytes parent folder | download | duplicates (2)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'

#########################

use Test;
BEGIN { plan tests => 12 }
my $res;

## BASIC MODULE TESTS

# Check include of module works.
use Math::Calculus::Differentiate;
ok(1);

# Create object.
my $exp = Math::Calculus::Differentiate->new;
ok($exp);

# Add a variable.
$res = $exp->addVariable('x');
ok($res);


## REGRESSION TESTS

# d[x] = 1
$exp->setExpression('x');
$exp->differentiate('x');
$exp->simplify;
$res = $exp->getExpression;
ok($res eq '1');

# d[-x] = -1
$exp->setExpression('-x');
$exp->differentiate('x');
$exp->simplify;
$res = $exp->getExpression;
ok($res eq '-1');

# d[x^2 + 4*x + 5] = 2*x + 4
$exp->setExpression('x^2 + 4*x + 5');
$exp->differentiate('x');
$exp->simplify;
$res = $exp->getExpression;
ok($res eq '2*x + 4');

# d[sin(-2 * x)] = -2*cos(-2*x)
$exp->setExpression('sin(-2 * x)');
$exp->differentiate('x');
$exp->simplify;
$res = $exp->getExpression;
ok($res eq '-2*cos(-2*x)');

# d[asin(x)] = 1/(1 - x^2)^0.5
$exp->setExpression('asin(x)');
$exp->differentiate('x');
$exp->simplify;
$res = $exp->getExpression;
ok($res eq '1/(1 - x^2)^0.5');

# d[ln(x^2)] = (2*x)/x^2
$exp->setExpression('ln(x^2)');
$exp->differentiate('x');
$exp->simplify;
$res = $exp->getExpression;
ok($res eq '(2*x)/x^2');

# d[x^x] = exp(ln(x)*x)*(1 + ln(x))
$exp->setExpression('x^x');
$exp->differentiate('x');
$exp->simplify;
$res = $exp->getExpression;
ok($res eq 'exp(ln(x)*x)*(1 + ln(x))');

# d[x/x] = 0
$exp->setExpression('x/x');
$exp->differentiate('x');
$exp->simplify;
$res = $exp->getExpression;
ok($res eq '0');

# d[x - x] = 0
$exp->setExpression('x - x');
$exp->differentiate('x');
$exp->simplify;
$res = $exp->getExpression;
ok($res eq '0');