Subversion Repositories eFlore/Applications.del

Rev

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