Пример #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);
        }
Пример #2
0
        public void QuantizedBlauPointSerializationTest()
        {
            Console.WriteLine("QuantizedBlauPointSerializationTest");
            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 bs = BlauSpace.create(dim, names, mins, maxs);

            SoapFormatter formatter = new SoapFormatter();
            // BinaryFormatter formatter = new BinaryFormatter();

            BlauPoint p1 = new BlauPoint(bs);

            p1.setCoordinate(0, 11.0);
            p1.setCoordinate(1, 21.0);
            p1.setCoordinate(2, 31.0);

            BlauPoint p2 = new BlauPoint(bs);

            p2.setCoordinate(0, 21.0);
            p2.setCoordinate(1, 31.0);
            p2.setCoordinate(2, 41.0);

            int []            steps = new int[3]; steps[0] = 10; steps[1] = 20; steps[2] = 30;
            IBlauSpaceLattice bsl   = BlauSpaceLattice.create(bs, steps);

            IBlauPoint qp1 = bsl.quantize(p1);
            IBlauPoint qp2 = bsl.quantize(p2);

            FileStream fs = new FileStream("p1.xml", FileMode.Create);

            formatter.Serialize(fs, p1);
            fs.Close();
            fs = new FileStream("p2.xml", FileMode.Create);
            formatter.Serialize(fs, p2);
            fs.Close();

            fs = new FileStream("qp1.xml", FileMode.Create);
            formatter.Serialize(fs, qp1);
            fs.Close();
            fs = new FileStream("qp2.xml", FileMode.Create);
            formatter.Serialize(fs, qp2);
            fs.Close();

            fs = new FileStream("qp1.xml", FileMode.Open);
            IBlauPoint p1r = (IBlauPoint)formatter.Deserialize(fs);

            fs.Close();
            fs = new FileStream("qp2.xml", FileMode.Open);
            IBlauPoint p2r = (IBlauPoint)formatter.Deserialize(fs);

            fs.Close();

            Assert.AreEqual(p1r.Space == p1.Space, true);
            Assert.AreEqual(p2r.Space == p2.Space, true);
            Assert.AreEqual(p1r.Space == p2r.Space, true);
            Assert.AreEqual(p1.Space == p2.Space, true);

            Assert.AreEqual(qp1 is QuantizedBlauPoint, true);
            Assert.AreEqual(qp2 is QuantizedBlauPoint, true);

            Assert.AreEqual(qp2.Space == p2.Space, true);
            Assert.AreEqual(qp1.Space == p1.Space, true);

            Assert.AreEqual(qp1.CompareTo(p1r), 0);
            Assert.AreEqual(qp2.CompareTo(p2r), 0);

            Assert.AreNotEqual(qp1.CompareTo(p1), 0);
            Assert.AreNotEqual(qp2.CompareTo(p2), 0);

            SingletonLogger.Instance().DebugLog(typeof(blau_tests), "Quantized points are as expected");
        }