porter_test.rs 825 B

123456789101112131415161718192021222324252627282930
  1. use std::fs::File;
  2. use std::io::*;
  3. use gecliht;
  4. // This test is in integration tests because it uses files
  5. #[test]
  6. fn test_porter ()-> std::io::Result<()> {
  7. let f = File::open("tests/porter-words.txt")?;
  8. let mut words = BufReader::new(f);
  9. let g = File::open("tests/porter-stems.txt")?;
  10. let mut stems = BufReader::new(g);
  11. let mut count = 0;
  12. loop {
  13. let mut word = String::new();
  14. let wlen = words.read_line(&mut word)?;
  15. if wlen == 0 { break; }
  16. let mut stem = String::new();
  17. let slen = stems.read_line(&mut stem)?;
  18. if slen == 0 { break; }
  19. word = word.trim().to_string();
  20. stem = stem.trim().to_string();
  21. assert_eq!(Ok(stem), gecliht::porter_stem(&word));
  22. count += 1;
  23. }
  24. println!("Ran {} tests", count);
  25. Ok(())
  26. }