Exemple #1
0
        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 int GetHashCode(IBlauPoint bx)
 {
     return(bx.GetHashCode());
 }