The Pex team has created a site that provides a great tool to exercise your brain, learn a bit of code, and see a bit about Pex.
To use it, just go to the PexForFun site. There are puzzles, learning exercises, and duels. Register and you can create your own challenges. (I’ll be doing this over the next month or so.)
The puzzle structure is a great demonstration of Pex. When you start a new puzzle, you have a empty implementation. You can click Ask Pex to get some test results on the hidden successful implementation. Pex then executes those tests on your code. You’ll see some failures, and you can fix your code to make the tests pass.
Then, you can click “Ask Pex” again, and see if a more extensive test suite still passes. Iterating this way gets you to write more code and your implementation gets closer to the expected solution. If you are not familiar with Test Driven Development, I highly recommend it. You’ll get a real feel for creating code to an executable specification instead of a written spec.
All in all, there are several reasons I like playing with PexForFun:
- It’s practice for Test Driven Development. you start with an empty implementation, and see a few failing tests. Keep making a few pass and you’ll get more tests. After a few iterations you’ll have everything working.
- It will give you some practice writing tests. Pex generates tests by analyzing your code. It determines a number of interesting inputs to code by analyzing its structure. You can read an overview here: http://www.pexforfun.com/Documentation.aspx#HowDoesPexWork By seeing the inputs it chooses, you’ll get some ideas how to write your own tests. By thinking about inputs it chooses to ignore, you can get better at writing useful tests instead of more tests.
- It exercises your brain. The puzzles range from introductory to rather complicated.
- You can pick different languages for your puzzles: C#, VB and F#.
Learn some new techniques, exercise your brain, and most of all: Have fun!