8000 GitHub - kaiohken1982/SrCalculator: A calculator test
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

kaiohken1982/SrCalculator

Repository files navigation

SrCalculator

Build Status Coverage Status

A calculator test

Description

This is a calculator that takes an equation from a string and gives the result.

How to use this module

Install using composer

composer.json

{
    "repositories": [
      {
        "type": "vcs",
        "url": "https://github.com/kaiohken1982/SrCalculator.git"
      }
    ],
    "require": {
      "kaiohken1982/srcalculator": "dev-master"
    }
}

index.php

<?php 
require __DIR__ . '/vendor/autoload.php';

use \SrCalculator\Calculator\Calculator;

//$argv[0]; // the script name
$equation = isset($argv[1]) ? $argv[1] : ''; // the first parameter
//$argv[2]; // the second parameter

try {
  $calculator = new Calculator();
  echo 'Result is ' . $calculator->calculate($equation) . PHP_EOL;
} catch (Exception $e) {
  echo 'Script ended with this message: ' . $e->getMessage() . PHP_EOL;
}

Run from console

php index.php 'your equation here'

php index.php 3*2 //6

php index.php '3*2 + 1.1 / 88' // 6.0125

php index.php '1 * hello' // error

Run unit test

Please note you must be in the module root.

curl -s http://getcomposer.org/installer | php 
php composer.phar install 
./vendor/bin/phpunit 

If you have xdebug enabled and you want to see code coverage run the command below

./vendor/bin/phpunit --coverage-html data/coverage 

About

A calculator test

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0