Skip to content
Aug 23 11

fatal error C1859

by Alex Peck

Once, a friend of mine set the welcome message on his Nokia 5110 to ‘fatal error’. This totally baffled the salesmen in Carphone Warehouse.

I was equally baffled when I returned to an old C++ project and tried to compile it in a freshly installed Visual Studio 2008 SP1. I was greeted with a series of these errors:

fatal error C1859: ‘Debug\blah.pch’ unexpected precompiled header error, simply rerunning the compiler might fix this problem

Not surprisingly, simply rerunning the compiler did not fix the problem. In fact, this is caused by address space layout randomization on Windows7/Server2008, as noted here.

The hotfix is available here: Fix for Visual C++ 2008 SP1 compiler error C1859

Jul 9 11

How to do unit test reviews

by Alex Peck

At work we have begun to push unit testing and even TDD. Consequently code reviews now include more unit tests. Often, reviewers are very focused on product code, and neglect to review tests in detail.

Letting poor quality test code slip in is a big problem. Fragile tests erode confidence in unit testing as a valuable exercise, and tests which are hard to maintain just slow you down when the inevitable changes are required.

When I review unit test code, I consider the following:

  • Unit tests must favour readability. They must be compact, have a clear relationship between cause and effect, and use descriptive and meaningful phrases (DAMP).
  • Unit tests should assert once. There must be a clear relationship between test case method name and the assertion(s). This way, it is easy to determine the purpose of the test at a glance, and it is obvious what it means if the test fails.
  • Prefer state verification to behaviour verification. If you must verify behaviour (because there is no state, or it is unreasonably difficult to test state), be very careful not to over specify expectations.
  • Unit tests must be based on the public interface of a class. Testing internals makes your tests fragile. This is related to behaviour verification, sometimes you need to verify internal interactions, but this is not the same as invoking private methods in order to test them.
  • Unit tests must not contain (or contain very little) conditional logic, such as branches or loops. Conditional logic makes code harder to read.
  • Unit tests must be easy to maintain. As far as possible, DRY by applying the following techniques: use test setup/tear down methods to execute code common to all tests; implement custom verification functions or classes; use framework features like CollectionAssert, IEqualityComparer or IComparer.

Further reading/viewing:

xUnit Test Patterns
Write Maintainable Unit Tests That Will Save You Time And Tears – Roy Osherove
How to do test reviews – Roy Osherove

Jun 24 11

Steven Sinofsky’s D9 Interview

by Alex Peck

Sinofsky seems overly defensive to me. I like the Metro UI, and I think it will work well for tablets. I’m less convinced with replacing the start menu with a Metro hub.

Jun 22 11

Extension method to compute standard deviation of IEnumerable<TimeSpan>

by Alex Peck

Recently, I have been writing some quick and dirty performance tests. I repeat each test scenario a few times and take an average of the execution time. In order to verify that I have a reasonably stable measurement, I wanted to also display the coefficient of variation, which is defined as the ratio of the standard deviation to the mean.

Given a set of TimeSpan values, I want to get the standard deviation as a TimeSpan. I implemented this based on the extension method I found here on StackOverflow. I implemented both sample (with Bessel’s correction) and population standard deviation.

public static class StandardDeviationExtensions
{
    public static double SampleStandardDeviation(this IEnumerable<double> values)
    {
        int count = values.Count();
 
        if (count > 1)
        {
            double average = values.Average();
            double sumOfSquaredDifferences = values.Sum(v => Math.Pow(v - average, 2));
            return Math.Sqrt(sumOfSquaredDifferences / (count - 1));
        }
 
        return 0.0;
    }
 
    public static double PopulationStandardDeviation(this IEnumerable<double> values)
    {
        if (values.Count() > 1)
        {
            double average = values.Average();
            return Math.Sqrt(values.Average(v => Math.Pow(v - average, 2)));
        }
 
        return 0.0;
    }
 
    public static TimeSpan SampleStandardDeviation(this IEnumerable<TimeSpan> values)
    {
        return new TimeSpan(
            (long)values
                .Select(v => (double)v.Ticks)
                .SampleStandardDeviation());
    }
 
    public static TimeSpan PopulationStandardDeviation(this IEnumerable<TimeSpan> values)
    {
        return new TimeSpan(
            (long)values
                .Select(v => (double)v.Ticks)
                .PopulationStandardDeviation());
    }
}

And here are the tests:

