MachineFloatingPointTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 26
c 1
b 0
f 1
dl 0
loc 53
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A provider() 0 23 1
A testWriteRead() 0 18 3
1
<?php
2
3
namespace SPSS\Tests;
4
5
use SPSS\Buffer;
6
use SPSS\Sav\Record\Info\MachineFloatingPoint;
7
8
class MachineFloatingPointTest extends TestCase
9
{
10
    public function provider()
11
    {
12
        return [
13
            [
14
                [
15
                    'sysmis' => -1,
16
                    'highest' => 5,
17
                    'lowest' => -10,
18
                ],
19
                [
20
                    'sysmis' => -1,
21
                    'highest' => 5,
22
                    'lowest' => -10,
23
                ],
24
            ],
25
            [
26
                [],
27
                // -1.7976931348623E+308 php min double
28
                //  1.7976931348623E+308 php max double
29
                [
30
                    'sysmis' => -1.7976931348623158E+308,
31
                    'highest' => 1.7976931348623158E+308,
32
                    'lowest' => -1.7976931348623158E+308,
33
                ],
34
            ],
35
        ];
36
    }
37
38
    /**
39
     * @dataProvider provider
40
     * @param array $attributes
41
     * @param array $expected
42
     */
43
    public function testWriteRead(array $attributes, array $expected)
44
    {
45
        $subject = new MachineFloatingPoint();
46
        foreach ($attributes as $key => $value) {
47
            $subject->{$key} = $value;
48
        }
49
        $buffer = Buffer::factory('', ['memory' => true]);
50
        $this->assertEquals(0, $buffer->position());
51
        $subject->write($buffer);
52
        $buffer->rewind();
53
        $buffer->skip(8);
54
        $read = MachineFloatingPoint::fill($buffer);
55
        $this->assertEquals(40, $buffer->position());
56
        foreach ($expected as $key => $value) {
57
            $expected = 0;
58
            $actual = bcsub($value, $read->{$key});
59
            $msg = "Wrong value received for '$key', expected '$value', got '{$read->{$key}}'";
60
            $this->assertEquals($expected, $actual, $msg);
61
        }
62
    }
63
}
64