|
| 1 | +package br.com.zevolution.datastructure.sequentialvector; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertEquals; |
| 4 | + |
| 5 | +import org.junit.Test; |
| 6 | + |
| 7 | +public class StudentsVectorTest { |
| 8 | + |
| 9 | +@Test |
| 10 | +public void should_Contain_OneRecordInStudentsVector() { |
| 11 | +StudentsVector students = new StudentsVector(); |
| 12 | +students.add(new Student("José Lucas")); |
| 13 | + |
| 14 | +assertEquals(1, students.size()); |
| 15 | +} |
| 16 | + |
| 17 | +@Test |
| 18 | +public void should_Contain_TwoRecordsInStudentsVector() { |
| 19 | +StudentsVector students = new StudentsVector(); |
| 20 | +students.add(new Student("Beatriz")); |
| 21 | +students.add(new Student("José Lucas")); |
| 22 | + |
| 23 | +assertEquals(2, students.size()); |
| 24 | +} |
| 25 | + |
| 26 | +@Test |
| 27 | +public void should_MakeSure_StudentsPosition() { |
| 28 | +StudentsVector students = new StudentsVector(); |
| 29 | +students.add(new Student("Beatriz")); |
| 30 | +students.add(new Student("José Lucas")); |
| 31 | +students.add(0, new Student("Laura")); |
| 32 | + |
| 33 | +assertEquals("Laura", students.get(0).getName()); |
| 34 | +assertEquals("Beatriz", students.get(1).getName()); |
| 35 | +assertEquals("José Lucas", students.get(2).getName()); |
| 36 | +} |
| 37 | + |
| 38 | +@Test |
| 39 | +public void should_Be_Empty() { |
| 40 | +StudentsVector students = new StudentsVector(); |
| 41 | +students.add(new Student("Beatriz")); |
| 42 | +students.add(new Student("José Lucas")); |
| 43 | +students.add(0, new Student("Laura")); |
| 44 | + |
| 45 | +for (int i = students.size(); i > 0; i--) { |
| 46 | +students.remove(i-1); |
| 47 | +} |
| 48 | + |
| 49 | +assertEquals(0, students.size()); |
| 50 | +} |
| 51 | + |
| 52 | +@Test |
| 53 | +public void should_Have_StudentLu() { |
| 54 | +StudentsVector students = new StudentsVector(); |
| 55 | +students.add(new Student("Beatriz")); |
| 56 | +students.add(new Student("José Lucas")); |
| 57 | +students.add(0, new Student("Laura")); |
| 58 | +students.add(new Student("Lu")); |
| 59 | + |
| 60 | +assertEquals(true, students.has(new Student("Lu"))); |
| 61 | +} |
| 62 | + |
| 63 | +@Test(expected = UnoccupiedPosition.class) |
| 64 | +public void should_ThrowException_When_UnoccupiedPosition() { |
| 65 | +StudentsVector students = new StudentsVector(); |
| 66 | +students.add(new Student("zevolution")); |
| 67 | + |
| 68 | +students.remove(1); |
| 69 | +} |
| 70 | + |
| 71 | +@Test(expected = InvalidPosition.class) |
| 72 | +public void should_ThrowException_When_InvalidPosition() { |
| 73 | +StudentsVector students = new StudentsVector(); |
| 74 | + |
| 75 | +students.add(1, new Student("zevolution")); |
| 76 | +} |
| 77 | + |
| 78 | +} |
0 commit comments