當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Calculator::roman_numerals方法代碼示例

本文整理匯總了PHP中Calculator::roman_numerals方法的典型用法代碼示例。如果您正苦於以下問題:PHP Calculator::roman_numerals方法的具體用法?PHP Calculator::roman_numerals怎麽用?PHP Calculator::roman_numerals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Calculator的用法示例。


在下文中一共展示了Calculator::roman_numerals方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: test

 test (1 + 1 == 2, "one and one are two");
 
 //test to see if there is a calculator class
 test (class_exists('Calculator'), "There is a calculator class");
 
  //create an instance of the calculator
 $calculator = new Calculator;
 
 //test to find an instance of the calculator
 test ($calculator != null, "An instance of the calculator exists");
 
 //test to see if the calculator is set to zero
 test ($calculator->register == 0, "The calculator is set to zero");
 
 //test to see if you can use the public functions in tandem
 test ($calculator->roman_numerals (41) == "Error: number too large to calculate", "The calculator can reject numbers too high to calculate");
 
 //test to see if the calculator can return 40
 test ($calculator->roman_numerals (40) == "XL", "The calculator can return 40.");
 
 //test for less than 40
 test ($calculator->roman_numerals (39) == "XXX", "The calculator can return less than 40.");
 /*
  //test to see if the calculator can reject too large a number
 test ($calculator->too_high (41) == "Error: number too large to calculate", "The calculator can reject numbers too high to calculate");
 test ($calculator->too_high (40) == "Error: number too large to calculate", "The calculator can reject numbers too high to calculate");
 
 //test to see if the calculator can return 40
 test ($calculator->equals_fourty (40) == "XL", "The calculator can return the Roman number 40");
 
 //test to see if the calculator can calculate the correct number of Xs
開發者ID:rmccaffrey,項目名稱:dig1108-assignments,代碼行數:31,代碼來源:RomanNumeral_Test.php

示例2: test

 
 //test to see if the calculator can return 40
 test ($calculator->equals_fourty (40) == "XL", "The calculator can return the Roman number 40");
 
 //test to see if the calculator can calculate the correct number of Xs
 test ($calculator->count_tens (30) == "XXX", "The calculator counts the correct number of tens 30");
 test ($calculator->count_tens (20) == "XX", "The calculator counts the correct number of tens 20");
 test ($calculator->count_tens (10) == "X", "The calculator counts the correct number of tens 10");
 test ($calculator->count_tens (39) == "XXX", "The calculator counts the correct number of tens 39");
 
 //test to see if calculator can return 9
 test ($calculator->equals_nine (9) == "IX", "The calculator can return the Roman number 9");
 
 //test to see if the calculator can return the correct number of Vs
 test ($calculator->count_fives (5) == "V", "The calculator counts the correct number of fives 5");
 test ($calculator->count_fives (15) == "VVV", "The calculator counts the correct number of fives 15");
 
 //test to see if calculator can return 4
 test ($calculator->equals_four (4) == "IV", "The calculator can return the Roman number 4");
 
 //test to see if the calculator can return the correct number of Is
 test ($calculator->count_ones (3) == "III", "The calculator counts the correct number of ones 3");
 test ($calculator->count_ones (2) == "II", "The calculator counts the correct number of ones 2");
 test ($calculator->count_ones (1) == "I", "The calculator counts the correct number of ones 1");
 
 //test to reject 0
 test ($calculator->reject_zero (0) == "The Romans never learned of zero", "The calculator can reject zero as input");
 
 //test whole shebang
 test ($calculator->roman_numerals (0) == 3, "The calculator can calculate any number from 0 to 40");
 
開發者ID:rmccaffrey,項目名稱:dig1108-assignments,代碼行數:29,代碼來源:Old_Roman_Tests.php

示例3: test

//write a generic test function
function test($assertion, $message = null)
{
    echo (@assert($assertion) ? "pass " : "fail ") . $message . "\n";
}
test(1 + 1 == 2, "one and one are two");
//test to see if there is a calculator class
test(class_exists('Calculator'), "There is a calculator class");
//create an instance of the calculator
$calculator = new Calculator();
//test to find an instance of the calculator
test($calculator != null, "An instance of the calculator exists");
//test to see if the calculator is set to zero
test($calculator->register == 0, "The calculator is set to zero");
//test to see if you can use the public functions in tandem
test($calculator->roman_numerals(41) == "Error: number too large to calculate", "The calculator can reject numbers too high to calculate");
//test to see if the calculator can return 40
test($calculator->roman_numerals(40) == "XL", "The calculator can return 40.");
//test for returning number of correct Xs
test($calculator->roman_numerals(30) == "XXX", "The calculator can return XXX for 30.");
echo $calculator->roman_numerals(30) . "\n";
//test to return 39
test($calculator->roman_numerals(39) == "XXXIX", "The calculator can return XXXIX for 39.");
echo $calculator->roman_numerals(39) . "\n";
//test to return 35
test($calculator->roman_numerals(35) == "XXXV", "The calculator can return for 35.");
echo $calculator->roman_numerals(35) . "\n";
//test to return 34
test($calculator->roman_numerals(34) == "XXXIV", "The calculator can return for 34.");
echo $calculator->roman_numerals(34) . "\n";
//test some 20s
開發者ID:rmccaffrey,項目名稱:dig1108-assignments,代碼行數:31,代碼來源:2015RomanNum_Test.php


注:本文中的Calculator::roman_numerals方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。