UNB/ CS/ David Bremner/ teaching/ cs2613/ labs/ Lab 12

Before the lab

Background


Discussion

Time
10 minutes

Completing test coverage for VillageState

Time
20 minutes
Activity
individual

Testing the random robot I/II

Time
20 minutes
Activity
individual, adding tests

The function runRobot provides several challenges to our usual unit testing methodology. The first is the we need to test it's output (i.e. from console.log) rather than it's return value.

describe("runRobot",
         function() {
             it("no parcels",
                 function() {
                    console.log = _________________________;
                    noParcels = new VillageState("Post Office",[]);
                    village.runRobot(noParcels);
                    expect(console.log).toHaveBeenCalledWith(________________);
                })});

Testing the random robot II/II

Time
25 minutes
Activity
Demo / individual
runRobot(VillageState.random(), randomRobot);

or, from the book in the browser

runRobotAnimation(VillageState.random(), randomRobot);

Robot with a route

Time
25 minutes
Activity
Individual, following book
     village.runRobot(village.VillageState.random(), village.routeRobot, []);
let village=require("./village.js");

function measureRobot(state, robot, memory) {
  for (let turn = 0;; turn++) {
    if (state.parcels.length == 0) {
        return turn;
    }
    let action = robot(state, memory);
    state = state.move(action.direction);
    memory = action.memory;
  }
}

function compareRobots(robot1, memory1, robot2, memory2) {
    // your code goes here
}

compareRobots(village.routeRobot,[], village.randomRobot, []);