Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F1432676
IsCloseTo.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
IsCloseTo.php
View Options
<?php
namespace
Hamcrest\Number
;
/*
Copyright (c) 2009 hamcrest.org
*/
use
Hamcrest\Description
;
use
Hamcrest\TypeSafeMatcher
;
/**
* Is the value a number equal to a value within some range of
* acceptable error?
*/
class
IsCloseTo
extends
TypeSafeMatcher
{
private
$_value
;
private
$_delta
;
public
function
__construct
(
$value
,
$delta
)
{
parent
::
__construct
(
self
::
TYPE_NUMERIC
);
$this
->
_value
=
$value
;
$this
->
_delta
=
$delta
;
}
protected
function
matchesSafely
(
$item
)
{
return
$this
->
_actualDelta
(
$item
)
<=
0.0
;
}
protected
function
describeMismatchSafely
(
$item
,
Description
$mismatchDescription
)
{
$mismatchDescription
->
appendValue
(
$item
)
->
appendText
(
' differed by '
)
->
appendValue
(
$this
->
_actualDelta
(
$item
))
;
}
public
function
describeTo
(
Description
$description
)
{
$description
->
appendText
(
'a numeric value within '
)
->
appendValue
(
$this
->
_delta
)
->
appendText
(
' of '
)
->
appendValue
(
$this
->
_value
)
;
}
/**
* Matches if value is a number equal to $value within some range of
* acceptable error $delta.
*
* @factory
*/
public
static
function
closeTo
(
$value
,
$delta
)
{
return
new
self
(
$value
,
$delta
);
}
// -- Private Methods
private
function
_actualDelta
(
$item
)
{
return
(
abs
((
$item
-
$this
->
_value
))
-
$this
->
_delta
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, May 16, 22:10 (1 d, 4 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
bf/21/4a67a2c42ad51d13cb4941baa4c7
Default Alt Text
IsCloseTo.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment