( VS2010 )

I use son of obsidian from http://studiostyl.es/ with the following change:

Current Line Extension to gray

I decided to try and do Test Driven Development here, so avoid any small problems.

Problem was that my test harness in VS2010 wouldn’t start the agent: http://stackoverflow.com/questions/4446416/vs2010-test-runner-unable-to-start-agent-process (Edit: It was Avira AntiVirus that was the culprit)

After reinstalling VS2010, and trying to remember all the changes I’ve made since it last worked.. I can run all the tests, just not in the debugger. Which is very useful.

Euler problem is interesting:

The sum of the squares of the first ten natural numbers is,

1^{2} + 2^{2} + ... + 10^{2} = 385

The square of the sum of the first ten natural numbers is,

(1 + 2 + ... + 10)^{2} = 55^{2} = 3025

Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 385 = 2640.

Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.

Source code here:

class Program

{

static void Main(string[] args)

{

stuff thing = new stuff();

double sumOfSqaures = thing.sumOfSquares(100);

double sqaureOfSums = thing.SquareOfSum(100);

double result = sqaureOfSums - sumOfSqaures;

Console.WriteLine(result);

}

}

public class stuff

{

public double sumOfSquares(double upToInt)

{

double total = 0;

for (int i = 1; i <= upToInt; i++)

total += Math.Pow(i, 2);

return total;

}

public double SquareOfSum(int upToInt)

{

double sum = 0;

for (int i = 0; i <= upToInt; i++)

sum += i;

return Math.Pow(sum, 2);

}

}

and test code:

[TestClass]

public class UnitTest1

{

[TestMethod]

public void SumOfSquaresOfFirst10()

{

stuff thing = new stuff();

double result = thing.sumOfSquares(10);

Assert.AreEqual(385, result);

}

[TestMethod]

public void SquareOfSumOfFirst10()

{

stuff thing = new stuff();

double result = thing.SquareOfSum(10);

Assert.AreEqual(3025, result);

}

[TestMethod]

public void DifferenceBetweenTwoAbove()

{

stuff thing = new stuff();

double sumOfSqaures = thing.sumOfSquares(10);

double sqaureOfSums = thing.SquareOfSum(10);

double result = sqaureOfSums - sumOfSqaures;

Assert.AreEqual(2640, result);

}

}

It was great using TDD.. made it very easy, and got answer right first time!

( VS2010 )

Debug.WriteLine("asdf");

System.Diagnostics.Trace.WriteLine("asdfasdf");

Second one works in release mode.

Useful to : "Redirect all Output Window text to the Immediate Window" is checked under Tools -> Options -> Debugging -> General.