This Saturday is the 2010 Chicago Code Camp (Last year's rocked!) For those who have a passion for coding, this is the event for you!
The idea is that you can have the most powerful technology in the world, but if it's not focused in a profitable direction, your business (which pays for the technology) will never get to the right place.
You need both tech and business, else you plateau very quickly. Without business understanding, the technologists can build amazing things - that no one wants. That's fine for hobbyists and CS college students, but not sustainable for companies.
Without technical understanding, the business people can dream of profitable ideas - that no one can build.
You can unit test random methods by running the method in a loop and checking for statistical results.
For example, say you have a method to return a random integer between 1 and 10 (this could just as easily be to return any type between any range). You could run the test 100,000 times and confirm that the statistical distribution makes sense. With a sufficient sample size, there should be at least one of each value. The mathematically advanced could apply better statistics, like checking the proper distribution.
Here's a simple sample. It runs the random method in a loop, and checks just that each value was returned at least once.
public class MathHelper
{
private static Random _r = new Random();
public static int GetRandomInt()
{
//return Random int between 1 and 10
//recall that upper bound is exclusive, so we use 11
return _r.Next(1, 11);
}
}
[TestMethod]
public void Random_1()
{
int iMinRandomValue = 1;
int iMaxRandomValue = 10;
//Initialize results array
//ignore 0 value
int[] aint = new int[11];
for (int i = iMinRandomValue; i <= iMaxRandomValue; i++)
{
aint[i] = 0;
}
//Run method many times, record result
//Every time a number is returned, increment its counter
const int iMaxLoops = 1000;
for (int i = 0; i < iMaxLoops; i++)
{
int n = MathHelper.GetRandomInt();
aint[n] = aint[n] + 1;
}
//assert that each value, 1-10, was returned
for (int i = iMinRandomValue; i <= iMaxRandomValue; i++)
{
Assert.IsTrue(aint[i] > 0,
string.Format("Value {0} never returned.", i));
}
}
Of course, this assumes you're explicitly trying to test the random method - you could mock it out if the method is just a dependency and you're trying to test something else.
Two things that really got my attention:
Thanks Lance!
The book is divided into 34 small chapters, each based on insightful stories based on in-the-trenches experiences. Lots of people-books offer fluff: "be nice to all your coworkers", "work hard", "always brush your teeth so your bad breath doesn't alienate your coworkers", etc... Michael bypasses the obvious and gets to the good stuff. Some of the big points I took away:
Blunt Truths
Other misc quotes
Most devs I meet hate process, almost like it's a stupidity-tax from some ivory-tower folk (who themselves don't actually need to use the process that they're imposing on others). These devs just want to get the app done, and they think that the process gets in their way with tedious constraints that add no value. I recall projects with "process" like forcing devs to go and update all the internal variable names to be compliant with some new coding standard, or not allowing devs to have admin rights to their own machines until three levels of paperwork is approved (good luck being a dev using a Windows OS if you're not an admin), or requiring that developers test the app by taking success screen shots of every single step - and then printing out that 600 page doc and getting it signed by QA.
That sort of stuff bothers me too, but I'm still a big fan of good process. What I realize is that I essentially view "process" as "developer infrastructure enhancements". I think of process as helpful things like automation, unit tests, code generation, proper tools, CI builds, checkout and install scripts, etc... Devs just want to get the job done, and good process assists them in doing that, it doesn't burden them with ivory-tower taxes. If your process code-generates the data access layer, then the dev need not do all that manual ADO.Net plumbing code, and hence the dev gets the job done faster.
Sure, it's semantics - "process" vs. "infrastructure enhancements", but semantics are important because it affects how a thought is communicated to other people, and people are important.