Exemple #1
0
        public void complex_highlight_types_single_word_incorrect_and_short()
        {
            var accuracy = new Accuracy(new AnalyticData()
            {
                TextShown = "qwer", TextEntered = "xwe"
            });

            accuracy.Compute();

            HighlightDeterminator det = new HighlightDeterminator();
            var details = det.Compute(accuracy);

            Assert.That(details.Count, Is.EqualTo(2));
            Assert.That(details, Is.EquivalentTo(new List <HighlightDetail>()
            {
                new HighlightDetail()
                {
                    HighlightType = HighlightType.IncorrectChar,
                    IndexStart    = 0,
                    IndexEnd      = 1,
                },
                new HighlightDetail()
                {
                    HighlightType = HighlightType.ShortChars,
                    IndexStart    = 3,
                    IndexEnd      = 4,
                }
            }));
        }
Exemple #2
0
        public void complex_highlight_types_multi_word_case01()
        {
            var accuracy = new Accuracy(new AnalyticData()
            {
                TextShown = "abc qwer asdf", TextEntered = "abx qw asdfasdf"
            });

            accuracy.Compute();

            HighlightDeterminator det = new HighlightDeterminator();
            var details = det.Compute(accuracy);

            Assert.That(details.Count, Is.EqualTo(3));
            Assert.That(details, Is.EquivalentTo(new List <HighlightDetail>()
            {
                new HighlightDetail()
                {
                    HighlightType = HighlightType.IncorrectChar,
                    IndexStart    = 2,
                    IndexEnd      = 3,
                },
                new HighlightDetail()
                {
                    HighlightType = HighlightType.ShortChars,
                    IndexStart    = 6,
                    IndexEnd      = 8,
                },
                new HighlightDetail()
                {
                    HighlightType = HighlightType.ExtraChars,
                    IndexStart    = 13,
                    IndexEnd      = 17,
                }
            }));
        }
Exemple #3
0
        public void unevalated_text_classified_at_end_with_extra_char_right_before(
            string shown, string entered)
        {
            var accuracy = new Accuracy(new AnalyticData()
            {
                TextShown = shown, TextEntered = entered
            });

            accuracy.Compute();

            HighlightDeterminator det = new HighlightDeterminator();
            var details = det.Compute(accuracy);

            Assert.That(details, Is.EquivalentTo(new List <HighlightDetail>()
            {
                new HighlightDetail()
                {
                    HighlightType = HighlightType.ExtraChars,
                    IndexStart    = 7,
                    IndexEnd      = 8,
                },

                new HighlightDetail()
                {
                    HighlightType = HighlightType.Unevaluated,
                    IndexStart    = 7,
                    IndexEnd      = 9,
                }
            }));
        }
