public void GetBayesFactorTest() { ScoreManager2 <string> sm = new ScoreManager2 <string>(); sm.Add("first", -3); sm.Add("second", 0); sm.Add("third", -1); double bayesFactor = sm.GetBayesFactor(); Assert.AreEqual(0.34901221676818633, bayesFactor, 1E-6); }
public void PurgeTest() { ScoreManager2 <string> sm = new ScoreManager2 <string>(); sm.Threshold = 0.99; bool added = sm.Add("zero", 0); added = sm.Add("one-half", 0.5); added = sm.Add("one", 1); Assert.AreEqual(sm.Count, 3); sm.Purge(); Assert.AreEqual(sm.Count, 2); }
public void ItemByNameTest() { ScoreManager2 <int> sm = new ScoreManager2 <int>(useNames: true); sm.Threshold = 10; sm.Add(0, -3); sm.Add(2, 0); sm.Add(1, -1); Assert.AreEqual(sm.Count, 3); int item = sm.ItemByName("0"); Assert.AreEqual(item, 0); item = sm.ItemByName("2"); Assert.AreEqual(item, 2); }
public void ContainsItemNamedTest() { ScoreManager2 <string> sm = new ScoreManager2 <string>(useNames: true); sm.Threshold = 10; sm.Add("first", -3); sm.Add("second", 0); sm.Add("third", -1); Assert.AreEqual(sm.Count, 3); bool contains = sm.ContainsItemNamed("second"); Assert.IsTrue(contains); contains = sm.ContainsItemNamed("fourth"); Assert.IsFalse(contains); }
public void ExponentiateAndNormalizeTest() { ScoreManager2 <string> sm = new ScoreManager2 <string>(); sm.Add("first", -3); sm.Add("second", -2); sm.Add("third", -1); sm.ExponentiateAndNormalize(); double sum = 0; foreach (ScoredObject <string> so in sm) { sum += so.Score; } Assert.AreEqual(sum, 1, 1E-6); }
public static double[] Test(int totalSize) { ScoreManager2 <int> manager = new ScoreManager2 <int>(); Random random = new Random(); manager.Threshold = 10; for (int i = 0; i < totalSize; i++) { manager.Add(i, random.NextDouble()); } System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch(); timer.Start(); manager.Threshold = 0.5; manager.Purge(); timer.Stop(); double purgeTime = timer.ElapsedMilliseconds; manager = new ScoreManager2 <int>(); manager.Threshold = 10; for (int i = 0; i < totalSize; i++) { manager.Add(i, random.NextDouble()); } timer.Reset(); timer.Start(); manager.Threshold = 0.5; manager.Revalidate(); timer.Stop(); double revalTime = timer.ElapsedMilliseconds; return(new double[] { purgeTime, revalTime }); }
public void AddTest1() { ScoreManager2 <string> sm = new ScoreManager2 <string>(useNames: true); sm.Threshold = 1; bool added = sm.Add(new ScoredObject <string>() { Item = "one", Score = 1 }); Assert.IsTrue(added); Assert.AreEqual(sm.Count, 1); Assert.AreEqual(sm.TopScore, 1); added = sm.Add(new ScoredObject <string>() { Item = "one-half", Score = 0.5 }); Assert.IsTrue(added); Assert.AreEqual(sm.Count, 2); added = sm.Add(new ScoredObject <string>() { Item = "minus-one", Score = -1 }); Assert.IsFalse(added); Assert.AreEqual(sm.Count, 2); added = sm.Add(new ScoredObject <string>() { Item = "two", Score = 2 }); Assert.IsTrue(added); Assert.AreEqual(sm.Count, 3); Assert.AreEqual(sm.TopScore, 2); Assert.AreEqual(sm.TopItem, "two"); added = sm.Add(new ScoredObject <string>() { Item = "one", Score = 3 }); Assert.IsFalse(added); }
public void SortTest() { ScoreManager2 <string> sm = new ScoreManager2 <string>(); sm.Threshold = 10; List <int> ordered = new List <int>() { 0, -1, -3 }; sm.Add("first", -3); sm.Add("second", 0); sm.Add("third", -1); sm.Sort(); int i = 0; foreach (ScoredObject <string> so in sm) { Assert.AreEqual(ordered[i], so.Score); i++; } }
public void AddTest() { ScoreManager2 <string> sm = new ScoreManager2 <string>(useNames: true); sm.Threshold = 1; bool added = sm.Add("one", 1); Assert.IsTrue(added); Assert.AreEqual(sm.Count, 1); Assert.AreEqual(sm.TopScore, 1); added = sm.Add("one-half", 0.5); Assert.IsTrue(added); Assert.AreEqual(sm.Count, 2); added = sm.Add("minus one", -1); Assert.IsFalse(added); Assert.AreEqual(sm.Count, 2); added = sm.Add("two", 2); Assert.IsTrue(added); Assert.AreEqual(sm.Count, 3); Assert.AreEqual(sm.TopScore, 2); Assert.AreEqual(sm.TopItem, "two"); added = sm.Add("one", 3); Assert.IsFalse(added); }