Exemple #1
0
        public void BlauSpaceLatticeTest()
        {
            Console.WriteLine("BlauSpaceLatticeTest");

            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);

            Assert.AreEqual(bsl.getStepSize(0), 100.0 / (double)STEPS);
            Assert.AreEqual(bsl.getStepSize(1), 100.0 / (double)STEPS);
            Assert.AreEqual(bsl.getStepSize(2), 100.0 / (double)STEPS);

            Assert.AreEqual(bsl.getSteps(0), STEPS);
            Assert.AreEqual(bsl.getSteps(1), STEPS);
            Assert.AreEqual(bsl.getSteps(2), STEPS);

            IBlauPoint bp = new BlauPoint(s);

            bp.setCoordinate(0, 11.0);
            bp.setCoordinate(1, 22.0);
            bp.setCoordinate(2, 33.0);

            IBlauPoint bpq = bsl.quantize(bp);

            Assert.AreNotEqual(bp.CompareTo(bpq), 0);

            IBlauPoint bp2 = new BlauPoint(s);

            bp2.setCoordinate(0, 10.0);
            bp2.setCoordinate(1, 20.0);
            bp2.setCoordinate(2, 30.0);

            IBlauPoint bpq2 = bsl.quantize(bp2);

            Assert.AreEqual(bp2.CompareTo(bpq2), 0);

            Assert.AreEqual(bpq.CompareTo(bp2), 0);
            Assert.AreEqual(bpq.CompareTo(bpq2), 0);

            IBlauPoint bp3 = new BlauPoint(s);

            bp3.setCoordinate(0, 9.0);
            bp3.setCoordinate(1, 19.0);
            bp3.setCoordinate(2, 29.0);
            IBlauPoint bpq3 = bsl.quantize(bp3);

            Assert.AreEqual(bpq3.CompareTo(bpq), 0);
            Assert.AreEqual(bpq3.CompareTo(bp2), 0);
            Assert.AreEqual(bpq3.CompareTo(bpq2), 0);
        }
Exemple #2
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);
        }