#!/usr/bin/perl -w

use Test;
use strict;

BEGIN
  {
  unshift @INC, '../..';
  plan tests => 12;
  }

use CoW::Size;
use CoW::Thing;

my $coord_w = new CoW::Size ( rel => 'l', val => 0.5 );
my $coord_h = new CoW::Size ( rel => '', val => 12 );
my $one = new CoW::Thing ( w => $coord_w, l => 16, h => $coord_h );

# test stringify and absolute of coord

ok ( "$coord_w", "8" );
ok ( "$coord_h", "12" );
ok ( "$one->{w}", "8" );
ok ( "$one->{h}", "12" );

# test wether storing coordinates makes copy of them
# instead of modifying orginal)
my $p1 = $one->{w}->{_parent};
my $two = new CoW::Thing ( z => $coord_w );
ok ($p1, $one->{w}->{_parent});

# test wether resizing thing makes the coords follow

$one->{l} = 32;
ok ( "$one->{w}", $one->{l} / 2 );

# check that scaling still holds this:

$one->scale(1,2,1);			# scale l by 2
ok ( "$one->{w}", $one->{l} / 2 );

$one->scale(2,1,1);			# scale w by 2 (making it == l)
ok ( "$one->{w}", $one->{l} );

# check min/max
my $c = new CoW::Size ( min => 0, max => 0, val => 0, rel => '' );

ok ($c->absolute(),0);
$c->{val} = 1;
ok ($c->absolute(),0);
$c->{max} = 10;
ok ($c->absolute(),1);
$c->{min} = -10;
$c->{val} = -1;
ok ($c->absolute(),-1);
