1#! perl 2use strict; 3use Test; 4BEGIN { plan tests => 16 } 5 6use Math::SimpleVariable; 7 8### construct some variables using a multitude of constructions 9my $x1; 10eval { $x1 = new Math::SimpleVariable(name => 'x1') }; 11ok(length($@) == 0); # 1 12ok($x1->name(),'x1'); # 2 13ok(!defined($x1->value())); # 3 14 15my $x2; 16eval { $x2 = new Math::SimpleVariable($x1) }; 17ok(length($@) == 0); # 4 18$x2->{name} = 'x2'; 19$x2->{value} = 3.1415; 20ok($x2->name(),'x2'); # 5 21ok($x2->value(), 3.1415); # 6 22 23my $x3; 24eval { $x3 = new Math::SimpleVariable({name => 'x3', value => -1.0}) }; 25ok(length($@) == 0); # 7 26ok($x3->name(),'x3'); # 8 27ok($x3->value(), -1.0); # 9 28 29my $x_bad; 30eval { $x_bad = new Math::SimpleVariable(value => 9.9) }; # no name => fatal error 31ok(length($@) > 0); # 10 32 33my $x3_clone; 34eval { $x3_clone = $x3->clone() }; 35ok(length($@) == 0); # 11 36ok($x3_clone->name(), $x3->name()); # 12 37ok($x3_clone->value(), $x3->value()); # 13 38 39### run some additional checks on the created variables 40ok($x3->id(),'x3'); # 14 41ok($x3->evaluate(), -1.0); # 15 42ok($x3->stringify(), 'x3'); # 16 43 44