Exemple #4
0
        public void one_word_all_wrong_chars()
        {
            string input    = "abc";
            string expected = "xyz";
            var    accuracy = new Accuracy(new AnalyticData {
                TextShown = input, TextEntered = expected
            });

            accuracy.Compute();

            var incorrectChars = accuracy.GetAllIncorrectCharacters();

            Assert.That(incorrectChars.Count, Is.EqualTo(3));
            Assert.That(incorrectChars, Is.EquivalentTo(new List <AccuracyIncorrectChar>()
            {
                new AccuracyIncorrectChar()
                {
                    Expected = 'a',
                    Found    = 'x',
                    Index    = 0
                },
                new AccuracyIncorrectChar()
                {
                    Expected = 'b',
                    Found    = 'y',
                    Index    = 1
                },
                new AccuracyIncorrectChar()
                {
                    Expected = 'c',
                    Found    = 'z',
                    Index    = 2
                }
            }));
        }
        public HttpResponseMessage RunForSequence(SequenceModel sequenceFromClient)
        {
            KeySequence keySeq = new History.UserSessionHistory().GetHistoryDetailsByKeySequence(sequenceFromClient.SequenceId);

            //if the text entered from the db and the text from the client is 
            //empty or null then return analysis unavailable
            if (string.IsNullOrWhiteSpace(keySeq.TextEntered)
                && string.IsNullOrWhiteSpace(sequenceFromClient.TextEntered))
            {
                var invalid =  new List<HighlightedText>() { new HighlightedText() {
                    HighlightType = HighlightType.Unevaluated,
                    Text = "No analysis available for this sequence.  No user provided text detected."
                }};
                return Request.CreateResponse(HttpStatusCode.OK, invalid);
            }

            Accuracy accuracy = new Accuracy(new AnalyticData() {
                TextShown = keySeq.TextShown,
                TextEntered = 
                    (string.IsNullOrWhiteSpace(keySeq.TextEntered))
                    ? sequenceFromClient.TextEntered : keySeq.TextEntered
            });
            accuracy.Compute();

            IList<HighlightDetail> details = new HighlightDeterminator().Compute(accuracy);
            HighlightedTextBuilder highlightBuilder = new HighlightedTextBuilder();
            Queue<HighlightedText> highlightedSections = highlightBuilder.Compute(keySeq.TextShown, details);

            return Request.CreateResponse(HttpStatusCode.OK, highlightedSections.ToList());
        }
        public void calculated_correctly_for_equal_length_strings(string input, string expected, double expectedAcc)
        {
            var accuracy = new Accuracy(new AnalyticData {
                TextShown = input, TextEntered = expected
            });

            accuracy.Compute();
            Assert.That(accuracy.AccuracyVal, Is.EqualTo(expectedAcc), string.Format("{0} vs {1} = {2}", input, expected, expectedAcc));
        }
        public void counts_num_extra_chars_when_expected_length_greater_than_shown(string input, string expected, int numExtraChars)
        {
            var accuracy = new Accuracy(new AnalyticData {
                TextShown = input, TextEntered = expected
            });

            accuracy.Compute();
            Assert.That(accuracy.NumExtraChars, Is.EqualTo(numExtraChars));
        }
        public void edge_cases(string input, string expected, double expectedAcc)
        {
            var accuracy = new Accuracy(new AnalyticData {
                TextShown = input, TextEntered = expected
            });

            accuracy.Compute();
            Assert.That(accuracy.AccuracyVal, Is.EqualTo(expectedAcc), string.Format("{0} vs {1} = {2}", input, expected, expectedAcc));
        }
        public void counts_number_of_correct_chars_for_equal_length_strings(string input, string expected, int numSameChars)
        {
            var accuracy = new Accuracy(new AnalyticData {
                TextShown = input, TextEntered = expected
            });

            accuracy.Compute();
            Assert.That(accuracy.NumCorrectChars, Is.EqualTo(numSameChars));
        }
        public void summary_contains_accuracy_percent()
        {
            var accuracy = new Accuracy(new AnalyticData {
                TextShown = "abcd", TextEntered = "abxx"
            });

            accuracy.Compute();
            Assert.That(accuracy.GetResultSummary(), Contains.Substring("50%"));
        }
        public void multi_word_incorrect_chars_base_cases(string shown, string entered, int numIncorrectChars)
        {
            var accuracy = new Accuracy(new AnalyticData {
                TextShown = shown, TextEntered = entered
            });

            accuracy.Compute();
            Assert.That(accuracy.NumIncorrectChars, Is.EqualTo(numIncorrectChars), string.Format("{0} vs {1}", shown, entered));
        }
        public void last_char_evaluated_accurate_for_extra_chars(
            string shown, string input, int numWords)
        {
            var accuracy = new Accuracy(new AnalyticData {
                TextShown = shown, TextEntered = input
            });

            accuracy.Compute();
            Assert.That(accuracy.IndexOfLastCharEvaluated, Is.EqualTo(numWords));
        }
        public void text_shown_and_entered_correct_after_compute(string input, string expected)
        {
            var accuracy = new Accuracy(new AnalyticData {
                TextShown = input, TextEntered = expected
            });

            accuracy.Compute();
            Assert.That(accuracy.GetTextShown(), Is.EqualTo(input));
            Assert.That(accuracy.GetTextEntered(), Is.EqualTo(expected));
        }
