Esempio n. 1
0
<?php

/**
 * Special test for out of range number
 */
/**
 * include original function for comparing
 * Not need the function anymore
 * include_once( "func.php");
 */
/**
 * include the class
 */
include_once "../src/NumberToWord.php";
$number = "99999999999999999999999999";
// original function by Karl
// convert_number_to_words($number);
$converter = new NumberToWord($number);
$result = $converter->convert($number);
if ($result === false) {
    echo $converter->getErrorMessage() . "\n";
    exit;
}
Esempio n. 2
0
 */
$errorMessage = array("NOT_NUMBER" => "The string entered is not a number.\n", "OUT_OF_RANGE" => "This code only accepts numbers between -" . PHP_INT_MAX . " and " . PHP_INT_MAX . ".\n");
/**
 * Start the script
 */
echo "Please enter a number to convert to word: \n";
/**
 * Get the input from command line
 */
$handle = fopen("php://stdin", "r");
$line = fgets($handle);
$number = trim($line);
/**
 * initial the class
 */
$converter = new NumberToWord($number);
/**
 * get the result
 */
$result = $converter->convert($number);
/**
 * error handling
 */
if ($result === false) {
    echo $errorMessage[$converter->getErrorMessage()] . "\n";
    exit;
}
/**
 * echo out the word if no error
 */
echo $result . "\n";
Esempio n. 3
0
 /**
  * test number with a string
  */
 public function testNotNumber()
 {
     $obj = new NumberToWord();
     $this->assertTrue($obj->convert("999x9") === false);
     $this->assertTrue($obj->getErrorMessage() == "NOT_NUMBER");
 }