Package org.rioproject.watch

Examples of org.rioproject.watch.Statistics


    /**
     * Tests the <code>Statistics()</code> constructor.
     */
    @Test
    public void testConstructor1() {
        Statistics stat = new Statistics();
        assertClean(stat);
    }
View Full Code Here


        for (int size = 0; size < N; size++) {
            List<Double> list = new ArrayList<Double>();
            for (int j = 0; j < size; j++) {
                list.add((double) j);
            }
            Statistics stat = new Statistics(list);
            Assert.assertEquals(list, stat.getValues());
            Assert.assertNotSame(list, stat.getValues());
        }

        List<Double> list = new ArrayList<Double>();
        Statistics stat = new Statistics(list);
        Assert.assertEquals(0, stat.count());
        list.add((double) 0);
        Assert.assertEquals(0, stat.count());

        try {
            new Statistics(null);
            Assert.fail("IllegalArgumentException expected but not thrown");
        } catch (IllegalArgumentException e) {
        }
    }
View Full Code Here

     *
     */
    @Test
    public void testClearAll() {

        Statistics stat = new Statistics();

        for (int i = 0; i < 5; i++) {
            stat.clearAll();
            assertClean(stat);
        }

        List<Double> list = new ArrayList<Double>();
        list.add((double) 0);
        list.add((double) 1);
        list.add((double) 2);
        stat.setValues(list);
        assertCorrect(list, stat);

        for (int i = 0; i < 5; i++) {
            stat.clearAll();
            assertClean(stat);
        }
    }
View Full Code Here

     * Tests statistical calculations
     */
    @Test
    public void testStats() {

        Statistics stat = new Statistics();

        for (int i = 0; i < 10; i++) {
            Vector<Double> v = new Vector<Double>();
            int count = (int) (Math.random() * 1000);
            for (int j = 0; j < count; j++) {
                double d = Math.random();
                stat.addValue(d);
                v.add(d);
            }
            assertCorrect(v, stat);
            stat.clearAll();
            assertCorrect(new Vector<Double>(), stat);
        }
    }
View Full Code Here

     * Tests the <code>getValues()</code> method.
     */
    @Test
    public void testGetValues() {

        Statistics stat = new Statistics();
        Assert.assertEquals(new Vector(), stat.getValues());

        for (int i = 0; i < 10; i++) {
            Vector<Double> v = new Vector<Double>();
            int count = (int) (Math.random() * 1000);
            for (int j = 0; j < count; j++) {
                double d = Math.random();
                stat.addValue(d);
                v.add(d);
            }
            Assert.assertEquals(v, stat.getValues());
            stat.clearAll();
            Assert.assertEquals(new Vector(), stat.getValues());
        }

        Vector<Double> v = new Vector<Double>();
        stat.setValues(v);
        Assert.assertEquals(v, stat.getValues());
        Assert.assertNotSame(v, stat.getValues());
    }
View Full Code Here

    /**
     * Tests the <code>addValue(Double)</code> method.
     */
    @Test
    public void testAddValue1() {
        Statistics stat = new Statistics();
        for (int i = 0; i < 10; i++) {
            Vector<Double> v = new Vector<Double>();
            int count = (int) (Math.random() * 100);
            for (int j = 0; j < count; j++) {
                Double d = Math.random();
                stat.addValue(d);
                v.add(d);
                assertCorrect(v, stat);
            }
            stat.clearAll();
        }

        try {
            stat.addValue(null);
            Assert.fail("IllegalArgumentException expected but not thrown");
        } catch (IllegalArgumentException e) {
        }
    }
View Full Code Here

     * Tests the <code>addValue(double)</code> method.
     */
    @Test
    public void testAddValue2() {

        Statistics stat = new Statistics();

        for (int i = 0; i < 10; i++) {
            Vector<Double> v = new Vector<Double>();
            int count = (int) (Math.random() * 100);
            for (int j = 0; j < count; j++) {
                double d = Math.random();
                stat.addValue(d);
                v.add(d);
                assertCorrect(v, stat);
            }
            stat.clearAll();
        }
    }
View Full Code Here

     * Tests the <code>setValues</code> method.
     */
    @Test
    public void testSetValues() {

        Statistics stat = new Statistics();

        for (int i = 0; i < 10; i++) {
            Vector<Double> v = new Vector<Double>();
            int count = (int) (Math.random() * 100);
            for (int j = 0; j < count; j++) {
                v.add(Math.random());
                stat.setValues(v);
                Assert.assertEquals(v, stat.getValues());
                Assert.assertNotSame(v, stat.getValues());
            }
        }

        List<Double> v = new ArrayList<Double>();
        stat.setValues(v);
        Assert.assertEquals(0, stat.count());
        v.add((double) 0);
        Assert.assertEquals(0, stat.count());

        try {
            stat.setValues((List<Double>)null);
            Assert.fail("IllegalArgumentException expected but not thrown");
        } catch (IllegalArgumentException e) {
        }
    }
View Full Code Here

            1, 2, 3, 4, 5, 6, 7, 8, 9,
            1, 2, 3, 4, 5, 6, 7, 8, 9, 10
        });

        {
            Statistics stat = new Statistics(vTest);
            for (int i = 0; i <= 10; i++) {
                stat.removeValues(i, false);
                vTest.remove(new Double(i));
                Assert.assertEquals(vTest, stat.getValues());
            }
        }

        {
            Statistics stat = new Statistics(vTest);
            for (int i = 0; i <= 10; i++) {
                stat.removeValues(i, true);
                vTest.removeAll(asList(new double[]{i}));
                Assert.assertEquals(vTest, stat.getValues());
            }
            assertClean(stat);
        }
    }
View Full Code Here

            1, 2, 3, 4, 5, 6, 7, 8, 9,
            1, 2, 3, 4, 5, 6, 7, 8, 9, 10
        });

        {
            Statistics stat = new Statistics(vTest);
            for (int i = 0; i <= 10; i++) {
                stat.removeValues(new Double(i), false);
                vTest.remove(new Double(i));
                Assert.assertEquals(vTest, stat.getValues());
            }
        }

        {
            Statistics stat = new Statistics(vTest);
            for (int i = 0; i <= 10; i++) {
                stat.removeValues(new Double(i), true);
                vTest.removeAll(asList(new double[]{i}));
                Assert.assertEquals(vTest, stat.getValues());
            }
            assertClean(stat);
        }

        try {
            new Statistics().removeValues(null, false);
            Assert.fail("IllegalArgumentException expected but not thrown");
        } catch (IllegalArgumentException e) {
        }

        try {
            new Statistics().removeValues(null, true);
            Assert.fail("IllegalArgumentException expected but not thrown");
        } catch (IllegalArgumentException e) {
        }
    }
View Full Code Here

TOP

Related Classes of org.rioproject.watch.Statistics

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.