public static void RunSequencesFinder(BestSequenceFinderTest.ITestSequenceModel tsm, KBestSequenceFinder sf) { ICounter <int[]> bestLabelsCounter = sf.KBestSequences(tsm, K2nr); IList <int[]> topValues = Counters.ToSortedList(bestLabelsCounter); IEnumerator <int[]> iter = topValues.GetEnumerator(); for (int i = 0; i < K2nr; i++) { int[] sequence = iter.Current; string strSequence = Arrays.ToString(sequence); double score = bestLabelsCounter.GetCount(sequence); // Deal with ties in the scoring ... only tied pairs handled. bool found = false; if (strSequence.Equals(test2nrAnswers[i])) { found = true; } else { if (i > 0 && Math.Abs(score - test2nrScores[i - 1]) < 1e-8 && strSequence.Equals(test2nrAnswers[i - 1])) { found = true; } else { if (i + 1 < test2nrScores.Length && Math.Abs(score - test2nrScores[i + 1]) < 1e-8 && strSequence.Equals(test2nrAnswers[i + 1])) { found = true; } } } NUnit.Framework.Assert.IsTrue("Best sequence is wrong. Correct: " + test2nrAnswers[i] + ", found: " + strSequence, found); NUnit.Framework.Assert.AreEqual("Best sequence score is wrong.", test2nrScores[i], score, 1e-8); } }
public static void RunPossibleValuesChecker(BestSequenceFinderTest.ITestSequenceModel tsm, IBestSequenceFinder sf) { int[] bestLabels = sf.BestSequence(tsm); // System.out.println("The best sequence is ... " + Arrays.toString(bestLabels)); for (int i = 0; i < bestLabels.Length; i++) { int[] possibleValues = tsm.GetPossibleValues(i); bool found = false; foreach (int possible in possibleValues) { if (bestLabels[i] == possible) { found = true; } } if (!found) { Fail("Returned impossible label " + bestLabels[i] + " for position " + i); } } }
// end class TestSequenceModel2 public static void RunSequenceFinder(BestSequenceFinderTest.ITestSequenceModel tsm, IBestSequenceFinder sf) { int[] bestLabels = sf.BestSequence(tsm); NUnit.Framework.Assert.IsTrue("Best sequence is wrong. Correct: " + Arrays.ToString(tsm.CorrectAnswers()) + ", found: " + Arrays.ToString(bestLabels), Arrays.Equals(tsm.CorrectAnswers(), bestLabels)); NUnit.Framework.Assert.AreEqual("Best sequence score is wrong.", tsm.BestSequenceScore(), tsm.ScoreOf(bestLabels)); }