Решение на Spell Checker от Моника Киркова

Обратно към всички решения

Към профила на Моника Киркова

Резултати

  • 17 точки от тестове
  • 0 бонус точки
  • 17 точки общо
  • 13 успешни тест(а)
  • 2 неуспешни тест(а)

Код

use std::collections::HashMap;
use std::collections::HashSet;
use std::fmt;
pub const ALPHABET_EN: &'static str = "abcdefghijklmnopqrstuvwxyz";
pub const ALPHABET_BG: &'static str = "абвгдежзийклмнопрстуфхцчшщъьюя";
pub fn clean_line(input: &str) -> String{
let mut output : String = "".to_string();
let mut count = 0;
let mut chars = input.chars();
let mut ch = chars.next();
while(ch.is_some()){
let mut c = ch.unwrap();
if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == ' ' || c == '-' || c == '`'
|| (c >= 'а' && c <= 'я') || (c >= 'А' && c <= 'Я')){
output.push(c);
}
else{
output.push(' ');
}
ch = chars.next();
count += 1;
}
output = output.trim().to_string();
return output
}
pub struct WordCounter {
word_count: HashMap<String, i32>,
}
impl WordCounter {
pub fn new() -> Self {
let mut hash = HashMap::new();
let mut words : WordCounter = WordCounter{word_count: hash};
return words
}
pub fn from_str(input: &str) -> Self {
let mut a : String = "".to_string();
let mut wordCounter = WordCounter::new();
let mut chars = input.chars();
let mut chs = chars.next();
let mut ch;
while(chs.is_some()){
ch = chs.unwrap();
let mut text : String = "".to_string();
while(ch != '\n'){
text.push(ch);
chs = chars.next();
if chs.is_none(){
break;
}
ch = chs.unwrap();
}
text = clean_line(&text);
chs = chars.next();
let mut texts = text.chars();
let mut text_chars = texts.next();
let mut text_ch;
while(text_chars.is_some()){
text_ch = text_chars.unwrap();
let mut word : String = "".to_string();
while(text_ch != ' '){
word.push(text_ch);
text_chars = texts.next();
if(text_chars.is_none()){
break;
}
text_ch = text_chars.unwrap();
}
text_chars = texts.next();
wordCounter.add(&word);
}
}
wordCounter.word_count.remove("");
return wordCounter
}
pub fn words(&self) -> Vec<&String> {
let mut vec = Vec::new();
for key in self.word_count.keys() {
vec.push(key);
}
vec.sort();
return vec
}
pub fn add(&mut self, item: &str) {
let mut word = item.to_lowercase();
if self.word_count.contains_key(&word){
for (key, val) in self.word_count.iter_mut() {
if *key == word{
*val += 1;
}
}
}
else{
&self.word_count.insert(word.to_string(), 1);
}
}
pub fn get(&self, word: &str) -> u32 {
let mut count: u32 = 0;
for (key, val) in self.word_count.iter() {
if key == word{
count = *val as u32
}
}
return count
}
pub fn total_count(&self) -> u32 {
let mut count: u32 = 0;
for val in self.word_count.values() {
count += *val as u32
}
return count
}
}
impl std::fmt::Display for WordCounter {
fn fmt(&self, f: &mut fmt::Formatter) -> std::fmt::Result {
let tmp = self.total_count().to_string();
f.write_str("WordCounter, total count: ");
f.pad(&tmp);
f.write_str("\n");
let mut maxVal:i32 = 0;
let mut maxKey:String = "".to_string();
let mut map:HashMap<String, i32> = HashMap::new();
for (key, val) in self.word_count.iter(){
map.insert(key.to_string(), *val);
}
while(!map.is_empty()){
for (key, val) in &map{
if val > &maxVal{
maxVal = *val;
maxKey = key.to_string();
}
}
f.write_str(&maxKey);
f.write_str(": ");
f.pad(&maxVal.to_string());
f.write_str("\n");
map.remove(&maxKey);
maxVal = 0;
}
Ok(())
}
}
pub struct SpellChecker {
corpus: String,
alphabet: String,
}
impl SpellChecker {
pub fn new(corpus: &str, alphabet: &str) -> Self {
let spell_checker: SpellChecker = SpellChecker{corpus: corpus.to_string(), alphabet: alphabet.to_string()};
return spell_checker
}
pub fn correction(&self, word: &str) -> String {
let mut rightWord: String = "".to_string();
let mut result: Vec<String> = Vec::new();
let mut lowerWord = word.to_lowercase().trim().to_string();
result = self.candidates(&lowerWord);
if result.len() == 1{
rightWord = result.pop().unwrap();
}else{
let mut wordCounter:WordCounter;
wordCounter = WordCounter::from_str(&self.corpus);
let mut maxCount: i32 = 0;
for (key, val) in wordCounter.word_count.iter_mut(){
if val > &mut maxCount && result.contains(key){
maxCount = *val;
rightWord = key.to_string();
}
}
}
return rightWord
}
pub fn probability(&self, word: &str) -> f64 {
let wordCounter:WordCounter;
wordCounter = WordCounter::from_str(&self.corpus);
return wordCounter.get(&word.to_lowercase()) as f64 / wordCounter.total_count() as f64
}
pub fn known<'a>(&self, words: &'a HashSet<String>) -> Vec<&'a String> {
let mut vec: Vec<&'a String> = Vec::new();
let wordCounter:WordCounter;
wordCounter = WordCounter::from_str(&self.corpus);
for x in words.iter(){
let lower : String = x.to_lowercase();
if wordCounter.word_count.contains_key(&lower){
vec.push(x);
}
}
return vec
}
pub fn candidates(&self, word: &str) -> Vec<String> {
let wordCounter:WordCounter;
wordCounter = WordCounter::from_str(&self.corpus);
let mut result: Vec<String> = Vec::new();
let mut result1: Vec<String> = Vec::new();
let mut result2: Vec<String> = Vec::new();
let lower : String = word.to_lowercase();
let mut edited1 = HashSet::new();
edited1 = self.edits1(word);
result1 = self.known(&edited1).iter().map(|x| x.to_string()).collect::<Vec<String>>();
let mut edited2 = HashSet::new();
edited2 = self.edits2(word);
result2 = self.known(&edited2).iter().map(|x| x.to_string()).collect::<Vec<String>>();
if wordCounter.word_count.contains_key(&lower){
result.push(word.to_string());
}else if !result1.is_empty(){
result = result1;
}else if !result2.is_empty(){
result = result2;
}else{
result.push(word.to_string());
}
return result
}
pub fn edits1(&self, word: &str) -> HashSet<String> {
let mut count = 0;
let mut result = HashSet::new();
let mut newWord: String = "".to_string();
let mut wordLength = word.len();
let mut i = 1;
if word != "" && word.get(0..1).is_none(){
i = 2;
}
while(count < word.len()){
newWord = word.to_string();
newWord.replace_range(count..count+i, "");
count += 1;
if newWord != ""{
result.insert(newWord);
}
if i == 2{
count += 1;
}
}
count = 0;
while(count < word.len() - i){
let mut a = word.get(count..count+i).unwrap();
let mut b = word.get(count+i..count+i+i).unwrap();
newWord = word.to_string();
newWord.replace_range(count..count+i, b);
newWord.replace_range(count+i..count+i+i, a);
result.insert(newWord);
count += 1;
if i == 2{
count += 1;
}
}
count = 0;
while(count < word.len()){
let mut alphabet = self.alphabet.chars();
let mut a = alphabet.next();
while(a.is_some()){
newWord = word.to_string();
newWord.replace_range(count..count+i, &a.unwrap().to_string());
a = alphabet.next();
result.insert(newWord);
}
count += 1;
if i == 2{
count += 1;
}
}
count = 0;
while(count <= word.len()){
let mut alphabet = self.alphabet.chars();
let mut a = alphabet.next();
while(a.is_some()){
newWord = String::from(word.to_string());
newWord.insert_str(count, &a.unwrap().to_string());
a = alphabet.next();
result.insert(newWord);
}
count += 1;
if i == 2{
count += 1;
}
}
return result
}
pub fn edits2(&self, word: &str) -> HashSet<String> {
let mut count = 0;
let mut result: HashSet<String> = HashSet::new();
let mut result1: HashSet<String> = HashSet::new();
result1 = self.edits1(word);
for x in result1{
let mut result2: HashSet<String> = self.edits1(&x);
for y in result2{
result.insert(y);
}
}
return result
}
}

Лог от изпълнението

Compiling solution v0.1.0 (/tmp/d20200114-2173579-pzntfm/solution)
warning: unnecessary parentheses around `while` condition
  --> src/lib.rs:13:10
   |
13 |     while(ch.is_some()){
   |          ^^^^^^^^^^^^^^ help: remove these parentheses
   |
   = note: `#[warn(unused_parens)]` on by default

warning: unnecessary parentheses around `if` condition
  --> src/lib.rs:15:11
   |
15 |           if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == ' ' || c == '-' || c == '`' 
   |  ___________^
16 | |         || (c >= 'а' && c <= 'я') || (c >= 'А' && c <= 'Я')){
   | |____________________________________________________________^
   |
help: remove these parentheses
   |
15 |         if (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == ' ' || c == '-' || c == '`' 
16 |         || (c >= 'а' && c <= 'я') || (c >= 'А' && c <= 'Я') {
   |

warning: unnecessary parentheses around `while` condition
  --> src/lib.rs:46:14
   |
46 |         while(chs.is_some()){
   |              ^^^^^^^^^^^^^^^ help: remove these parentheses

warning: unnecessary parentheses around `while` condition
  --> src/lib.rs:49:18
   |
49 |             while(ch != '\n'){
   |                  ^^^^^^^^^^^^ help: remove these parentheses

warning: unnecessary parentheses around `while` condition
  --> src/lib.rs:62:18
   |
62 |             while(text_chars.is_some()){
   |                  ^^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses

warning: unnecessary parentheses around `while` condition
  --> src/lib.rs:65:22
   |
65 |                 while(text_ch != ' '){
   |                      ^^^^^^^^^^^^^^^^ help: remove these parentheses

warning: unnecessary parentheses around `if` condition
  --> src/lib.rs:68:23
   |
68 |                     if(text_chars.is_none()){
   |                       ^^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses

warning: unnecessary parentheses around `while` condition
   --> src/lib.rs:138:14
    |
138 |         while(!map.is_empty()){
    |              ^^^^^^^^^^^^^^^^^ help: remove these parentheses

warning: unnecessary parentheses around `while` condition
   --> src/lib.rs:244:14
    |
244 |         while(count < word.len()){
    |              ^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses

warning: unnecessary parentheses around `while` condition
   --> src/lib.rs:256:14
    |
256 |         while(count < word.len() - i){
    |              ^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses

warning: unnecessary parentheses around `while` condition
   --> src/lib.rs:270:14
    |
270 |         while(count < word.len()){
    |              ^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses

warning: unnecessary parentheses around `while` condition
   --> src/lib.rs:273:18
    |
273 |             while(a.is_some()){
    |                  ^^^^^^^^^^^^^ help: remove these parentheses

warning: unnecessary parentheses around `while` condition
   --> src/lib.rs:285:14
    |
285 |         while(count <= word.len()){
    |              ^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses

warning: unnecessary parentheses around `while` condition
   --> src/lib.rs:288:18
    |
288 |             while(a.is_some()){
    |                  ^^^^^^^^^^^^^ help: remove these parentheses

warning: variable `count` is assigned to, but never used
  --> src/lib.rs:10:13
   |
10 |     let mut count = 0;
   |             ^^^^^
   |
   = note: `#[warn(unused_variables)]` on by default
   = note: consider using `_count` instead

warning: unused variable: `a`
  --> src/lib.rs:41:17
   |
41 |         let mut a : String = "".to_string();
   |                 ^ help: consider prefixing with an underscore: `_a`

warning: value assigned to `result` is never read
   --> src/lib.rs:170:17
    |
170 |         let mut result: Vec<String> = Vec::new();
    |                 ^^^^^^
    |
    = note: `#[warn(unused_assignments)]` on by default
    = help: maybe it is overwritten before being read?

warning: value assigned to `result1` is never read
   --> src/lib.rs:214:17
    |
214 |         let mut result1: Vec<String> = Vec::new();
    |                 ^^^^^^^
    |
    = help: maybe it is overwritten before being read?

warning: value assigned to `result2` is never read
   --> src/lib.rs:215:17
    |
215 |         let mut result2: Vec<String> = Vec::new();
    |                 ^^^^^^^
    |
    = help: maybe it is overwritten before being read?

warning: value assigned to `edited1` is never read
   --> src/lib.rs:217:17
    |
217 |         let mut edited1 = HashSet::new(); 
    |                 ^^^^^^^
    |
    = help: maybe it is overwritten before being read?

warning: value assigned to `edited2` is never read
   --> src/lib.rs:220:17
    |
220 |         let mut edited2 = HashSet::new();
    |                 ^^^^^^^
    |
    = help: maybe it is overwritten before being read?

warning: value assigned to `newWord` is never read
   --> src/lib.rs:238:17
    |
238 |         let mut newWord: String = "".to_string();
    |                 ^^^^^^^
    |
    = help: maybe it is overwritten before being read?

warning: unused variable: `wordLength`
   --> src/lib.rs:239:17
    |
239 |         let mut wordLength = word.len();
    |                 ^^^^^^^^^^ help: consider prefixing with an underscore: `_wordLength`

warning: unused variable: `count`
   --> src/lib.rs:303:17
    |
303 |         let mut count = 0;
    |                 ^^^^^ help: consider prefixing with an underscore: `_count`

warning: value assigned to `result1` is never read
   --> src/lib.rs:305:17
    |
305 |         let mut result1: HashSet<String> = HashSet::new();
    |                 ^^^^^^^
    |
    = help: maybe it is overwritten before being read?

warning: variable does not need to be mutable
  --> src/lib.rs:14:13
   |
14 |         let mut c = ch.unwrap();
   |             ----^
   |             |
   |             help: remove this `mut`
   |
   = note: `#[warn(unused_mut)]` on by default

warning: variable does not need to be mutable
  --> src/lib.rs:35:13
   |
35 |         let mut hash = HashMap::new();
   |             ----^^^^
   |             |
   |             help: remove this `mut`

warning: variable does not need to be mutable
  --> src/lib.rs:36:13
   |
36 |         let mut words : WordCounter = WordCounter{word_count: hash};
   |             ----^^^^^
   |             |
   |             help: remove this `mut`

warning: variable does not need to be mutable
  --> src/lib.rs:41:13
   |
41 |         let mut a : String = "".to_string();
   |             ----^
   |             |
   |             help: remove this `mut`

warning: variable does not need to be mutable
  --> src/lib.rs:92:13
   |
92 |         let mut word = item.to_lowercase();
   |             ----^^^^
   |             |
   |             help: remove this `mut`

warning: variable does not need to be mutable
   --> src/lib.rs:171:13
    |
171 |         let mut lowerWord = word.to_lowercase().trim().to_string();
    |             ----^^^^^^^^^
    |             |
    |             help: remove this `mut`

warning: variable does not need to be mutable
   --> src/lib.rs:239:13
    |
239 |         let mut wordLength = word.len();
    |             ----^^^^^^^^^^
    |             |
    |             help: remove this `mut`

warning: variable does not need to be mutable
   --> src/lib.rs:257:17
    |
257 |             let mut a = word.get(count..count+i).unwrap();
    |                 ----^
    |                 |
    |                 help: remove this `mut`

warning: variable does not need to be mutable
   --> src/lib.rs:258:17
    |
258 |             let mut b = word.get(count+i..count+i+i).unwrap();
    |                 ----^
    |                 |
    |                 help: remove this `mut`

warning: variable does not need to be mutable
   --> src/lib.rs:303:13
    |
303 |         let mut count = 0;
    |             ----^^^^^
    |             |
    |             help: remove this `mut`

warning: variable does not need to be mutable
   --> src/lib.rs:308:17
    |
308 |             let mut result2: HashSet<String> = self.edits1(&x);
    |                 ----^^^^^^^
    |                 |
    |                 help: remove this `mut`

warning: variable `wordCounter` should have a snake case name
  --> src/lib.rs:42:17
   |
42 |         let mut wordCounter = WordCounter::new();
   |                 ^^^^^^^^^^^ help: convert the identifier to snake case: `word_counter`
   |
   = note: `#[warn(non_snake_case)]` on by default

warning: unused `std::result::Result` that must be used
   --> src/lib.rs:129:9
    |
129 |         f.write_str("WordCounter, total count: ");
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `#[warn(unused_must_use)]` on by default
    = note: this `Result` may be an `Err` variant, which should be handled

warning: unused `std::result::Result` that must be used
   --> src/lib.rs:130:9
    |
130 |         f.pad(&tmp);
    |         ^^^^^^^^^^^^
    |
    = note: this `Result` may be an `Err` variant, which should be handled

warning: unused `std::result::Result` that must be used
   --> src/lib.rs:131:9
    |
131 |         f.write_str("\n");
    |         ^^^^^^^^^^^^^^^^^^
    |
    = note: this `Result` may be an `Err` variant, which should be handled

warning: variable `maxVal` should have a snake case name
   --> src/lib.rs:132:17
    |
132 |         let mut maxVal:i32 = 0;
    |                 ^^^^^^ help: convert the identifier to snake case: `max_val`

warning: variable `maxKey` should have a snake case name
   --> src/lib.rs:133:17
    |
133 |         let mut maxKey:String = "".to_string();
    |                 ^^^^^^ help: convert the identifier to snake case: `max_key`

warning: unused `std::result::Result` that must be used
   --> src/lib.rs:145:13
    |
145 |             f.write_str(&maxKey);
    |             ^^^^^^^^^^^^^^^^^^^^^
    |
    = note: this `Result` may be an `Err` variant, which should be handled

warning: unused `std::result::Result` that must be used
   --> src/lib.rs:146:13
    |
146 |             f.write_str(": ");
    |             ^^^^^^^^^^^^^^^^^^
    |
    = note: this `Result` may be an `Err` variant, which should be handled

warning: unused `std::result::Result` that must be used
   --> src/lib.rs:147:13
    |
147 |             f.pad(&maxVal.to_string());
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: this `Result` may be an `Err` variant, which should be handled

warning: unused `std::result::Result` that must be used
   --> src/lib.rs:148:13
    |
148 |             f.write_str("\n");
    |             ^^^^^^^^^^^^^^^^^^
    |
    = note: this `Result` may be an `Err` variant, which should be handled

warning: variable `rightWord` should have a snake case name
   --> src/lib.rs:169:17
    |
169 |         let mut rightWord: String = "".to_string();
    |                 ^^^^^^^^^ help: convert the identifier to snake case: `right_word`

warning: variable `lowerWord` should have a snake case name
   --> src/lib.rs:171:17
    |
171 |         let mut lowerWord = word.to_lowercase().trim().to_string();
    |                 ^^^^^^^^^ help: convert the identifier to snake case: `lower_word`

warning: variable `wordCounter` should have a snake case name
   --> src/lib.rs:176:21
    |
176 |             let mut wordCounter:WordCounter;
    |                     ^^^^^^^^^^^ help: convert the identifier to snake case: `word_counter`

warning: variable `maxCount` should have a snake case name
   --> src/lib.rs:178:21
    |
178 |             let mut maxCount: i32 = 0;
    |                     ^^^^^^^^ help: convert the identifier to snake case: `max_count`

warning: variable `wordCounter` should have a snake case name
   --> src/lib.rs:190:13
    |
190 |         let wordCounter:WordCounter;
    |             ^^^^^^^^^^^ help: convert the identifier to snake case: `word_counter`

warning: variable `wordCounter` should have a snake case name
   --> src/lib.rs:198:13
    |
198 |         let wordCounter:WordCounter;
    |             ^^^^^^^^^^^ help: convert the identifier to snake case: `word_counter`

warning: variable `wordCounter` should have a snake case name
   --> src/lib.rs:211:13
    |
211 |         let wordCounter:WordCounter;
    |             ^^^^^^^^^^^ help: convert the identifier to snake case: `word_counter`

warning: variable `newWord` should have a snake case name
   --> src/lib.rs:238:17
    |
238 |         let mut newWord: String = "".to_string();
    |                 ^^^^^^^ help: convert the identifier to snake case: `new_word`

warning: variable `wordLength` should have a snake case name
   --> src/lib.rs:239:17
    |
239 |         let mut wordLength = word.len();
    |                 ^^^^^^^^^^ help: convert the identifier to snake case: `word_length`

warning: unnecessary parentheses around `while` condition
  --> src/lib.rs:13:10
   |
13 |     while(ch.is_some()){
   |          ^^^^^^^^^^^^^^ help: remove these parentheses
   |
   = note: `#[warn(unused_parens)]` on by default

warning: unnecessary parentheses around `if` condition
  --> src/lib.rs:15:11
   |
15 |           if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == ' ' || c == '-' || c == '`' 
   |  ___________^
16 | |         || (c >= 'а' && c <= 'я') || (c >= 'А' && c <= 'Я')){
   | |____________________________________________________________^
   |
help: remove these parentheses
   |
15 |         if (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == ' ' || c == '-' || c == '`' 
16 |         || (c >= 'а' && c <= 'я') || (c >= 'А' && c <= 'Я') {
   |

warning: unnecessary parentheses around `while` condition
  --> src/lib.rs:46:14
   |
46 |         while(chs.is_some()){
   |              ^^^^^^^^^^^^^^^ help: remove these parentheses

warning: unnecessary parentheses around `while` condition
  --> src/lib.rs:49:18
   |
49 |             while(ch != '\n'){
   |                  ^^^^^^^^^^^^ help: remove these parentheses

warning: unnecessary parentheses around `while` condition
  --> src/lib.rs:62:18
   |
62 |             while(text_chars.is_some()){
   |                  ^^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses

warning: unnecessary parentheses around `while` condition
  --> src/lib.rs:65:22
   |
65 |                 while(text_ch != ' '){
   |                      ^^^^^^^^^^^^^^^^ help: remove these parentheses

warning: unnecessary parentheses around `if` condition
  --> src/lib.rs:68:23
   |
68 |                     if(text_chars.is_none()){
   |                       ^^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses

warning: unnecessary parentheses around `while` condition
   --> src/lib.rs:138:14
    |
138 |         while(!map.is_empty()){
    |              ^^^^^^^^^^^^^^^^^ help: remove these parentheses

warning: unnecessary parentheses around `while` condition
   --> src/lib.rs:244:14
    |
244 |         while(count < word.len()){
    |              ^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses

warning: unnecessary parentheses around `while` condition
   --> src/lib.rs:256:14
    |
256 |         while(count < word.len() - i){
    |              ^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses

warning: unnecessary parentheses around `while` condition
   --> src/lib.rs:270:14
    |
270 |         while(count < word.len()){
    |              ^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses

warning: unnecessary parentheses around `while` condition
   --> src/lib.rs:273:18
    |
273 |             while(a.is_some()){
    |                  ^^^^^^^^^^^^^ help: remove these parentheses

warning: unnecessary parentheses around `while` condition
   --> src/lib.rs:285:14
    |
285 |         while(count <= word.len()){
    |              ^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses

warning: unnecessary parentheses around `while` condition
   --> src/lib.rs:288:18
    |
288 |             while(a.is_some()){
    |                  ^^^^^^^^^^^^^ help: remove these parentheses

warning: variable `count` is assigned to, but never used
  --> src/lib.rs:10:13
   |
10 |     let mut count = 0;
   |             ^^^^^
   |
   = note: `#[warn(unused_variables)]` on by default
   = note: consider using `_count` instead

warning: unused variable: `a`
  --> src/lib.rs:41:17
   |
41 |         let mut a : String = "".to_string();
   |                 ^ help: consider prefixing with an underscore: `_a`

warning: value assigned to `result` is never read
   --> src/lib.rs:170:17
    |
170 |         let mut result: Vec<String> = Vec::new();
    |                 ^^^^^^
    |
    = note: `#[warn(unused_assignments)]` on by default
    = help: maybe it is overwritten before being read?

warning: value assigned to `result1` is never read
   --> src/lib.rs:214:17
    |
214 |         let mut result1: Vec<String> = Vec::new();
    |                 ^^^^^^^
    |
    = help: maybe it is overwritten before being read?

warning: value assigned to `result2` is never read
   --> src/lib.rs:215:17
    |
215 |         let mut result2: Vec<String> = Vec::new();
    |                 ^^^^^^^
    |
    = help: maybe it is overwritten before being read?

warning: value assigned to `edited1` is never read
   --> src/lib.rs:217:17
    |
217 |         let mut edited1 = HashSet::new(); 
    |                 ^^^^^^^
    |
    = help: maybe it is overwritten before being read?

warning: value assigned to `edited2` is never read
   --> src/lib.rs:220:17
    |
220 |         let mut edited2 = HashSet::new();
    |                 ^^^^^^^
    |
    = help: maybe it is overwritten before being read?

warning: value assigned to `newWord` is never read
   --> src/lib.rs:238:17
    |
238 |         let mut newWord: String = "".to_string();
    |                 ^^^^^^^
    |
    = help: maybe it is overwritten before being read?

warning: unused variable: `wordLength`
   --> src/lib.rs:239:17
    |
239 |         let mut wordLength = word.len();
    |                 ^^^^^^^^^^ help: consider prefixing with an underscore: `_wordLength`

warning: unused variable: `count`
   --> src/lib.rs:303:17
    |
303 |         let mut count = 0;
    |                 ^^^^^ help: consider prefixing with an underscore: `_count`

warning: value assigned to `result1` is never read
   --> src/lib.rs:305:17
    |
305 |         let mut result1: HashSet<String> = HashSet::new();
    |                 ^^^^^^^
    |
    = help: maybe it is overwritten before being read?

warning: variable does not need to be mutable
  --> src/lib.rs:14:13
   |
14 |         let mut c = ch.unwrap();
   |             ----^
   |             |
   |             help: remove this `mut`
   |
   = note: `#[warn(unused_mut)]` on by default

warning: variable does not need to be mutable
  --> src/lib.rs:35:13
   |
35 |         let mut hash = HashMap::new();
   |             ----^^^^
   |             |
   |             help: remove this `mut`

warning: variable does not need to be mutable
  --> src/lib.rs:36:13
   |
36 |         let mut words : WordCounter = WordCounter{word_count: hash};
   |             ----^^^^^
   |             |
   |             help: remove this `mut`

warning: variable does not need to be mutable
  --> src/lib.rs:41:13
   |
41 |         let mut a : String = "".to_string();
   |             ----^
   |             |
   |             help: remove this `mut`

warning: variable does not need to be mutable
  --> src/lib.rs:92:13
   |
92 |         let mut word = item.to_lowercase();
   |             ----^^^^
   |             |
   |             help: remove this `mut`

warning: variable does not need to be mutable
   --> src/lib.rs:171:13
    |
171 |         let mut lowerWord = word.to_lowercase().trim().to_string();
    |             ----^^^^^^^^^
    |             |
    |             help: remove this `mut`

warning: variable does not need to be mutable
   --> src/lib.rs:239:13
    |
239 |         let mut wordLength = word.len();
    |             ----^^^^^^^^^^
    |             |
    |             help: remove this `mut`

warning: variable does not need to be mutable
   --> src/lib.rs:257:17
    |
257 |             let mut a = word.get(count..count+i).unwrap();
    |                 ----^
    |                 |
    |                 help: remove this `mut`

warning: variable does not need to be mutable
   --> src/lib.rs:258:17
    |
258 |             let mut b = word.get(count+i..count+i+i).unwrap();
    |                 ----^
    |                 |
    |                 help: remove this `mut`

warning: variable does not need to be mutable
   --> src/lib.rs:303:13
    |
303 |         let mut count = 0;
    |             ----^^^^^
    |             |
    |             help: remove this `mut`

warning: variable does not need to be mutable
   --> src/lib.rs:308:17
    |
308 |             let mut result2: HashSet<String> = self.edits1(&x);
    |                 ----^^^^^^^
    |                 |
    |                 help: remove this `mut`

warning: variable `wordCounter` should have a snake case name
  --> src/lib.rs:42:17
   |
42 |         let mut wordCounter = WordCounter::new();
   |                 ^^^^^^^^^^^ help: convert the identifier to snake case: `word_counter`
   |
   = note: `#[warn(non_snake_case)]` on by default

warning: unused `std::result::Result` that must be used
   --> src/lib.rs:129:9
    |
129 |         f.write_str("WordCounter, total count: ");
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `#[warn(unused_must_use)]` on by default
    = note: this `Result` may be an `Err` variant, which should be handled

warning: unused `std::result::Result` that must be used
   --> src/lib.rs:130:9
    |
130 |         f.pad(&tmp);
    |         ^^^^^^^^^^^^
    |
    = note: this `Result` may be an `Err` variant, which should be handled

warning: unused `std::result::Result` that must be used
   --> src/lib.rs:131:9
    |
131 |         f.write_str("\n");
    |         ^^^^^^^^^^^^^^^^^^
    |
    = note: this `Result` may be an `Err` variant, which should be handled

warning: variable `maxVal` should have a snake case name
   --> src/lib.rs:132:17
    |
132 |         let mut maxVal:i32 = 0;
    |                 ^^^^^^ help: convert the identifier to snake case: `max_val`

warning: variable `maxKey` should have a snake case name
   --> src/lib.rs:133:17
    |
133 |         let mut maxKey:String = "".to_string();
    |                 ^^^^^^ help: convert the identifier to snake case: `max_key`

warning: unused `std::result::Result` that must be used
   --> src/lib.rs:145:13
    |
145 |             f.write_str(&maxKey);
    |             ^^^^^^^^^^^^^^^^^^^^^
    |
    = note: this `Result` may be an `Err` variant, which should be handled

warning: unused `std::result::Result` that must be used
   --> src/lib.rs:146:13
    |
146 |             f.write_str(": ");
    |             ^^^^^^^^^^^^^^^^^^
    |
    = note: this `Result` may be an `Err` variant, which should be handled

warning: unused `std::result::Result` that must be used
   --> src/lib.rs:147:13
    |
147 |             f.pad(&maxVal.to_string());
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: this `Result` may be an `Err` variant, which should be handled

warning: unused `std::result::Result` that must be used
   --> src/lib.rs:148:13
    |
148 |             f.write_str("\n");
    |             ^^^^^^^^^^^^^^^^^^
    |
    = note: this `Result` may be an `Err` variant, which should be handled

warning: variable `rightWord` should have a snake case name
   --> src/lib.rs:169:17
    |
169 |         let mut rightWord: String = "".to_string();
    |                 ^^^^^^^^^ help: convert the identifier to snake case: `right_word`

warning: variable `lowerWord` should have a snake case name
   --> src/lib.rs:171:17
    |
171 |         let mut lowerWord = word.to_lowercase().trim().to_string();
    |                 ^^^^^^^^^ help: convert the identifier to snake case: `lower_word`

warning: variable `wordCounter` should have a snake case name
   --> src/lib.rs:176:21
    |
176 |             let mut wordCounter:WordCounter;
    |                     ^^^^^^^^^^^ help: convert the identifier to snake case: `word_counter`

warning: variable `maxCount` should have a snake case name
   --> src/lib.rs:178:21
    |
178 |             let mut maxCount: i32 = 0;
    |                     ^^^^^^^^ help: convert the identifier to snake case: `max_count`

warning: variable `wordCounter` should have a snake case name
   --> src/lib.rs:190:13
    |
190 |         let wordCounter:WordCounter;
    |             ^^^^^^^^^^^ help: convert the identifier to snake case: `word_counter`

warning: variable `wordCounter` should have a snake case name
   --> src/lib.rs:198:13
    |
198 |         let wordCounter:WordCounter;
    |             ^^^^^^^^^^^ help: convert the identifier to snake case: `word_counter`

warning: variable `wordCounter` should have a snake case name
   --> src/lib.rs:211:13
    |
211 |         let wordCounter:WordCounter;
    |             ^^^^^^^^^^^ help: convert the identifier to snake case: `word_counter`

warning: variable `newWord` should have a snake case name
   --> src/lib.rs:238:17
    |
238 |         let mut newWord: String = "".to_string();
    |                 ^^^^^^^ help: convert the identifier to snake case: `new_word`

warning: variable `wordLength` should have a snake case name
   --> src/lib.rs:239:17
    |
239 |         let mut wordLength = word.len();
    |                 ^^^^^^^^^^ help: convert the identifier to snake case: `word_length`

    Finished test [unoptimized + debuginfo] target(s) in 4.21s
     Running target/debug/deps/solution-a73e64ec87929bd0

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-38971695424b36d5

running 15 tests
test solution_test::test_best_word_is_returned ... ok
test solution_test::test_clean_line_removes_punctuation ... FAILED
test solution_test::test_clean_line_trims_the_input ... ok
test solution_test::test_correction ... ok
test solution_test::test_correction_fails_to_produce_new_result ... FAILED
test solution_test::test_correction_normalizes_case ... ok
test solution_test::test_counting ... ok
test solution_test::test_display ... ok
test solution_test::test_edits1 ... ok
test solution_test::test_edits2 ... ok
test solution_test::test_empty_counter ... ok
test solution_test::test_from_empty_str ... ok
test solution_test::test_from_str ... ok
test solution_test::test_known_words ... ok
test solution_test::test_probability ... ok

failures:

---- solution_test::test_clean_line_removes_punctuation stdout ----
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `"foo  bar  baz"`,
 right: `"foo bar baz"`', tests/solution_test.rs:60:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

---- solution_test::test_correction_fails_to_produce_new_result stdout ----
thread 'main' panicked at 'assertion failed: self.is_char_boundary(n)', src/liballoc/string.rs:1602:30


failures:
    solution_test::test_clean_line_removes_punctuation
    solution_test::test_correction_fails_to_produce_new_result

test result: FAILED. 13 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out

error: test failed, to rerun pass '--test solution_test'

История (1 версия и 0 коментара)

Моника качи първо решение на 14.01.2020 10:16 (преди над 5 години)