Repository navigation
Expand file tree
/
Copy pathFilterTest.java
More file actions
58 lines (45 loc) · 1.7 KB
/
Copy pathFilterTest.java
File metadata and controls
58 lines (45 loc) · 1.7 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
package bwapi;
import org.junit.*;
import java.util.*;
import static bwapi.UnitFilter.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
public class FilterTest {
List<Unit> units;
@Before
public void setup() {
Unit u = mock(Unit.class);
when(u.getHitPoints()).thenReturn(20);
when(u.getType()).thenReturn(UnitType.Resource_Mineral_Field);
units = Arrays.asList(u);
}
@Test
public void testBasicFilters() {
assertTrue(units.stream().anyMatch(IsMineralField));
assertTrue(units.stream().noneMatch(IsRefinery));
}
@Test
public void testVariableFilters() {
assertTrue(units.stream().anyMatch(GetType(t -> t == UnitType.Resource_Mineral_Field)));
assertTrue(units.stream().anyMatch(HP(x -> x > 10)));
assertTrue(units.stream().noneMatch(HP(x -> x == 10)));
}
@Test
public void testFilterCombinations() {
assertTrue(units.stream().anyMatch(IsMineralField.or(IsRefinery)));
assertTrue(units.stream().noneMatch(IsMineralField.and(IsRefinery)));
assertTrue(units.stream().noneMatch(IsMineralField.negate()));
}
@Test
public void isTransportShouldMatchDropshipAndExcludeBunker() {
Unit dropship = mock(Unit.class);
when(dropship.getType()).thenReturn(UnitType.Terran_Dropship);
Unit bunker = mock(Unit.class);
when(bunker.getType()).thenReturn(UnitType.Terran_Bunker);
Unit marine = mock(Unit.class);
when(marine.getType()).thenReturn(UnitType.Terran_Marine);
assertTrue(IsTransport.test(dropship));
assertFalse(IsTransport.test(bunker));
assertFalse(IsTransport.test(marine));
}
}