PHP code example of mocking-magician / moneysaurus

1. Go to this page and download the library: Download mocking-magician/moneysaurus library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mocking-magician / moneysaurus example snippets


<?

use MockingMagician\Moneysaurus\System;
use MockingMagician\Moneysaurus\QuantifiedSystem;
use MockingMagician\Moneysaurus\Algorithms\GreedyAlgorithm;

// There, you can see an example with the Euro currency system 
$euroSystem = new System(...[
    0.01, 
    0.02, 
    0.05, 
    0.10, 
    0.20, 
    0.50, 
    1.0,  
    2.0,  
    5.0,  
    10.0, 
    20.0, 
    50.0, 
    100.0,
    200.0,
    500.0,
]);

// Then initialize a quantified system.
// A quantified system, is a system with a defined quantity of each coin/bank note available.

$quantifiedSystem = new QuantifiedSystem($euroSystem);
// By default, each value has been initialized with an zero amount quantity value.
// So after you can set the available quantity for each coin/bank note
$quantifiedSystem->setQuantity(0.01,  50);
$quantifiedSystem->setQuantity(0.02,  50);
$quantifiedSystem->setQuantity(0.05,  50);
$quantifiedSystem->setQuantity(0.10,  50);
$quantifiedSystem->setQuantity(0.20,  50);
$quantifiedSystem->setQuantity(0.50,  50);
$quantifiedSystem->setQuantity(1.0,   50);
$quantifiedSystem->setQuantity(2.0,   50);
$quantifiedSystem->setQuantity(5.0,   50);
$quantifiedSystem->setQuantity(10.0,  50);
$quantifiedSystem->setQuantity(20.0,  50);
$quantifiedSystem->setQuantity(50.0,  50);
$quantifiedSystem->setQuantity(100.0, 50);
$quantifiedSystem->setQuantity(200.0, 50);
$quantifiedSystem->setQuantity(500.0, 50);

$resolver = new GreedyAlgorithm($quantifiedSystem);
$change = $resolver->change(11.21);


<?

use MockingMagician\Moneysaurus\QuantifiedSystem;
use MockingMagician\Moneysaurus\Algorithms\GreedyAlgorithm;

$quantifiedSystem = new QuantifiedSystem();
$quantifiedSystem->addValue(0.01,  50);
$quantifiedSystem->addValue(0.02,  50);
$quantifiedSystem->addValue(0.05,  50);
$quantifiedSystem->addValue(0.10,  50);
$quantifiedSystem->addValue(0.20,  50);
$quantifiedSystem->addValue(0.50,  50);
$quantifiedSystem->addValue(1.0,   50);
$quantifiedSystem->addValue(2.0,   50);
$quantifiedSystem->addValue(5.0,   50);
$quantifiedSystem->addValue(10.0,  50);
$quantifiedSystem->addValue(20.0,  50);
$quantifiedSystem->addValue(50.0,  50);
$quantifiedSystem->addValue(100.0, 50);
$quantifiedSystem->addValue(200.0, 50);
$quantifiedSystem->addValue(500.0, 50);

$resolver = new GreedyAlgorithm($quantifiedSystem);
$change = $resolver->change(11.21);