Nav apraksta
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

task2.rs 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. extern crate task2;
  2. use task2::Config;
  3. #[test]
  4. fn test_parse_config_1() {
  5. let a = vec!["Not interested".to_string(), "e".to_string(), "Numero Due".to_string()];
  6. let c = Config {
  7. search: 'e',
  8. line: "Numero Due".to_string(),
  9. };
  10. assert_eq!(Config::new(&a), Ok(c));
  11. }
  12. #[test]
  13. #[should_panic]
  14. fn test_parse_config_2() {
  15. let a = vec!["Not interested".to_string(), "x".to_string(), "Numero Due".to_string()];
  16. let c = Config {
  17. search: 'e',
  18. line: "Numero Due".to_string(),
  19. };
  20. assert_eq!(Config::new(&a), Ok(c));
  21. }
  22. #[test]
  23. fn test_parse_config_3() {
  24. let a = vec!["Not interested".to_string(), "0".to_string(), "0".to_string()];
  25. let c = Config {
  26. search: '0',
  27. line: "0".to_string(),
  28. };
  29. assert_eq!(Config::new(&a), Ok(c));
  30. }
  31. #[test]
  32. fn test_parse_config_err_1() {
  33. let a = vec!["Not interested".to_string(), "e".to_string()];
  34. assert_eq!(Config::new(&a), Err("not enough arguments"));
  35. }
  36. #[test]
  37. fn test_parse_config_err_2() {
  38. let a = vec!["Not interested".to_string()];
  39. assert_eq!(Config::new(&a), Err("not enough arguments"));
  40. }
  41. #[test]
  42. fn test_run_1() {
  43. let c = Config {
  44. search: 'e',
  45. line: "Numero Due".to_string(),
  46. };
  47. assert_eq!(task2::run(&c), 2);
  48. }
  49. #[test]
  50. fn test_run_2() {
  51. let c = Config {
  52. search: '♥',
  53. line: "♥ The quick brown fox jumps over the lazy dog. ♥".to_string(),
  54. };
  55. assert_eq!(task2::run(&c), 2);
  56. }
  57. #[test]
  58. #[should_panic]
  59. fn test_run_3() {
  60. let c = Config {
  61. search: 'q',
  62. line: "♥ The quick brown fox jumps over the lazy dog. ♥".to_string(),
  63. };
  64. assert_eq!(task2::run(&c), 2);
  65. }
  66. #[test]
  67. fn test_run_4() {
  68. let c = Config {
  69. search: '!',
  70. line: "♥ The quick brown fox jumps over the lazy dog. ♥".to_string(),
  71. };
  72. assert_eq!(task2::run(&c), 0);
  73. }