Completed
Push — master ( ac41f4...7a5cb9 )
by Hannes
02:54
created

BilinearInterpolationTest::testCenter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Runalyze DEM Reader.
5
 *
6
 * (c) RUNALYZE <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Runalyze\DEM\tests\Interpolation;
13
14
use Runalyze\DEM\Interpolation\BilinearInterpolation;
15
16
class BilinearInterpolationTest extends \PHPUnit_Framework_TestCase
17
{
18
    /** @var BilinearInterpolation */
19
    protected $Interpolation;
20
21
    public function setUp()
22
    {
23
        $this->Interpolation = new BilinearInterpolation();
24
    }
25
26
    public function testBoundaryPoints()
27
    {
28
        $boundingBox = [3, 42, 1337, 666];
29
30
        $this->assertEquals(3.0, $this->Interpolation->interpolate(0.0, 0.0, $boundingBox));
31
        $this->assertEquals(42.0, $this->Interpolation->interpolate(1.0, 0.0, $boundingBox));
32
        $this->assertEquals(1337.0, $this->Interpolation->interpolate(0.0, 1.0, $boundingBox));
33
        $this->assertEquals(666.0, $this->Interpolation->interpolate(1.0, 1.0, $boundingBox));
34
    }
35
36
    public function testPointsOnBoundaryLines()
37
    {
38
        $boundingBox = [10, 20, 30, 40];
39
40
        $this->assertEquals(15, $this->Interpolation->interpolate(0.5, 0.0, $boundingBox));
41
        $this->assertEquals(20, $this->Interpolation->interpolate(0.0, 0.5, $boundingBox));
42
        $this->assertEquals(30, $this->Interpolation->interpolate(1.0, 0.5, $boundingBox));
43
        $this->assertEquals(35, $this->Interpolation->interpolate(0.5, 1.0, $boundingBox));
44
    }
45
46
    public function testCenter()
47
    {
48
        $this->assertEquals(20, $this->Interpolation->interpolate(0.5, 0.5, [20, 20, 20, 20]));
49
        $this->assertEquals(15, $this->Interpolation->interpolate(0.5, 0.5, [10, 10, 20, 20]));
50
        $this->assertEquals(15, $this->Interpolation->interpolate(0.5, 0.5, [20, 20, 10, 10]));
51
        $this->assertEquals(15, $this->Interpolation->interpolate(0.5, 0.5, [10, 20, 10, 20]));
52
        $this->assertEquals(15, $this->Interpolation->interpolate(0.5, 0.5, [20, 10, 20, 10]));
53
        $this->assertEquals(75, $this->Interpolation->interpolate(0.5, 0.5, [100, 100, 100, 0]));
54
        $this->assertEquals(38, $this->Interpolation->interpolate(0.5, 0.5, [10, 42, 31, 69]));
55
    }
56
}
57