Created
August 25, 2010 20:22
-
-
Save marcomoura/550213 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Description of VerificaPalavra | |
* | |
* @author | |
* Marco Moura | |
* Rafael | |
* Patricia | |
* Luciana | |
* Natalia | |
* Carlos | |
*/ | |
class VerificaPalavra { | |
public function alphaToNum($alpha){ | |
for($i="a";$i<=$alpha;$i++){ | |
$number ++; | |
} | |
if ($this->VerificarMaiuscula($alpha)) $number += 26; | |
return $number; | |
} | |
public function separaAlpha($alpha){ | |
$array = str_split($alpha); | |
return $array; | |
} | |
public function wordToNum($alpha){ | |
$arrayletra = $this->separaAlpha($alpha); | |
foreach($arrayletra as $letra){ | |
$valor += $this->alphaToNum($letra); | |
} | |
return $valor; | |
} | |
public function wordIsPrimo($param) { | |
$alpha_number = $this->wordToNum($param); | |
return $this->IsPrimo($alpha_number); | |
} | |
public function IsPrimo($param){ | |
for($i=($param-1); $i>1; $i--){ | |
$r = $param % $i; | |
if($r == 0){ | |
return false; | |
} | |
} | |
return true; | |
} | |
public function VerificarMaiuscula($param){ | |
if( $param == strtoupper($param)) | |
return true; | |
else | |
return false; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'PHPUnit/Framework.php'; | |
require_once dirname(__FILE__) . '/../../../../../var/www/PalavraPrima/VerificaPalavra.php'; | |
/** | |
* Test class for VerificaPalavra. | |
* Generated by PHPUnit on 2010-08-24 at 08:26:53. | |
*/ | |
class VerificaPalavraTest extends PHPUnit_Framework_TestCase { | |
/** | |
* @var VerificaPalavra | |
* @access protected | |
*/ | |
protected $object; | |
/** | |
* Sets up the fixture, for example, opens a network connection. | |
* This method is called before a test is executed. | |
* | |
* @access protected | |
*/ | |
protected function setUp() { | |
$this->object = new VerificaPalavra; | |
} | |
/** | |
* Tears down the fixture, for example, closes a network connection. | |
* This method is called after a test is executed. | |
* | |
* @access protected | |
*/ | |
protected function tearDown() { | |
} | |
public function testConverterLetraAMinusculaparaUm(){ | |
$resultado = $this->object->alphaToNum("a"); | |
$this->assertEquals(1,$resultado); | |
} | |
public function testVerificarLetraBto2Minusculo(){ | |
$resultado = $this->object->alphaToNum("b"); | |
$this->assertEquals(2,$resultado); | |
} | |
public function testVerificarLetraCto3Minusculo(){ | |
$resultado = $this->object->alphaToNum("c"); | |
$this->assertEquals(3,$resultado); | |
} | |
public function testSeparaABMinusculo(){ | |
$resultado = $this->object->separaAlpha("ab"); | |
$this->assertEquals(array("a","b"),$resultado); | |
} | |
public function testSeparaBCDRMinusculo(){ | |
$resultado = $this->object->separaAlpha("bcdr"); | |
$this->assertEquals(array("b","c","d","r"),$resultado); | |
} | |
public function testSeparaAMinusculo(){ | |
$resultado = $this->object->separaAlpha("a"); | |
$this->assertEquals(array("a"),$resultado); | |
} | |
public function testRetornValorABMinusculo(){ | |
$resultado = $this->object->wordToNum("ab"); | |
$this->assertEquals(3,$resultado); | |
} | |
public function testRetornValorABCMinusculo(){ | |
$resultado = $this->object->wordToNum("abc"); | |
$this->assertEquals(6,$resultado); | |
} | |
public function testRetornValorAMinusculoArray(){ | |
$resultado = $this->object->wordToNum("a"); | |
$this->assertEquals(1,$resultado); | |
} | |
public function testNumPrimoCinco(){ | |
$resultado = $this->object->IsPrimo(5); | |
$this->assertEquals(true,$resultado); | |
} | |
public function testNumPrimoQuatro(){ | |
$resultado = $this->object->IsPrimo(4); | |
$this->assertEquals(false,$resultado); | |
} | |
public function testPalavraPrimoABMinusculo(){ | |
$resultado = $this->object->wordIsPrimo("ab"); | |
$this->assertEquals(true,$resultado); | |
} | |
public function testPalavraPrimoABCMinusculo(){ | |
$resultado = $this->object->wordIsPrimo("abc"); | |
$this->assertEquals(false,$resultado); | |
} | |
public function testVerificarMaiuscula(){ | |
$resultado = $this->object->VerificarMaiuscula("A"); | |
$this->assertEquals(True,$resultado); | |
} | |
public function testUFRN(){ | |
$resultado = $this->object->VerificarMaiuscula("UFRN"); | |
$this->assertEquals(True,$resultado); | |
} | |
public function testcontest(){ | |
$resultado = $this->object->VerificarMaiuscula("contest"); | |
$this->assertEquals(false,$resultado); | |
} | |
public function testAcM(){ | |
$resultado = $this->object->VerificarMaiuscula("AcM"); | |
$this->assertEquals(false,$resultado); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment