1+ package bwapi ;
2+
3+ import static org .assertj .core .api .Assertions .assertThat ;
4+ import static org .mockito .BDDMockito .given ;
5+ import static org .mockito .Mockito .mock ;
6+
7+ import java .util .ArrayList ;
8+ import java .util .List ;
9+ import org .junit .Before ;
10+ import org .junit .experimental .theories .DataPoints ;
11+ import org .junit .experimental .theories .FromDataPoints ;
12+ import org .junit .experimental .theories .Theories ;
13+ import org .junit .experimental .theories .Theory ;
14+ import org .junit .runner .RunWith ;
15+
16+ @ RunWith (Theories .class )
17+ public class GameTest {
18+
19+ private List <Unit > allUnits = new ArrayList <>();
20+ private Game sut = new Game (mock (Client .class )) {
21+ @ Override
22+ public List <Unit > getAllUnits () {
23+ return allUnits ;
24+ }
25+ };
26+ private Unit dummy ;
27+
28+ @ DataPoints ("overlapping" )
29+ public static final Pair [] overlapping = {
30+ new Pair <>(new Position (15 , 35 ), new Position (20 , 40 )),
31+ new Pair <>(new Position (15 , 32 ), new Position (25 , 38 )),
32+ new Pair <>(new Position (15 , 28 ), new Position (25 , 42 )),
33+ new Pair <>(new Position (5 , 35 ), new Position (15 , 40 )),
34+ new Pair <>(new Position (0 , 32 ), new Position (15 , 38 )),
35+ new Pair <>(new Position (0 , 28 ), new Position (15 , 42 )),
36+ new Pair <>(new Position (12 , 25 ), new Position (22 , 35 )),
37+ new Pair <>(new Position (15 , 38 ), new Position (28 , 42 )),
38+ new Pair <>(new Position (5 , 20 ), new Position (25 , 45 ))
39+ };
40+
41+ @ DataPoints ("non-overlapping" )
42+ public static final Pair [] nonOverlapping = {
43+ new Pair <>(new Position (0 , 0 ), new Position (200 , 20 )),
44+ new Pair <>(new Position (50 , 0 ), new Position (55 , 200 )),
45+ new Pair <>(new Position (0 , 0 ), new Position (5 , 200 )),
46+ new Pair <>(new Position (0 , 45 ), new Position (20 , 50 ))
47+ };
48+
49+ @ Before
50+ public void setup () {
51+ dummy = mock (Unit .class );
52+ given (dummy .getLeft ()).willReturn (10 );
53+ given (dummy .getRight ()).willReturn (20 );
54+ given (dummy .getTop ()).willReturn (30 );
55+ given (dummy .getBottom ()).willReturn (40 );
56+ }
57+
58+ @ Theory
59+ public void shouldFindOverlappingUnits (
60+ @ FromDataPoints ("overlapping" ) Pair <Position , Position > rect ) {
61+ // GIVEN
62+ allUnits .add (dummy );
63+
64+ // WHEN
65+ List <Unit > unitsInRectangle = sut
66+ .getUnitsInRectangle (rect .getLeft (), rect .getRight (), unused -> true );
67+
68+ // THEN
69+ assertThat (unitsInRectangle ).contains (dummy );
70+ }
71+
72+ @ Theory
73+ public void shouldNotFindNonOverlappingUnits (
74+ @ FromDataPoints ("non-overlapping" ) Pair <Position , Position > rect ) {
75+ // GIVEN
76+ allUnits .add (dummy );
77+
78+ // WHEN
79+ List <Unit > unitsInRectangle = sut
80+ .getUnitsInRectangle (rect .getLeft (), rect .getRight (), unused -> true );
81+
82+ // THEN
83+ assertThat (unitsInRectangle ).doesNotContain (dummy );
84+ }
85+ }
0 commit comments