Subversion Repositories eFlore/Applications.del

Rev

Rev 658 | Rev 882 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
271 aurelien 1
package org.tela_botanica.del.test.services;
173 aurelien 2
 
3
import static org.junit.Assert.assertTrue;
4
 
5
import java.util.ArrayList;
6
import java.util.Date;
7
import java.util.List;
8
 
9
import org.junit.Test;
690 gduche 10
import org.tela_botanica.del.client.modeles.Contributeur;
173 aurelien 11
import org.tela_botanica.del.client.modeles.MoyenneVote;
12
import org.tela_botanica.del.client.modeles.PropositionDetermination;
13
import org.tela_botanica.del.client.modeles.VoteDetermination;
14
import org.tela_botanica.del.client.services.CalculVoteDeterminationService;
15
 
271 aurelien 16
public class CalculVoteDeterminationServiceTest {
173 aurelien 17
 
18
	@Test
271 aurelien 19
	public void testCalculerVoteDetermination() {
173 aurelien 20
 
21
		VoteDetermination voteDetermination = new VoteDetermination();
22
		voteDetermination.setVote(1);
23
		voteDetermination.setDate(new Date());
24
		voteDetermination.setContributeur("benjamin");
25
 
26
		PropositionDetermination propositionDetermination = new PropositionDetermination();
27
		propositionDetermination.setEspece("Iris lutescens subsp. lutescens");
690 gduche 28
		propositionDetermination.setContributeur(new Contributeur("contrib", "test", "contrib@test.com"));
173 aurelien 29
		propositionDetermination.setId("1");
30
		propositionDetermination.ajouterVoteDetermination(voteDetermination);
31
 
32
		MoyenneVote moyenneVote = CalculVoteDeterminationService
33
				.calculerVoteDetermination(propositionDetermination);
34
 
35
		assertTrue(moyenneVote.getScore() == 100);
36
 
37
	}
38
 
39
	@Test
271 aurelien 40
	public void testCalculerVoteDeterminationPlusPopulaire() {
173 aurelien 41
 
42
		VoteDetermination voteDetermination1 = new VoteDetermination();
43
		voteDetermination1.setVote(1);
44
		voteDetermination1.setDate(new Date());
45
		voteDetermination1.setContributeur("benjamin");
46
 
47
		VoteDetermination voteDetermination2 = new VoteDetermination();
48
		voteDetermination2.setVote(1);
49
		voteDetermination2.setDate(new Date());
50
		voteDetermination2.setContributeur("aurelien");
51
 
52
		VoteDetermination voteDetermination3 = new VoteDetermination();
53
		voteDetermination3.setVote(0);
54
		voteDetermination3.setDate(new Date());
55
		voteDetermination3.setContributeur("benjamin");
56
 
57
		VoteDetermination voteDetermination4 = new VoteDetermination();
58
		voteDetermination3.setVote(0);
59
		voteDetermination3.setDate(new Date());
60
		voteDetermination3.setContributeur("benjamin");
61
 
62
		VoteDetermination voteDetermination5 = new VoteDetermination();
63
		voteDetermination4.setVote(1);
64
		voteDetermination4.setDate(new Date());
65
		voteDetermination4.setContributeur("benjamin");
66
 
67
		PropositionDetermination propositionDetermination = new PropositionDetermination();
68
		propositionDetermination.setEspece("Iris lutescens subsp. lutescens");
690 gduche 69
		propositionDetermination.setContributeur(new Contributeur("contrib", "test", "contrib@test.com"));
173 aurelien 70
		propositionDetermination.setId("1");
71
		propositionDetermination.ajouterVoteDetermination(voteDetermination1);
72
		propositionDetermination.ajouterVoteDetermination(voteDetermination2);
73
		propositionDetermination.ajouterVoteDetermination(voteDetermination3);
74
		propositionDetermination.ajouterVoteDetermination(voteDetermination4);
75
 
76
		PropositionDetermination propositionDetermination2 = new PropositionDetermination();
77
		propositionDetermination2.setEspece("Iris urticans");
690 gduche 78
		propositionDetermination2.setContributeur(new Contributeur("contrib", "test", "contrib@test.com"));
173 aurelien 79
		propositionDetermination2.setId("2");
80
		propositionDetermination2.ajouterVoteDetermination(voteDetermination1);
81
		propositionDetermination2.ajouterVoteDetermination(voteDetermination2);
82
		propositionDetermination2.ajouterVoteDetermination(voteDetermination3);
83
		propositionDetermination2.ajouterVoteDetermination(voteDetermination5);
84
 
85
		List<PropositionDetermination> listePropositions = new ArrayList<PropositionDetermination>();
86
		listePropositions.add(propositionDetermination2);
87
		listePropositions.add(propositionDetermination);
88
 
89
		List<MoyenneVote> listeMoyenneVote = CalculVoteDeterminationService
90
				.calculerVoteDeterminationPlusPopulaire(listePropositions);
91
 
92
		// le premier vote est sensé être celui qui possède le plus gros score
271 aurelien 93
		assertTrue(listeMoyenneVote.get(0).getIntituleAssocie().equals("Iris lutescens subsp. lutescens"));
173 aurelien 94
	}
95
 
96
}