Subversion Repositories eFlore/Applications.del

Rev

Go to most recent revision | Details | 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;
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
 
271 aurelien 15
public class CalculVoteDeterminationServiceTest {
173 aurelien 16
 
17
	@Test
271 aurelien 18
	public void testCalculerVoteDetermination() {
173 aurelien 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");
658 benjamin 27
		propositionDetermination.setAuteur("contributeur test");
173 aurelien 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
271 aurelien 39
	public void testCalculerVoteDeterminationPlusPopulaire() {
173 aurelien 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");
658 benjamin 68
		propositionDetermination.setAuteur("contributeur test");
173 aurelien 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");
658 benjamin 77
		propositionDetermination2.setAuteur("contributeur test2");
173 aurelien 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
271 aurelien 92
		assertTrue(listeMoyenneVote.get(0).getIntituleAssocie().equals("Iris lutescens subsp. lutescens"));
173 aurelien 93
	}
94
 
95
}