PHP Classes

File: test/KlammerTest.php

Recommend this page to a friend!
  Classes of stefan   PHP Calculator   test/KlammerTest.php   Download  
File: test/KlammerTest.php
Role: Class source
Content type: text/plain
Description: Class source
Class: PHP Calculator
Calculate the result of multiple math operations
Author: By
Last change: resolve error ( and sin( in same term
Date: 2 years ago
Size: 2,223 bytes
 

Contents

Class file image Download
<?php declare(strict_types=1);
use
PHPUnit\Framework\TestCase;
    use
Taschenrechner\Classes\Calculator;
    use
Taschenrechner\Classes\Operationen\Klammer;
    use
Taschenrechner\Classes\Concatinator;
require_once
"init.php";
require_once(
dirname(__FILE__)."/../vendor/autoload.php");
final class
KlammerTest extends TestCase
{
    private
$operation;
    private
$concatinator;
    private
$calculator;

    protected function
setUp(): void
   
{
       
$this->calculator = $this->createMock(Calculator::class);
       
$this->concatinator = $this->createMock(Concatinator::class);
    }
   
    public function
testTermKlammer5Minus5KlammerZuMinus5EqualsKlammer5Minus5KlammerZuMinus5(): void
   
{
       
$this->operation = new Klammer($this->calculator, $this->concatinator);
       
$this->concatinator->method('concatinateArray')->willReturn(array("(","5","-","5",")","-", "5"));
       
$this->calculator->method('calculate')->willReturn("0");
       
       
$this->assertSame("0-5", $this->operation->findAndCalculateTerm("(5-5)-5", (new Init())->operations()));

    }
   
    public function
testTerm5MalKlammer5Minus5KlammerZuEquals5MalKlammer5Minus5KlammerZu(): void
   
{
       
$this->operation = new Klammer($this->calculator, $this->concatinator);
       
$this->concatinator->method('concatinateArray')->willReturn(array("5", "*","(","5","-","5",")"));
       
$this->calculator->method('calculate')->willReturn("0");
       
       
$this->assertSame("5*0", $this->operation->findAndCalculateTerm("5*(5-5)", (new Init())->operations()));

    }
    public function
testTerm5MalKlammer5MinusKlammer5Plus5KlammerZuKlammerZuEquals5MalKlammer5Minus10KlammerZuKlammerZu(): void
   
{
       
$this->operation = new Klammer($this->calculator, $this->concatinator);
       
$this->concatinator->method('concatinateArray')->willReturn(array("5", "*","(","5","-","(","5", "+", "5", ")",")"));
       
$this->calculator->method('calculate')->willReturn("(5-10)");


       
$this->assertSame("5*(5-10)", $this->operation->findAndCalculateTerm("5*(5-(5+5))", (new Init())->operations()));

    }

    protected function
tearDown(): void
   
{
       
$this->calculator = NULL;
       
$this->concatinator = NULL;

    }
  
}