Subversion Repositories eFlore/Applications.del

Rev

Rev 210 | Rev 690 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.tela_botanica.del.test.services;

import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import junit.framework.TestCase;

import org.junit.Test;
import org.tela_botanica.del.client.modeles.MoyenneVote;
import org.tela_botanica.del.client.modeles.PropositionDetermination;
import org.tela_botanica.del.client.modeles.VoteDetermination;
import org.tela_botanica.del.client.services.CalculVoteDeterminationService;

public class CalculVoteDeterminationServiceTest {

        @Test
        public void testCalculerVoteDetermination() {

                VoteDetermination voteDetermination = new VoteDetermination();
                voteDetermination.setVote(1);
                voteDetermination.setDate(new Date());
                voteDetermination.setContributeur("benjamin");

                PropositionDetermination propositionDetermination = new PropositionDetermination();
                propositionDetermination.setEspece("Iris lutescens subsp. lutescens");
                propositionDetermination.setContributeur("contributeur test");
                propositionDetermination.setId("1");
                propositionDetermination.ajouterVoteDetermination(voteDetermination);

                MoyenneVote moyenneVote = CalculVoteDeterminationService
                                .calculerVoteDetermination(propositionDetermination);

                assertTrue(moyenneVote.getScore() == 100);

        }
        
        @Test
        public void testCalculerVoteDeterminationPlusPopulaire() {

                VoteDetermination voteDetermination1 = new VoteDetermination();
                voteDetermination1.setVote(1);
                voteDetermination1.setDate(new Date());
                voteDetermination1.setContributeur("benjamin");
                
                VoteDetermination voteDetermination2 = new VoteDetermination();
                voteDetermination2.setVote(1);
                voteDetermination2.setDate(new Date());
                voteDetermination2.setContributeur("aurelien");
                
                VoteDetermination voteDetermination3 = new VoteDetermination();
                voteDetermination3.setVote(0);
                voteDetermination3.setDate(new Date());
                voteDetermination3.setContributeur("benjamin");
                
                VoteDetermination voteDetermination4 = new VoteDetermination();
                voteDetermination3.setVote(0);
                voteDetermination3.setDate(new Date());
                voteDetermination3.setContributeur("benjamin");
                
                VoteDetermination voteDetermination5 = new VoteDetermination();
                voteDetermination4.setVote(1);
                voteDetermination4.setDate(new Date());
                voteDetermination4.setContributeur("benjamin");

                PropositionDetermination propositionDetermination = new PropositionDetermination();
                propositionDetermination.setEspece("Iris lutescens subsp. lutescens");
                propositionDetermination.setContributeur("contributeur test");
                propositionDetermination.setId("1");
                propositionDetermination.ajouterVoteDetermination(voteDetermination1);
                propositionDetermination.ajouterVoteDetermination(voteDetermination2);
                propositionDetermination.ajouterVoteDetermination(voteDetermination3);
                propositionDetermination.ajouterVoteDetermination(voteDetermination4);
                
                PropositionDetermination propositionDetermination2 = new PropositionDetermination();
                propositionDetermination2.setEspece("Iris urticans");
                propositionDetermination2.setContributeur("contributeur test2");
                propositionDetermination2.setId("2");
                propositionDetermination2.ajouterVoteDetermination(voteDetermination1);
                propositionDetermination2.ajouterVoteDetermination(voteDetermination2);
                propositionDetermination2.ajouterVoteDetermination(voteDetermination3);
                propositionDetermination2.ajouterVoteDetermination(voteDetermination5);
                
                List<PropositionDetermination> listePropositions = new ArrayList<PropositionDetermination>();
                listePropositions.add(propositionDetermination2);
                listePropositions.add(propositionDetermination);

                List<MoyenneVote> listeMoyenneVote = CalculVoteDeterminationService
                                .calculerVoteDeterminationPlusPopulaire(listePropositions);

                // le premier vote est sensé être celui qui possède le plus gros score
                assertTrue(listeMoyenneVote.get(0).getIntituleAssocie().equals("Iris lutescens subsp. lutescens"));
        }

}