SlideShare une entreprise Scribd logo
1  sur  27
Télécharger pour lire hors ligne
Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Bilan du jeux de coding
C. Brun <christophe.brun.cl194@gadz.org>
Perso
Septembre 2013
Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Sommaire
Introduction
Etape1 : Sujet Classe + Ajouter
Etape 2 : Exception
Etape 3 : Ajouter plusieurs valeurs
Etape 4 : Soustraction
Etape 5 : InitResultat
Etape 6 : Test Résultat Après Init
Ultimate
Bilan
Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Introduction I
But du jeux
Introduction au TDD
Voir votre comportement sans spécifications
Voir votre façon de coder
Bilan
Confronter les résultats de chacun (anonyme)
Réagir
Evoluer
Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Etape 1 : Sujet Classe + Ajouter

 class CalculatriceTest extends PHPUnit_Framework_TestCase {
 public function testInstances()
 {
 new Calculatrice;
 }

 public function testResultatDefaultsZero()
 {
 $calc = new Calculatrice;
 $this->assertSame(0,$calc->getResultat());
 }

 public function testAjouterNombre()
 {
 $calc = new Calculatrice;
 $calc->ajouter(2);
 $this->assertEquals(2,$calc->getResultat());
 }
 }
 ?>
Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Etape 1 : Reponse 1

 class Calculatrice {
 private $resultat = 0;

 public function getResultat()
 {
 return $this->resultat;
 }

 public function ajouter($nombre)
 {
 $this->resultat=2;
 }
 }
 ?>
Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Etape 1 : Reponse 2
 class Calculatrice {

 private $resultats = 0;

 function __construct() {
 $this->resultats = 0;
 }

 function ajouter($nb) {
 $this->resultats += $nb;
 }

 function getResultat() {
 return $this->resultats;
 }
 }
 ?>
Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Etape 1 : Reponse 3

 class Calculatrice {

 protected $_result = 0;

 public function __construct() {
 }

 public function ajouter( $nbr ) {
 $this->_result += intval( $nbr );
 }

 public function getResultat() {
 return $this->_result;
 }
 }
 ?>
Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Etape 1 : Reponse 4
 class Calculatrice {

 var $resultat;

 function Calculatrice() {
 $this->resultat = 0;
 }

 public function ajouter( $num ) {
 if (!is_numeric($num)) {
 throw new Exception(’"’ . $num . ’" n’est pas de type numérique.’);
 }
 $this->resultat += $num;
 }

 public function getResultat() {
 return $this->resultat;
 }

 }

 ?>
Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Etape 1 : Reponse 5
 class Calculatrice {

 public function __construct() {
 $this->Result = 0;
 }

 public function getResultat() {
 return $this->Result;
 }


 /*
 * PRIVATE
 */

 private function calculer( $signe, $nb ) {
 $this->Result = $this->Result . $signe . $nb;
 }


 /*
 * OPERATION
 */

 public function ajouter( $nb ) {
 $nb = isset( $nb ) ? $nb : $this->Result;
 self::calculer( (int)’+’, $nb );
 }

 }
 ?>
Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Etape 1 : Reponse 6
 Class Calculatrice {

 private $vResultat;
 private $vInitial;

 /**
 * Constructeur
 */
 function __construct() {
 $this->setDefaut();
 }

 /**
 * Méthode pour faire l’addition
 * @param $valeur
 */
 public function ajouter($valeur) {
 $this->vResultat = $this->vInitial + $valeur;
 }

 /**
 * Méthode pour faire la soustraction
 * @param $valeur
 */
 public function suprimer($valeur) {
 $this->vResultat = $this->vInitial - $valeur;
 }

 /**
 * Méthode pour faire la multiplication
 * @param $valeur
 */
 public function multiplier($valeur) {
 $this->vResultat = $this->vInitial * $valeur;
 }

 /**
 * Méthode pour faire la division
 * @param $valeur
 */
 public function diviser($valeur) {
 $this->vResultat = $this->vInitial / $valeur;
 }

 /**
 * Méthode pour faire la puissance 2
 * @param $valeur
 */
 public function exposant2($valeur) {
 $this->vResultat = $valeur * $valeur;
 }

Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Etape 2 : Exception
 public function testAjouterNombre()
 {
 $calc = new Calculatrice;
 $calc->ajouter(2);
 $this->assertEquals(2,$calc->getResultat());
 }

 /**
 * @expectedException InvalidArgumentException
 */
 public function testValeurNumerique()
 {
 $calc = new Calculatrice;
 $calc->ajouter(’un chiffre’);
 }
 }
 ?>
Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Etape 2 : Reponse 1

 class Calculatrice {
 private $resultat = 0;

 public function getResultat()
 {
 return $this->resultat;
 }

 public function ajouter($nombre)
 {
 if ($nombre == ’un chiffre’)
 throw new InvalidArgumentException;
 $this->resultat=2;
 }
 }
 ?>
Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Etape 2 : Response 2
 class Calculatrice {

 private $resultats;

 function __construct() {
 $this->resultats = 0;
 }

 function ajouter($nb) {
 if (!is_numeric($nb)) {
 throw new InvalidArgumentException(’You must give a numeric.’);
 }
 $this->resultats += $nb;
 }

 function getResultat() {
 return $this->resultats;
 }

 }
 ?>
Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Etape 2 : Response 3
 */

 Class Calculatrice {

 private $vResultat;
 private $vInitial;

 /**
 * Constructeur
 */
 function __construct() {
 $this->setDefaut();
 }

 /**
 * Méthode pour faire l’addition
 * @param $valeur
 */
 public function ajouter($valeur) {
 if( !is_numeric($valeur) )
 throw new InvalidArgumentException(’Argument non valide : ’
 $this->vResultat = $this->vInitial + $valeur;
 }

 public function getResultat() {
 $this->vInitial = $this->vResultat;
 return $this->vResultat;
 }

 /**
 * Méthode Mettre tous les valeur par defaut
 */
 public function setDefaut() {
 $this->vResultat = $this->vInitial = 0;
 }

 }

 ?>
Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Etape 3 : Ajouter plusieurs valeurs
 /**
 * @expectedException InvalidArgumentException
 */
 public function testValeurNumerique()
 {
 $calc = new Calculatrice;
 $calc->ajouter(’un chiffre’);
 }

 public function testAjouterPlusieursValeurs()
 {
 $calc = new Calculatrice;
 $calc->ajouter(1,2,3,4,5);
 $this->assertEquals(15,$calc->getResultat());
 }
 }

 ?>
Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Etape 3 : Response 1
 class Calculatrice {

 private $resultats;

 function __construct() {
 $this->resultats = 0;
 }

 function ajouter() {
 $numberList = func_get_args();
 foreach ($numberList as $key => $number) {
 if (!is_numeric($number)) {
 throw new InvalidArgumentException(’You must provide a number for the argument #’.($key+1));
 }
 $this->resultats += $number;
 }
 }

 function getResultat() {
 return $this->resultats;
 }

 }
 ?>
Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Etape 3 : Response 2

 class Calculatrice {

 protected $_result = 0;

 public function __construct() {
 }

 public function ajouter( ) {
 $numargs = func_num_args();
 if( $numargs == 0 ) {
 throw new InvalidArgumentException();
 }
 $arg_list = func_get_args();
 foreach( $arg_list as $nbr ) {
 if( !is_numeric( $nbr ) ) {
 throw new InvalidArgumentException();
 }
 $this->_result += $nbr;
 }
 }

 public function getResultat() {
 return $this->_result;
 }
 }
 ?>
Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Etape 3 : Response 3
 */

 Class Calculatrice {

 private $vResultat;
 private $vInitial;

 /**
 * Constructeur
 */
 function __construct() {
 $this->setDefaut();
 }

 /**
 * Méthode pour faire l’addition
 * @param $valeur
 */
 public function ajouter() {
 $args = func_get_args();
 $valeur = 0;

 foreach($args as $arg)
 {
 if( !is_numeric($arg) ) {
 throw new InvalidArgumentException(’Argument non valide : ’
 }
 $valeur += $arg;
 }

 $this->vResultat = $this->vInitial + $valeur;
 }

 public function getResultat() {
 $this->vInitial = $this->vResultat;
 return $this->vResultat;
 }

 /**
 * Méthode Mettre tous les valeur par defaut
 */
 public function setDefaut() {
 $this->vResultat = $this->vInitial = 0;
 }

 }

 ?>
Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Etape 4 : soustraire
 public function testSoustraire()
 {
 $this->calc->soustraire(4);
 $this->assertEquals(-4,$this->calc->getResultat());
 }

 /**
 * @expectedException InvalidArgumentException
 */
 public function testValeurNumeriqueSoustraction()
 {
 $this->calc->soustraire(’bonjour’);
 }

 public function testSoustrairePlusieursValeurs()
 {
 $this->calc->soustraire(4,2);
 $this->assertEquals(-6,$this->calc->getResultat());
 }
 }

 ?>
Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Etape 4 : Response 1

 class Calculatrice {
 const ERROR_VAL_NOT_NUMERIC = "La valeur à ajouter n’est pas numérique";

 private $resultat;


 function __construct ()
 {
 $this->resultat = 0;
 }


 public function getResultat()
 {
 return $this->resultat;
 }


 public function ajouter()
 {
 foreach(func_get_args() as $nombre){
 if (!is_numeric($nombre)) {
 throw new InvalidArgumentException(self::ERROR_VAL_NOT_NUMERIC);
 }
 else {
 $this->resultat += $nombre;
 }
 }
 }


 public function soustraire()
 {
 foreach(func_get_args() as $nombre){
 if (!is_numeric($nombre)) {
 throw new InvalidArgumentException(self::ERROR_VAL_
 }
 else {
 $this->resultat -= $nombre;
 }
 }
 }


 }

 ?>
Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Etape 4 : Response 2

 class Calculatrice {

 private $resultats;

 function __construct() {
 $this->resultats = 0;
 }

 function getResultat() {
 return $this->resultats;
 }

 function operate($numberList, $operation) {
 foreach ($numberList as $key => $number) {
 if (!is_numeric($number)) {
 throw new InvalidArgumentException(’You must provide a number for the argument #’.($key+1));
 }
 switch ($operation) {
 case ’add’:
 $this->resultats += $number;
 break;
 case ’rem’:
 $this->resultats -= $number;
 break;
 }
 }
 }

 function ajouter() {
 call_user_func_array(array($this, "operate"), array(func_get_a
 }

 function soustraire() {
 call_user_func_array(array($this, "operate"), array(func_get_a
 }

 }
 ?>
Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Etape 4 : Response 3

 class Calculatrice {

 private $resultat;

 function __construct() {
 $this->resultat = 0;
 }

 // Effectue l’opération $operation pour chacun des arguments $args
 private function effectuerOperation( $operation, $args ) {
 foreach( $args as $num ) {
 if (!is_numeric($num)) {
 throw new InvalidArgumentException(’"’ . $num . ’" n’est pas de type numérique.’);
 }
 $this->$operation($num);
 }
 }

 /*************************************************
 * OPERATIONS
 *************************************************/

 private function addition( $num ) {
 $this->resultat += $num;
 }

 private function soustraction( $num ) {
 $this->resultat -= $num;
 }


 /*************************************************
 * INTERFACE
 *************************************************/

 public function ajouter() {
 $this->effectuerOperation( ’addition’, func_get_args() );
 }

 public function soustraire() {
 $this->effectuerOperation( ’soustraction’, func_get_args() );
 }

 public function getResultat() {
 return $this->resultat;
 }

 }

 ?>
Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Etape 5 : InitResultat
 {
 $this->calc->soustraire(’bonjour’);
 }

 public function testSoustrairePlusieursValeurs()
 {
 $this->calc->soustraire(4,2);
 $this->assertEquals(-6,$this->calc->getResultat());
 }

 public function testInitResultat()
 {
 $this->assertEquals(4,$this->calc->initResultat(4));
 }
 }

 ?>
Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Etape 6 : Test Resultat Apres Init
 }

 public function testResultatApresInit()
 {
 $this->calc->initResultat(6);
 $this->assertEquals(6,$this->calc->getResultat());
 }
 }

 ?>
Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Niveau Bonus
Toujours TDD
Refactoring ?
Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Un bilan ? ? ?
TDD c’est bien ?
TDD c’est facile ?
Mauvais / Bon coding ? ? ? ?
Il ne faut pas aller trop et/ou pas assez loin (pas
toujours)
Le refactoring ?
CodeToTrash ?
BabyTask ?
guard ? qui ?
Bilan du jeux de
coding
C. Brun
<christophe.brun.c
Introduction
Etape1 : Sujet
Classe + Ajouter
Etape 2 :
Exception
Etape 3 :
Ajouter plusieurs
valeurs
Etape 4 :
Soustraction
Etape 5 :
InitResultat
Etape 6 : Test
Résultat Après
Init
Ultimate
Bilan
Et Maintenant

Contenu connexe

En vedette

Global Services - Outlook 2012 issue
Global Services - Outlook 2012 issueGlobal Services - Outlook 2012 issue
Global Services - Outlook 2012 issuedivination55555
 
Egypt - Outsourcing Destination
Egypt - Outsourcing DestinationEgypt - Outsourcing Destination
Egypt - Outsourcing Destinationdivination55555
 
Flinter Aland proefvaart 8-6-2011
Flinter Aland proefvaart 8-6-2011Flinter Aland proefvaart 8-6-2011
Flinter Aland proefvaart 8-6-2011Flinter
 
Printwell design theme 2
Printwell design theme 2Printwell design theme 2
Printwell design theme 2Kelly Callender
 
Move it or lose it: Getting people to care about personal data
Move it or lose it: Getting people to care about personal dataMove it or lose it: Getting people to care about personal data
Move it or lose it: Getting people to care about personal dataNicholas Oliver
 
2012 Global Services Compendium - GS100
2012 Global Services Compendium - GS1002012 Global Services Compendium - GS100
2012 Global Services Compendium - GS100divination55555
 
Philippines - Outsourcing Destination
Philippines - Outsourcing DestinationPhilippines - Outsourcing Destination
Philippines - Outsourcing Destinationdivination55555
 
WIP’s First 40 years
WIP’s First 40 yearsWIP’s First 40 years
WIP’s First 40 yearswipny
 
Valunique Research blog
Valunique Research blogValunique Research blog
Valunique Research blogNiels Visser
 
Lila flash cards ch4
Lila flash cards ch4Lila flash cards ch4
Lila flash cards ch4Duane March
 
Some key words related to EED
Some key words related to EEDSome key words related to EED
Some key words related to EEDHk Sarawgi
 
Object Oriented Sushi(オブジェクト指向寿司)
Object Oriented Sushi(オブジェクト指向寿司)Object Oriented Sushi(オブジェクト指向寿司)
Object Oriented Sushi(オブジェクト指向寿司)Irie Taichi
 
En_De_Lektion_01
En_De_Lektion_01En_De_Lektion_01
En_De_Lektion_01Duane March
 
Lila flash cards ch4
Lila flash cards ch4Lila flash cards ch4
Lila flash cards ch4Duane March
 

En vedette (20)

Free ridegamesPPT
Free ridegamesPPTFree ridegamesPPT
Free ridegamesPPT
 
Unizo Presentatie 6/10/2011
Unizo Presentatie 6/10/2011Unizo Presentatie 6/10/2011
Unizo Presentatie 6/10/2011
 
Global Services - Outlook 2012 issue
Global Services - Outlook 2012 issueGlobal Services - Outlook 2012 issue
Global Services - Outlook 2012 issue
 
Egypt - Outsourcing Destination
Egypt - Outsourcing DestinationEgypt - Outsourcing Destination
Egypt - Outsourcing Destination
 
Flinter Aland proefvaart 8-6-2011
Flinter Aland proefvaart 8-6-2011Flinter Aland proefvaart 8-6-2011
Flinter Aland proefvaart 8-6-2011
 
Printwell design theme 2
Printwell design theme 2Printwell design theme 2
Printwell design theme 2
 
Cg sketchpad design
Cg sketchpad designCg sketchpad design
Cg sketchpad design
 
Move it or lose it: Getting people to care about personal data
Move it or lose it: Getting people to care about personal dataMove it or lose it: Getting people to care about personal data
Move it or lose it: Getting people to care about personal data
 
2012 Global Services Compendium - GS100
2012 Global Services Compendium - GS1002012 Global Services Compendium - GS100
2012 Global Services Compendium - GS100
 
Philippines - Outsourcing Destination
Philippines - Outsourcing DestinationPhilippines - Outsourcing Destination
Philippines - Outsourcing Destination
 
Technology update
Technology updateTechnology update
Technology update
 
WIP’s First 40 years
WIP’s First 40 yearsWIP’s First 40 years
WIP’s First 40 years
 
Valunique Research blog
Valunique Research blogValunique Research blog
Valunique Research blog
 
Lila flash cards ch4
Lila flash cards ch4Lila flash cards ch4
Lila flash cards ch4
 
Some key words related to EED
Some key words related to EEDSome key words related to EED
Some key words related to EED
 
Object Oriented Sushi(オブジェクト指向寿司)
Object Oriented Sushi(オブジェクト指向寿司)Object Oriented Sushi(オブジェクト指向寿司)
Object Oriented Sushi(オブジェクト指向寿司)
 
GS100 Compendium 2011
GS100 Compendium 2011GS100 Compendium 2011
GS100 Compendium 2011
 
En_De_Lektion_01
En_De_Lektion_01En_De_Lektion_01
En_De_Lektion_01
 
Hat’s story
Hat’s storyHat’s story
Hat’s story
 
Lila flash cards ch4
Lila flash cards ch4Lila flash cards ch4
Lila flash cards ch4
 

Similaire à Bilan jeux TDD php

Tableau objetjava
Tableau objetjavaTableau objetjava
Tableau objetjavaMoez Moezm
 
Déployer avec les tests
Déployer avec les testsDéployer avec les tests
Déployer avec les testsneuros
 
Meet up symfony 11 octobre 2016 - Les formulaire
Meet up symfony 11 octobre 2016 - Les formulaireMeet up symfony 11 octobre 2016 - Les formulaire
Meet up symfony 11 octobre 2016 - Les formulaireJulien Vinber
 
TP2 Atelier C++/ GL2 INSAT / Tunisie
TP2 Atelier C++/ GL2 INSAT / TunisieTP2 Atelier C++/ GL2 INSAT / Tunisie
TP2 Atelier C++/ GL2 INSAT / TunisieMariem ZAOUALI
 
Chap 2--POO avec JAVA.pdf
Chap 2--POO avec JAVA.pdfChap 2--POO avec JAVA.pdf
Chap 2--POO avec JAVA.pdframadanmahdi
 
Cours de C++ / Tronc commun deuxième année ISIMA
Cours de C++ / Tronc commun deuxième année ISIMACours de C++ / Tronc commun deuxième année ISIMA
Cours de C++ / Tronc commun deuxième année ISIMALoic Yon
 
Python avancé : Gestion d'erreurs et mécanisme d'exception
Python avancé : Gestion d'erreurs et mécanisme d'exceptionPython avancé : Gestion d'erreurs et mécanisme d'exception
Python avancé : Gestion d'erreurs et mécanisme d'exceptionECAM Brussels Engineering School
 

Similaire à Bilan jeux TDD php (7)

Tableau objetjava
Tableau objetjavaTableau objetjava
Tableau objetjava
 
Déployer avec les tests
Déployer avec les testsDéployer avec les tests
Déployer avec les tests
 
Meet up symfony 11 octobre 2016 - Les formulaire
Meet up symfony 11 octobre 2016 - Les formulaireMeet up symfony 11 octobre 2016 - Les formulaire
Meet up symfony 11 octobre 2016 - Les formulaire
 
TP2 Atelier C++/ GL2 INSAT / Tunisie
TP2 Atelier C++/ GL2 INSAT / TunisieTP2 Atelier C++/ GL2 INSAT / Tunisie
TP2 Atelier C++/ GL2 INSAT / Tunisie
 
Chap 2--POO avec JAVA.pdf
Chap 2--POO avec JAVA.pdfChap 2--POO avec JAVA.pdf
Chap 2--POO avec JAVA.pdf
 
Cours de C++ / Tronc commun deuxième année ISIMA
Cours de C++ / Tronc commun deuxième année ISIMACours de C++ / Tronc commun deuxième année ISIMA
Cours de C++ / Tronc commun deuxième année ISIMA
 
Python avancé : Gestion d'erreurs et mécanisme d'exception
Python avancé : Gestion d'erreurs et mécanisme d'exceptionPython avancé : Gestion d'erreurs et mécanisme d'exception
Python avancé : Gestion d'erreurs et mécanisme d'exception
 

Bilan jeux TDD php

  • 1. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Bilan du jeux de coding C. Brun <christophe.brun.cl194@gadz.org> Perso Septembre 2013
  • 2. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Sommaire Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan
  • 3. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Introduction I But du jeux Introduction au TDD Voir votre comportement sans spécifications Voir votre façon de coder Bilan Confronter les résultats de chacun (anonyme) Réagir Evoluer
  • 4. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Etape 1 : Sujet Classe + Ajouter   class CalculatriceTest extends PHPUnit_Framework_TestCase {  public function testInstances()  {  new Calculatrice;  }   public function testResultatDefaultsZero()  {  $calc = new Calculatrice;  $this->assertSame(0,$calc->getResultat());  }   public function testAjouterNombre()  {  $calc = new Calculatrice;  $calc->ajouter(2);  $this->assertEquals(2,$calc->getResultat());  }  }  ?>
  • 5. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Etape 1 : Reponse 1   class Calculatrice {  private $resultat = 0;   public function getResultat()  {  return $this->resultat;  }   public function ajouter($nombre)  {  $this->resultat=2;  }  }  ?>
  • 6. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Etape 1 : Reponse 2  class Calculatrice {   private $resultats = 0;   function __construct() {  $this->resultats = 0;  }   function ajouter($nb) {  $this->resultats += $nb;  }   function getResultat() {  return $this->resultats;  }  }  ?>
  • 7. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Etape 1 : Reponse 3   class Calculatrice {   protected $_result = 0;   public function __construct() {  }   public function ajouter( $nbr ) {  $this->_result += intval( $nbr );  }   public function getResultat() {  return $this->_result;  }  }  ?>
  • 8. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Etape 1 : Reponse 4  class Calculatrice {   var $resultat;   function Calculatrice() {  $this->resultat = 0;  }   public function ajouter( $num ) {  if (!is_numeric($num)) {  throw new Exception(’"’ . $num . ’" n’est pas de type numérique.’);  }  $this->resultat += $num;  }   public function getResultat() {  return $this->resultat;  }   }   ?>
  • 9. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Etape 1 : Reponse 5  class Calculatrice {   public function __construct() {  $this->Result = 0;  }   public function getResultat() {  return $this->Result;  }    /*  * PRIVATE  */   private function calculer( $signe, $nb ) {  $this->Result = $this->Result . $signe . $nb;  }    /*  * OPERATION  */   public function ajouter( $nb ) {  $nb = isset( $nb ) ? $nb : $this->Result;  self::calculer( (int)’+’, $nb );  }   }  ?>
  • 10. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Etape 1 : Reponse 6  Class Calculatrice {   private $vResultat;  private $vInitial;   /**  * Constructeur  */  function __construct() {  $this->setDefaut();  }   /**  * Méthode pour faire l’addition  * @param $valeur  */  public function ajouter($valeur) {  $this->vResultat = $this->vInitial + $valeur;  }   /**  * Méthode pour faire la soustraction  * @param $valeur  */  public function suprimer($valeur) {  $this->vResultat = $this->vInitial - $valeur;  }   /**  * Méthode pour faire la multiplication  * @param $valeur  */  public function multiplier($valeur) {  $this->vResultat = $this->vInitial * $valeur;  }   /**  * Méthode pour faire la division  * @param $valeur  */  public function diviser($valeur) {  $this->vResultat = $this->vInitial / $valeur;  }   /**  * Méthode pour faire la puissance 2  * @param $valeur  */  public function exposant2($valeur) {  $this->vResultat = $valeur * $valeur;  } 
  • 11. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Etape 2 : Exception  public function testAjouterNombre()  {  $calc = new Calculatrice;  $calc->ajouter(2);  $this->assertEquals(2,$calc->getResultat());  }   /**  * @expectedException InvalidArgumentException  */  public function testValeurNumerique()  {  $calc = new Calculatrice;  $calc->ajouter(’un chiffre’);  }  }  ?>
  • 12. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Etape 2 : Reponse 1   class Calculatrice {  private $resultat = 0;   public function getResultat()  {  return $this->resultat;  }   public function ajouter($nombre)  {  if ($nombre == ’un chiffre’)  throw new InvalidArgumentException;  $this->resultat=2;  }  }  ?>
  • 13. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Etape 2 : Response 2  class Calculatrice {   private $resultats;   function __construct() {  $this->resultats = 0;  }   function ajouter($nb) {  if (!is_numeric($nb)) {  throw new InvalidArgumentException(’You must give a numeric.’);  }  $this->resultats += $nb;  }   function getResultat() {  return $this->resultats;  }   }  ?>
  • 14. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Etape 2 : Response 3  */   Class Calculatrice {   private $vResultat;  private $vInitial;   /**  * Constructeur  */  function __construct() {  $this->setDefaut();  }   /**  * Méthode pour faire l’addition  * @param $valeur  */  public function ajouter($valeur) {  if( !is_numeric($valeur) )  throw new InvalidArgumentException(’Argument non valide : ’  $this->vResultat = $this->vInitial + $valeur;  }   public function getResultat() {  $this->vInitial = $this->vResultat;  return $this->vResultat;  }   /**  * Méthode Mettre tous les valeur par defaut  */  public function setDefaut() {  $this->vResultat = $this->vInitial = 0;  }   }   ?>
  • 15. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Etape 3 : Ajouter plusieurs valeurs  /**  * @expectedException InvalidArgumentException  */  public function testValeurNumerique()  {  $calc = new Calculatrice;  $calc->ajouter(’un chiffre’);  }   public function testAjouterPlusieursValeurs()  {  $calc = new Calculatrice;  $calc->ajouter(1,2,3,4,5);  $this->assertEquals(15,$calc->getResultat());  }  }   ?>
  • 16. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Etape 3 : Response 1  class Calculatrice {   private $resultats;   function __construct() {  $this->resultats = 0;  }   function ajouter() {  $numberList = func_get_args();  foreach ($numberList as $key => $number) {  if (!is_numeric($number)) {  throw new InvalidArgumentException(’You must provide a number for the argument #’.($key+1));  }  $this->resultats += $number;  }  }   function getResultat() {  return $this->resultats;  }   }  ?>
  • 17. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Etape 3 : Response 2   class Calculatrice {   protected $_result = 0;   public function __construct() {  }   public function ajouter( ) {  $numargs = func_num_args();  if( $numargs == 0 ) {  throw new InvalidArgumentException();  }  $arg_list = func_get_args();  foreach( $arg_list as $nbr ) {  if( !is_numeric( $nbr ) ) {  throw new InvalidArgumentException();  }  $this->_result += $nbr;  }  }   public function getResultat() {  return $this->_result;  }  }  ?>
  • 18. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Etape 3 : Response 3  */   Class Calculatrice {   private $vResultat;  private $vInitial;   /**  * Constructeur  */  function __construct() {  $this->setDefaut();  }   /**  * Méthode pour faire l’addition  * @param $valeur  */  public function ajouter() {  $args = func_get_args();  $valeur = 0;   foreach($args as $arg)  {  if( !is_numeric($arg) ) {  throw new InvalidArgumentException(’Argument non valide : ’  }  $valeur += $arg;  }   $this->vResultat = $this->vInitial + $valeur;  }   public function getResultat() {  $this->vInitial = $this->vResultat;  return $this->vResultat;  }   /**  * Méthode Mettre tous les valeur par defaut  */  public function setDefaut() {  $this->vResultat = $this->vInitial = 0;  }   }   ?>
  • 19. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Etape 4 : soustraire  public function testSoustraire()  {  $this->calc->soustraire(4);  $this->assertEquals(-4,$this->calc->getResultat());  }   /**  * @expectedException InvalidArgumentException  */  public function testValeurNumeriqueSoustraction()  {  $this->calc->soustraire(’bonjour’);  }   public function testSoustrairePlusieursValeurs()  {  $this->calc->soustraire(4,2);  $this->assertEquals(-6,$this->calc->getResultat());  }  }   ?>
  • 20. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Etape 4 : Response 1   class Calculatrice {  const ERROR_VAL_NOT_NUMERIC = "La valeur à ajouter n’est pas numérique";   private $resultat;    function __construct ()  {  $this->resultat = 0;  }    public function getResultat()  {  return $this->resultat;  }    public function ajouter()  {  foreach(func_get_args() as $nombre){  if (!is_numeric($nombre)) {  throw new InvalidArgumentException(self::ERROR_VAL_NOT_NUMERIC);  }  else {  $this->resultat += $nombre;  }  }  }    public function soustraire()  {  foreach(func_get_args() as $nombre){  if (!is_numeric($nombre)) {  throw new InvalidArgumentException(self::ERROR_VAL_  }  else {  $this->resultat -= $nombre;  }  }  }    }   ?>
  • 21. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Etape 4 : Response 2   class Calculatrice {   private $resultats;   function __construct() {  $this->resultats = 0;  }   function getResultat() {  return $this->resultats;  }   function operate($numberList, $operation) {  foreach ($numberList as $key => $number) {  if (!is_numeric($number)) {  throw new InvalidArgumentException(’You must provide a number for the argument #’.($key+1));  }  switch ($operation) {  case ’add’:  $this->resultats += $number;  break;  case ’rem’:  $this->resultats -= $number;  break;  }  }  }   function ajouter() {  call_user_func_array(array($this, "operate"), array(func_get_a  }   function soustraire() {  call_user_func_array(array($this, "operate"), array(func_get_a  }   }  ?>
  • 22. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Etape 4 : Response 3   class Calculatrice {   private $resultat;   function __construct() {  $this->resultat = 0;  }   // Effectue l’opération $operation pour chacun des arguments $args  private function effectuerOperation( $operation, $args ) {  foreach( $args as $num ) {  if (!is_numeric($num)) {  throw new InvalidArgumentException(’"’ . $num . ’" n’est pas de type numérique.’);  }  $this->$operation($num);  }  }   /*************************************************  * OPERATIONS  *************************************************/   private function addition( $num ) {  $this->resultat += $num;  }   private function soustraction( $num ) {  $this->resultat -= $num;  }    /*************************************************  * INTERFACE  *************************************************/   public function ajouter() {  $this->effectuerOperation( ’addition’, func_get_args() );  }   public function soustraire() {  $this->effectuerOperation( ’soustraction’, func_get_args() );  }   public function getResultat() {  return $this->resultat;  }   }   ?>
  • 23. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Etape 5 : InitResultat  {  $this->calc->soustraire(’bonjour’);  }   public function testSoustrairePlusieursValeurs()  {  $this->calc->soustraire(4,2);  $this->assertEquals(-6,$this->calc->getResultat());  }   public function testInitResultat()  {  $this->assertEquals(4,$this->calc->initResultat(4));  }  }   ?>
  • 24. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Etape 6 : Test Resultat Apres Init  }   public function testResultatApresInit()  {  $this->calc->initResultat(6);  $this->assertEquals(6,$this->calc->getResultat());  }  }   ?>
  • 25. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Niveau Bonus Toujours TDD Refactoring ?
  • 26. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Un bilan ? ? ? TDD c’est bien ? TDD c’est facile ? Mauvais / Bon coding ? ? ? ? Il ne faut pas aller trop et/ou pas assez loin (pas toujours) Le refactoring ? CodeToTrash ? BabyTask ? guard ? qui ?
  • 27. Bilan du jeux de coding C. Brun <christophe.brun.c Introduction Etape1 : Sujet Classe + Ajouter Etape 2 : Exception Etape 3 : Ajouter plusieurs valeurs Etape 4 : Soustraction Etape 5 : InitResultat Etape 6 : Test Résultat Après Init Ultimate Bilan Et Maintenant