Graph-Layout-Aesthetic
view release on metacpan or search on metacpan
t/05_GnuPlot.t view on Meta::CPAN
return;
}
sleep 1 if $now > $start+1;
}
pass(@_ ? shift : ());
}
my $topo = Graph::Layout::Aesthetic::Topology->new_vertices(4);
$topo->add_edge(0, 1);
$topo->add_edge(1, 2);
$topo->add_edge(2, 3);
$topo->add_edge(3, 0);
$topo->finish;
my $aglo = Graph::Layout::Aesthetic->new($topo);
$aglo->add_force("MinEdgeLength");
{
local @Graph::Layout::Aesthetic::Monitor::GnuPlot::gnu_plot = qw(/);
if ($^O ne "MSWin32") {
eval { Graph::Layout::Aesthetic::Monitor::GnuPlot->new };
like($@, qr!^Could not start /: !, "/ isn't executable");
}
(my $fh, my $tmp_name) = tempfile(UNLINK => 1);
open($tmp, "<", $tmp_name) || die "Could not open $tmp_name: $!";
@Graph::Layout::Aesthetic::Monitor::GnuPlot::gnu_plot =
($^X, "t/tofile.pl", $tmp_name);
$curpos = 0;
$have = "";
my $monitor = Graph::Layout::Aesthetic::Monitor::GnuPlot->new;
is($monitor->last_plot_time, undef, "No plots yet");
my $terminal = $^O eq "MSWin32" ? "windows" : "X11";
tail("set terminal $terminal
set data style linespoints
set offsets 0.1, 0.1, 0.1, 0.1
set nokey
set clip two
", "Proper initialization");
$aglo->all_coordinates([0, 0], [1, 1], [0, 1], [1, 0]);
$monitor->plot($aglo);
tail(qr!set xrange \[ -0.050* : 1.050* \]
set yrange \[ -0.050* : 1.050* \]
set title "Time=\d+\s+Temp=100.0*"
plot "-"
0 0
1 1
1 1
0 1
0 1
1 0
1 0
0 0
e
!, "Proper plot commands");
my $from = time;
$aglo->gloss(iterations => 1,
hold => 1,
monitor => $monitor,
monitor_delay => 0);
tail(qr!set xrange \[ -0.050* : 1.050* \]
set yrange \[ -0.050* : 1.050* \]
set title "Time=\d+\s+Temp=100.0*"
plot "-"
0 0
1 1
1 1
0 1
0 1
1 0
1 0
0 0
e
set xrange \[ -1.6056\d+ : 2.6056\d+ \]
set yrange \[ -1.6056\d+ : 2.6056\d+ \]
set title "Time=\d+ Temp=0.001"
plot "-"
2.414\d+ 1.414\d+
-1.414\d+ -0.414\d+
-1.414\d+ -0.414\d+
2.414\d+ -0.414\d+
2.414\d+ -0.414\d+
-1.414\d+ 1.414\d+
-1.414\d+ 1.414\d+
2.414\d+ 1.414\d+
e
!);
my $to = time;
my $last_time = $monitor->last_plot_time;
ok($from <= $last_time, "Time goes forward");
ok($to >= $last_time, "Time goes forward");
$monitor->command("foo");
$monitor->commandf("%s %d", "baz", 12.3);
$monitor->command_flush("bar");
tail("foo\nbaz 12\nbar\n");
$monitor = undef;
tail("quit\n");
my $plot_count = 0;
$monitor = Graph::Layout::Aesthetic::Monitor::GnuPlot->new
(after_plot => sub { $plot_count++ });
is($plot_count, 0);
$monitor->plot($aglo);
is($plot_count, 1);
$monitor->plot($aglo);
is($plot_count, 2);
$monitor = undef;
is($plot_count, 2);
( run in 0.645 second using v1.01-cache-2.11-cpan-71847e10f99 )