Subversion Repositories eFlore/Applications.del

Rev

Details | Last modification | View Log | RSS feed

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