forked from vinkla/hashids
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMathInterfaceTest.php
91 lines (80 loc) · 2.04 KB
/
MathInterfaceTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/*
* This file is part of Hashids.
*
* (c) Ivan Akimov <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Hashids\Tests;
use Hashids\Math\Bc;
use Hashids\Math\Gmp;
use PHPUnit\Framework\TestCase;
/**
* Test available MathInterface classes.
*
* @author Vincent Klaiber <[email protected]>
* @author Johnson Page <[email protected]>
*/
class MathInterfaceTest extends TestCase
{
public function mathProvider()
{
return [
[new Bc()],
[new Gmp()],
];
}
/**
* @dataProvider mathProvider
*/
public function testAdd($math)
{
$this->assertEquals($math->get(3), $math->add(1, 2));
}
/**
* @dataProvider mathProvider
*/
public function testMultiply($math)
{
$this->assertEquals($math->get(12), $math->multiply(2, 6));
}
/**
* @dataProvider mathProvider
*/
public function testDivide($math)
{
$this->assertEquals($math->get(2), $math->divide(4, 2));
}
/**
* @dataProvider mathProvider
*/
public function testGreaterThan($math)
{
$this->assertTrue($math->greaterThan('18446744073709551615', '9223372036854775807'));
$this->assertFalse($math->greaterThan('9223372036854775807', '18446744073709551615'));
$this->assertFalse($math->greaterThan('9223372036854775807', '9223372036854775807'));
}
/**
* @dataProvider mathProvider
*/
public function testMod($math)
{
$this->assertEquals($math->get(15), $math->mod('18446744073709551615', '100'));
}
/**
* @dataProvider mathProvider
*/
public function testIntval($math)
{
$this->assertSame(9223372036854775807, $math->intval('9223372036854775807'));
}
/**
* @dataProvider mathProvider
*/
public function testStrval($math)
{
$this->assertSame('18446744073709551615', $math->strval($math->add('0', '18446744073709551615')));
}
}