import static org.junit.Assert.*;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
public class StudenteTest {
public List<Studente> l = new LinkedList<Studente>();
public List<Studente> ArrayListOmonimi = new LinkedList<Studente>();
@Before
public void setUp() throws Exception {
l.add(new Studente("Alessandro","Cavolo", 599));
l.add(new Studente("Paolo","Rossi",233));
l.add(new Studente("Valter","Michele",16));
l.add(new Studente("Giacomo","Merso",299));
ArrayListOmonimi.add(new Studente("Alessandro","Cavolo", 599));
ArrayListOmonimi.add(new Studente("Alessandro","Rossi",233));
ArrayListOmonimi.add(new Studente("Davide","De Rubeis",16));
ArrayListOmonimi.add(new Studente("Davide","De Rubeis",299));
}
@Test
public void testSort() {
Collections.sort(l);
assertEquals("Valter",l.get(0).getNome());
assertEquals("Paolo",l.get(1).getNome());
assertEquals("Giacomo",l.get(2).getNome());
assertEquals("Alessandro",l.get(3).getNome());
}
@Test
public void testSortNome(){
ComparatorePerStudenteNome comparatore = new ComparatorePerStudenteNome();
Collections.sort(l,comparatore);
assertEquals("Paolo",l.get(0).getNome());
assertEquals("Valter",l.get(1).getNome());
assertEquals("Giacomo",l.get(2).getNome());
assertEquals("Alessandro",l.get(3).getNome());
assertEquals(0,comparatore.compare(l.get(0),l.get(0)));
assertEquals(-1,comparatore.compare(l.get(0),l.get(1)));
assertEquals(1,comparatore.compare(l.get(1),l.get(0)));
}
@Test
public void testSortCognome(){
ComparatorePerStudenteCognome comparatore = new ComparatorePerStudenteCognome();
Collections.sort(l,comparatore);
assertEquals("Rossi",l.get(0).getCognome());
assertEquals("Merso",l.get(1).getCognome());
assertEquals("Cavolo",l.get(2).getCognome());
assertEquals("Michele",l.get(3).getCognome());
assertEquals(0,comparatore.compare(l.get(0),l.get(0)));
assertEquals(-1,comparatore.compare(l.get(0),l.get(2)));
assertEquals(1,comparatore.compare(l.get(3),l.get(0)));
}
@Test
public void testSortNomeCognome_TestListSemplice(){
ComparatorePerStudenteNomeCognome comparatore = new ComparatorePerStudenteNomeCognome();
Collections.sort(l,comparatore);
assertEquals("Paolo",l.get(0).getNome());
assertEquals("Valter",l.get(1).getNome());
assertEquals("Giacomo",l.get(2).getNome());
assertEquals("Alessandro",l.get(3).getNome());
assertEquals(0,comparatore.compare(l.get(0),l.get(0)));
assertEquals(-1,comparatore.compare(l.get(0),l.get(1)));
assertEquals(1,comparatore.compare(l.get(1),l.get(0)));
}
//ArrayListOmonimi
@Test
public void testSortNomeCognome_TestOmonimi(){
ComparatorePerStudenteNomeCognome comparatore = new ComparatorePerStudenteNomeCognome();
Collections.sort(ArrayListOmonimi,comparatore);
assertEquals("Davide",ArrayListOmonimi.get(0).getNome());
assertEquals("Davide",ArrayListOmonimi.get(1).getNome());
assertEquals("Alessandro",ArrayListOmonimi.get(2).getNome());
assertEquals("Alessandro",ArrayListOmonimi.get(3).getNome());
assertEquals(0,comparatore.compare(ArrayListOmonimi.get(0),ArrayListOmonimi.get(0)));
assertEquals(-1,comparatore.compare(ArrayListOmonimi.get(0),ArrayListOmonimi.get(2)));
assertEquals(1,comparatore.compare(ArrayListOmonimi.get(2),ArrayListOmonimi.get(0)));
}
}
By ImaginSystems & Queen Gin