xeluxee / competitest.nvim

CompetiTest.nvim is a Neovim plugin for Competitive Programming: it can manage and check testcases, download problems and contests from online judges and much more
GNU Lesser General Public License v3.0
381 stars 15 forks source link

How to write test cases #13

Closed zackfall closed 2 years ago

zackfall commented 2 years ago

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.

xeluxee commented 2 years ago

Launch :CompetitestAdd, write input and output and press CTRL-s to save Then launch :CompetitestRun

zackfall commented 2 years ago

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

xeluxee commented 2 years ago

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:

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)

zackfall commented 2 years ago

Ooooh, okay i got it now, thanks, I though it was something like the test that occurs in exercism. Thanks a lot

xeluxee commented 2 years ago

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