<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

/**
 * Generated by PHPUnit_SkeletonGenerator on 2017-08-08 at 15:30:08.
 */
class MathOperationsTest extends \PHPUnit\Framework\TestCase
{
  /**
   * @var MathOperations
   */
  protected $object;

  /**
   * Sets up the fixture, for example, opens a network connection.
   * This method is called before a test is executed.
   */
  protected function setUp(): void
  {
    $this->object = new MathOperations();
  }

  /**
   * Tears down the fixture, for example, closes a network connection.
   * This method is called after a test is executed.
   */
  protected function tearDown(): void
  {
  }

  /**
   * @covers MathOperations::getEditedVars
   * @test
   */
  public function grammToKilo_UnevengToKilo_threeDecimalPlaces()
  {
    //Sinn: wenn die letzte Stelle ungleich 0 ist: drei Dezimalstellen anzeigen
    $input = 1;
    $expected = '0,001';
    $result = $this->object->grammToKilo($input);
    $this->assertEquals($expected, $result);

    $input = 79;
    $expected = '0,079';
    $result = $this->object->grammToKilo($input);
    $this->assertEquals($expected, $result);

    $input = 179;
    $expected = '0,179';
    $result = $this->object->grammToKilo($input);
    $this->assertEquals($expected, $result);

    $input = 1079;
    $expected = '1,079';
    $result = $this->object->grammToKilo($input);
    $this->assertEquals($expected, $result);

    $input = 10000001;
    $expected = '10000,001';
    $result = $this->object->grammToKilo($input);
    $this->assertEquals($expected, $result);
  }

  /**
   * @covers MathOperations::getEditedVars
   * @test
   */
  public function grammToKilo_10gToKilo_twoDecimalPlaces()
  {
    $input = 10;
    $expected = '0,01';

    $result = $this->object->grammToKilo($input);
    $this->assertEquals($expected, $result);
  }

  /**
   * @covers MathOperations::getEditedVars
   * @test
   */
  public function grammToKilo_EvengToKilo_twoDecimalPlacesRounded()
  {
    $input = 10;
    $expected = '0,01';
    $result = $this->object->grammToKilo($input);
    $this->assertEquals($expected, $result);

    $input = 100;
    $expected = '0,10';
    $result = $this->object->grammToKilo($input);
    $this->assertEquals($expected, $result);

    $input = 1000;
    $expected = '1,00';
    $result = $this->object->grammToKilo($input);
    $this->assertEquals($expected, $result);

    $input = 10000000;
    $expected = '10000,00';
    $result = $this->object->grammToKilo($input);
    $this->assertEquals($expected, $result);
  }

  /**
   * @covers MathOperations::getEditedVars
   * @test
   */
  public function grammToKilo_thousandSeparator()
  {
    $input = 1000001;
    $expected = '1.000,001';
    $result = $this->object->grammToKilo($input, true);
    $this->assertEquals($expected, $result);

    $input = 1000000;
    $expected = '1.000,00';
    $result = $this->object->grammToKilo($input, true);
    $this->assertEquals($expected, $result);
  }

  /**
   * @covers MathOperations::isNumeric
   * @test
   */
  public function isNumeric()
  {
    $this->assertTrue($this->object->isNumeric(123));
    $this->assertTrue($this->object->isNumeric('123'));
    $this->assertTrue($this->object->isNumeric(123.45));
    $this->assertTrue($this->object->isNumeric('123.45'));

    $this->assertFalse($this->object->isNumeric('a'));
    $this->assertFalse($this->object->isNumeric(array()));

    //Exponentialschreibweise soll explizit nicht durchgelassen werden
    $this->assertFalse($this->object->isNumeric('123e10'));
    $this->assertFalse($this->object->isNumeric('211E329'));
    $this->assertFalse($this->object->isNumeric('211e-329'));
    $this->assertFalse($this->object->isNumeric('211E-329'));
    $this->assertFalse($this->object->isNumeric('211D329'));
  }

  /**
   * @covers MathOperations::allgRund
   * @test
   */
  public function allgRund_typ9()
  {
    $typ = 9;//auf 1,00 aufgerundet
    $this->assertEquals(9.00, $this->object->allgRund(8.51, $typ));
    $this->assertEquals(9.00, $this->object->allgRund(8.49, $typ));
    $this->assertEquals(9.00, $this->object->allgRund(8.499999, $typ));
    $this->assertEquals(9.00, $this->object->allgRund(8.01, $typ));
    $this->assertEquals(9.00, $this->object->allgRund(8.9999, $typ));
    $this->assertEquals(9.00, $this->object->allgRund(9.00, $typ));
  }
}
