test: fix tests and groups

pull/40/head
RuiAlonso 4 years ago
parent a527a1390a
commit a5fb9ed8df

@ -18,6 +18,7 @@ void main() {
'loads correctly',
(game) async {
final ball = Ball(position: Vector2.zero());
await game.ready();
await game.ensureAdd(ball);
expect(game.contains(ball), isTrue);

@ -7,8 +7,8 @@ import 'package:pinball/game/game.dart';
import '../../helpers/helpers.dart';
class FakeRampArea extends RampArea {
FakeRampArea({
class TestRampArea extends RampArea {
TestRampArea({
required Vector2 position,
required RampOrientation orientation,
required int categoryBits,
@ -30,8 +30,8 @@ class FakeRampArea extends RampArea {
]);
}
class FakeRampAreaCallback extends RampAreaCallback<FakeRampArea> {
FakeRampAreaCallback() : super();
class TestRampAreaCallback extends RampAreaCallback<TestRampArea> {
TestRampAreaCallback() : super();
final _ballsInside = <Ball>{};
@ -67,7 +67,7 @@ void main() {
flameTester.test(
'loads correctly',
(game) async {
final ramp = FakeRampArea(
final ramp = TestRampArea(
position: Vector2.zero(),
orientation: RampOrientation.down,
categoryBits: RampType.all.maskBits,
@ -84,7 +84,7 @@ void main() {
'positions correctly',
(game) async {
final position = Vector2.all(10);
final ramp = FakeRampArea(
final ramp = TestRampArea(
position: position,
orientation: RampOrientation.down,
categoryBits: RampType.all.maskBits,
@ -99,7 +99,7 @@ void main() {
flameTester.test(
'is static',
(game) async {
final ramp = FakeRampArea(
final ramp = TestRampArea(
position: Vector2.zero(),
orientation: RampOrientation.down,
categoryBits: RampType.all.maskBits,
@ -111,36 +111,48 @@ void main() {
);
group('fixtures', () {
const maskBits = 1234;
flameTester.test(
'has only one shape',
'exists',
(game) async {
final ramp = FakeRampArea(
final ramp = TestRampArea(
position: Vector2.zero(),
orientation: RampOrientation.down,
categoryBits: RampType.all.maskBits,
categoryBits: maskBits,
);
await game.ensureAdd(ramp);
expect(ramp.body.fixtures.length, 1);
expect(ramp.body.fixtures[0], isA<Fixture>());
},
);
flameTester.test(
'shape is a polygon',
(game) async {
final ramp = TestRampArea(
position: Vector2.zero(),
orientation: RampOrientation.down,
categoryBits: maskBits,
);
await game.ensureAdd(ramp);
for (final fixture in ramp.body.fixtures) {
expect(fixture, isA<Fixture>());
expect(fixture.shape, isA<PolygonShape>());
}
final fixture = ramp.body.fixtures[0];
expect(fixture.shape.shapeType, equals(ShapeType.polygon));
},
);
flameTester.test(
'is sensor',
(game) async {
final ramp = FakeRampArea(
final ramp = TestRampArea(
position: Vector2.zero(),
orientation: RampOrientation.down,
categoryBits: RampType.all.maskBits,
categoryBits: maskBits,
);
await game.ensureAdd(ramp);
final fixture = ramp.body.fixtures.first;
final fixture = ramp.body.fixtures[0];
expect(fixture.isSensor, isTrue);
},
);
@ -148,16 +160,15 @@ void main() {
flameTester.test(
'sets filter categoryBits correctly',
(game) async {
const maskBits = 1234;
final ramp = FakeRampArea(
final ramp = TestRampArea(
position: Vector2.zero(),
orientation: RampOrientation.down,
categoryBits: maskBits,
);
await game.ready();
await game.ensureAdd(ramp);
final fixture = ramp.body.fixtures.first;
final fixture = ramp.body.fixtures[0];
expect(
fixture.filterData.categoryBits,
equals(maskBits),
@ -176,12 +187,12 @@ void main() {
'is saved into collection and set maskBits to path', () {
final ball = MockBall();
final body = MockBody();
final area = FakeRampArea(
final area = TestRampArea(
position: Vector2(0, 10),
orientation: RampOrientation.down,
categoryBits: categoryBits,
);
final callback = FakeRampAreaCallback();
final callback = TestRampAreaCallback();
when(() => body.position).thenReturn(Vector2(0, 20));
when(() => ball.body).thenReturn(body);
@ -203,12 +214,12 @@ void main() {
'is saved into collection and set maskBits to path', () {
final ball = MockBall();
final body = MockBody();
final area = FakeRampArea(
final area = TestRampArea(
position: Vector2(0, 10),
orientation: RampOrientation.up,
categoryBits: categoryBits,
);
final callback = FakeRampAreaCallback();
final callback = TestRampAreaCallback();
when(() => body.position).thenReturn(Vector2.zero());
when(() => ball.body).thenReturn(body);
@ -230,12 +241,12 @@ void main() {
'is removed from collection and set maskBits to collide all', () {
final ball = MockBall();
final body = MockBody();
final area = FakeRampArea(
final area = TestRampArea(
position: Vector2(0, 10),
orientation: RampOrientation.down,
categoryBits: categoryBits,
);
final callback = FakeRampAreaCallback();
final callback = TestRampAreaCallback();
when(() => body.position).thenReturn(Vector2.zero());
when(() => ball.body).thenReturn(body);
@ -257,12 +268,12 @@ void main() {
'is removed from collection and set maskBits to collide all', () {
final ball = MockBall();
final body = MockBody();
final area = FakeRampArea(
final area = TestRampArea(
position: Vector2(0, 10),
orientation: RampOrientation.down,
categoryBits: categoryBits,
);
final callback = FakeRampAreaCallback()..ballsInside.add(ball);
final callback = TestRampAreaCallback()..ballsInside.add(ball);
when(() => body.position).thenReturn(Vector2.zero());
when(() => ball.body).thenReturn(body);
@ -282,12 +293,12 @@ void main() {
'is removed from collection and set maskBits to collide all', () {
final ball = MockBall();
final body = MockBody();
final area = FakeRampArea(
final area = TestRampArea(
position: Vector2(0, 10),
orientation: RampOrientation.up,
categoryBits: categoryBits,
);
final callback = FakeRampAreaCallback()..ballsInside.add(ball);
final callback = TestRampAreaCallback()..ballsInside.add(ball);
when(() => body.position).thenReturn(Vector2(0, 20));
when(() => ball.body).thenReturn(body);

@ -16,76 +16,64 @@ void main() {
final flameTester = FlameTester(PinballGameTest.create);
group('JetpackRamp', () {
group('body', () {
bool Function(Component) pathwaySelector(Vector2 position) =>
(component) =>
component is Pathway && component.body.position == position;
flameTester.test(
'has a Pathway.arc at position',
(game) async {
final position = Vector2.all(10);
final jetpackRamp = JetpackRamp(
position: position,
);
await game.ready();
await game.ensureAdd(jetpackRamp);
flameTester.test(
'loads correctly',
(game) async {
final ramp = JetpackRamp(
position: Vector2.zero(),
);
await game.ready();
await game.ensureAdd(ramp);
expect(
() => jetpackRamp.children.singleWhere(
pathwaySelector(position),
),
returnsNormally,
);
},
);
expect(game.contains(ramp), isTrue);
},
);
group('constructor', () {
flameTester.test(
'path is static',
'positions correctly',
(game) async {
final position = Vector2.all(10);
final jetpackRamp = JetpackRamp(
final position = Vector2.zero();
final ramp = JetpackRamp(
position: position,
);
await game.ready();
await game.ensureAdd(jetpackRamp);
await game.ensureAdd(ramp);
final pathways = jetpackRamp.children.whereType<Pathway>().toList();
for (final pathway in pathways) {
expect(pathway.body.bodyType, equals(BodyType.static));
}
expect(ramp.position, equals(position));
},
);
});
group('children', () {
flameTester.test(
'has a two sensors for the ramp',
'has only one Pathway.arc',
(game) async {
final jetpackRamp = JetpackRamp(
final ramp = JetpackRamp(
position: Vector2.zero(),
);
await game.ready();
await game.ensureAdd(jetpackRamp);
await game.ensureAdd(ramp);
final rampAreas =
jetpackRamp.children.whereType<JetpackRampArea>().toList();
expect(rampAreas.length, 2);
expect(
() => ramp.children.singleWhere(
(component) => component is Pathway,
),
returnsNormally,
);
},
);
flameTester.test(
'sensors are static',
'has a two sensors for the ramp',
(game) async {
final jetpackRamp = JetpackRamp(
final ramp = JetpackRamp(
position: Vector2.zero(),
);
await game.ready();
await game.ensureAdd(jetpackRamp);
await game.ensureAdd(ramp);
final rampAreas =
jetpackRamp.children.whereType<JetpackRampArea>().toList();
for (final rampArea in rampAreas) {
expect(rampArea.body.bodyType, equals(BodyType.static));
}
final rampAreas = ramp.children.whereType<JetpackRampArea>().toList();
expect(rampAreas.length, 2);
},
);
});
@ -93,21 +81,7 @@ void main() {
group('JetpackRampArea', () {
flameTester.test(
'loads correctly',
(game) async {
final ramp = JetpackRampArea(
position: Vector2.zero(),
orientation: RampOrientation.down,
);
await game.ready();
await game.ensureAdd(ramp);
expect(game.contains(ramp), isTrue);
},
);
flameTester.test(
'orientation correctly',
'orientation is down',
(game) async {
final position = Vector2.all(10);
final ramp = JetpackRampArea(
@ -120,91 +94,6 @@ void main() {
expect(ramp.orientation, RampOrientation.down);
},
);
group('body', () {
flameTester.test(
'positions correctly',
(game) async {
final position = Vector2.all(10);
final ramp = JetpackRampArea(
position: position,
orientation: RampOrientation.down,
);
await game.ready();
await game.ensureAdd(ramp);
expect(ramp.body.position, position);
},
);
flameTester.test(
'is static',
(game) async {
final ramp = JetpackRampArea(
position: Vector2.zero(),
orientation: RampOrientation.down,
);
await game.ready();
await game.ensureAdd(ramp);
expect(ramp.body.bodyType, equals(BodyType.static));
},
);
group('fixtures', () {
flameTester.test(
'has only one shape',
(game) async {
final ramp = JetpackRampArea(
position: Vector2.zero(),
orientation: RampOrientation.down,
);
await game.ready();
await game.ensureAdd(ramp);
expect(ramp.body.fixtures.length, 1);
for (final fixture in ramp.body.fixtures) {
expect(fixture, isA<Fixture>());
expect(fixture.shape, isA<PolygonShape>());
}
},
);
flameTester.test(
'is sensor',
(game) async {
final ramp = JetpackRampArea(
position: Vector2.zero(),
orientation: RampOrientation.down,
);
await game.ready();
await game.ensureAdd(ramp);
final fixture = ramp.body.fixtures.first;
expect(fixture.isSensor, isTrue);
},
);
flameTester.test(
'sets correctly filter categoryBits to RampType.jetpack',
(game) async {
final ramp = JetpackRampArea(
position: Vector2.zero(),
orientation: RampOrientation.down,
);
await game.ready();
await game.ensureAdd(ramp);
final fixture = ramp.body.fixtures.first;
expect(
fixture.filterData.categoryBits,
equals(RampType.jetpack.maskBits),
);
},
);
});
});
});
group('JetpackRampAreaCallback', () {

@ -16,76 +16,64 @@ void main() {
final flameTester = FlameTester(PinballGameTest.create);
group('SparkyRamp', () {
group('body', () {
bool Function(Component) pathwaySelector(Vector2 position) =>
(component) =>
component is Pathway && component.body.position == position;
flameTester.test(
'has a Pathway.arc at position',
(game) async {
final position = Vector2.all(10);
final sparkyRamp = SparkyRamp(
position: position,
);
await game.ready();
await game.ensureAdd(sparkyRamp);
flameTester.test(
'loads correctly',
(game) async {
final ramp = SparkyRamp(
position: Vector2.zero(),
);
await game.ready();
await game.ensureAdd(ramp);
expect(
() => sparkyRamp.children.singleWhere(
pathwaySelector(position),
),
returnsNormally,
);
},
);
expect(game.contains(ramp), isTrue);
},
);
group('constructor', () {
flameTester.test(
'path is static',
'positions correctly',
(game) async {
final position = Vector2.all(10);
final sparkyRamp = SparkyRamp(
final position = Vector2.zero();
final ramp = SparkyRamp(
position: position,
);
await game.ready();
await game.ensureAdd(sparkyRamp);
await game.ensureAdd(ramp);
final pathways = game.children.whereType<Pathway>().toList();
for (final pathway in pathways) {
expect(pathway.body.bodyType, equals(BodyType.static));
}
expect(ramp.position, equals(position));
},
);
});
group('children', () {
flameTester.test(
'has a two sensors for the ramp',
'has only one Pathway.arc',
(game) async {
final sparkyRamp = SparkyRamp(
final ramp = SparkyRamp(
position: Vector2.zero(),
);
await game.ready();
await game.ensureAdd(sparkyRamp);
await game.ensureAdd(ramp);
final rampAreas =
sparkyRamp.children.whereType<SparkyRampArea>().toList();
expect(rampAreas.length, 2);
expect(
() => ramp.children.singleWhere(
(component) => component is Pathway,
),
returnsNormally,
);
},
);
flameTester.test(
'sensors are static',
'has a two sensors for the ramp',
(game) async {
final sparkyRamp = SparkyRamp(
final ramp = SparkyRamp(
position: Vector2.zero(),
);
await game.ready();
await game.ensureAdd(sparkyRamp);
await game.ensureAdd(ramp);
final rampAreas =
sparkyRamp.children.whereType<SparkyRampArea>().toList();
for (final rampArea in rampAreas) {
expect(rampArea.body.bodyType, equals(BodyType.static));
}
final rampAreas = ramp.children.whereType<SparkyRampArea>().toList();
expect(rampAreas.length, 2);
},
);
});
@ -93,21 +81,7 @@ void main() {
group('SparkyRampArea', () {
flameTester.test(
'loads correctly',
(game) async {
final ramp = SparkyRampArea(
position: Vector2.zero(),
orientation: RampOrientation.down,
);
await game.ready();
await game.ensureAdd(ramp);
expect(game.contains(ramp), isTrue);
},
);
flameTester.test(
'orientation correctly',
'orientation is down',
(game) async {
final position = Vector2.all(10);
final ramp = SparkyRampArea(
@ -120,91 +94,6 @@ void main() {
expect(ramp.orientation, RampOrientation.down);
},
);
group('body', () {
flameTester.test(
'positions correctly',
(game) async {
final position = Vector2.all(10);
final ramp = SparkyRampArea(
position: position,
orientation: RampOrientation.down,
);
await game.ready();
await game.ensureAdd(ramp);
expect(ramp.body.position, position);
},
);
flameTester.test(
'is static',
(game) async {
final ramp = SparkyRampArea(
position: Vector2.zero(),
orientation: RampOrientation.down,
);
await game.ready();
await game.ensureAdd(ramp);
expect(ramp.body.bodyType, equals(BodyType.static));
},
);
group('fixtures', () {
flameTester.test(
'has only one shape',
(game) async {
final ramp = SparkyRampArea(
position: Vector2.zero(),
orientation: RampOrientation.down,
);
await game.ready();
await game.ensureAdd(ramp);
expect(ramp.body.fixtures.length, 1);
for (final fixture in ramp.body.fixtures) {
expect(fixture, isA<Fixture>());
expect(fixture.shape, isA<PolygonShape>());
}
},
);
flameTester.test(
'is sensor',
(game) async {
final ramp = SparkyRampArea(
position: Vector2.zero(),
orientation: RampOrientation.down,
);
await game.ready();
await game.ensureAdd(ramp);
final fixture = ramp.body.fixtures.first;
expect(fixture.isSensor, isTrue);
},
);
flameTester.test(
'sets correctly filter categoryBits to RampType.sparky',
(game) async {
final ramp = SparkyRampArea(
position: Vector2.zero(),
orientation: RampOrientation.down,
);
await game.ready();
await game.ensureAdd(ramp);
final fixture = ramp.body.fixtures.first;
expect(
fixture.filterData.categoryBits,
equals(RampType.sparky.maskBits),
);
},
);
});
});
});
group('SparkyRampAreaCallback', () {

Loading…
Cancel
Save