import 'package:tdd_katas/mars_rover.dart'; import 'package:test/test.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)); }); }); group('Executing Command Sequences:', () { test('single command L', () { final rover = Rover(x: 0, y: 0, direction: 'N'); rover.execute('L'); expect(rover.direction, equals('W')); }); test('single command R', () { final rover = Rover(x: 0, y: 0, direction: 'N'); rover.execute('R'); expect(rover.direction, equals('E')); }); test('single command M', () { final rover = Rover(x: 0, y: 0, direction: 'N'); rover.execute('M'); expect(rover.y, equals(1)); }); test('complex sequence MMRMMLM', () { final rover = Rover(x: 0, y: 0, direction: 'N'); rover.execute('MMRMMLM'); expect(rover.x, equals(2)); expect(rover.y, equals(3)); expect(rover.direction, equals('N')); }); test('example from Mars Rover kata', () { final rover = Rover(x: 1, y: 2, direction: 'N'); rover.execute('LMLMLMLMM'); expect(rover.x, equals(1)); expect(rover.y, equals(3)); expect(rover.direction, equals('N')); }); }); group('Plateau Boundaries:', () { test('wraps around when moving North past boundary', () { final rover = Rover( x: 0, y: 5, direction: 'N', plateauWidth: 5, plateauHeight: 5, ); rover.moveForward(); expect(rover.y, equals(0)); }); test('wraps around when moving East past boundary', () { final rover = Rover( x: 5, y: 0, direction: 'E', plateauWidth: 5, plateauHeight: 5, ); rover.moveForward(); expect(rover.x, equals(0)); }); test('wraps around when moving South past boundary', () { final rover = Rover( x: 0, y: 0, direction: 'S', plateauWidth: 5, plateauHeight: 5, ); rover.moveForward(); expect(rover.y, equals(5)); }); test('wraps around when moving West past boundary', () { final rover = Rover( x: 0, y: 0, direction: 'W', plateauWidth: 5, plateauHeight: 5, ); rover.moveForward(); expect(rover.x, equals(5)); }); test('example with wrapping', () { final rover = Rover( x: 5, y: 5, direction: 'N', plateauWidth: 5, plateauHeight: 5, ); rover.execute('MMM'); expect(rover.y, equals(2)); }); }); }); }