Torna indietro   Hardware Upgrade Forum > Software > Programmazione

Ecovacs Goat O1200 LiDAR Pro: la prova del robot tagliaerba con tagliabordi integrato
Ecovacs Goat O1200 LiDAR Pro: la prova del robot tagliaerba con tagliabordi integrato
Nuova frontiera per i robot tagliaerba, con Ecovacs GOAT O1200 LiDAR Pro che riconosce l'ambiente in maniera perfetta, grazie a due sensori LiDAR, e dopo la falciatura può anche rifinire il bordo con il tagliabordi a filo integrato
Recensione Samsung Galaxy S26+: sfida l'Ultra, ma ha senso di esistere?
Recensione Samsung Galaxy S26+: sfida l'Ultra, ma ha senso di esistere?
Equilibrio e potenza definiscono il Samsung Galaxy S26+, un flagship che sfida la variante Ultra e la fascia alta del mercato con il primo processore mobile a 2nm. Pur mantenendo l'hardware fotografico precedente, lo smartphone brilla per un display QHD+ da 6,7 pollici d'eccellenza, privo però del trattamento antiriflesso dell'Ultra, e per prestazioni molto elevate. Completano il quadro la ricarica wireless a 20W e, soprattutto, un supporto software settennale
Zeekr X e 7X provate: prezzi, autonomia fino a 615 km e ricarica in 13 minuti
Zeekr X e 7X provate: prezzi, autonomia fino a 615 km e ricarica in 13 minuti
Zeekr sbarca ufficialmente in Italia con tre modelli elettrici premium, X, 7X e 001, distribuiti da Jameel Motors su una rete di 52 punti vendita già attivi. La Zeekr X parte da 39.900 euro, la 7X da 54.100: piattaforma a 800V, chip Snapdragon di ultima generazione, ricarica ultraveloce e un'autonomia dichiarata fino a 615 km WLTP. Le prime consegne sono previste a metà aprile
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


Ecovacs Goat O1200 LiDAR Pro: la prova del robot tagliaerba con tagliabordi integrato Ecovacs Goat O1200 LiDAR Pro: la prova del robot...
Recensione Samsung Galaxy S26+: sfida l'Ultra, ma ha senso di esistere? Recensione Samsung Galaxy S26+: sfida l'Ultra, m...
Zeekr X e 7X provate: prezzi, autonomia fino a 615 km e ricarica in 13 minuti Zeekr X e 7X provate: prezzi, autonomia fino a 6...
Marathon: arriva il Fortnite hardcore Marathon: arriva il Fortnite hardcore
HP Imagine 2026: abbiamo visto HP IQ all’opera, ecco cosa può (e non può) fare HP Imagine 2026: abbiamo visto HP IQ all’opera, ...
Le 10 migliori offerte Amazon di Pasqua:...
Nuove fotografie dagli astronauti di Art...
La toilette della capsula Orion Integrit...
GeForce NOW: ecco tutte le novità in arr...
Il Realme 16 5G debutta sul mercato glob...
HONOR svela tre nuovi tablet: il più int...
Tineco Floor One S9 Master: aspira e pul...
Vivo X300 Ultra, il lancio globale è ini...
Offerte robot aspirapolvere Amazon: ECOV...
L'AI genera codice in 8 minuti e i senio...
Ring Intercom Audio a 44,99€ su Amazon: ...
Apple iPhone 16 crolla a 689€: ecco perc...
Google Pixel 9 a 449,90€ con caricatore ...
Ecco la top 7 delle offerte Amazon, aggi...
Ex ingegnere ammette il sabotaggio: migl...
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: 23:05.


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