-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimalShelterTest.java
More file actions
executable file
·82 lines (62 loc) · 2.71 KB
/
Copy pathAnimalShelterTest.java
File metadata and controls
executable file
·82 lines (62 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package algorithm.cracking.stacks;
import algorithm.cracking.stacks.AnimalShelter.Cat;
import algorithm.cracking.stacks.AnimalShelter.Dog;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.time.LocalDateTime;
class AnimalShelterTest {
AnimalShelter animalShelter;
//Order of Animal arrival
Dog dog1 = Dog.builder().name("dog1").arrivalDate(LocalDateTime.now()).build();
Cat cat1 = Cat.builder().name("cat1").arrivalDate(LocalDateTime.now()).build();
Dog dog2 = Dog.builder().name("dog2").arrivalDate(LocalDateTime.now()).build();
Dog dog3 = Dog.builder().name("dog3").arrivalDate(LocalDateTime.now()).build();
Cat cat2 = Cat.builder().name("cat2").arrivalDate(LocalDateTime.now()).build();
Cat cat3 = Cat.builder().name("cat3").arrivalDate(LocalDateTime.now()).build();
@BeforeEach
void init() {
animalShelter = new AnimalShelter();
}
@Test
void enqueue() {
animalShelter.enqueue(dog1);
animalShelter.enqueue(cat1);
animalShelter.enqueue(dog2);
Assertions.assertEquals(1, animalShelter.queueCats.size());
Assertions.assertEquals(2, animalShelter.queueDogs.size());
}
@Test
void dequeueAny() {
animalShelter.enqueue(dog1);
animalShelter.enqueue(cat1);
animalShelter.enqueue(dog2);
animalShelter.enqueue(dog3);
animalShelter.enqueue(cat2);
Assertions.assertEquals(dog1, animalShelter.dequeueAny().get());
Assertions.assertEquals(cat1, animalShelter.dequeueAny().get());
Assertions.assertEquals(dog2, animalShelter.dequeueAny().get());
Assertions.assertEquals(dog3, animalShelter.dequeueAny().get());
Assertions.assertEquals(cat2, animalShelter.dequeueAny().get());
Assertions.assertTrue(animalShelter.dequeueAny().isEmpty());
}
@Test
void dequeueDog() {
animalShelter.enqueue(dog1);
animalShelter.enqueue(cat1);
animalShelter.enqueue(dog2);
Assertions.assertEquals(dog1, animalShelter.dequeueDog().get());
Assertions.assertEquals(dog2, animalShelter.dequeueDog().get());
Assertions.assertTrue(animalShelter.dequeueDog().isEmpty());
}
@Test
void dequeueCat() {
animalShelter.enqueue(dog1);
animalShelter.enqueue(cat1);
animalShelter.enqueue(dog2);
animalShelter.enqueue(cat3);
Assertions.assertEquals(cat1, animalShelter.dequeueCat().get());
Assertions.assertEquals(cat3, animalShelter.dequeueCat().get());
Assertions.assertTrue(animalShelter.dequeueCat().isEmpty());
}
}