1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* User: alec |
4
|
|
|
* Date: 12.11.18 |
5
|
|
|
* Time: 16:17 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Tests\Unit\Helpers; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
|
13
|
|
|
class HelpersTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @test |
17
|
|
|
* @dataProvider cAvgDataProvider |
18
|
|
|
* @param $expected |
19
|
|
|
* @param $first |
20
|
|
|
* @param $second |
21
|
|
|
*/ |
22
|
|
|
public function FunctionCAvg($expected, $first, $second): void |
23
|
|
|
{ |
24
|
|
|
$this->assertEquals($expected, c_avg($first, $second)); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function cAvgDataProvider(): array |
28
|
|
|
{ |
29
|
|
|
return [ |
30
|
|
|
// [$expected, $first, $second], |
31
|
|
|
[1, 1, 1], |
32
|
|
|
[0.1, 0.1, 0.1], |
33
|
|
|
[0.0001, 0.0001, 0.0001], |
34
|
|
|
[0.00000001, 0.00000001, 0.00000001], |
35
|
|
|
[2, 4, 0], |
36
|
|
|
]; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @test |
41
|
|
|
* @dataProvider cArrayDivDataProvider |
42
|
|
|
* @param $expected |
43
|
|
|
* @param $argument |
44
|
|
|
* @param $divider |
45
|
|
|
*/ |
46
|
|
|
public function FunctionCArrayDiv($expected, $argument, $divider): void |
47
|
|
|
{ |
48
|
|
|
$this->assertEquals($expected, c_array_div($argument, $divider)); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function cArrayDivDataProvider(): array |
52
|
|
|
{ |
53
|
|
|
return [ |
54
|
|
|
// [$expected, $argument, $divider], |
55
|
|
|
[[1], [1], 1], |
56
|
|
|
[[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6], 1], |
57
|
|
|
[[1, 2, 3, 4, 5, 6], [2, 4, 6, 8, 10, 12], 2], |
58
|
|
|
[[4, 8, 12, 16, 20, 24], [2, 4, 6, 8, 10, 12], 0.5], |
59
|
|
|
[[2], [4], 2], |
60
|
|
|
]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @test |
66
|
|
|
* @dataProvider cArrayAlignedSubDataProvider |
67
|
|
|
* @param $expected |
68
|
|
|
* @param $first |
69
|
|
|
* @param $second |
70
|
|
|
*/ |
71
|
|
|
public function FunctionCArrayAlignedSub($expected, $first, $second): void |
72
|
|
|
{ |
73
|
|
|
$this->assertEquals($expected, c_array_aligned_sub($first, $second)); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function cArrayAlignedSubDataProvider(): array |
77
|
|
|
{ |
78
|
|
|
return [ |
79
|
|
|
// [$expected, $first, $second], |
80
|
|
|
[[], [], []], |
81
|
|
|
[ |
82
|
|
|
[ |
83
|
|
|
30 => 3, |
84
|
|
|
40 => 3, |
85
|
|
|
50 => 3, |
86
|
|
|
60 => 3, |
87
|
|
|
], |
88
|
|
|
[ |
89
|
|
|
10 => 4, |
90
|
|
|
20 => 4, |
91
|
|
|
30 => 4, |
92
|
|
|
40 => 4, |
93
|
|
|
50 => 4, |
94
|
|
|
60 => 4, |
95
|
|
|
], |
96
|
|
|
[ |
97
|
|
|
30 => 1, |
98
|
|
|
40 => 1, |
99
|
|
|
50 => 1, |
100
|
|
|
60 => 1, |
101
|
|
|
70 => 1, |
102
|
|
|
80 => 1, |
103
|
|
|
] |
104
|
|
|
], |
105
|
|
|
]; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @test |
110
|
|
|
* @dataProvider heartbeatDataProvider |
111
|
|
|
* @param $expected |
112
|
|
|
*/ |
113
|
|
|
public function heartbeat($expected): void |
114
|
|
|
{ |
115
|
|
|
$this->assertEquals($expected, heartbeat()); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function heartbeatDataProvider(): array |
119
|
|
|
{ |
120
|
|
|
return [ |
121
|
|
|
// [$expected], |
122
|
|
|
[HEARTBEAT_0], |
123
|
|
|
[HEARTBEAT_1], |
124
|
|
|
[HEARTBEAT_2], |
125
|
|
|
[HEARTBEAT_3], |
126
|
|
|
[HEARTBEAT_0], |
127
|
|
|
[HEARTBEAT_1], |
128
|
|
|
[HEARTBEAT_2], |
129
|
|
|
[HEARTBEAT_3], |
130
|
|
|
[HEARTBEAT_0], |
131
|
|
|
[HEARTBEAT_1], |
132
|
|
|
[HEARTBEAT_2], |
133
|
|
|
[HEARTBEAT_3], |
134
|
|
|
]; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
} |