Design unit tests for grid navigation

Quick Overview

This question evaluates unit test design, mocking/stubbing of external APIs, deterministic simulation, and correctness of grid-navigation controller logic under edge cases, loops, performance limits, and API error behaviors.

Design unit tests for grid navigation

Company: Meta

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: medium

Interview Round: Technical Screen

Propose a comprehensive set of unit tests for the mouse-maze controller described above. Include tests for: single-cell maze; unreachable cheese; narrow corridors and cul-de-sacs; loops/cycles; large open spaces; obstacle directly ahead; repeated visits and backtracking correctness; multiple cheeses (ensure the first found is returned); performance and stack-depth limits; and API error behavior (e.g., move() throwing). Describe how to stub/simulate the interface deterministically.

Quick Answer: This question evaluates unit test design, mocking/stubbing of external APIs, deterministic simulation, and correctness of grid-navigation controller logic under edge cases, loops, performance limits, and API error behaviors.

|Home/Software Engineering Fundamentals/Meta
Meta logo
Meta
Sep 6, 2025, 12:00 AM
mediumSoftware EngineerTechnical ScreenSoftware Engineering Fundamentals
3
0

Mouse-Maze Controller: Design a Comprehensive Unit Test Suite

Context (assumptions to make the task self-contained)

Assume we are testing a controller that navigates a grid-based maze to find cheese. The controller drives an abstract Maze API and must return the first cheese it finds according to a deterministic neighbor-order policy. Multiple cheeses may exist; some may be unreachable.

  • Grid representation: rectangular grid with walls and open cells.
  • Start position: a single cell where the mouse begins.
  • Cheese: one or more target cells; reaching any one ends the search successfully.
  • Deterministic neighbor exploration order: Up, Right, Down, Left (URDL), unless otherwise specified.
  • The Maze API can signal walls/valid moves and may throw errors on move attempts.
  • Controller output: either a path (sequence of directions) to a found cheese, or a NotFound/Failure result.

You may minimally adjust the exact API shape but keep behavior semantically equivalent to the above.

Task

Propose a comprehensive set of unit tests for the mouse-maze controller. Include tests for:

  1. Single-cell maze
  2. Unreachable cheese
  3. Narrow corridors and cul-de-sacs
  4. Loops/cycles
  5. Large open spaces
  6. Obstacle directly ahead
  7. Repeated visits and backtracking correctness
  8. Multiple cheeses (ensure the first found is returned)
  9. Performance and stack-depth limits
  10. API error behavior (e.g., move() throwing)

Also describe how to stub/simulate the Maze API deterministically to support these tests.

Loading comments...