[TestClass]
public class StandardDeviationTest
{
    private readonly double[] EmptySet = new double[] {};
    private readonly double[] SingleValue = new double[] { 1.0 };
    private readonly double[] SameValues = new double[] { 5.0, 5.0, 5.0 };
    private readonly double[] ScenarioValues = new double[] { 2.0, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0 };
 
    private const double ScenarioValuesSampleDeviation = 2.13809;
    private const double ScenarioValuesPopulationDeviation = 2.0;
 
    [TestMethod]
    public void SampleStandardDeviation_EmptySet_HasZeroDeviation()
    {
        Assert.AreEqual(0.0, EmptySet.SampleStandardDeviation());
    }
 
    [TestMethod]
    public void SampleStandardDeviation_SingleValue_HasZeroDeviation()
    {
        Assert.AreEqual(0.0, SingleValue.SampleStandardDeviation());
    }
 
    [TestMethod]
    public void SampleStandardDeviation_SetOfSameValues_HasZeroDeviation()
    {
        Assert.AreEqual(0.0, SameValues.SampleStandardDeviation());
    }
 
    [TestMethod]
    public void SampleStandardDeviation_ScenarioValues_HaveExpectedDeviation()
    {
        Assert.AreEqual(ScenarioValuesSampleDeviation, Math.Round(ScenarioValues.SampleStandardDeviation(), 5));
    }
 
    [TestMethod]
    public void SampleStandardDeviation_TimeSpanScenarioValues_HaveExpectedDeviation()
    {
        var timeSpanValues = ScenarioValues.Select(seconds => new TimeSpan(0, 0, (int)seconds));
        var result = timeSpanValues.SampleStandardDeviation().TotalSeconds;
        Assert.AreEqual(ScenarioValuesSampleDeviation, Math.Round(result, 5));
    }
 
    [TestMethod]
    public void PopulationStandardDeviation_EmptySet_HasZeroDeviation()
    {
        Assert.AreEqual(0.0, EmptySet.PopulationStandardDeviation());
    }
 
    [TestMethod]
    public void PopulationStandardDeviation_SingleValue_HasZeroDeviation()
    {
        Assert.AreEqual(0.0, SingleValue.PopulationStandardDeviation());
    }
 
    [TestMethod]
    public void PopulationStandardDeviation_SetOfSameValues_HasZeroDeviation()
    {
        Assert.AreEqual(0.0, SameValues.PopulationStandardDeviation());
    }
 
    [TestMethod]
    public void PopulationStandardDeviation_ScenarioValues_HaveExpectedDeviation()
    {
        Assert.AreEqual(ScenarioValuesPopulationDeviation, Math.Round(ScenarioValues.PopulationStandardDeviation(), 5));
    }
 
    [TestMethod]
    public void PopulationStandardDeviation_TimeSpanScenarioValues_HaveExpectedDeviation()
    {
        var timeSpanValues = ScenarioValues.Select(seconds => new TimeSpan(0, 0, (int)seconds));
        var result = timeSpanValues.PopulationStandardDeviation().TotalSeconds;
        Assert.AreEqual(ScenarioValuesPopulationDeviation, Math.Round(result, 5));
    }
}
Jun 18 11

Battlefield 3: Thunder Run

by Alex Peck

Mar 2 11

Battlefield 3

by Alex Peck

I cannot wait.

Nov 22 10

Windows Phone 7 OneNote SkyDrive synchronization

by Alex Peck

This would appear to be a straightforward process, as described here. However, when I did it, I persistently received Error 8007002: synchronization failure.

My workaround was as follows:

      1. Using a PC, create a new notebook in SkyDrive. Open the new notebook and the Personal (Web) notebook in seperate tabs. Copy the contents from the old to teh new (the tedious part).
      2. Using your phone, go to office.live.com and log in. Open the new notebook in OneNote.
      3. Using your phone, set the new notebook as default and remove Personal (Web).
      4. Using a PC, delete the Personal (Web) notebook from skydrive

I later got Error 8007002 after renaming a section (which is a bug), and had to repeat the process yet again. So, don’t rename sections!

Nov 5 10

Programming Windows Phone 7

by Alex Peck

Programming Windows Phone 7 by Charles Petzold is available for free here.

Charles Petzold: Branded

Oct 19 10

Natural User Interface TechTalk

by Alex Peck


Get Microsoft Silverlight

Bill Buxton gives a great historical perspective on user interfaces and the pace of innovation.

Sep 16 10

Ken Block Gymkhana 3 Part 2

by Alex Peck

Not sure I’m a big fan of the Fiesta.