Skip to content

Instantly share code, notes, and snippets.

@labra
Created October 9, 2014 13:48
Show Gist options
  • Select an option

  • Save labra/de3923e1e4753bd1756b to your computer and use it in GitHub Desktop.

Select an option

Save labra/de3923e1e4753bd1756b to your computer and use it in GitHub Desktop.
Ejercicio PHP: Corrector test
<?php
require_once 'corrector.php';
class CorrectorTest extends PHPUnit_Framework_TestCase {
private $examen, $evaluacion, $resultado, $corrector ;
function __construct() {
$this->examen = json_decode('[
{"pregunta": 1, "correcta": "a"},
{"pregunta": 2, "correcta": "b"}]',true) ;
$this->evaluacion =
json_decode('[ {"alumno" : 2456,
"respuestas" : [{ "pregunta" : 1, "respuesta" : "a"},
{ "pregunta" : 2, "respuesta" : "b"}]},
{"alumno" : 4321,
"respuestas" : [{ "pregunta": 1, "respuesta": "b"},
{ "pregunta": 2, "respuesta": "b"}]},
{"alumno": 6789,
"respuestas": [{ "pregunta": 1, "respuesta": "b"},
{ "pregunta": 2, "respuesta": "a"}]}
]',true) ;
$this->resultado = json_decode('
[ {"alumno": 2456, "nota": 2},
{"alumno": 4321, "nota": 0.75},
{"alumno": 6789, "nota": -0.5}
]',true);
$this->respuestas = json_decode('
[{ "pregunta": 1, "respuesta": "b"},
{ "pregunta": 2, "respuesta": "a"}]',true);
$this->corrector = new Corrector();
}
function test_not_null_resultado() {
$this->assertNotNull($this->resultado);
}
function test_not_null_examen() {
$this->assertNotNull($this->examen);
}
function test_not_null_evaluacion() {
$this->assertNotNull($this->evaluacion);
}
function test_corrector() {
$devuelto = $this->corrector->corrige($this->examen,$this->evaluacion);
$this->assertEquals($this->resultado, $devuelto);
}
function test_busca1() {
$this->assertEquals("b",$this->corrector->busca(1,$this->respuestas));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment