From: Vincent Pit Date: Wed, 21 Jul 2010 10:36:58 +0000 (+0200) Subject: Test geometrical sets X-Git-Tag: v0.01~31 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FLaTeX-TikZ.git;a=commitdiff_plain;h=d6ce9bd1690e1ed3ceb9beb90380c94a4efa6e54 Test geometrical sets --- diff --git a/MANIFEST b/MANIFEST index 5a07244..8cda4e2 100644 --- a/MANIFEST +++ b/MANIFEST @@ -35,6 +35,7 @@ t/00-load.t t/01-api.t t/10-set.t t/11-point.t +t/12-geo.t t/20-mod.t t/21-layer.t t/22-clip.t diff --git a/t/12-geo.t b/t/12-geo.t new file mode 100644 index 0000000..ab56eaa --- /dev/null +++ b/t/12-geo.t @@ -0,0 +1,138 @@ +#!perl -T + +use strict; +use warnings; + +use Test::More tests => 11 + 2 * 10; + +use Math::Complex; + +use LaTeX::TikZ; + +my $tikz = Tikz->formatter( + format => '%d', +); + +sub check { + my ($set, $desc, $exp) = @_; + + local $Test::Builder::Level = $Test::Builder::Level + 1; + + my ($head, $decl, $body) = eval { + $tikz->render(ref $set eq 'ARRAY' ? @$set : $set); + }; + is $@, '', "$desc: no error"; + + unless (ref $exp eq 'ARRAY') { + $exp = [ split /\n/, $exp ]; + } + unshift @$exp, '\begin{tikzpicture}'; + push @$exp, '\end{tikzpicture}'; + + is_deeply $body, $exp, $desc; +} + +my $o = Tikz->point(0); +my $z = Tikz->point(1+2*i); + +# Line + +my $l = eval { + Tikz->line($o => $z); +}; +is $@, '', 'creating a line from two TikZ points doesn\'t croak'; + +check $l, 'a line from two Tikz points', <<'RES'; +\draw (0cm,0cm) -- (1cm,2cm) ; +RES + +$l = eval { + Tikz->line([-1,2] => 3-4*i); +}; +is $@, '', 'creating a line from constants doesn\'t croak'; + +check $l, 'a line from two Tikz points', <<'RES'; +\draw (-1cm,2cm) -- (3cm,-4cm) ; +RES + +# Rectangle + +my $r = eval { + Tikz->rectangle($o => $z); +}; +is $@, '', 'creating a rectangle from two TikZ points doesn\'t croak'; + +check $r, 'a rectangle from two Tikz points', <<'RES'; +\draw (0cm,0cm) rectangle (1cm,2cm) ; +RES + +$r = eval { + Tikz->rectangle([-1,2] => 3-4*i); +}; +is $@, '', 'creating a rectangle from constants doesn\'t croak'; + +check $r, 'a rectangle from two Tikz points', <<'RES'; +\draw (-1cm,2cm) rectangle (3cm,-4cm) ; +RES + +$r = eval { + Tikz->rectangle($z => -3); +}; +is $@, '', 'creating a rectangle from a TikZ point and a constant doesn\'t croak'; + +check $r, 'a rectangle from a TikZ point and a constant', <<'RES'; +\draw (1cm,2cm) rectangle (-3cm,0cm) ; +RES + +$r = eval { + Tikz->rectangle($o => { width => 3, height => -4 }); +}; +is $@, '', 'creating a rectangle from a TikZ point and width/height doesn\'t croak'; + +check $r, 'a rectangle from a TikZ point and width/height', <<'RES'; +\draw (0cm,0cm) rectangle (3cm,-4cm) ; +RES + +$r = eval { + Tikz->rectangle((-1+2*i) => { width => 3, height => -4 }); +}; +is $@, '', 'creating a rectangle from a constant and width/height doesn\'t croak'; + +check $r, 'a rectangle from a constant and width/height', <<'RES'; +\draw (-1cm,2cm) rectangle (2cm,-2cm) ; +RES + +# Circle + +my $c = eval { + Tikz->circle($z => 3); +}; +is $@, '', 'creating a circle from a TikZ point and a constant doesn\'t croak'; + +check $c, 'a circle from a Tikz point and a constant', <<'RES'; +\draw (1cm,2cm) circle (3cm) ; +RES + +$c = eval { + Tikz->circle([-1,2] => 3); +}; +is $@, '', 'creating a circle from an array ref and a constant doesn\'t croak'; + +check $c, 'a circle from an array ref and a constant', <<'RES'; +\draw (-1cm,2cm) circle (3cm) ; +RES + +$c = eval { + Tikz->circle((4-5*i) => 3); +}; +is $@, '', 'creating a circle from a complex and a constant doesn\'t croak'; + +check $c, 'a circle from a complex and a constant', <<'RES'; +\draw (4cm,-5cm) circle (3cm) ; +RES + +eval { + Tikz->circle($o => -1); +}; +like $@, qr/isn't a non-negative real number/, + 'creating a circle with a negative radius croaks';