Ad
  • Custom User Avatar
  • Custom User Avatar
  • Custom User Avatar

    Notes:

    • There are no negative values possible. Please reflect that by using u32 types for input and output.
    • All assertions need proper messages. The default messages you get from Rust do not tell the user what "left" and "right" refer to (since in a normal setting, the user can see the tests, or even wrote them). In general, it is always good practice to return an erroneous value from your initial solution to see what failed tests look like, and work on them until you are satisfied they present all necessary information to the user in a pleasing way. Here are two commonly used variants:
      • assert_eq!(actual, expected, "\nYour result (left) did not match the expected output (right) for the input {input:?}")
      • assert!(actual == expected, "Expected output {expected:?}, but instead got {actual:?} for the input {input:?}\n")
      • Note that, unlike assert_eq!, assert! does not force any boilerplate output in the assertion, but it does include the at line n in blah.rs line at the end, hence the trailing newline.
    • Please use expressive variable names like actual and expected, so other people can understand what your code is doing without having to parse virtually identical function names. result is entirely ambiguous.
    • Add todo! to the solution setup, so that the function compiles out of the box (currently it generates an error because it returns ().
    • use only what you need from the user's solution, i.e. use super::rental_car_cost, not *. Hygiene is a good habit.
    • This is a nitpick, but try to adhere to common formatting standards. Specifically, add whitespace between variable names/colons and types, and between binary operators like <=.

    I'll reject this translation in its current state, but feel free to fork it and apply the requested changes.