public CheckResult Check(string input) { var result = new CheckResult(); if (string.IsNullOrWhiteSpace(input)) { result.State = CheckState.Incorrect; } else { var distance = LevenshteinDistance.Compute(_currentItem.Translation, input); var longer = input.Length; if (_currentItem.Translation.Length > longer) { longer = _currentItem.Translation.Length; } result.Correctness = (int)Math.Floor(100 - (distance/(float) longer*100)); result.State = result.Correctness >= _treshold ? CheckState.Correct : CheckState.Incorrect; } result.CorrectAnswer = _currentItem.Translation; if (result.State == CheckState.Correct) { Completed++; _currentItem = null; } if (result.State == CheckState.Correct && _items.Count == 0) { result.State = CheckState.Done; } return result; }
private void ChangeStateByResult(CheckResult result) { switch (result.State) { case CheckState.Correct: ChangeState(result, TestState.Next, "Progress " + _manager.Progress); break; case CheckState.Incorrect: Result.Message = string.Format("Incorrect! ({0}%)", result.Correctness); Result.Color = new SolidColorBrush(Colors.Red); CurrentTestState = TestState.Next; CorrectAnswer = result.CorrectAnswer; ShowCorrectAnswerButton = true; break; case CheckState.Done: ChangeState(result, TestState.Done, "All done!"); break; default: throw new ArgumentOutOfRangeException(); } }
private void ChangeState(CheckResult result, TestState state, string progressText) { Result.Message = string.Format("Correct! ({0}%)", result.Correctness); Result.Color = new SolidColorBrush(Colors.Green); CurrentTestState = state; if (result.Correctness != 100) { CorrectAnswer = result.CorrectAnswer; ShowCorrectAnswerButton = true; } Progress = progressText; }