Created
August 25, 2010 20:28
-
-
Save marcomoura/550229 to your computer and use it in GitHub Desktop.
Segundo encontro
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 | |
/** | |
* @author | |
* Marco Moura | |
* Rafael | |
* Patricia | |
* Natalia | |
* Carlos | |
*/ | |
class RomanNumerals { | |
//put your code here | |
public function changeNumber($numero){ | |
$numero = strtoupper($numero); | |
$tabelaDeValores['I'] = 1; | |
$tabelaDeValores['V'] = 5; | |
$tabelaDeValores['X'] = 10; | |
$tabelaDeValores['L'] = 50; | |
$tabelaDeValores['C'] = 100; | |
$tabelaDeValores['D'] = 500; | |
$tabelaDeValores['M'] = 1000; | |
if($numero == 2){ | |
$temp = $arrayN[1].$arrayN[1]; | |
return $temp; | |
}elseif($numero == 3){ | |
$temp = $arrayN[1].$arrayN[1].$arrayN[1]; | |
return $temp; | |
} | |
if(array_key_exists($numero, $tabelaDeValores)) | |
return $tabelaDeValores[$numero]; | |
else if(in_array($numero, $tabelaDeValores)) | |
foreach($tabelaDeValores as $key => $value) | |
if($value == $numero) | |
return $key; | |
} | |
public function SeparaString($numero){ | |
$valor = explode('',$numero); | |
return $valor; | |
} | |
} | |
?> |
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/CodingDojo2/RomanNumerals.php'; | |
/** | |
* Test class for RomanNumerals. | |
* Generated by PHPUnit on 2010-08-17 at 08:39:36. | |
*/ | |
class RomanNumeralsTest extends PHPUnit_Framework_TestCase { | |
/** | |
* @var RomanNumerals | |
* @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 RomanNumerals; | |
} | |
/** | |
* 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 testEntraIESaiUm(){ | |
$valorConvertido = $this->object->changeNumber("I"); | |
$this->assertEquals(1, $valorConvertido ); | |
} | |
public function testEntraVESaiCinco(){ | |
$valorConvertido = $this->object->changeNumber("V"); | |
$this->assertEquals(5, $valorConvertido ); | |
} | |
public function testEntraVMinisculoESaiCinco(){ | |
$valorConvertido = $this->object->changeNumber("v"); | |
$this->assertEquals(5, $valorConvertido ); | |
} | |
public function testEntraXESaiDez(){ | |
$valorConvertido = $this->object->changeNumber("X"); | |
$this->assertEquals(10, $valorConvertido ); | |
} | |
public function testEntraLESaiCinquenta(){ | |
$valorConvertido = $this->object->changeNumber("L"); | |
$this->assertEquals(50, $valorConvertido ); | |
} | |
public function testEntraCESaiCem(){ | |
$valorConvertido = $this->object->changeNumber("C"); | |
$this->assertEquals(100, $valorConvertido ); | |
} | |
public function testEntraDESaiQuinhentos(){ | |
$valorConvertido = $this->object->changeNumber("D"); | |
$this->assertEquals(500, $valorConvertido ); | |
} | |
public function testEntraMESaiMil(){ | |
$valorConvertido = $this->object->changeNumber("M"); | |
$this->assertEquals(1000, $valorConvertido ); | |
} | |
public function testEntraUmESaiI(){ | |
$valorConvertido = $this->object->changeNumber(1); | |
$this->assertEquals("I", $valorConvertido ); | |
} | |
public function testEntraCincoESaiV(){ | |
$valorConvertido = $this->object->changeNumber(5); | |
$this->assertEquals("V", $valorConvertido ); | |
} | |
public function testEntraDezESaiX(){ | |
$valorConvertido = $this->object->changeNumber(10); | |
$this->assertEquals("X", $valorConvertido ); | |
} | |
public function testEntraCinquentaESaiL(){ | |
$valorConvertido = $this->object->changeNumber(50); | |
$this->assertEquals("L", $valorConvertido ); | |
} | |
public function testEntraCemESaiC(){ | |
$valorConvertido = $this->object->changeNumber(100); | |
$this->assertEquals("C", $valorConvertido ); | |
} | |
public function testEntraQuinhentosESaiD(){ | |
$valorConvertido = $this->object->changeNumber(500); | |
$this->assertEquals("D", $valorConvertido ); | |
} | |
public function testEntraMilESaiM(){ | |
$valorConvertido = $this->object->changeNumber(1000); | |
$this->assertEquals("M", $valorConvertido ); | |
} | |
public function testEntraDoisESaiII(){ | |
$valorConvertido = $this->object->changeNumber(2); | |
$this->assertEquals("II" , $valorConvertido ); | |
} | |
public function testEntraTresESaiIII(){ | |
$valorConvertido = $this->object->changeNumber(3); | |
$this->assertEquals("III" , $valorConvertido ); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment