The ChallengeFactorial puzzle indicates that 15! is 2004310016, which is an obvious error since 15! is actually 130767436800.
The error is caused by an int being able to store only up to 12!, any higher values will cause an overflow of an int variable.
Pex should be able to detect this and report it as an error condition (boundary test case) not as an expected result.
HectorSaturday, October 23, 2010 10:55 PM
Well, from my perspective Pex just takes the duel ChallengeFactorial as it was provided/implemented by whoever published it as a duel. Up to this it's just some function that maps ints to ints (and may or may not throw Exceptions for some input).
Pex just cannot (and MUST NOT) make any assumptions *just by the sheer name*, i.e. it's only us who expect to get i! from a function having "factorial" in its name. What would you expect if the name was, for example, "f"? What would you expect Pex to expect from "f"?
One way to express things such as you ask for (and thus: tell Pex) is to use code contracts. Plz have a look at the alternative duel "FactorialWithContractsInt" and drop a note on what you think about it.
Sunday, October 24, 2010 8:12 PM
- Edited by meisl Wednesday, October 27, 2010 10:01 PM
Addendum/cross-ref: your Q, Hector, made me think about PexForFun in general, as a platform/concept. You're touching really something I think:
How to deal with seemingly / "obviously" flawed/stupid challenges?
The big problem is that such may very quickly kill ppl's interest/curiosity in this otherwise very exciting and promising platform.
More on this, if you like, in "PexForFun: REALLY great for teaching | learning!" .
__Wednesday, October 27, 2010 9:15 PM
Another one for those who are interested in (to find out) what makes nice, motivating & interesting duels on PexForFun:
__Monday, November 01, 2010 9:43 PM