Start from one of the following templates to create your own puzzle. You can also click the New button on the main Pex for fun page to load a template.
(Note that you can only create Coding Duels for C# and F#.)
Puzzle
When you click Ask Pex!, Pex for fun will explore a particular method.
You can indicate the method to explore in one of two ways:
PexClass
PexMethod
Download the regular desktop version of Pex to explore any method in your code.
How does Pex choose input values? Pex does not
Instead, Pex generates input values by analyzing the program code. For every statement in the code, Pex eventually tries to create input values that will reach that statement. Pex performs a case analysis for every conditional branch in the codeāfor example, if statements, assertions, and all operations that can throw exceptions. In other words, the number of input values that Pex generates depends on the number and possible combinations of conditional branches in the code. Pex operates in a feedback loop: it executes the code multiple times and learns about the program's behavior by monitoring the control and data flow.
After each run, Pex does the following:
The code is executed again with the new input values, and the process repeats. On each run, Pex might discover new code and dig deeper into the implementation. In this way, Pex explores the behavior of the code.
Visit the Learn area to learn with examples and exercises how it works in detail.
Pex for fun is a simplified version of Pex. Download the regular desktop version of Pex, which integrates into Visual Studio, can explore an entire project at once, and can automatically generate a comprehensive test suite of traditional unit tests.
Pex for fun is a simplified version of Pex.
One of its limitations is that it only allows you to use certain system libraries and types you define explicitly in the provided code.
Download the regular desktop version of Pex to overcome this limitation.
Code Contracts provide a language-agnostic way to express coding assumptions in .NET programs. The contracts take the form of preconditions, postconditions, and object invariants. Contracts act as checked documentation of your external and internal APIs.
Pex uses contracts to find runtime errors, such as cases where postconditions or invariants are not satisfied.
Contracts are expressed by using static method calls at method entries. Tools take care to interpret these declarative contracts in the right places. These methods are found in the System.Diagnostics.Contracts namespace, which is part of .NET 4.0.
System.Diagnostics.Contracts
Contract.Requires
Contract.Ensures
Contract.Result
Full details are in the Code Contracts user documentation.
The contracts are checked when running or exploring your code with Pex. In addition to the runtime checking, a static checker can be invoked by clicking Ask Code Contracts Verifier, a button that only appears when the program text contains contracts, and the [ContractVerification(true)] attribute.
[ContractVerification(true)]
If you want to use Contracts in your own project in Visual Studio, you need to download the Code Contracts tools, which are not included in .NET 4.0. Read the Code Contracts documentation to learn how to enable them in your project.
Pex for fun comes with a sample puzzle that uses Code Contracts.
When Pex for fun thinks, it is actually solving constraint systems, which is a CPU-intensive task on our servers. Our servers might be busy at peak times.
Unlike the desktop version of Pex, Pex for fun can only deal with programs that are less than 16384 characters long.
For some inputs, Pex might find that the program runs for a very long time. This indicates that the program may not terminate.
Pex for fun has built-in time limits that you cannot configure.
Download the regular desktop version of Pex to overcome this limitation; the regular desktop version allows you to configure all bounds.
Due to an internal limitation, Pex for fun cannot send mail with custom programs. As a workaround, please create a URL first, and then copy and paste it into your favorite email client.
Pex for fun uses Windows Live ID to identify users. Please review our Terms Of Use and Privacy Statement.
To sign in, click on the Sign In link in the upper right corner of the main Pex for fun page.
When you are signed in, Pex for fun will remember which Coding Duels you have tried to win, which you have won, and which you created, and published.
You can only join and access previously joined courses when you are signed in. To resume any previously joined course:
Pex for fun will also remember the last program text for each Coding Duel that you have been working on. To resume any previously started Coding Duel:
When you are signed in, you can rate Coding Duels and Pex for fun will track your achievements.
When you are signed in, you can associate a nickname with your account.
To choose your nickname:
You can see where are you in the high score lists by clicking the Community link on the main Pex for fun page.
Teachers can get access to special features: Teachers can track the progress of their students on all Coding Duels, teachers can create new courses and pages.
In the Learn area, you can learn more about teaching with Pex for fun.
To become a teacher:
If you sign in, create a nickname and allow your nickname to be shown with your published Coding Duels, you can publish the Coding Duels which you created yourself.
To publish (or unpublish) any particular Coding Duel (that you created when you were signed in):
If you allow your nickname to be shown with your published Coding Duels, other people can view your published Coding Duels by clicking the Choose button or the Community link on the main Pex for fun page.
Every puzzle has a unique Permalink. A Permalink is a URL that uniquely identifies a particular puzzle.
You can create a Permalink for the current puzzle by clicking on Permalink. This displays a URL that uniquely identifies the current puzzle. You can copy and paste the URL to share the puzzle with other people.
To share and discuss your puzzles with other people, you can post them by using their Permalinks on our MSDN Forums for Pex.
The generated URL itself encodes the language and program text in a compressed form. As a result, the URLs might be quite long, depending on the size of the program text. This is normal.
A Coding Duel is an interactive puzzle. In a Coding Duel, your task is to implement the Puzzle method to have exactly the same behavior as a secret Puzzle method. (Coding Duels are different from simple puzzles, where your task is to simply guess what a given Puzzle method does, by studying the code of the Puzzle method.) After you make a change to your implementation of the Puzzle method, click Ask Pex! to see if your implementation behaves differently from the secret implementation in any way. You will get feedback about any behavior mismatches. If there are none, you win the Coding Duel!
You can create a new Coding Duel yourself, by turning an implementation into the secret implementation. Visit the Learn area to learn how.
You can turn a Puzzle method into a Coding Duel only if the method fulfills certain requirements, including the following technical restrictions:
void
Clone
When you win a Coding Duel, a Winning Number will be revealed to you.
The Winning Number always has the format xxx-xxx-xxx.
xxx-xxx-xxx
It is a hash that is derived from the program text of the secret implementation in a Coding Duel. When you create a new Coding Duel, its Winning Number is shown to you. When someone wins that Coding Duel later, its Winning Number is revealed to the winner.
While solving a Coding Duel, you typically click Ask Pex! many times. If you are signed in, Pex for fun stores the most recent version of your program text for each Coding Duel, but does not store all intermediate versions. Every time you click Ask Pex!, an entry is added to a History section at the very end of the page:
In this way, your browser records all the intermediate steps you go through, including links to all the intermediate code versions, and how much time elapsed between the events.
This detailed history is accessible only until you close your browser window or tab.