Passed
Push — master ( 62401f...daf94f )
by Alec
07:24
created

DataOHLCVSimpleTest::simpleDataProvider()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 123
Code Lines 93

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 93
nc 1
nop 0
dl 0
loc 123
rs 8.1527
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * User: alec
4
 * Date: 31.10.18
5
 * Time: 16:33
6
 */
7
8
namespace Unit;
9
10
11
use AlecRabbit\DataOHLCV;
12
use PHPUnit\Framework\TestCase;
13
14
class DataOHLCVSimpleTest extends TestCase
15
{
16
    /** @var DataOHLCV */
17
    protected $ohlcv;
18
19
    public function setUp()
20
    {
21
        $this->ohlcv = new DataOHLCV('btc_usd', 500);
22
        foreach ($this->simpleData() as $item) {
23
            [$timestamp, $type, $price, $amount] = $item;
24
            $this->ohlcv->addTrade($timestamp, $type, $price, $amount);
25
        }
26
    }
27
28
    public function simpleData(): array
29
    {
30
        return [
31
            [1512570380, 'bid', 12820.7, 0.0538594],
32
            [1512571380, 'bid', 12820.7, 0.00596801],
33
            [1512572380, 'bid', 12821.3, 0.19551],
34
            [1512573380, 'bid', 12807.6, 0.0464246],
35
            [1512574380, 'bid', 12793, 0.0538914],
36
            [1512575380, 'ask', 12792, 0.0475634],
37
            [1512576380, 'bid', 12793, 0.0499],
38
            [1512577380, 'bid', 12810.2, 0.171179],
39
            [1512578380, 'bid', 12810.2, 0.0223277],
40
            [1512579380, 'bid', 12818.5, 0.00210018],
41
            [1512585380, 'ask', 12792, 0.0475634],
42
            [1512586380, 'bid', 12793, 0.0499],
43
            [1512587380, 'bid', 12810.2, 0.171179],
44
            [1512588380, 'bid', 12810.2, 0.0223277],
45
            [1512589380, 'bid', 12818.5, 0.00210018],
46
            [1513589380, 'bid', 12818.5, 0.00210018],
47
        ];
48
    }
49
50
    /**
51
     * @test
52
     * @dataProvider simpleDataProvider
53
     * @param $expected
54
     * @param $resolution
55
     */
56
    public function simpleDataCheck($expected, $resolution): void
57
    {
58
        $this->assertEquals($expected, $this->ohlcv->getTimestamps($resolution));
59
    }
60
61
    public function simpleDataProvider():array
62
    {
63
        return [
64
            [
65
                [
66
                    1512570360,
67
                    1512571380,
68
                    1512572340,
69
                    1512573360,
70
                    1512574380,
71
                    1512575340,
72
                    1512576360,
73
                    1512577380,
74
                    1512578340,
75
                    1512579360,
76
                    1512585360,
77
                    1512586380,
78
                    1512587340,
79
                    1512588360,
80
                    1512589380,
81
                ],
82
                RESOLUTION_01min
83
            ],
84
            [
85
                [
86
                    1512570240,
87
                    1512571320,
88
                    1512572220,
89
                    1512573300,
90
                    1512574380,
91
                    1512575280,
92
                    1512576360,
93
                    1512577260,
94
                    1512578340,
95
                    1512579240,
96
                    1512585360,
97
                    1512586260,
98
                    1512587340,
99
                    1512588240,
100
                    1512589320,
101
                ],
102
                RESOLUTION_03min
103
            ],
104
            [
105
                [
106
                    1512570300,
107
                    1512571200,
108
                    1512572100,
109
                    1512573300,
110
                    1512574200,
111
                    1512575100,
112
                    1512576300,
113
                    1512577200,
114
                    1512578100,
115
                    1512579300,
116
                    1512585300,
117
                    1512586200,
118
                    1512587100,
119
                    1512588300,
120
                    1512589200,
121
                ],
122
                RESOLUTION_05min
123
            ],
124
            [
125
                [
126
                    1512569700,
127
                    1512570600,
128
                    1512571500,
129
                    1512573300,
130
                    1512574200,
131
                    1512575100,
132
                    1512576000,
133
                    1512576900,
134
                    1512577800,
135
                    1512578700,
136
                    1512585000,
137
                    1512585900,
138
                    1512586800,
139
                    1512587700,
140
                    1512588600,
141
                ],
142
                RESOLUTION_15min
143
            ],
144
            [
145
                [
146
                    1512568800,
147
                    1512570600,
148
                    1512572400,
149
                    1512574200,
150
                    1512576000,
151
                    1512577800,
152
                    1512585000,
153
                    1512586800,
154
                    1512588600,
155
                ],
156
                RESOLUTION_30min
157
            ],
158
            [
159
                [
160
                    1512569700,
161
                    1512572400,
162
                    1512575100,
163
                    1512577800,
164
                    1512583200,
165
                    1512585900,
166
                    1512588600,
167
                ],
168
                RESOLUTION_45min
169
            ],
170
            [
171
                [
172
                    1512568800,
173
                    1512572400,
174
                    1512576000,
175
                    1512583200,
176
                    1512586800,
177
                ],
178
                RESOLUTION_01hour
179
            ],
180
            [[1512568800, 1512576000,1512583200], RESOLUTION_02hour],
181
            [[1512561600, 1512572400,1512583200], RESOLUTION_03hour],
182
            [[1512561600,1512576000], RESOLUTION_04hour],
183
            [[1512518400], RESOLUTION_01day],
184
        ];
185
    }
186
187
188
}