![]() |
![]() |
|
Due: Feb.20 (Thu), at start of class
The purpose of this exercise is to make sure that you have all the Rust tools installed correctly, and that you know how to use them.
This assignment has multiple files that you need to submit. Make sure not to miss one; they are described at the bottom of these instructions.
Note that these instructions mention VSCode, However, if you want to try out RustRover, feel free. All the same features should be available one way or another — it's just that you're (more) on your own when it comes to figuring it out.
Note: Alternately, you can install Rust Rover. It seems to require both more disk space and more RAM, compared to VSCode.You should verify that you can cargo run a new project from the command-line, per VSCode's Hello World instructions.
Hmm, writing unit tests forces us to consider: what is the sign of zero? For this problem, we shall simply declare that 0 can be considered either sign (since +0 = -0 = 0 ?). Being optimists, we will therefore declare that 0 and 3 have the same sign, and that 0 and -3 have the same sign, for the purposes of this function1.
After this step, you should have code that compiles and runs, but of course cargo test reports that it fails a test, since same_sign is still stubbed out.
hint: While you may certainly use if-else-if statements, you can sneakily just multiply your two inputs, and then (somehow) use that to get your answer; your function body could be as few as 6 characters plus whitespace for readability!Do not use num_traits::signum, since we have no idea how to import crates!
Note: No, I won't be able to confirm that you wrote your unit-tests and a stub before completing same-sign's body. However, doing so is good practice that never costs you time, and occasionally saves you a lot of time.
After you run and test your main program, install the debugging tools for Rust. This is by far the hardest step, but if you carefully read the instructions here, then you should be fine. Note that, for Windows, you should scroll to the bottom and install C/C++ build tools first before you install the plugin for VSCode. The build tools can be found a[#:href "https://visualstudio.microsoft.com/visual-cpp-build-tools/"]{here}. If you don't do that, this the VSCode debugger will behave very oddly...
Then, proceed with these debugging instructions. Once you have both the C / C++ build tools and the appropriate extension installed, you should be able to set breakpoints, run the program in debug mode, stop the program at breakpoints, and step through the program line by line. Make sure to test out this last part: stepping through line by line. If (for Windows) you didn't install C/C++ build tools correctly, then this will behave oddly, making your debugger useless.
Submit the following four files on D2L. Use only the following formats: .rs, .txt, .pdf, .jpg, .png. Notably: Not .docx. Submit each file to D2L separately; do not submit a .zip. You are encouraged to keep screenshots small (i.e. only capturing the part of the screen which shows what's being asked for).
This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |