PexForFun: ChallengeFactorial error?

    General discussion

  • 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.


    Saturday, October 23, 2010 10:55 PM

All replies

  • 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.





    • Edited by meisl Wednesday, October 27, 2010 10:01 PM
    Sunday, October 24, 2010 8:12 PM
  • Oh, btw, there are two more interesting duels: EulerShakingHands (arithmetic) and UniqueElementsOrderPreserving (Linq,Contracts)



    • Edited by meisl Wednesday, October 27, 2010 10:01 PM
    Monday, October 25, 2010 6:28 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:

    PexForFun: Nothing easier than boolean operators... really?!



    Monday, November 01, 2010 9:43 PM