mirror of
git://develop.git.wordpress.org/
synced 2025-01-17 12:58:25 +01:00
Tests: Add unit tests for wp_fuzzy_number_match()
.
Props pbearne, costdev, mukesh27, hellofromTonya, SergeyBiryukov. Fixes #54239. git-svn-id: https://develop.svn.wordpress.org/trunk@53321 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
6eeaa587e7
commit
4d7e8125ae
112
tests/phpunit/tests/functions/wpFuzzyNumberMatch.php
Normal file
112
tests/phpunit/tests/functions/wpFuzzyNumberMatch.php
Normal file
@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Test wp_fuzzy_number_match().
|
||||
*
|
||||
* @group functions.php
|
||||
* @covers ::wp_fuzzy_number_match
|
||||
*/
|
||||
class Tests_Functions_wpFuzzyNumberMatch extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* @dataProvider data_wp_fuzzy_number_match
|
||||
*
|
||||
* @ticket 54239
|
||||
*
|
||||
* @param int|float $expected The expected value.
|
||||
* @param int|float $actual The actual number.
|
||||
* @param int|float $precision The allowed variation.
|
||||
* @param bool $result Whether the numbers match within the specified precision.
|
||||
*/
|
||||
public function test_wp_fuzzy_number_match( $expected, $actual, $precision, $result ) {
|
||||
$this->assertSame( $result, wp_fuzzy_number_match( $expected, $actual, $precision ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider.
|
||||
*
|
||||
* @return array[] Test parameters {
|
||||
* @type int|float $expected The expected value.
|
||||
* @type int|float $actual The actual number.
|
||||
* @type int|float $precision The allowed variation.
|
||||
* @type bool $result Whether the numbers match within the specified precision.
|
||||
* }
|
||||
*/
|
||||
public function data_wp_fuzzy_number_match() {
|
||||
return array(
|
||||
'expected 1 int, actual 1 int' => array(
|
||||
'expected' => 1,
|
||||
'actual' => 1,
|
||||
'precision' => 1,
|
||||
'result' => true,
|
||||
),
|
||||
'expected 1 int, actual 2 int' => array(
|
||||
'expected' => 1,
|
||||
'actual' => 2,
|
||||
'precision' => 1,
|
||||
'result' => true,
|
||||
),
|
||||
'expected 1 int, actual 3 int' => array(
|
||||
'expected' => 1,
|
||||
'actual' => 3,
|
||||
'precision' => 1,
|
||||
'result' => false,
|
||||
),
|
||||
'expected 1 int, actual 1 string' => array(
|
||||
'expected' => 1,
|
||||
'actual' => '1',
|
||||
'precision' => 1,
|
||||
'result' => true,
|
||||
),
|
||||
'expected 1 int, actual 11 int, precision 10' => array(
|
||||
'expected' => 1,
|
||||
'actual' => 11,
|
||||
'precision' => 10,
|
||||
'result' => true,
|
||||
),
|
||||
'expected 1 int, actual 12 int, precision 10' => array(
|
||||
'expected' => 1,
|
||||
'actual' => 12,
|
||||
'precision' => 10,
|
||||
'result' => false,
|
||||
),
|
||||
'expected 1.234 float, actual 1 int' => array(
|
||||
'expected' => 1.234,
|
||||
'actual' => 1,
|
||||
'precision' => 1,
|
||||
'result' => true,
|
||||
),
|
||||
'expected 2.234 float, actual 2 int' => array(
|
||||
'expected' => 1.234,
|
||||
'actual' => 2,
|
||||
'precision' => 1,
|
||||
'result' => true,
|
||||
),
|
||||
'expected 1 int, actual 2.0001 float' => array(
|
||||
'expected' => 1,
|
||||
'actual' => 2.0001,
|
||||
'precision' => 1,
|
||||
'result' => false,
|
||||
),
|
||||
'expected 1 int, actual 3.23 float' => array(
|
||||
'expected' => 1,
|
||||
'actual' => 3.234,
|
||||
'precision' => 1,
|
||||
'result' => false,
|
||||
),
|
||||
'expected 1.2e1 float (12), actual 1.3e1 float (13)' => array(
|
||||
'expected' => 1.2e1,
|
||||
'actual' => 1.3e1,
|
||||
'precision' => 1,
|
||||
'result' => true,
|
||||
),
|
||||
'expected 1.2e3 float (1200), actual 1.2e3 float, precision 1000' => array(
|
||||
'expected' => 1.2e3,
|
||||
'actual' => 1.2e3,
|
||||
'precision' => 1000,
|
||||
'result' => true,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user