public void add_1()
        {
            PerfSerie ps = new PerfSerie();

            Assert.IsTrue(ps.add(new PerfPoint(1, 5, false)));
            Assert.IsFalse(ps.add(new PerfPoint(1, 10, false)));
        }
        public void sortedClosestPoints_1()
        {
            PerfSerie ps = new PerfSerie();

            int[] table;

            Assert.IsNull(ps._A_sortedClosestPoints(0));

            ps.add(new PerfPoint(-12, 10, false));
            table = ps._A_sortedClosestPoints(-13);
            Assert.AreEqual(0, table[0]);

            ps.add(new PerfPoint(-9, 5, true));
            table = ps._A_sortedClosestPoints(-10);
            Assert.AreEqual(1, table[0]);
            Assert.AreEqual(0, table[1]);

            ps.add(new PerfPoint(-8, 5, true));
            ps.add(new PerfPoint(-5, -1, false));
            ps.add(new PerfPoint(-1, -1, false));
            ps.add(new PerfPoint(0, 1, false));
            ps.add(new PerfPoint(1, 1, false));
            ps.add(new PerfPoint(3, 0, false));
            ps.add(new PerfPoint(7, 3, false));
            ps.add(new PerfPoint(11, 0, false));
            ps.add(new PerfPoint(15, 9, false));
            ps.add(new PerfPoint(32, 41, false));

            table = ps._A_sortedClosestPoints(-13);
            Assert.AreEqual(0, table[0]);
            Assert.AreEqual(11, table[11]);

            table = ps._A_sortedClosestPoints(-7.5);
            Assert.AreEqual(2, table[0]);
        }
        public void add_2()
        {
            PerfSerie ps = new PerfSerie();

            ps.add(new PerfPoint(3, 10, false));
            ps.add(new PerfPoint(1, 5, true));
            ps.add(new PerfPoint(-5, 1, false));
            ps.add(new PerfPoint(-1, 15, false));
            ps.add(new PerfPoint(8, 6, false));

            Assert.AreEqual(-5, ps.pointAt(0).factorValue);
            Assert.AreEqual(-1, ps.pointAt(1).factorValue);
            Assert.AreEqual(1, ps.pointAt(2).factorValue);
            Assert.AreEqual(3, ps.pointAt(3).factorValue);
            Assert.AreEqual(8, ps.pointAt(4).factorValue);
        }
        public void PerfSerie_1()
        {
            PerfSerie ps = new PerfSerie();

            ps.add(new PerfPoint(3, 10, false));
            ps.add(new PerfPoint(1, 5, true));
            ps.add(new PerfPoint(-5, 1, false));

            PerfSerie psClone = new PerfSerie(ps);

            Assert.AreEqual(3, psClone.count);

            for (int count = 0; count < ps.count; count++)
            {
                Assert.AreEqual(ps.pointAt(count).factorValue, psClone.pointAt(count).factorValue);
            }
        }
        public void selectPoints_1()
        {
            PerfSerie ps = new PerfSerie();

            Assert.IsFalse(ps._A_selectPoints(0, 5));

            ps.add(new PerfPoint(-12, 10, false));
            Assert.IsTrue(ps._A_selectPoints(0, 5));
            Assert.IsTrue(ps.pointAt(0).selected);

            ps.add(new PerfPoint(-9, 5, false));
            Assert.IsTrue(ps._A_selectPoints(0, 3));
            Assert.IsTrue(ps.pointAt(0).selected);
            Assert.IsTrue(ps.pointAt(1).selected);

            ps.add(new PerfPoint(-8, 5, false));
            Assert.IsTrue(ps._A_selectPoints(-10, 2));
            Assert.IsTrue(ps.pointAt(0).selected);
            Assert.IsTrue(ps.pointAt(1).selected);
            Assert.IsFalse(ps.pointAt(2).selected);

            ps.add(new PerfPoint(-5, -1, false));
            ps.add(new PerfPoint(-1, -1, false));
            Assert.IsTrue(ps._A_selectPoints(-5.5, 4));
            Assert.IsTrue(ps.pointAt(3).selected);
            Assert.IsTrue(ps.pointAt(2).selected);
            Assert.IsTrue(ps.pointAt(1).selected);
            Assert.IsTrue(ps.pointAt(4).selected);
            Assert.IsFalse(ps.pointAt(0).selected);

            ps.add(new PerfPoint(0, 1, false));
            ps.add(new PerfPoint(1, 1, false));
            ps.add(new PerfPoint(3, 0, false));
            ps.add(new PerfPoint(7, 3, false));
            Assert.IsTrue(ps._A_selectPoints(-1.5, 3));
            Assert.IsFalse(ps.pointAt(0).selected);
            Assert.IsFalse(ps.pointAt(1).selected);
            Assert.IsFalse(ps.pointAt(2).selected);
            Assert.IsFalse(ps.pointAt(3).selected);
            Assert.IsTrue(ps.pointAt(4).selected);
            Assert.IsTrue(ps.pointAt(5).selected);
            Assert.IsTrue(ps.pointAt(6).selected);
            Assert.IsFalse(ps.pointAt(7).selected);
            Assert.IsFalse(ps.pointAt(8).selected);
        }
        public void getIndexOf_1()
        {
            PerfSerie ps  = new PerfSerie();
            PerfPoint pp1 = new PerfPoint(1, 5, true);
            PerfPoint pp2 = new PerfPoint(-5, 1, true);
            PerfPoint pp3 = new PerfPoint(-1, 15, false);
            PerfPoint pp4 = new PerfPoint(8, 6, false);

            ps.add(pp1);
            ps.add(pp2);
            ps.add(pp3);
            ps.add(pp4);

            Assert.AreEqual(0, ps.getIndexOf(pp2));
            Assert.AreEqual(1, ps.getIndexOf(pp3));
            Assert.AreEqual(2, ps.getIndexOf(pp1));
            Assert.AreEqual(3, ps.getIndexOf(pp4));
        }
        public void selectedCount_1()
        {
            PerfSerie ps  = new PerfSerie();
            PerfPoint pp1 = new PerfPoint(1, 5, true);
            PerfPoint pp2 = new PerfPoint(-5, 1, true);
            PerfPoint pp3 = new PerfPoint(-1, 15, false);
            PerfPoint pp4 = new PerfPoint(8, 6, false);
            PerfPoint pp5 = new PerfPoint(3, 10, false);

            ps.add(pp1);
            ps.add(pp2);
            ps.add(pp3);
            ps.add(pp4);
            ps.add(pp5);
            pp3.selected = true;
            pp4.selected = true;

            Assert.AreEqual(2, ps.selectedCount());
        }
        public void interpolate_2()
        {
            ps = new PerfSerie();
            // Polynome               0.5 . x^2 + x -1
            ps.add(new PerfPoint(3, 0.5 * Math.Pow(3, 2) + (3) - 1, false));
            ps.add(new PerfPoint(1, 0.5 * Math.Pow(1, 2) + (1) - 1, false));
            ps.add(new PerfPoint(-5, 0.5 * Math.Pow(-5, 2) + (-5) - 1, false));
            ps.add(new PerfPoint(-1, 0.5 * Math.Pow(-1, 2) + (-1) - 1, false));
            ps.add(new PerfPoint(8, 0.5 * Math.Pow(8, 2) + (8) - 1, false));
            ps.setRange();
            pi = new PolInter(ps);

            // Lève une exception quand aucun point n'est sélectionné

            bool result = false;

            try {
                ps.selectNone();
                pi.interpolate(0.0);
            }
            catch (ModelException e) {
                result = (e.nature == AeroCalc.E_VOID_SYSTEM ? true : false);
            }
            Assert.IsTrue(result);

            // Test de la prédiction de niveau 2 ( polynôme ^2 )

            result = true;
            double calculation = 0.0;
            double expected    = 0.5 * Math.Pow(5, 2) + (5) - 1; // 16.5

            try {
                ps.selectAll();
                calculation = pi.interpolate(5);
            }
            catch (ModelException e) {
                // Dans ce cas, aucune exception ne doit être levée
                result = false;
            }
            Assert.AreEqual(expected, calculation);
            Assert.IsTrue(result);
        }
        public void predict_1()
        {
            PerfSerie ps     = new PerfSerie();
            bool      result = false;

            // Lève une exception quand aucun point n'est inséré dans la série
            try {
                ps.predict(0);
            }
            catch (ModelException e) {
                result = true;
            }
            Assert.IsTrue(result);

            // Insertion de layers (pp1 ; pp2 = (1/8)pp1² + pp1 + 3)
            ps.add(new PerfPoint(-8, 3, false));
            ps.add(new PerfPoint(-4, 1, false));

            // Lève une exception quand on tente une interpolation en dehors du domaine de calcul
            result = false;
            try {
                ps.predict(10);
            }
            catch (ModelException e) {
                result = true;
            }
            Assert.IsTrue(result);

            // Interpolation linéaire quand il n'pp2 a que deux layers
            Assert.AreEqual(2.5, ps.predict(-7));

            ps.add(new PerfPoint(1, (1 / 8) * Math.Pow(1, 2) + (1) + 3, false));
            ps.add(new PerfPoint(3, (1 / 8) * Math.Pow(3, 2) + (3) + 3, false));
            ps.add(new PerfPoint(8, (1 / 8) * Math.Pow(8, 2) + (8) + 3, false));
            ps.setRange();

            // Test de la prédiction de niveau 2 (polynôme ² avec 3 layers)
            Assert.IsTrue(isWithinPrecision((double)ps.predict(5),
                                            (1 / 8) * Math.Pow(5, 2) + (5) + 3,
                                            0.0000001));
        }
Esempio n. 10
0
        public void predict_1()
        {
            bool      result = false;
            PerfSerie ps1    = new PerfSerie(100);
            PerfSerie ps2    = new PerfSerie(200);
            PerfSerie ps3    = new PerfSerie(300);
            PerfLayer pl     = new PerfLayer();

            ps1.add(new PerfPoint(-8, 1, false));
            ps1.add(new PerfPoint(-4, 1, false));
            ps1.add(new PerfPoint(-1, 1, false));
            ps1.add(new PerfPoint(0, 1, false));
            ps1.add(new PerfPoint(6, 1, false));

            ps2.add(new PerfPoint(-10, 2, false));
            ps2.add(new PerfPoint(-3, 2, false));
            ps2.add(new PerfPoint(-1, 2, false));
            ps2.add(new PerfPoint(7, 2, false));
            ps2.add(new PerfPoint(9, 2, false));

            ps3.add(new PerfPoint(-6, 4, false));
            ps3.add(new PerfPoint(-2.5, 4, false));
            ps3.add(new PerfPoint(-0.5, 4, false));
            ps3.add(new PerfPoint(0.5, 4, false));
            ps3.add(new PerfPoint(4, 4, false));

            pl.add(ps1);
            pl.add(ps2);
            pl.add(ps3);

            result = true;
            try {
                Assert.AreEqual(1.375, pl.predict(2, 150));
            }
            catch (ModelException) {
                // No exception should be raised here
                result = false;
            }
            Assert.IsTrue(result);
        }
Esempio n. 11
0
 public void SetUp()
 {
     ps = new PerfSerie();
     pi = new PolInter(ps);
 }