| 1 | package UnitConverter; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use unit; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 111 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||
| 9 | 111 | my ( $class, $scale, $offset, $inverse ) = @_; | |||||||||||||||||||||||||||||||
| 10 | 111 | ▶ | $class = ref($class) || $class; | ||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||
| 11 | 111 | my $this = {}; | |||||||||||||||||||||||||||||||
| 12 | 111 | bless($this, $class); | |||||||||||||||||||||||||||||||
| 13 | 111 | $this->{SCALE} = $scale; | |||||||||||||||||||||||||||||||
| 14 | 111 | ▶ | $this->{OFFSET} = $offset ||= 0.; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$offset ||= 0
MC/DC100%1/1
$offset ||= 0
$offset
Truth table100%2/2
A
A= $offset
| |||||||||||||||||||||||||||||||||
| 15 | 111 | ▶ | $this->{INVERSE} = $inverse | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$scale == 1 and $offset == 0
MC/DC100%2/2
$scale == 1 and $offset == 0
$scale == 1
$offset == 0
Truth table100%3/3
A and B
A= $scale == 1B= $offset == 0
| |||||||||||||||||||||||||||||||||
| 16 | ? $inverse | ||||||||||||||||||||||||||||||||
| 17 | : ($scale == 1.000000000000000000 && $offset == 0.000000000000000000) | ||||||||||||||||||||||||||||||||
| 18 | ? $this # si on détecte l'identité, elle est son propre inverse | ||||||||||||||||||||||||||||||||
| 19 | : UnitConverter->new(1. / $scale, -$offset / $scale, $this); | ||||||||||||||||||||||||||||||||
| 20 | 111 | return $this; | |||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 144 | ▶ | sub scale { | ||||||||||||||||||||||||||||||
|
Subroutine
scale: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 24 | 144 | my $this = shift; | |||||||||||||||||||||||||||||||
| 25 | 144 | return $this->{SCALE}; | |||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | 113 | ▶ | sub offset { | ||||||||||||||||||||||||||||||
|
Subroutine
offset: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 29 | 113 | my $this = shift; | |||||||||||||||||||||||||||||||
| 30 | 113 | return $this->{OFFSET}; | |||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 15 | ▶ | sub inverse { | ||||||||||||||||||||||||||||||
|
Subroutine
inverse: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 34 | 15 | my $this = shift; | |||||||||||||||||||||||||||||||
| 35 | 15 | return $this->{INVERSE}; | |||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub linear { | ||||||||||||||||||||||||||||||
|
Subroutine
linear: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 39 | 0 | my $this = shift; | |||||||||||||||||||||||||||||||
| 40 | # comparaison volontaire avec un double | ||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if ($this->offset == 0.000000000000000000) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 42 | 0 | return $this; | |||||||||||||||||||||||||||||||
| 43 | } else { | ||||||||||||||||||||||||||||||||
| 44 | 0 | return UnitConverter->new($this->scale); | |||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 18 | ▶ | sub linearPow { | ||||||||||||||||||||||||||||||
|
Subroutine
linearPow: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 49 | 18 | my ( $this, $pow ) = @_; | |||||||||||||||||||||||||||||||
| 50 | # comparaison volontaire avec des doubles | ||||||||||||||||||||||||||||||||
| 51 | 18 | ▶ | if ($this->offset == 0.00000000000000000 and $pow == 1.00000000000000000) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$this->offset == 0 and $pow == 1
MC/DC100%2/2
$this->offset == 0 and $pow == 1
$this->offset == 0
$pow == 1
Truth table100%3/3
A and B
A= $this->offset == 0B= $pow == 1
| |||||||||||||||||||||||||||||||||
| 52 | 7 | return $this; | |||||||||||||||||||||||||||||||
| 53 | } else { | ||||||||||||||||||||||||||||||||
| 54 | 11 | return UnitConverter->new($this->scale ** $pow); | |||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | 54 | ▶ | sub convert { | ||||||||||||||||||||||||||||||
|
Subroutine
convert: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 59 | 54 | my ( $this, $value ) = @_; | |||||||||||||||||||||||||||||||
| 60 | 54 | return $value * $this->scale + $this->offset; | |||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | 39 | ▶ | sub concatenate { | ||||||||||||||||||||||||||||||
|
Subroutine
concatenate: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 64 | 39 | my ( $this, $converter ) = @_; | |||||||||||||||||||||||||||||||
| 65 | 39 | return UnitConverter->new($converter->scale * $this->scale, $this->convert($converter->offset)); | |||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | # static | ||||||||||||||||||||||||||||||||
| 69 | 12 | ▶ | sub newLinear { | ||||||||||||||||||||||||||||||
|
Subroutine
newLinear: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 70 | 12 | my ( $class, $scale ) = @_; | |||||||||||||||||||||||||||||||
| 71 | 12 | return UnitConverter->new($scale, 0.); | |||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | # static | ||||||||||||||||||||||||||||||||
| 75 | 1 | ▶ | sub newTranslation { | ||||||||||||||||||||||||||||||
|
Subroutine
newTranslation: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 76 | 1 | my ( $class, $offset ) = @_; | |||||||||||||||||||||||||||||||
| 77 | 1 | return UnitConverter->new(1., $offset); | |||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | # static | ||||||||||||||||||||||||||||||||
| 81 | 1 | my $identity = UnitConverter->newLinear(1.0); | |||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | # static | ||||||||||||||||||||||||||||||||
| 84 | 32 | ▶ | sub identity { | ||||||||||||||||||||||||||||||
|
Subroutine
identity: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 85 | 32 | return $identity; | |||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | UnitConverter - representation of an unit converter | ||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | This module maps a conceptual class that represents an unit converter. | ||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | Samuel Andres | ||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | =head1 LICENSE | ||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | UnLicense | ||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | =cut | ||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | 1 | 1; | |||||||||||||||||||||||||||||||