I'm brand new to Rust and I'm currently working through the rust book. I wanted to work on some Codewars challenges at the same time as well. I was wondering if anyone has experience doing challenges on Codewars and how they go about organizing their project files on their local machine. Ideally I would like to be able to do all of the work and run the tests locally on my machine instead of using the Codewars editor/interface to do this. I'm curious what other people's workflows look like for doing this.
Here's an example challenge that I would like to work on: Training on From A to Z | Codewars
This is the test section from the codewars editor window:
// Add your tests here.
// See https://doc.rust-lang.org/stable/rust-by-example/testing/unit_testing.html
#[cfg(test)]
mod tests {
use super::gimme_the_letters;
fn dotest(sp: &str, expected: &str) {
let actual = gimme_the_letters(sp);
assert!(actual == expected,
"With sp = \"{sp}\"\nExpected \"{expected}\" but got \"{actual}\"")
}
#[test]
fn fixed_tests() {
dotest("a-z", "abcdefghijklmnopqrstuvwxyz");
dotest("h-o", "hijklmno");
dotest("Q-Z", "QRSTUVWXYZ");
dotest("J-J", "J");
dotest("a-b", "ab");
dotest("A-A", "A");
dotest("g-i", "ghi");
dotest("H-I", "HI");
dotest("y-z", "yz");
dotest("e-k", "efghijk");
dotest("a-q", "abcdefghijklmnopq");
dotest("F-O", "FGHIJKLMNO");
}
}
This is the provided starting code to be completed:
fn gimme_the_letters(sp: &str) -> String {
todo!()
}
-
What is the shortest amount of steps to take these test cases and have them run locally on my machine? Is it possible to just copy out the test case code and drop it in a file then run my function against the test cases on my own machine some how?
-
Which file should I be putting my function and the tests into after I create a project folder with
cargo new from_a_to_z
? is it src/lib.rs or src/main.rs for something like this? -
Is it possible using cargo to run all these tests and have the output of the results regardless of pass or fail show up in the console? I've been trying running
cargo test
with these but if the test passes it just saystest result: ok
and doesn't show me the output for each of the tests.
I'm sure a lot of this will be answered the further I get into the documentation and to be honest I just really don't know what I'm doing yet... I'm just eager to start doing some challenges and I want to make sure I'm organizing my local rust project files as efficiently as possible. Any advice would be greatly appreciated!