How to write test cases
zackfall opened this issue · 5 comments
I was trying to use this with rust, but I don't really know how to start, I mean, I writed a simple lib to do tests but when I added a test case, it doesn't take the inputs, so I don't really know what to do, and sorry if this is a dummy question, I never tried something like this before.
Launch :CompetitestAdd
, write input and output and press CTRL-s
to save
Then launch :CompetitestRun
Yeah, I did that. I created a lib where I created a function sum
fn sum(x: i32, y: i32) -> i32 {
x + y
}
// Then I created the test module
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = sum(5, 3);
assert_eq!(result, 8);
}
}
Then I executed CompetitestAdd
and I writed 5, 6
to try with just one input and I saved the testcase, then I run the testcases but when I was watching the test case I wrote, it does not output anything, because there wasn't a main function, so the stderr of the compile case show that error. When i created a main function, Only the println I created calling the sum function was in the output, so I don't know how I have to do to make it work
I'm not understanding what you are trying to do. Why are you defining a function to check the result? What do you expect competitest
to do?
Competitest does the following:
- compiles your source file (with
rustc filename.rs
for rust) - runs the executable
- sends input text on stdin
- takes stdout and displays it in output popup
- compares stdout and the correct answer (provided by you in output popup after launching
:CompetiTestAdd
), establishing whether your solution was correct or not
So yes, main
is needed because your program must read from stdin
and print to stdout
(see https://github.com/xeluxee/competitest.nvim#usage-notes)
Ooooh, okay i got it now, thanks, I though it was something like the test that occurs in exercism. Thanks a lot
You're welcome. CompetiTest is designed for competitive programming contest, as the ones held on codeforces.
The name itself is the union of Competitive and Tester