Skip to content

Commit

Permalink
Export Slic3r::Test::_eq()
Browse files Browse the repository at this point in the history
  • Loading branch information
alranel committed Dec 21, 2012
1 parent 494a1a8 commit 701c98c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 5 additions & 1 deletion lib/Slic3r/Test.pm
Expand Up @@ -2,6 +2,10 @@ package Slic3r::Test;
use strict;
use warnings;

require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(_eq);

use IO::Scalar;
use Slic3r::Geometry qw(epsilon);

Expand Down Expand Up @@ -48,7 +52,7 @@ sub gcode {
return $gcode;
}

sub compare {
sub _eq {
my ($a, $b) = @_;
return abs($a - $b) < epsilon;
}
Expand Down
12 changes: 6 additions & 6 deletions t/retraction.t
Expand Up @@ -8,7 +8,7 @@ BEGIN {
}

use Slic3r;
use Slic3r::Test;
use Slic3r::Test qw(_eq);

my $config = Slic3r::Config->new_from_defaults;

Expand All @@ -32,21 +32,21 @@ my $test = sub {

if ($info->{dist_Z}) {
# lift move or lift + change layer
if (Slic3r::Test::compare($info->{dist_Z}, $conf->retract_lift->[$tool])
|| (Slic3r::Test::compare($info->{dist_Z}, $conf->layer_height + $conf->retract_lift->[$tool]) && $conf->retract_lift->[$tool] > 0)) {
if (_eq($info->{dist_Z}, $conf->retract_lift->[$tool])
|| (_eq($info->{dist_Z}, $conf->layer_height + $conf->retract_lift->[$tool]) && $conf->retract_lift->[$tool] > 0)) {
fail 'only lifting while retracted' if !$retracted[$tool] && !($conf->g0 && $info->{retracting});
$lifted = 1;
}
if ($info->{dist_Z} < 0) {
fail 'going down only after lifting' if !$lifted;
fail 'going down by the same amount of the lift'
if !Slic3r::Test::compare($info->{dist_Z}, -$conf->retract_lift->[$tool]);
if !_eq($info->{dist_Z}, -$conf->retract_lift->[$tool]);
$lifted = 0;
}
}
if ($info->{retracting}) {
fail 'retracted by the correct amount'
if !Slic3r::Test::compare(-$info->{dist_E}, $conf->retract_length->[$tool]);
if !_eq(-$info->{dist_E}, $conf->retract_length->[$tool]);
fail 'combining retraction and travel with G0'
if $cmd ne 'G0' && $conf->g0 && ($info->{dist_Z} || $info->{dist_XY});
$retracted[$tool] = 1;
Expand All @@ -59,7 +59,7 @@ my $test = sub {
$expected_amount = $conf->retract_length_toolchange->[$tool] + $conf->retract_restart_extra_toolchange->[$tool];
}
fail 'unretracted by the correct amount'
if !Slic3r::Test::compare($info->{dist_E}, $expected_amount);
if !_eq($info->{dist_E}, $expected_amount);
$retracted[$tool] = 0;
}
}
Expand Down

0 comments on commit 701c98c

Please sign in to comment.