Torna indietro   Hardware Upgrade Forum > Software > Programmazione

realme 16 Pro Harry Potter Edition: il nuovo midrange ha uno stemma di Hogwarts che cambia colore al sole!
realme 16 Pro Harry Potter Edition: il nuovo midrange ha uno stemma di Hogwarts che cambia colore al sole!
Hogwarts arriva in fascia media grazie a realme, con una special edition che unisce la Quadra Light-Sensing Color-changing Tech, un baule in stile Hogwarts Express pieno di collezionabili e una scheda tecnica sostanzialmente identica al 16 Pro di partenza: ecco cosa cambia davvero, come si comporta nell'uso quotidiano e quanto vale in base al prezzo di 699,99 euro
Recensione REDMI Note 17 Pro: il midrange con batteria da 8.340 mAh e ricarica veloce
Recensione REDMI Note 17 Pro: il midrange con batteria da 8.340 mAh e ricarica veloce
REDMI Note 17 Pro porta in fascia media una batteria da 8.340 mAh con ricarica HyperCharge a 67W, un display AMOLED da 6,83 pollici capace di picchi di luminosità molto elevati e una struttura certificata TÜV SÜD contro cadute e infiltrazioni d'acqua, il tutto racchiuso in una scocca da 223 grammi. Lo abbiamo provato per diversi giorni tra fotocamera, prestazioni, autonomia e prezzo sul mercato italiano
Insta360 Luna Ultra: la potenza del sensore da 1 pollice incontra la portabilità estrema
Insta360 Luna Ultra: la potenza del sensore da 1 pollice incontra la portabilità estrema
Insta360 Luna Ultra integra un sensore da 1 pollice 8K, ottiche Leica e triplo chip IA. Tra schermo OLED rimovibile, workflow I-Log a 10 bit e stabilizzazione a tre assi, analizziamo le doti tecniche di una gimbal camera pensata per i professionisti
Tutti gli articoli Tutte le news

Vai al Forum
Rispondi
 
Strumenti
Old 11-01-2006, 20:49   #1
fek
Senior Member
 
L'Avatar di fek
 
Iscritto dal: Oct 2002
Città: San Jose, California
Messaggi: 11794
[TASK 8.2.3] Pair Programming: Fek vs Jappilas (The Yooung Padawan)

Questo e' il task:

8.2.3:
Modificare bagofgem in modo che il punteggio delle gemme che fanno parte di un gruppo sia moltiplicato per un Bonus. Il valore del bonus deve essere modificabile da GameConfig.xml


Prima la lista di test:

- Aggiunta di una gem con bonus
- Rimozione di una gem con bonus
- Calcolo del punteggio totale, passando il bonus attraverso il costruttore
fek è offline   Rispondi citando il messaggio o parte di esso
Old 11-01-2006, 21:04   #2
fek
Senior Member
 
L'Avatar di fek
 
Iscritto dal: Oct 2002
Città: San Jose, California
Messaggi: 11794
Ed ecco il primo test:

Codice:
package it.diamonds.tests;

import it.diamonds.gems.BagOfGems;
import it.diamonds.gems.Gem;
import junit.framework.TestCase;

public class TestBagOfGems extends TestCase
{
 
    public void testAddGemWithBonus()
    {
        BagOfGems bag = new BagOfGems();
        
        bag.addGemWithBonus(Gem.diamond(0));
        assertAreEqual(1, bag.getNumberOfGemsWithBonus());
    }

}
Il codice minimo che lo faccia passare
fek è offline   Rispondi citando il messaggio o parte di esso
Old 11-01-2006, 21:54   #3
jappilas
Senior Member
 
L'Avatar di jappilas
 
Iscritto dal: Apr 2003
Città: Genova
Messaggi: 4747
aggiunti due metodi in BagOfGems.java:
Codice:
    public void addGemWithBonus(Gem gem)
    {
        // TODO Auto-generated method stub        
    }


    public int getNumberOfGemsWithBonus()
    {
        return 1;
    }
implementazioni minime, rispettando il comandamento "make it simple, stupid"

green bar
__________________
Jappilas is a character created by a friend for his own comic - I feel honored he allowed me to bear his name
Saber's true name belongs to myth - a Heroic Soul out of legends, fighting in our time to fullfill her only wish
Let her image remind of her story, and of the emotions that flew from my heart when i assisted to her Fate

