mageekguy\atoum\asserters\phpFloat: lines coverage

87% of 183

OPs

88% of 26

Lines

75% of 28

Branches

14% of 28

Paths
Method OPs OPs % Lines Line % Branches Branches % Paths Path %
mageekguy\atoum\asserters\phpFloat::setWith() 41 100% 7 100% 5 80% 2 50%
mageekguy\atoum\asserters\phpFloat::isNearlyEqualTo() 130 82% 18 83% 22 73% 25 8%
mageekguy\atoum\asserters\phpFloat::isZero() 12 100% 1 100% 1 100% 1 100%
#
1
<?php
2

                    
3
namespace mageekguy\atoum\asserters;
4

                    
5
use
6
	mageekguy\atoum\asserters,
7
	mageekguy\atoum\exceptions,
8
	mageekguy\atoum\tools\diffs
9
;
10

                    
11
class phpFloat extends asserters\integer
12
{
13
	public function setWith($value)100%
14
	{
15
		variable::setWith($value);
16

                    
17
		if ($this->analyzer->isFloat($this->value) === true)
18
		{
19
			$this->pass();
20
		}
21
		else
22
		{
23
			$this->fail($this->_('%s is not a float', $this));
24
		}
25

                    
26
		return $this;
27
	}
28

                    
29
	public function isNearlyEqualTo($value, $epsilon = null, $failMessage = null)83%
30
	{
31
		if ($this->valueIsSet()->value !== $value)
32
		{
33
			// see http://www.floating-point-gui.de/errors/comparison/ for more informations
34
			$absValue = abs($value);
35
			$absCurrentValue = abs($this->value);
36
			$offset = abs($absCurrentValue - $absValue);
37
			$offsetIsNaN = is_nan($offset);
38

                    
39
			if ($offsetIsNaN === false && $epsilon === null)
40
			{
41
				$epsilon = pow(10, - ini_get('precision'));
42
			}
43

                    
44
			switch (true)
45
			{
46
				case $offsetIsNaN === true:
47
				case $offset / ($absCurrentValue + $absValue) >= $epsilon:
48
				case $absCurrentValue * $absValue == 0 && $offset >= pow($epsilon, 2):
49
					$this->fail(($failMessage ?: $this->_('%s is not nearly equal to %s with epsilon %s', $this, $this->getTypeOf($value), $epsilon)) . PHP_EOL . $this->diff($value));
50
			}
51
		}
52

                    
53
		return $this;
54
	}
55

                    
56
	public function isZero($failMessage = null)100%
57
	{
58
		return $this->isEqualTo(0.0, $failMessage);
59
	}
60
}