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

DataOHLCVSimpleUnsortedTest::simpleData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 17
nc 1
nop 0
dl 0
loc 19
rs 9.7
c 0
b 0
f 0
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 DataOHLCVSimpleUnsortedTest extends TestCase
15
{
16
    /** @var DataOHLCV */
17
    protected $ohlcv;
18
19
    /**
20
     * @test
21
     */
22
    public function simpleDataCheck(): void
23
    {
24
        $this->ohlcv = new DataOHLCV('btc_usd', 500);
25
26
        $this->expectException(\RuntimeException::class);
27
        foreach ($this->simpleData() as $item) {
28
            [$timestamp, $type, $price, $amount] = $item;
29
            $this->ohlcv->addTrade($timestamp, $type, $price, $amount);
30
        }
31
    }
32
33
    public function simpleData(): array
34
    {
35
        return [
36
            [1512570380, 'bid', 12820.7, 0.0538594],
37
            [1512578380, 'bid', 12810.2, 0.0223277],
38
            [1512571380, 'bid', 12820.7, 0.00596801],
39
            [1512572380, 'bid', 12821.3, 0.19551],
40
            [1512573380, 'bid', 12807.6, 0.0464246],
41
            [1512574380, 'bid', 12793, 0.0538914],
42
            [1512575380, 'ask', 12792, 0.0475634],
43
            [1512576380, 'bid', 12793, 0.0499],
44
            [1512577380, 'bid', 12810.2, 0.171179],
45
            [1512579380, 'bid', 12818.5, 0.00210018],
46
            [1512585380, 'ask', 12792, 0.0475634],
47
            [1512586380, 'bid', 12793, 0.0499],
48
            [1512587380, 'bid', 12810.2, 0.171179],
49
            [1512588380, 'bid', 12810.2, 0.0223277],
50
            [1512589380, 'bid', 12818.5, 0.00210018],
51
            [1513589380, 'bid', 12818.5, 0.00210018],
52
        ];
53
    }
54
    /**
55
     * @test
56
     */
57
    public function simpleDataTrimCheck(): void
58
    {
59
        $this->ohlcv = new DataOHLCV('btc_usd', 10);
60
61
        foreach ($this->simpleTrimData() as $item) {
62
            [$timestamp, $type, $price, $amount] = $item;
63
            $this->ohlcv->addTrade($timestamp, $type, $price, $amount);
64
        }
65
        $this->assertEquals(10, $this->ohlcv->getSize());
66
    }
67
68
    public function simpleTrimData(): \Generator
69
    {
70
        $n = 1000;
71
        $timestamp = 1512570380;
72
        for($i = 0; $i< $n; $i++) {
73
            yield [$timestamp, 'bid', 10000.0, 0.0001];
74
            $timestamp += 6400;
75
        }
76
    }
77
78
}