您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
phpunit断言-assertInfinite
发布时间:2021-10-03 11:39:15编辑:雪饮阅读()
assertInfinite断言用来断言一个实际值是否是INF,若是INF则断言成功。
INF这个值,这个值在PHP中代表的是无穷大的意思,计算不当,或者计算值超过服务器的上限则计算结果就是INF。
INF也算是php的一个全局常量。
InfiniteTest.php:
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class InfiniteTest extends TestCase
{
public function testFailure(): void
{
$this->assertInfinite(1);
}
public function testSuccess(): void
{
//pow计算一个base的exp次方
//参数1为base,参数2为exp
$a=pow(9999,9999);
$this->assertInfinite($a);
}
public function testTwo(): void
{
$this->assertInfinite(INF);
}
}
use PHPUnit\Framework\TestCase;
final class InfiniteTest extends TestCase
{
public function testFailure(): void
{
$this->assertInfinite(1);
}
public function testSuccess(): void
{
//pow计算一个base的exp次方
//参数1为base,参数2为exp
$a=pow(9999,9999);
$this->assertInfinite($a);
}
public function testTwo(): void
{
$this->assertInfinite(INF);
}
}
运行结果如:
C:\Users\Administrator>D:\phpstudy_pro\Extensions\php\php7.4.3nts\php.exe C:\Users\Administrator\PhpstormProjects\untitled\vendor\phpunit\phpunit\phpunit -c C:\Users\Administrator\PhpstormProjects\untitled\organizing\phpunit.xml C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\InfiniteTest.php
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.
F.. 3 / 3 (100%)
Time: 00:00.008, Memory: 4.00 MB
There was 1 failure:
1) InfiniteTest::testFailure
Failed asserting that 1 is infinite.
C:\Users\Administrator\PhpstormProjects\untitled\organizing\tests\InfiniteTest.php:8
FAILURES!
Tests: 3, Assertions: 3, Failures: 1.
关键字词:phpunit,assertInfinite