Exemple #14
0
        public void incorrect_char_list_is_empty_for_equal_strings()
        {
            string input    = "abcd";
            string expected = "abcd";
            var    accuracy = new Accuracy(new AnalyticData {
                TextShown = input, TextEntered = expected
            });

            accuracy.Compute();
            Assert.That(accuracy.GetAllIncorrectCharacters(), Is.Empty);
        }
        public void char_index_accounts_for_spaces_two_words()
        {
            var accuracy = new Accuracy(new AnalyticData {
                TextShown = "abc xyz", TextEntered = "abc xyz"
            });

            accuracy.Compute();
            Assert.That(accuracy.Measurements.Count, Is.EqualTo(2));
            Assert.That(accuracy.Measurements[0].IndexInLargerText, Is.EqualTo(0));
            Assert.That(accuracy.Measurements[1].IndexInLargerText, Is.EqualTo(4));
        }
        public void double_spaces_between_words_doesnt_affect_accuracy()
        {
            var accuracy = new Accuracy(new AnalyticData {
                TextShown = "abc xyz", TextEntered = "abc  xyz"
            });

            accuracy.Compute();
            Assert.That(accuracy.NumIncorrectChars, Is.EqualTo(0));
            Assert.That(accuracy.TotalNumWordsShown, Is.EqualTo(accuracy.TotalNumWordsEntered));
            Assert.That(accuracy.NumShortChars, Is.EqualTo(0));
            Assert.That(accuracy.NumExtraChars, Is.EqualTo(0));
        }
Exemple #17
0
        public IList <HighlightDetail> run_determinator(string shown, string entered)
        {
            var accuracy = new Accuracy(new AnalyticData()
            {
                TextShown = shown, TextEntered = entered
            });

            accuracy.Compute();

            HighlightDeterminator   det     = new HighlightDeterminator();
            IList <HighlightDetail> details = det.Compute(accuracy);

            return(details);
        }
        public void is_calculated_to_configured_precision()
        {
            var accuracy = new Accuracy(new AnalyticData {
                TextShown = "qwerty", TextEntered = "qwer"
            });

            accuracy.Compute();

            double wrongExpected = (double)2 / 3;

            Assert.That(accuracy.AccuracyVal, Is.Not.EqualTo(wrongExpected));

            double expected = Math.Round((double)2 / 3, Constants.PRECISION_FOR_DECIMALS);

            Assert.That(accuracy.AccuracyVal, Is.EqualTo(expected));
        }
Exemple #19
0
        public void unevalated_text_classified_at_end(
            string shown, string entered, int start, int end)
        {
            var accuracy = new Accuracy(new AnalyticData()
            {
                TextShown = shown, TextEntered = entered
            });

            accuracy.Compute();

            HighlightDeterminator det = new HighlightDeterminator();
            var details = det.Compute(accuracy);

            Assert.That(details, Is.EquivalentTo(new List <HighlightDetail>()
            {
                new HighlightDetail()
                {
                    HighlightType = HighlightType.Unevaluated,
                    IndexStart    = start,
                    IndexEnd      = end,
                }
            }));
        }
Exemple #20
0
        public void multi_word_one_wrong_word()
        {
            string input    = "abc zy";
            string expected = "abc yy";
            var    accuracy = new Accuracy(new AnalyticData {
                TextShown = input, TextEntered = expected
            });

            accuracy.Compute();

            var measurements   = accuracy.Measurements;
            var incorrectChars = measurements.SelectMany(m => m.IncorrectChars).ToList();

            Assert.That(incorrectChars.Count, Is.EqualTo(1));
            Assert.That(incorrectChars, Is.EquivalentTo(new List <AccuracyIncorrectChar>()
            {
                new AccuracyIncorrectChar()
                {
                    Expected = 'z',
                    Found    = 'y',
                    Index    = 0
                }
            }));
        }
Exemple #21
0
        public void one_word_one_extra_chars(
            string shown, string entered, int start, int end)
        {
            var accuracy = new Accuracy(new AnalyticData()
            {
                TextShown = shown, TextEntered = entered
            });

            accuracy.Compute();

            HighlightDeterminator det = new HighlightDeterminator();
            var details = det.Compute(accuracy);

            Assert.That(details.Count, Is.EqualTo(1));
            Assert.That(details, Is.EquivalentTo(new List <HighlightDetail>()
            {
                new HighlightDetail()
                {
                    HighlightType = HighlightType.ExtraChars,
                    IndexStart    = start,
                    IndexEnd      = end,
                }
            }));
        }