-
Notifications
You must be signed in to change notification settings - Fork 246
/
Exercise5Test.java
98 lines (88 loc) · 3.54 KB
/
Exercise5Test.java
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* Copyright (c) 2022 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.collections.petkata;
import java.util.ArrayList;
import java.util.HashSet;
import org.eclipse.collections.api.bag.MutableBag;
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.function.primitive.DoubleFunction;
import org.eclipse.collections.api.block.function.primitive.IntFunction;
import org.eclipse.collections.api.block.predicate.Predicate;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.list.primitive.MutableDoubleList;
import org.eclipse.collections.api.partition.list.PartitionMutableList;
import org.eclipse.collections.api.set.primitive.MutableIntSet;
import org.eclipse.collections.impl.factory.Sets;
import org.eclipse.collections.impl.factory.primitive.IntSets;
import org.eclipse.collections.impl.test.Verify;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
/**
* In these tests, you will be able to discover some additional methods available on the Eclipse Collections API.
*
* {@link MutableList#partition(Predicate)}<br>
* {@link PartitionMutableList#getSelected()}<br>
* {@link PartitionMutableList#getRejected()}<br>
* {@link MutableList#flatCollect(Function)}<br>
* {@link MutableList#maxBy(Function)}<br>
* {@link MutableList#collectDouble(DoubleFunction)}<br>
* {@link MutableDoubleList#average()}<br>
* {@link MutableList#collectInt(IntFunction)}<br>
* {@link MutableBag#selectDuplicates()}<br>
*/
public class Exercise5Test extends PetDomainForKata
{
@Test
@Tag("KATA")
public void partitionPetAndNonPetPeople()
{
PartitionMutableList<Person> partitionMutableList = null;
Verify.assertSize(7, partitionMutableList.getSelected());
Verify.assertSize(1, partitionMutableList.getRejected());
}
@Test
@Tag("KATA")
@DisplayName("getOldestPet - 🐶")
public void getOldestPet()
{
Pet oldestPet = null;
Assertions.assertEquals(PetType.DOG, oldestPet.getType());
Assertions.assertEquals(4, oldestPet.getAge());
}
@Test
@Tag("KATA")
public void getAveragePetAge()
{
double averagePetAge = 0;
Assertions.assertEquals(1.88888, averagePetAge, 0.00001);
}
@Test
@Tag("KATA")
public void addPetAgesToExistingSet()
{
// Hint: Use petAges as a target collection
MutableIntSet petAges = IntSets.mutable.with(5);
var expectedSet = IntSets.mutable.with(1, 2, 3, 4, 5);
Assertions.assertEquals(expectedSet, petAges);
}
@Test
@Tag("KATA")
@DisplayName("findOwnerWithMoreThanOnePetOfTheSameType - 🐹 🐹")
public void findOwnerWithMoreThanOnePetOfTheSameType()
{
/* Hint: find the owner with a short circuit detect . Use a predicate
that utilizes Bags to find duplicates of a given pet type*/
Person petOwner = null;
Assertions.assertEquals("Harry Hamster", petOwner.getFullName());
Assertions.assertEquals("🐹 🐹", petOwner.getPets().makeString(" "));
}
}