So, here's code to fix the problem from yesterday:
foreach (Seat c in seats) {
if (c.Free) {
if (computerQueue.Count [GREATERTHAN] 0) {
c.currentUser = computerQueue[0];
computerQueue.RemoveAt(0);
}
}
}
I could move the conditional outside the foreach statement, meaning that the system would not bother trying to fill seats if there were no users to fill them with.
Oh, that wouldn't work – what if there was one user waiting and two seats to fill?
So, the current version passes the existing tests.
At this point, there's no reporting of results. I'm going to start tackling that now. (There is lots of work – lots of work – left to do on the simulation behavior. I want to implements some results code now so that I can make better tests for the behavior.
My approach for this is to create a Results class that will have whatever I want to track. Here's a first draft:
public class Results
{
// FIELDS
public int totalUsers;
public int usersAbandoned;
public int usersExpired;
public int totalUserWaitTime;
public int totalSystemFreeTime;
}
There'll be a bunch more code – methods to collect and process the data.
I added a new Results object to the Simulation fields:
private Results results;
And I added that result object to the calls to the ticks:
foreach (DataUser a in computerQueue) {
a.tick(simTick, results);
}
foreach (Seat b in seats) {
b.tick(results);
Which means that I have to add a result object to the tick methods for those files.
The plan is for the results object to record state changes when the system calls a tick on each object – datauser or seat. Next time, I'll start implementing that record keeping.
The other thing that this change did was to break a number of existing tests. Several of them call tick directly on some objects. Since the method signatures are changed, there's nothing for them to call.
I fixed this by creating wrappers in the test code:
public void tick(int x)
{
tick(x, new Results());
}
…
#if DEBUG
// TESTING CODE
public void tick()
{
tick(new Results());
}
#endif
And that's it for today.
No comments:
Post a Comment