<?php declare(strict_types=1);

use PHPUnit\TestCase;

class SpeedTest extends TestCase
{
    /** 
     * @test 
     * @expectedException NegativeSpeedException
     */
    public function itShouldThrownAnExceptionWhenAmountIsNegative()
    {
        Speed::inKilometersPerHour(0);
        Speed::inMilesPerHour(0);
    }

    /** @test */
    public function itShouldCompareWithOthers()
    {
        $speedA = Speed::inKilometersPerHour(100);
        $speedB = Speed::inKilometersPerHour(100);

        $this->assertTrue($speedA->equalsTo($speedB));

        $speedB = Speed::inMilesPerHour(100);

        $this->assertFalse($speedA->equalsTo($speedB));
    }

    /** @test */
    public function originalSpeedShouldNotBeModifiedOnIncrease()
    {
        $speedA = Speed::inKilometersPerHour(100);
        $speedB = Speed::inKilometersPerHour(100);
        $speedA->increase($speedB);

        $this->assertEquals(100, $speedA->getAmount());
    }

    /** @test */
    public function speedShouldBeIncreased()
    {
        $speedA = Speed::inKilometersPerHour(100);
        $speedB = Speed::inKilometersPerHour(100);
        $speedC = $speedA->increase($speedB);

        $this->assertEquals(200, $speedC->getAmount());
    }

    /** 
     * @test 
     * @expectedException MagnitudeMismatchException
     */
    public function speedShouldNotBeIncreasedIfMagnitudeIsDifferent()
    {
        $speedA = Speed::inKilometersPerHour(100);
        $speedB = Speed::inMilesPerHour(100);
        $speedC = $speedA->increase($speedB);
    }
}