<?php
use Luticate\Utils\Dbo\LuDboDeserializeException;
use Luticate\Utils\Dbo\LuFloatDboArray;
use Luticate\Utils\Dbo\LuFloatDbo;

/**
 * Created by PhpStorm.
 * User: robin
 * Date: 5/29/16
 * Time: 2:57 PM
 */

class LuFloatDboArrayTest extends \PHPUnit_Framework_TestCase
{

    public function testArrayEmpty()
    {
        $dbo = LuFloatDboArray::jsonDeserialize([]);
        $this->assertSame([], $dbo->getArray());
    }
    
    public function testArrayString()
    {
        $dbo = LuFloatDboArray::jsonDeserialize(["42"]);
        $this->assertSame([42.0], $dbo->getArray());
    }

    public function testArrayMultipleString()
    {
        $dbo = LuFloatDboArray::jsonDeserialize(["42", "24", "48"]);
        $this->assertSame([42.0, 24.0, 48.0], $dbo->getArray());
    }

    public function testArrayInt()
    {
        $dbo = LuFloatDboArray::jsonDeserialize([42]);
        $this->assertSame([42.0], $dbo->getArray());
    }

    public function testArrayMultipleInt()
    {
        $dbo = LuFloatDboArray::jsonDeserialize([42, 24, 48]);
        $this->assertSame([42.0, 24.0, 48.0], $dbo->getArray());
    }

    public function testArrayMultipleIntAndFloat()
    {
        $dbo = LuFloatDboArray::jsonDeserialize([42, 24, 48.0]);
        $this->assertSame([42.0, 24.0, 48.0], $dbo->getArray());
    }

    public function testArrayMultipleIntAndFloatAndString()
    {
        $dbo = LuFloatDboArray::jsonDeserialize([42, 24.0, "48.0e+01"]);
        $this->assertSame([42.0, 24.0, 480.0], $dbo->getArray());
    }

    public function testArrayFloat()
    {
        $dbo = LuFloatDboArray::jsonDeserialize([42.42]);
        $this->assertSame([42.42], $dbo->getArray());
    }

    public function testArrayStringIntPlusData()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuFloatDboArray::jsonDeserialize(["42test"]);
    }

    public function testArrayMultipleStringIntPlusData()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuFloatDboArray::jsonDeserialize(["42", 42, "42test"]);
    }
    
    public function testIntString()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuFloatDboArray::jsonDeserialize("42");
    }
    
    public function testInt()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuFloatDboArray::jsonDeserialize(42);
    }
    public function testIntNegativeString()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuFloatDboArray::jsonDeserialize("-42");
    }

    public function testIntNegative()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuFloatDboArray::jsonDeserialize(-42);
    }

    public function testFloat()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuFloatDboArray::jsonDeserialize(42.42);
    }

    public function testFloatString()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuFloatDboArray::jsonDeserialize("42.42");
    }

    public function testExponentialString()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuFloatDboArray::jsonDeserialize("42e+01");
    }

    public function testBool()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuFloatDboArray::jsonDeserialize(true);
    }

    public function testBoolString()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuFloatDboArray::jsonDeserialize("true");
    }

    public function testNull()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuFloatDboArray::jsonDeserialize(null);
    }

    public function testObject()
    {
        $this->expectException(LuDboDeserializeException::class);
        LuFloatDboArray::jsonDeserialize(new self());
    }
}