Brak opisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

task2.rs 1.9KB

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