-
Notifications
You must be signed in to change notification settings - Fork 16
/
BigFloatTest.php
138 lines (120 loc) · 3.63 KB
/
BigFloatTest.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
namespace hpez\tests;
use hpez\bignum\BigFloat;
use PHPUnit\Framework\TestCase;
require_once __DIR__.'/../vendor/autoload.php';
class BigFloatTest extends TestCase
{
public function testAddWorks(): void
{
$bigFloat1 = new BigFloat('123456.111');
$bigFloat2 = new BigFloat('654321.22');
$this->assertEquals(
new BigFloat('777777.331'),
$bigFloat1->add($bigFloat2)
);
$bigFloat1 = new BigFloat('1378217817817842.121438218481312');
$bigFloat2 = new BigFloat('8139829181.42424124');
$this->assertEquals(
new BigFloat('1378225957647023.545679458481312'),
$bigFloat1->add($bigFloat2)
);
$bigFloat1 = new BigFloat('8139829181.42424124');
$bigFloat2 = new BigFloat('1378217817817842.121438218481312');
$this->assertEquals(
new BigFloat('1378225957647023.545679458481312'),
$bigFloat1->add($bigFloat2)
);
}
public function testAddDouble(): void
{
$bigFloat = new BigFloat('1.1');
$this->assertEquals(new BigFloat('1.2'), $bigFloat->add(0.1));
}
public function testSubWorks(): void
{
$bigFloat1 = new BigFloat('123456.111');
$bigFloat2 = new BigFloat('654321.22');
$this->assertEquals(
new BigFloat('530865.109'),
$bigFloat2->sub($bigFloat1)
);
}
public function testSubDouble(): void
{
$bigFloat = new BigFloat('1.2');
$this->assertEquals(new BigFloat('1.1'), $bigFloat->sub(0.1));
}
public function testSubWorks2(): void
{
$bigFloat1 = new BigFloat('9');
$bigFloat2 = new BigFloat('3.00001');
$this->assertEquals(
new BigFloat('5.99999'),
$bigFloat1->sub($bigFloat2)
);
}
public function testMultiplyWorks(): void
{
$bigFloat1 = new BigFloat('123456.111');
$bigFloat2 = new BigFloat('654321.22');
$this->assertEquals(
new BigFloat('80779953165.97542'),
$bigFloat1->multiply($bigFloat2)
);
}
public function testDivWorks(): void
{
$bigFloat1 = new BigFloat('123456.111');
$bigFloat2 = new BigFloat('654321.22');
$this->assertEquals(
new BigFloat('0.188678'),
$bigFloat1->div($bigFloat2)
);
}
public function testDivDouble(): void
{
$bigFloat = new BigFloat('10');
$this->assertEquals(new BigFloat('100.000000'), $bigFloat->div(0.1));
}
public function testAddWithLongerLengthResult(): void
{
$bigFloat = new BigFloat('9.0');
$this->assertEquals(new BigFloat('18.0'), $bigFloat->add(9));
}
public function testDivWorks2(): void
{
$bigFloat1 = new BigFloat('9');
$bigFloat2 = new BigFloat('3.00001');
$this->assertEquals(
new BigFloat('2.999990'),
$bigFloat1->div($bigFloat2)
);
}
public function testDivWorks3(): void
{
$bigFloat1 = new BigFloat('0.000552');
$bigFloat2 = new BigFloat('6.000184');
$this->assertEquals(
new BigFloat('0.000092'),
$bigFloat1->
div($bigFloat2)
);
}
public function testSqrt(): void
{
$bigFloat = new BigFloat('9');
$this->assertEquals(
new BigFloat('3.000000'),
$bigFloat->sqrt()
);
}
public function testSqrt2(): void
{
$bigFloat = new BigFloat('2');
$this->assertEquals(
new BigFloat('1.4142136'),
$bigFloat->sqrt(7)
);
}
}