96 lines
2.7 KiB
Dart
96 lines
2.7 KiB
Dart
import 'package:test/test.dart';
|
|
import 'package:tdd_katas/mars_rover.dart';
|
|
|
|
void main() {
|
|
group('Mars Rover:', () {
|
|
test('rover reports initial position and direction', () {
|
|
final rover = Rover(x: 0, y: 0, direction: 'N');
|
|
|
|
expect(rover.x, equals(0));
|
|
expect(rover.y, equals(0));
|
|
expect(rover.direction, equals('N'));
|
|
});
|
|
|
|
group('Turning Left:', () {
|
|
test('from North faces West', () {
|
|
final rover = Rover(x: 0, y: 0, direction: 'N');
|
|
rover.turnLeft();
|
|
expect(rover.direction, equals('W'));
|
|
});
|
|
|
|
test('from West faces South', () {
|
|
final rover = Rover(x: 0, y: 0, direction: 'W');
|
|
rover.turnLeft();
|
|
expect(rover.direction, equals('S'));
|
|
});
|
|
|
|
test('from South faces East', () {
|
|
final rover = Rover(x: 0, y: 0, direction: 'S');
|
|
rover.turnLeft();
|
|
expect(rover.direction, equals('E'));
|
|
});
|
|
|
|
test('from East faces North', () {
|
|
final rover = Rover(x: 0, y: 0, direction: 'E');
|
|
rover.turnLeft();
|
|
expect(rover.direction, equals('N'));
|
|
});
|
|
});
|
|
|
|
group('Turning Right:', () {
|
|
test('from North faces East', () {
|
|
final rover = Rover(x: 0, y: 0, direction: 'N');
|
|
rover.turnRight();
|
|
expect(rover.direction, equals('E'));
|
|
});
|
|
|
|
test('from East faces South', () {
|
|
final rover = Rover(x: 0, y: 0, direction: 'E');
|
|
rover.turnRight();
|
|
expect(rover.direction, equals('S'));
|
|
});
|
|
|
|
test('from South faces West', () {
|
|
final rover = Rover(x: 0, y: 0, direction: 'S');
|
|
rover.turnRight();
|
|
expect(rover.direction, equals('W'));
|
|
});
|
|
|
|
test('from West faces North', () {
|
|
final rover = Rover(x: 0, y: 0, direction: 'W');
|
|
rover.turnRight();
|
|
expect(rover.direction, equals('N'));
|
|
});
|
|
});
|
|
|
|
group('Moving Forward:', () {
|
|
test('facing North increases Y', () {
|
|
final rover = Rover(x: 0, y: 0, direction: 'N');
|
|
rover.moveForward();
|
|
expect(rover.x, equals(0));
|
|
expect(rover.y, equals(1));
|
|
});
|
|
|
|
test('facing East increases X', () {
|
|
final rover = Rover(x: 0, y: 0, direction: 'E');
|
|
rover.moveForward();
|
|
expect(rover.x, equals(1));
|
|
expect(rover.y, equals(0));
|
|
});
|
|
|
|
test('facing South decreases Y', () {
|
|
final rover = Rover(x: 0, y: 5, direction: 'S');
|
|
rover.moveForward();
|
|
expect(rover.x, equals(0));
|
|
expect(rover.y, equals(4));
|
|
});
|
|
|
|
test('facing West decreases X', () {
|
|
final rover = Rover(x: 5, y: 0, direction: 'W');
|
|
rover.moveForward();
|
|
expect(rover.x, equals(4));
|
|
expect(rover.y, equals(0));
|
|
});
|
|
});
|
|
});
|
|
}
|