### ----------------------------------------------------
### -- Physics::Measure
### -- Licenses: Artistic-2.0
### -- Authors: librasteve
### -- File: t/03-add.rakutest
### ----------------------------------------------------
#!/usr/bin/env raku
#t/03-add.t 
#TESTALL$ prove6 ./t      [from root]
use lib '../lib';
use Test;
plan 26;

use Physics::Measure :ALL;

my $units = Measure.unit-find('m');       #get Unit object to construct a Measure
my Length $d .=new(value => 1e4, :$units);
my Length $e .=new(value => 42,  :$units);

my $f = $d + ♎️'42 m';
ok $f.value == 10042,                                                           'add:M+S';

$f = $d + $e;
ok $f.value == 10042,                                                           'add:M+S';

my Length $a = ♎️ '23 m';
my Length $b = ♎️ '42 m';
my Length $c;
my Area $area;
my Dimensionless $r;
my Measure $m;

$c = $a + $b;
ok $c.value == 65,                                                              'add:M+S';
$c = $a + 17;
ok $c.value == 40,                                                              'add:M+R';
$c = 1.12 + $b;
ok $c.value == 43.12,                                                           'add:R+M';
$c = $a - $b;
ok $c.value == -19,                                                             'sub:M-M';
$c = $a - ♎️'1 m';
ok $c.value == 22,                                                              'sub:M-S';
$c = ♎️'1 m' - $a;
ok $c.value == -22,                                                             'sub:S-M';
$area = $a * $b;
ok $area.value == 966,                                                          'mul:M*M';
$area = ♎️'22 m' * $b;
ok $area.value == 924,                                                          'mul:S*M';
$c = $a * 2;
ok $c.value == 46,                                                              'mul:M*R';
$r = $a / $b;
ok $r == <23/42>,                                                               'div:M/M';
$c = $a / 37.0;
ok $c.value == <23/37>,                                                         'div:M/R';
is $c.units.name, 'm',                                                          'div:M/R';

my $id = Measure.unit-find( '1 / m' );
class iddy is Measure {}
$id.type-bind('iddy');
$m = 37.0 / $b;
ok $m.value == <37/42>,                                                         'div:R/M';
is $m.units.name, '1 / m',                                                        'div:R/M';
$c = - $b;
ok $c.value == -42,                                                             'neg:M';
is $c.units.name, 'm',                                                          'neg:M';
$m = $b.reciprocal;
ok $m.value == <1/42>,                                                          'inv:M';
is $m.units.name, '1 / m',                                                      'inv:M';
$c = $b.negate;
ok $c.value == -42,                                                             'neg:M';
is $c.units.name, 'm',                                                          'neg:M';
$a = ♎️ '4.3 m';
$b = ♎️ '42 m';
$c = - $a + $b;
ok $c.value == 37.7,                                                            '2op:M';
$c = - $a - $b;
ok $c.value == -46.3,                                                           '2op:M';
$c = - $a + - $b;
ok $c.value == -46.3,                                                           '2op:M';
$c = ( $a + $b ) * 30;
ok $c.value == 1389,                                                            '3op:M';

# done-testing;



