Monday, August 15, 2011

CQ Simulation: Fixing Assigning Users to Seats

I want to do two things in the next few days:

  • Add the current tick to the Results class. Since I'm passing the results object back and forth between classes and since some of the results will need to know what time it is in the simulation, it seems to make sense.
  • Fix the assigning of users to seats so that it respects the time of the simulation. (Per the last post.)

After that, I want to take a break from working on functionality to do some infrastructure work:

  • Clean up the method tests and get them all in documented files.
  • Fill in any method tests that haven't been written (as well as constructor tests, if necessary).
  • Code-level documentation for all classes.
  • Change the names of variables. I picked some really, really confusing names.

I didn't do code-level docs yet because the code has been in flux. Now that the basic methods have been laid out, I can document method signatures.

Today: Assigning users to seats.

Here's my first run at the code:

foreach (Seat c in seats) {

if (c.Free) {

if (computerQueue.Count [GREATERTHAN] 0) {

foreach (DataUser e in computerQueue) {

if (e.QueueUpTime [GREATERTHAN]= simTick) {

c.currentUser = e;

computerQueue.Remove(e);

}

}

}

}

}

(And I HATE how complicated this looks.)

Let's see if it works.


Except for one typo that I just fixed, it compiled. It does fail one test. Hold on a second.

Oops – since the Remove method changes the list, it can't proceed through the foreach loop.

Actually, I don't want it to. I wonder if I can just slip in a break statement.

Ah, that fixed the coding problem, but it still leaves the wrong test result. That is, the simulation is still consuming 6 of the users when it should not consume any on the first tick.

Ah – I put in [GREATERTHAN]=, not [LESSTHAN]=. Fixing that fixes the problem.

Tomorrow, I'll write a better test for this.


No comments:

Post a Comment