Exemplo n.º 1
0
		/// <summary>
		/// Compare results with the original test set.
		/// </summary>
		/// <param name="results"></param>
		/// <param name="nMostFrequent"></param>
		/// <param name="testSet"></param>
		private void TestResult(WordOccurences results, int nMostFrequent, TestData[] testSet)
		{
			Assert.AreEqual(results.Count, nMostFrequent, "Incorrect number of results.");

			int i = 0;
			foreach (OccurenceInfo oi in results)
			{
				TestResult(oi, testSet[i++]);
			}

		}
Exemplo n.º 2
0
		/// <summary>
		/// Traverse frequency array from the back to get n most frequency words.
		/// </summary>
		/// <param name="frequencyArray"></param>
		/// <param name="n"></param>
		/// <returns></returns>
		private WordOccurences GetTopNWords(OccurenceInfo[] frequencyArray, int n)
		{
			WordOccurences result = new WordOccurences();

			//have to filter out null array entries
			int len = frequencyArray.Length;
			int index = 0;
			int count = 0;
			while (count < n)
			{
				OccurenceInfo fi = frequencyArray[len - index - 1]; //start at the back of the array
				if (fi != null)
				{
					result.Add(fi);
					count++;
				}
				index++;
			}

			return result;
		}