given($context = new CUT()) ->when($result = $context->getVariables()) ->then ->object($result) ->isInstanceOf('ArrayObject') ->array(iterator_to_array($result)) ->isEmpty(); } public function case_context_exception_when_getting_unknown_variable() { $this ->given( $name = 'foo', $context = new CUT() ) ->then ->exception(function () use ($context, $name) { $context->getVariable($name); }) ->isInstanceOf('Hoa\Math\Exception\UnknownVariable'); } public function case_context_returns_variable_value() { $this ->given( $name = 'foo', $value = 42, $callable = function () use ($value) { return $value; }, $context = new CUT(), $context->addVariable($name, $callable) ) ->when($result = $context->getVariable($name)) ->then ->integer($result) ->isEqualTo($value); } public function case_context_has_predefined_constants() { $this ->given($context = new CUT()) ->when($result = $context->getConstants()) ->then ->object($result) ->isInstanceOf('ArrayObject') ->array(iterator_to_array($result)) ->isEqualTo([ 'PI' => M_PI, 'PI_2' => M_PI_2, 'PI_4' => M_PI_4, 'E' => M_E, 'SQRT_PI' => M_SQRTPI, 'SQRT_2' => M_SQRT2, 'SQRT_3' => M_SQRT3, 'LN_PI' => M_LNPI, 'LOG_2E' => M_LOG2E, 'LOG_10E' => M_LOG10E, 'LN_2' => M_LN2, 'LN_10' => M_LN10, 'ONE_OVER_PI' => M_1_PI, 'TWO_OVER_PI' => M_2_PI, 'TWO_OVER_SQRT_PI' => M_2_SQRTPI, 'ONE_OVER_SQRT_2' => M_SQRT1_2, 'EULER' => M_EULER, 'INFINITE' => INF ]); } public function case_context_exception_when_getting_unknown_constant() { $this ->given( $name = 'FOO', $context = new CUT() ) ->then ->exception(function () use ($context, $name) { $context->getConstant($name); }) ->isInstanceOf('Hoa\Math\Exception\UnknownConstant'); } public function case_context_exception_when_setting_already_defined_constant() { $this ->given( $name = 'PI', $context = new CUT() ) ->then ->exception(function () use ($context, $name) { $context->addConstant($name, 42); }) ->isInstanceOf('Hoa\Math\Exception\AlreadyDefinedConstant'); } public function case_context_returns_constant_value() { $this ->given( $name = 'FOO', $value = 42, $context = new CUT(), $context->addConstant($name, $value) ) ->when($result = $context->getConstant($name)) ->then ->variable($result) ->isEqualTo($value); } public function case_context_has_predefined_functions() { $this ->given($context = new CUT()) ->when($result = $context->getFunctions()) ->then ->object($result) ->isInstanceOf('ArrayObject') ->array(iterator_to_array($result)) ->hasSize(23) ->hasKey('abs') ->hasKey('acos') ->hasKey('asin') ->hasKey('atan') ->hasKey('average') ->hasKey('avg') ->hasKey('ceil') ->hasKey('cos') ->hasKey('count') ->hasKey('deg2rad') ->hasKey('exp') ->hasKey('floor') ->hasKey('ln') ->hasKey('log') ->hasKey('max') ->hasKey('min') ->hasKey('pow') ->hasKey('rad2deg') ->hasKey('round') ->hasKey('round') ->hasKey('sin') ->hasKey('sqrt') ->hasKey('sum') ->hasKey('tan'); } public function case_context_exception_when_getting_unknown_function() { $this ->given( $name = 'foo', $context = new CUT() ) ->then ->exception(function () use ($context, $name) { $context->getFunction($name); }) ->isInstanceOf('Hoa\Math\Exception\UnknownFunction'); } public function case_context_exception_when_setting_unknown_function() { $this ->given( $name = 'foo', $context = new CUT() ) ->then ->exception(function () use ($context, $name) { $context->addFunction($name); }) ->isInstanceOf('Hoa\Math\Exception\UnknownFunction'); } public function case_context_returns_function_callable() { $this ->given( $name = 'foo', $callable = function () {}, $context = new CUT(), $context->addFunction($name, $callable) ) ->when($result = $context->getFunction($name)) ->then ->object($result) ->isInstanceOf('Hoa\Consistency\Xcallable'); } public function case_context_returns_the_right_function_callable() { $this ->given( $name = 'foo', $value = 42, $callable = function () use ($value) { return $value; }, $context = new CUT(), $context->addFunction($name, $callable) ) ->when($result = $context->getFunction($name)) ->then ->integer($result()) ->isEqualTo($value); } }