Ultima modifica di jappilas : 12-01-2006 alle 15:23.
jappilas è offline   Rispondi citando il messaggio o parte di esso
Old 11-01-2006, 22:32   #4
fek
Senior Member
 
L'Avatar di fek
 
Iscritto dal: Oct 2002
Città: San Jose, California
Messaggi: 11794
Ci aggiorniamo a domani sera.
fek è offline   Rispondi citando il messaggio o parte di esso
Old 11-01-2006, 22:33   #5
jappilas
Senior Member
 
L'Avatar di jappilas
 
Iscritto dal: Apr 2003
Città: Genova
Messaggi: 4747
spero di aver ammansito la formica errante per allora...

( per chi si stesse chiedendo di che parlo, Ant che fa un po' i capricci per come è configurato il mio environment... )
__________________
Jappilas is a character created by a friend for his own comic - I feel honored he allowed me to bear his name
Saber's true name belongs to myth - a Heroic Soul out of legends, fighting in our time to fullfill her only wish
Let her image remind of her story, and of the emotions that flew from my heart when i assisted to her Fate
jappilas è offline   Rispondi citando il messaggio o parte di esso
Old 12-01-2006, 20:07   #6
jappilas
Senior Member
 
L'Avatar di jappilas
 
Iscritto dal: Apr 2003
Città: Genova
Messaggi: 4747
Update: la Formica ( ) è stata ammansita e il build process è successful anche sulla mia macchina, grazie alle direttive di Francesco (colgo l' occasione per ringraziarlo sinceramente della pazienza e del tempo che mi dedica ultimamente)

i prossimi test e relativi fix nel flusso di sviluppo TDD, arriveranno presto
__________________
Jappilas is a character created by a friend for his own comic - I feel honored he allowed me to bear his name
Saber's true name belongs to myth - a Heroic Soul out of legends, fighting in our time to fullfill her only wish
Let her image remind of her story, and of the emotions that flew from my heart when i assisted to her Fate
jappilas è offline   Rispondi citando il messaggio o parte di esso
Old 14-01-2006, 13:52   #7
fek
Senior Member
 
L'Avatar di fek
 
Iscritto dal: Oct 2002
Città: San Jose, California
Messaggi: 11794
Ecco il prossimo test:

Codice:
    public void testAddTwoGemsWithBonus()
    {
        BagOfGems bag = new BagOfGems();
        
        bag.addGemWithBonus(Gem.diamond(0));
        bag.addGemWithBonus(Gem.diamond(0));        
        
        assertEquals(2, bag.getNumberOfGemsWithBonus());
    }
fek è offline   Rispondi citando il messaggio o parte di esso
Old 14-01-2006, 15:11   #8
jappilas
Senior Member
 
L'Avatar di jappilas
 
Iscritto dal: Apr 2003
Città: Genova
Messaggi: 4747
dichiarata
Codice:
    private int gemsWithBonus;
e modificate le funzioni precedentemente aggiunte:
Codice:
    public void addGemWithBonus(Gem gem)
    {
        gemsWithBonus ++ ;        
    }


    public int getNumberOfGemsWithBonus()
    {
        int tempValue = gemsWithBonus;
        gemsWithBonus =0;
        return tempValue;
    }
per la seconda, so che potrebbe esistere codice più semplice, ma ho fatto prima a digitare questo che non a cancellarlo e pensare in modo diverso...


green bar
__________________
Jappilas is a character created by a friend for his own comic - I feel honored he allowed me to bear his name
Saber's true name belongs to myth - a Heroic Soul out of legends, fighting in our time to fullfill her only wish
Let her image remind of her story, and of the emotions that flew from my heart when i assisted to her Fate
jappilas è offline   Rispondi citando il messaggio o parte di esso
Old 14-01-2006, 15:16   #9
fek
Senior Member
 
L'Avatar di fek
 
Iscritto dal: Oct 2002
Città: San Jose, California
Messaggi: 11794
Per prima cosa: Keep It Simple Sweety.

Questo codice fa passare tutti i test:

Codice:
    public int getNumberOfGemsWithBonus()
    {
        return gemsWithBonus;
    }
Poi ho fatto un po' di refactoring dei test perche' c'erano delle duplicazioni, ed ho aggiunto un nuovo test per testare l'aggiunta di gemme di tipo diverso:

Codice:
public class TestBagOfGems extends TestCase
{
    BagOfGems bag;
 
    public void setUp()
    {
        bag = new BagOfGems();        
    }
    
    
    public void testAddGemWithBonus()
    {
        bag.addGemWithBonus(createDiamond());
        
        assertEquals(1, bag.getNumberOfGemsWithBonus());
    }
    
    
    public void testAddTwoGemsWithBonus()
    {
        bag.addGemWithBonus(createDiamond());
        bag.addGemWithBonus(createDiamond());        
        
        assertEquals(2, bag.getNumberOfGemsWithBonus());
    }


    public void testAddTwoDifferentGemsWithBonus()
    {
        bag.addGemWithBonus(createDiamond());
        bag.addGemWithBonus(createRuby());        
        
        assertEquals(1, bag.getNumberOfGemsWithBonus(GemType.DIAMOND));
        assertEquals(1, bag.getNumberOfGemsWithBonus(GemType.RUBY));        
    }


    private Gem createRuby()
    {
        return Gem.create(GemType.RUBY, 0);
    }
    

    private Gem createDiamond()
    {
        return Gem.diamond(0);
    }    

}
Test in grassetto. A te
fek è offline   Rispondi citando il messaggio o parte di esso
Old 14-01-2006, 15:33   #10
jappilas
Senior Member
 
L'Avatar di jappilas
 
Iscritto dal: Apr 2003
Città: Genova
Messaggi: 4747
la prima versione del test aggiunto è soddisfatta da codice molto minimale
( ammetto di essermela cavata con poco )
Codice:
    public Object getNumberOfGemsWithBonus(GemType gem)
    {
        return 1;
    }
__________________
Jappilas is a character created by a friend for his own comic - I feel honored he allowed me to bear his name
Saber's true name belongs to myth - a Heroic Soul out of legends, fighting in our time to fullfill her only wish
Let her image remind of her story, and of the emotions that flew from my heart when i assisted to her Fate

Ultima modifica di jappilas : 14-01-2006 alle 15:39.
jappilas è offline   Rispondi citando il messaggio o parte di esso
Old 14-01-2006, 15:41   #11
fek
Senior Member
 
L'Avatar di fek
 
Iscritto dal: Oct 2002
Città: San Jose, California
Messaggi: 11794
Ottimo

Codice:
    public void testAddManyDifferentGemsWithBonus()
    {
        bag.addGemWithBonus(createDiamond());
        bag.addGemWithBonus(createDiamond());
        bag.addGemWithBonus(createRuby());
        bag.addGemWithBonus(createRuby());
        bag.addGemWithBonus(createSapphire());
        
        assertEquals(2, bag.getNumberOfGemsWithBonus(GemType.DIAMOND));
        assertEquals(2, bag.getNumberOfGemsWithBonus(GemType.RUBY));
        assertEquals(1, bag.getNumberOfGemsWithBonus(GemType.SAPPHIRE));
        
    }
Sta volta non te la cavi con poco
fek è offline   Rispondi citando il messaggio o parte di esso
Old 14-01-2006, 17:10   #12
jappilas
Senior Member
 
L'Avatar di jappilas
 
Iscritto dal: Apr 2003
Città: Genova
Messaggi: 4747
Quote:
Originariamente inviato da fek
Sta volta non te la cavi con poco
hai ragione, per colpa della mia scarsa pratica con la code base ho impiegato un'infinità a rivedere la barra verde
aggiunta una seconda hashmap e relativa inizializzazione nel costruttore
Codice:
 private HashMap<GemType, Integer> numberOfGemsWithBonus;
Codice:
        numberOfGemsWithBonus = new HashMap<GemType, Integer>();
        numberOfGemsWithBonus.put(EMERALD, 0);
        numberOfGemsWithBonus.put(RUBY, 0);
        numberOfGemsWithBonus.put(SAPPHIRE, 0);
        numberOfGemsWithBonus.put(TOPAZ, 0);
        numberOfGemsWithBonus.put(DIAMOND, 0);
modificate addGemWithBonus e getNumberOfGemsWithBonus
Codice:
    public void addGemWithBonus(Gem gem)
    {
        ++gemsWithBonus;  
        numberOfGemsWithBonus.put(gem.getType(), 
            numberOfGemsWithBonus.get(gem.getType()) + 1);
    }
Codice:
    public Object getNumberOfGemsWithBonus(GemType gem)
    {
        return numberOfGemsWithBonus.get(gem);    
    }
recuperare il contenuto della hashmap nella seconda, è quello che mi ha preso più tempo
con queste modifiche, all green
__________________
Jappilas is a character created by a friend for his own comic - I feel honored he allowed me to bear his name
Saber's true name belongs to myth - a Heroic Soul out of legends, fighting in our time to fullfill her only wish
Let her image remind of her story, and of the emotions that flew from my heart when i assisted to her Fate

Ultima modifica di jappilas : 17-01-2006 alle 10:17.
jappilas è offline   Rispondi citando il messaggio o parte di esso
Old 14-01-2006, 18:09   #13
fek
Senior Member
 
L'Avatar di fek
 
Iscritto dal: Oct 2002
Città: San Jose, California
Messaggi: 11794
Ed ecco il prossimo test, per la rimozione delle gemme.

Codice:
    public void testRemoveGemWithBonus()
    {
        Gem ruby = createRuby();
        
        bag.addGemWithBonus(createDiamond());
        bag.addGemWithBonus(ruby);
        bag.removeGem(ruby);
        
        assertEquals(1, bag.getNumberOfGemsWithBonus(GemType.DIAMOND));
        assertEquals(0, bag.getNumberOfGemsWithBonus(GemType.RUBY));
        assertEquals(1, bag.getNumberOfGemsWithBonus());
    }
fek è offline   Rispondi citando il messaggio o parte di esso
Old 14-01-2006, 19:29   #14
jappilas
Senior Member
 
L'Avatar di jappilas
 
Iscritto dal: Apr 2003
Città: Genova
Messaggi: 4747
aggiunto metodo removeGemWithBonus alla classe BagOfGems:
Codice:
    public void removeGemWithBonus(Gem gem)
    {
        --gemsWithBonus;
        numberOfGemsWithBonus.put(gem.getType(), numberOfGemsWithBonus.get(gem.getType()) - 1);
        
    }
green bar, build successful
__________________
Jappilas is a character created by a friend for his own comic - I feel honored he allowed me to bear his name
Saber's true name belongs to myth - a Heroic Soul out of legends, fighting in our time to fullfill her only wish
Let her image remind of her story, and of the emotions that flew from my heart when i assisted to her Fate
jappilas è offline   Rispondi citando il messaggio o parte di esso
Old 14-01-2006, 19:37   #15
fek
Senior Member
 
L'Avatar di fek
 
Iscritto dal: Oct 2002
Città: San Jose, California
Messaggi: 11794
Ed ecco l'ultimo test:

Codice:
   public void setUp()
    {
        bag = new BagOfGems(BONUS_PERCENTAGE);
    }
 
    public void testScoreWithBonus()
    {        
        bag.addGemWithBonus(createDiamond());
        bag.addGemWithBonus(createRuby());
        bag.addGem(createDiamond());
        
        assertEquals(
            GemType.DIAMOND.score() + 
            GemType.RUBY.score() * BONUS_PERCENTAGE / 100 +
            GemType.DIAMOND.score() * BONUS_PERCENTAGE / 100, 
            bag.computeTotalScore());
    }
fek è offline   Rispondi citando il messaggio o parte di esso
Old 14-01-2006, 21:11   #16
jappilas
Senior Member
 
L'Avatar di jappilas
 
Iscritto dal: Apr 2003
Città: Genova
Messaggi: 4747
modificata la computeTotalScore
Codice:
    public int computeTotalScore()
    {
        int totalScore = 0;

        for(GemType gemType : numberOfGems.keySet())
        {
            totalScore += computeScore(gemType);
        }
        for(GemType gemType : numberOfGemsWithBonus.keySet())
        {
            totalScore += computeScoreWithBonus(gemType);                        
        }
        return totalScore; 
    }
aggiunta computeScoreWithBonus, necessaria perchè adesso ho due strutture dati su cui iterare
Codice:
    private int computeScoreWithBonus(GemType gemType)
    {
	return numberOfGemsWithBonus.get(gemType) * gemType.score() 
		* gemScorePercentageBonus / 100;         
    }
il checkstyle di Ant non gradiva la replicazione di parte del codice dei costruttori quindi ho racchiuso la parte in comune in una terza funzione
Codice:
    public BagOfGems()
    {        
        mainBagConstructor();
        gemScorePercentageBonus = 100;

    }

    public BagOfGems(int bonusPercent)
    {
        mainBagConstructor();
        gemScorePercentageBonus = bonusPercent;
    }
    
    private void mainBagConstructor() 
    {   
        numberOfGems = new HashMap<GemType, Integer>();
        numberOfGems.put(EMERALD, 0);
        numberOfGems.put(RUBY, 0);
        numberOfGems.put(SAPPHIRE, 0);
        numberOfGems.put(TOPAZ, 0);
        numberOfGems.put(DIAMOND, 0);
    
        numberOfGemsWithBonus = new HashMap<GemType, Integer>();
        numberOfGemsWithBonus.put(EMERALD, 0);
        numberOfGemsWithBonus.put(RUBY, 0);
        numberOfGemsWithBonus.put(SAPPHIRE, 0);
        numberOfGemsWithBonus.put(TOPAZ, 0);
        numberOfGemsWithBonus.put(DIAMOND, 0);
    
        gemsWithBonus = 0;    
    };
green bar e build successful (pare)
__________________
Jappilas is a character created by a friend for his own comic - I feel honored he allowed me to bear his name
Saber's true name belongs to myth - a Heroic Soul out of legends, fighting in our time to fullfill her only wish
Let her image remind of her story, and of the emotions that flew from my heart when i assisted to her Fate
jappilas è offline   Rispondi citando il messaggio o parte di esso
Old 14-01-2006, 21:12   #17
fek
Senior Member
 
L'Avatar di fek
 
Iscritto dal: Oct 2002
Città: San Jose, California
Messaggi: 11794
Ed ecco il codice di BagOfGems dopo un po' di refactoring:

Codice:
package it.diamonds.gems;



import java.util.HashMap;
import static it.diamonds.gems.GemType.*;


public class BagOfGems
{
    private HashMap<GemType, Integer> numberOfGems;
    private HashMap<GemType, Integer> numberOfGemsWithBonus;
    
    final private int bonusPercentage;

    public BagOfGems(int bonusPercentage)
    {
        this.bonusPercentage = bonusPercentage;
        
        numberOfGems = new HashMap<GemType, Integer>();
        numberOfGems.put(EMERALD, 0);
        numberOfGems.put(RUBY, 0);
        numberOfGems.put(SAPPHIRE, 0);
        numberOfGems.put(TOPAZ, 0);
        numberOfGems.put(DIAMOND, 0);
    
        numberOfGemsWithBonus = new HashMap<GemType, Integer>();
        numberOfGemsWithBonus.put(EMERALD, 0);
        numberOfGemsWithBonus.put(RUBY, 0);
        numberOfGemsWithBonus.put(SAPPHIRE, 0);
        numberOfGemsWithBonus.put(TOPAZ, 0);
        numberOfGemsWithBonus.put(DIAMOND, 0);
    };
    
    
    private int computeScore(GemType gemType)
    {
        return numberOfGems.get(gemType) * gemType.score();     
    }

    
    private int computeScoreWithBonus(GemType gemType)
    {
        return numberOfGemsWithBonus.get(gemType) * gemType.score() * bonusPercentage / 100;     
    }
   

    public int computeTotalScore()
    {
        int totalScore = 0;

        for(GemType gemType : numberOfGems.keySet())
        {
            totalScore += computeScore(gemType);
        }
        
        for(GemType gemType : numberOfGemsWithBonus.keySet())
        {
            totalScore += computeScoreWithBonus(gemType);                        
        }
        
        return totalScore;
    }


    public int getNumberOfGemsWithoutBonus()
    {
        int totalNumber = 0;

        for(int value : numberOfGems.values())
        {
            totalNumber += value;
        }

        return totalNumber;
    }

    
    public int getNumberOfGemsWithBonus()
    {
        int totalNumber = 0;

        for(int value : numberOfGemsWithBonus.values())
        {
            totalNumber += value;
        }

        return totalNumber;
    }
    

    public void addGem(Gem gem)
    {
        numberOfGems.put(gem.getType(), numberOfGems.get(gem.getType()) + 1);
    }


    public void removeGem(Gem gem)
    {
        numberOfGems.put(gem.getType(), numberOfGems.get(gem.getType()) - 1);
    }


    public void addGemWithBonus(Gem gem)
    {
        numberOfGemsWithBonus.put(gem.getType(), numberOfGemsWithBonus.get(gem.getType()) + 1);
    }



    public int getNumberOfGemsWithBonus(GemType gem)
    {
        return numberOfGemsWithBonus.get(gem);    
    }
    

    public void removeGemWithBonus(Gem gem)
    {
        numberOfGemsWithBonus.put(gem.getType(), numberOfGemsWithBonus.get(gem.getType()) - 1);
    }
}
fek è offline   Rispondi citando il messaggio o parte di esso
Old 14-01-2006, 23:00   #18
jappilas
Senior Member
 
L'Avatar di jappilas
 
Iscritto dal: Apr 2003
Città: Genova
Messaggi: 4747
aggiunta una riga
Codice:
bagOfGems = new BagOfGems(config.getInteger("BonusPercentage"));
nel costruttore della classe Grid;

aggiunta la property BonusPercentage in GameConfig.xml;

task da considerare concluso ?
__________________
Jappilas is a character created by a friend for his own comic - I feel honored he allowed me to bear his name
Saber's true name belongs to myth - a Heroic Soul out of legends, fighting in our time to fullfill her only wish
Let her image remind of her story, and of the emotions that flew from my heart when i assisted to her Fate

Ultima modifica di jappilas : 15-01-2006 alle 19:30.
jappilas è offline   Rispondi citando il messaggio o parte di esso
 Rispondi


realme 16 Pro Harry Potter Edition: il nuovo midrange ha uno stemma di Hogwarts che cambia colore al sole! realme 16 Pro Harry Potter Edition: il nuovo mid...
Recensione REDMI Note 17 Pro: il midrange con batteria da 8.340 mAh e ricarica veloce Recensione REDMI Note 17 Pro: il midrange con ba...
Insta360 Luna Ultra: la potenza del sensore da 1 pollice incontra la portabilità estrema Insta360 Luna Ultra: la potenza del sensore da 1...
Marvel's Wolverine, la recensione: Logan torna protagonista in un'avventura brutale e intensa Marvel's Wolverine, la recensione: Logan torna p...
DJI Romo 2: tante novità lo rendono un robot completo DJI Romo 2: tante novità lo rendono un ro...
28 offerte Amazon da non perdere: e-bike...
'Il rapporto con Sony è rimasto f...
Vision AI Upscaling e Micro RGB AI Engin...
NVIDIA GeForce RTX 6000, anche il leaker...
In arrivo la 'pagella' per i datacenter:...
Celle perovskite-silicio al 34% grazie a...
Apple prepara il suo nuovo hub intellige...
La Cadillac Lyriq-V elettrica sbarca in ...
Amazon: arriva l'opzione per aggiungere ...
Un developer usa Claude Code per creare ...
Relativity Space annuncia i progressi ne...
Il nuovo Resident Evil supera ogni prece...
Hai appena sconfitto un boss e parte lo ...
Ray tracing anche senza montagne di VRAM...
TSMC prepara il processo a 1,4 nm: quatt...
Chromium
GPU-Z
OCCT
LibreOffice Portable
Opera One Portable
Opera One 106
CCleaner Portable
CCleaner Standard
Cpu-Z
Driver NVIDIA GeForce 546.65 WHQL
SmartFTP
Trillian
Google Chrome Portable
Google Chrome 120
VirtualBox
Tutti gli articoli Tutte le news Tutti i download

Strumenti

Regole
Non Puoi aprire nuove discussioni
Non Puoi rispondere ai messaggi
Non Puoi allegare file
Non Puoi modificare i tuoi messaggi

Il codice vB è On
Le Faccine sono On
Il codice [IMG] è On
Il codice HTML è Off
Vai al Forum


Tutti gli orari sono GMT +1. Ora sono le: 21:51.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Served by www3v