Recently I’ve been eagerly reading “The
New Turing Omnibus – 66 Excursions in Computer Science” by A. K. Dewdney
and let me tell you, this book is addictive. An interesting essay was about
Simulation and the
wasn’t anything exciting in the actual explanation of the process but the
deduction lead to the concept of having test scenarios based on simulation. Test
Correctness strategies currently follow this approach in a specialized way
however there is no general toolset available in which, lets say, one can
integrate the test fixtures with different distribution based inputs.
The idea is not novele as papers has been written about Toward models for probabilistic program correctness as early
as 1978 however, we have yet to see the availability for a commoner in a unit
testing framework developers actively use.
- Generating test suites for software load testing
- Testable algorithms for self-avoiding walks
- Fast Monte Carlo algorithms for permutation groups
- Track 2: grid computing (part 2): Grid result checking
- Designing programs that check their work
For instance, this simple teller based simulation for management
from Discrete
Event Simulation which I’ve translated to C#, an ideal candidate for such a
text fixture.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace Discrete.NET
{
class SimpleInventorySystem
{
string FILENAME="sis1.dat"; /* input data file */
long MINIMUM=20; /* 's' inventory policy parameter */
long MAXIMUM=80; /* 'S' inventory policy parameter */
long GetDemand(FILE *fp)
{
long d;
fscanf(fp, "%ld\n", &d);
return (d);
}
int Process()
{
File fp; /* input data file */
long index = 0; /* time interval index */
long inventory = MAXIMUM; /* current inventory level */
long demand; /* amount of demand */
long order; /* amount of order */
struct sum
{ /* sum of ... */
double setup; /* setup instances */
double holding; /* inventory held (+) */
double shortage; /* inventory short (-) */
double order; /* orders */
double demand; /* demands */
};
//= { 0.0, 0.0, 0.0, 0.0, 0.0 };
//Open the file and check if its null;
//fprintf(stderr, "Cannot open input file %s\n", FILENAME);
while (!feof(fp)) {
index++;
if (inventory < MINIMUM) { /* place an order */
order = MAXIMUM - inventory;
sum.setup++;
sum.order += order;
}
else /* no order */
order = 0;
inventory += order; /* there is no delivery lag */
demand = GetDemand(fp);
sum.demand += demand;
if (inventory > demand)
sum.holding += (inventory - 0.5 * demand);
else {
sum.holding += sqr(inventory) / (2.0 * demand);
sum.shortage += sqr(demand - inventory) / (2.0 * demand);
}
inventory -= demand;
}
if (inventory < MAXIMUM) /* force the final inventory to */
{
order = MAXIMUM - inventory; /* match the initial inventory */
sum.setup++;
sum.order += order;
inventory += order;
}
printf("\nfor %ld time intervals ", index);
printf("with an average demand of %6.2f\n", sum.demand / index);
printf("and policy parameters (s, S) = (%d, %d)\n\n", MINIMUM, MAXIMUM);
printf(" average order ............ = %6.2f\n", sum.order / index);
printf(" setup frequency .......... = %6.2f\n", sum.setup / index);
printf(" average holding level .... = %6.2f\n", sum.holding / index);
printf(" average shortage level ... = %6.2f\n", sum.shortage / index);
//fclose(fp); close the file
return (0);
} // Ends Class
} // Ends namespace