You need to sign in or sign up before continuing.×
Ad
  • Custom User Avatar

    It's been a while so you've probably learned this, but you can change the tests.

  • Custom User Avatar

    Forked because original translator inactive.

    • Removed unnecessary macro rule, replaced with regular test function.
    • Updated assertion message
    • Fixed random tests to actually generate valid inputs half the time
  • Custom User Avatar

    I'm fairly sure your "statistics" are off:
    There are 62 alphanumeric characters in the ASCII range 0..127, so roughly 50%. So, each time you randomly sample that range, you have a ~50% chance of getting an alphanumeric character. However, repeatedly sampling n times, each individually with 0.5 probability, means you have a total probability of 0.5 ^ n that the final string is completely comprised of alphanumeric characters.

    Oh, on another note, make sure your custom assertion messages start with a newline \n or else they will be concatenated directly after the existing assertion output, which looks bad.

  • Custom User Avatar

    It doesn't fail the test case so it's technically fine 🤷

  • Custom User Avatar

    I already know a few ways to improve this, but I'm going to have someone else make the first move

  • Custom User Avatar

    Another issue I didn't mention the first time around:

    • The assertion need proper message formatting, since the builtin defaults are useless in a situation where the author of the code is not the author of the tests.
    • todo! should be preferred over unimplemented!, because semantically, the former implies that it should be replaced with a working implementation, whereas the latter means "this function exists, but doesn't (and never will) do anything".
  • Custom User Avatar

    I used macros becuase I think it makes the tests more readable.

  • Custom User Avatar
    • The input type should be &str, not &String (this would avoid the extra allocation in your macro (.to_string())
    • The use of a macro to perform the assertion is total overkill, though I guess you could put this down to a matter of personal preference. Really, a simple function that takes a &str and an expected boolean value and ran the assertion with them would suffice and be easier to read, especially in the sample tests which are user-facing.
    • Your solution is strictly speaking incorrect, though I will discuss this in Discord for spoiler reasons.