public void BlauPointComparerTest() { Console.WriteLine("BlauPointComparerTest"); int dim = 3; string [] names = new string [3] { "x", "y", "z" }; double [] mins = new double [3] { 0.0, 0.0, 0.0 }; double [] maxs = new double [3] { 100.0, 200.0, 300.0 }; IBlauSpace s = BlauSpace.create(dim, names, mins, maxs); IBlauPoint bp = new BlauPoint(s); bp.setCoordinate(0, 10.0); bp.setCoordinate(1, 20.0); bp.setCoordinate(2, 30.0); IBlauPoint bp2 = bp.clone(); Dictionary <IBlauPoint, int> dic = new Dictionary <IBlauPoint, int>(new BlauPointComparer()); dic.Add(bp, 1); Assert.AreEqual(dic.ContainsKey(bp), true); Assert.AreEqual(dic.ContainsKey(bp2), true); Assert.Throws <System.ArgumentException>(delegate { dic.Add(bp2, 2); }); Assert.AreEqual(dic.Count, 1); Assert.AreEqual(dic[bp], 1); Assert.AreEqual(dic[bp2], 1); Dictionary <IBlauPoint, int> dic2 = new Dictionary <IBlauPoint, int>(new BlauPointComparer()); dic2.Add(bp2, 2); Assert.AreEqual(dic2.ContainsKey(bp2), true); Assert.AreEqual(dic2.ContainsKey(bp), true); Assert.Throws <System.ArgumentException>(delegate { dic.Add(bp, 1); }); Assert.AreEqual(dic2.Count, 1); Assert.AreEqual(dic2[bp], 2); Assert.AreEqual(dic2[bp2], 2); }
public void BlauPointTest() { Console.WriteLine("BlauPointTest"); int dim = 3; string [] names = new string [3] { "x", "y", "z" }; double [] mins = new double [3] { 0.0, 0.0, 0.0 }; double [] maxs = new double [3] { 100.0, 200.0, 300.0 }; IBlauSpace s = BlauSpace.create(dim, names, mins, maxs); IBlauPoint bp = new BlauPoint(s); bp.setCoordinate(0, 10.0); bp.setCoordinate(1, 20.0); bp.setCoordinate(2, 30.0); Assert.AreEqual(bp.getCoordinate(0), 10.0); Assert.AreEqual(bp.getCoordinate(1), 20.0); Assert.AreEqual(bp.getCoordinate(2), 30.0); Assert.Throws <Exception>(delegate { bp.setCoordinate(0, -10.0); }); Assert.Throws <Exception>(delegate { bp.setCoordinate(0, 110.0); }); Assert.Throws <Exception>(delegate { bp.setCoordinate(1, -10.0); }); Assert.Throws <Exception>(delegate { bp.setCoordinate(1, 210.0); }); Assert.Throws <Exception>(delegate { bp.setCoordinate(2, -10.0); }); Assert.Throws <Exception>(delegate { bp.setCoordinate(2, 310.0); }); IBlauPoint bp2 = bp.clone(); Assert.AreEqual(bp.CompareTo(bp2), 0); Assert.AreEqual(bp2.CompareTo(bp), 0); int h, h2; h = bp.GetHashCode(); h2 = bp2.GetHashCode(); Assert.AreEqual(h, h2); bp.setCoordinate(0, 11.0); h = bp.GetHashCode(); h2 = bp2.GetHashCode(); Assert.AreNotEqual(h, h2); bp2.setCoordinate(0, 11.0); h = bp.GetHashCode(); h2 = bp2.GetHashCode(); Assert.AreEqual(h, h2); bp.setCoordinate(1, 22.0); h = bp.GetHashCode(); h2 = bp2.GetHashCode(); Assert.AreNotEqual(h, h2); bp2.setCoordinate(1, 22.0); h = bp.GetHashCode(); h2 = bp2.GetHashCode(); Assert.AreEqual(h, h2); bp.setCoordinate(2, 33.0); h = bp.GetHashCode(); h2 = bp2.GetHashCode(); Assert.AreNotEqual(h, h2); bp2.setCoordinate(2, 33.0); h = bp.GetHashCode(); h2 = bp2.GetHashCode(); Assert.AreEqual(h, h2); Dictionary <IBlauPoint, int> dic = new Dictionary <IBlauPoint, int>(); dic.Add(bp, 1); Assert.AreEqual(dic.ContainsKey(bp), true); Assert.AreEqual(dic.ContainsKey(bp2), false); SortedDictionary <IBlauPoint, int> dic2 = new SortedDictionary <IBlauPoint, int>(); dic2.Add(bp, 1); Assert.AreEqual(dic2.ContainsKey(bp), true); Assert.AreEqual(dic2.ContainsKey(bp2), true); }
public void BlauSpaceEvaluationTest() { Console.WriteLine("BlauSpaceEvaluationTest"); int dim = 3; string [] names = new string [3] { "x", "y", "z" }; double [] mins = new double [3] { 0.0, 0.0, 0.0 }; double [] maxs = new double [3] { 100.0, 100.0, 100.0 }; IBlauSpace s = BlauSpace.create(dim, names, mins, maxs); int STEPS = 10; int [] STEPSarray = new int[s.Dimension]; for (int j = 0; j < s.Dimension; j++) { STEPSarray[j] = STEPS; } IBlauSpaceLattice bsl = BlauSpaceLattice.create(s, STEPSarray); IBlauSpaceMultiEvaluation mev = new BlauSpaceMultiEvaluation("net worth", bsl); IBlauPoint bp = new BlauPoint(s); bp.setCoordinate(0, 11.0); bp.setCoordinate(1, 22.0); bp.setCoordinate(2, 33.0); mev.set(bp, 10.0); mev.set(bp, 20.0); IBlauPoint bp2 = bp.clone(); mev.set(bp2, 30.0); mev.set(bp2, 40.0); IBlauPoint bp3 = new BlauPoint(s); bp3.setCoordinate(0, 12.0); bp3.setCoordinate(1, 23.0); bp3.setCoordinate(2, 34.0); mev.set(bp3, 50.0); IBlauPoint bpX = new BlauPoint(s); bpX.setCoordinate(0, 22.0); bpX.setCoordinate(1, 33.0); bpX.setCoordinate(2, 44.0); mev.set(bpX, 100.0); IBlauSpaceEvaluation bse = new BlauSpaceEvaluation("net worth", bsl); foreach (IBlauPoint p in mev.AssignedLatticePoints) { LinkedList <IScore> scores = mev.eval(p); double total = 0.0; double count = 0.0; foreach (IScore sc in scores) { total += sc.Value; count += 1.0; } if (p.CompareTo(bp) == 0) { Assert.AreEqual(total, 150.0); Assert.AreEqual(count, 5.0); } if (p.CompareTo(bpX) == 0) { Assert.AreEqual(total, 100.0); Assert.AreEqual(count, 1.0); } double ave = total / count; bse.set(p, ave); Assert.Throws <Exception>(delegate { bse.set(p, ave); }); Assert.Throws <Exception>(delegate { bse.set(p.clone(), ave); }); Assert.AreEqual(bse.eval(p), ave); Assert.AreEqual(bse.eval(p.clone()), ave); } SingletonLogger.Instance().DebugLog(typeof(metrics_tests), "bse: " + bse.ToStringLong()); }
public void BlauSpaceMultiEvaluationTest() { Console.WriteLine("BlauSpaceMultiEvaluationTest"); int dim = 3; string [] names = new string [3] { "x", "y", "z" }; double [] mins = new double [3] { 0.0, 0.0, 0.0 }; double [] maxs = new double [3] { 100.0, 100.0, 100.0 }; IBlauSpace s = BlauSpace.create(dim, names, mins, maxs); int STEPS = 10; int [] STEPSarray = new int[s.Dimension]; for (int j = 0; j < s.Dimension; j++) { STEPSarray[j] = STEPS; } IBlauSpaceLattice bsl = BlauSpaceLattice.create(s, STEPSarray); IBlauSpaceMultiEvaluation mev = new BlauSpaceMultiEvaluation("net worth", bsl); IBlauPoint bp = new BlauPoint(s); bp.setCoordinate(0, 11.0); bp.setCoordinate(1, 22.0); bp.setCoordinate(2, 33.0); mev.set(bp, 10.0); Assert.AreEqual(mev.eval(bp).Count, 1); mev.set(bp, 20.0); Assert.AreEqual(mev.eval(bp).Count, 2); IBlauPoint bp2 = bp.clone(); mev.set(bp2, 30.0); Assert.AreEqual(mev.eval(bp).Count, 3); Assert.AreEqual(mev.eval(bp2).Count, 3); mev.set(bp2, 40.0); Assert.AreEqual(mev.eval(bp).Count, 4); Assert.AreEqual(mev.eval(bp2).Count, 4); Assert.AreEqual(mev.AssignedLatticePoints.Count, 1); IBlauPoint bp3 = new BlauPoint(s); bp3.setCoordinate(0, 12.0); bp3.setCoordinate(1, 23.0); bp3.setCoordinate(2, 34.0); mev.set(bp3, 50.0); Assert.AreEqual(mev.eval(bp).Count, 5); Assert.AreEqual(mev.eval(bp2).Count, 5); Assert.AreEqual(mev.eval(bp3).Count, 5); Assert.AreEqual(mev.AssignedLatticePoints.Count, 1); IBlauPoint bpX = new BlauPoint(s); bpX.setCoordinate(0, 22.0); bpX.setCoordinate(1, 33.0); bpX.setCoordinate(2, 44.0); mev.set(bpX, 100.0); Assert.AreEqual(mev.eval(bp).Count, 5); Assert.AreEqual(mev.eval(bp2).Count, 5); Assert.AreEqual(mev.eval(bp3).Count, 5); Assert.AreEqual(mev.eval(bpX).Count, 1); Assert.AreEqual(mev.AssignedLatticePoints.Count, 2); SingletonLogger.Instance().DebugLog(typeof(metrics_tests), "mev: " + mev.ToStringLong()); }