Making Sample Data Can Be Fun


I’ve just released the first year coursework specification. We are going to be creating a system for a record shop which will track customer orders and suggest new records to buy. I think the only reason I went for a record shop was so I could call it “Vinyl Destination”, but that is by the by.

The program needs to be able to track huge numbers of records and customers, along with their orders. The problem is that, at the start, we don’t have any customers or orders, or anything. And anyone that thinks the way to solve this problem is to sit down and enter some details when the program has been built is very, very wrong.

I make the test data right at the start. I use a program to do it. All it takes is a few loops. Now, I could give the customers names like “Customer1”, “Customer2” and so on. But I can do better than that. All I need are some names to start with:

string [] firstNames = new string [] { "Rob", "Fred", "Jim", 
  "Ethel", "Nigel", "Simon", "Gloria", "Evadne" };
string [] surnames = new string[] { "Bloggs", "Smith", 
 "Jones", "Thompson", "Wooster", "Brown", "Acaster", 
  "Berry", "Ackerman" };

Here we have two arrays, one of first names and the other of surnames. I can now make myself a whole bunch of reasonable looking customers:

foreach (string surname in surnames)
    foreach (string firstname in firstNames)
        Customer c = new Customer(firstname + " " 
                                  + surname);

This makes us a whole bunch of customers, from “Rob Bloggs” all the way to “Evadne Ackerman”. We can do something similar with the names for each of the recording artists:

string[] artist1 = new string[] { "Pink", "Flying", "Random", 
    "Singing", "Uptown", "Family", "Floating" };
string[] artist2 = new string[] { "Chicken", "Circus",
    "Banana", "Kitchen", "Groats", "Monkey", "Collective", "Pyjamas" };

I can combine the words to make random artist names.

string artist = artist1[rand.Next(artist1.Length)] + 
    " " + artist2[rand.Next(artist2.Length)];

This picks a random word from the first list and adds it to the second one (rand is just a random number generator that I use to make my test data). So I can have “Pink Pyjamas” and “Singing Groat”, among others. I do something similar for the track names, except that I have three parts. As you can see in the screenshot, this makes for some quite funny combinations, that liven up testing no end.