Clover coverage report - Dependency Finder
Coverage timestamp: Mon Nov 29 2010 15:00:50 PST
file stats: LOC: 154   Methods: 3
NCLOC: 89   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TestMetricsComparator.java - 100% 100% 100%
coverage
 1    /*
 2    * Copyright (c) 2001-2009, Jean Tessier
 3    * All rights reserved.
 4    *
 5    * Redistribution and use in source and binary forms, with or without
 6    * modification, are permitted provided that the following conditions
 7    * are met:
 8    *
 9    * * Redistributions of source code must retain the above copyright
 10    * notice, this list of conditions and the following disclaimer.
 11    *
 12    * * Redistributions in binary form must reproduce the above copyright
 13    * notice, this list of conditions and the following disclaimer in the
 14    * documentation and/or other materials provided with the distribution.
 15    *
 16    * * Neither the name of Jean Tessier nor the names of his contributors
 17    * may be used to endorse or promote products derived from this software
 18    * without specific prior written permission.
 19    *
 20    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 21    * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 22    * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 23    * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
 24    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 25    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 26    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 27    * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 28    * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 29    * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 30    * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 31    */
 32   
 33    package com.jeantessier.metrics;
 34   
 35    import junit.framework.*;
 36   
 37    public class TestMetricsComparator extends TestCase {
 38  1 public void testSortOn() {
 39  1 MetricsComparator c = new MetricsComparator("foo", StatisticalMeasurement.DISPOSE_IGNORE);
 40   
 41  1 assertEquals("c.Name()", "foo", c.getName());
 42  1 assertEquals("c.Direction()", MetricsComparator.ASCENDING, c.getDirection());
 43   
 44  1 c.sortOn("foo", StatisticalMeasurement.DISPOSE_IGNORE);
 45   
 46  1 assertEquals("c.Name()", "foo", c.getName());
 47  1 assertEquals("c.Direction()", MetricsComparator.DESCENDING, c.getDirection());
 48   
 49  1 c.sortOn("foo", StatisticalMeasurement.DISPOSE_IGNORE);
 50   
 51  1 assertEquals("c.Name()", "foo", c.getName());
 52  1 assertEquals("c.Direction()", MetricsComparator.ASCENDING, c.getDirection());
 53   
 54  1 c.sortOn("bar", StatisticalMeasurement.DISPOSE_IGNORE);
 55   
 56  1 assertEquals("c.Name()", "bar", c.getName());
 57  1 assertEquals("c.Direction()", MetricsComparator.ASCENDING, c.getDirection());
 58   
 59  1 c.sortOn("bar", StatisticalMeasurement.DISPOSE_IGNORE);
 60   
 61  1 assertEquals("c.Name()", "bar", c.getName());
 62  1 assertEquals("c.Direction()", MetricsComparator.DESCENDING, c.getDirection());
 63   
 64  1 c.sortOn("baz", StatisticalMeasurement.DISPOSE_IGNORE);
 65   
 66  1 assertEquals("c.Name()", "baz", c.getName());
 67  1 assertEquals("c.Direction()", MetricsComparator.ASCENDING, c.getDirection());
 68   
 69  1 c.sortOn("foobar", StatisticalMeasurement.DISPOSE_IGNORE);
 70   
 71  1 assertEquals("c.Name()", "foobar", c.getName());
 72  1 assertEquals("c.Direction()", MetricsComparator.ASCENDING, c.getDirection());
 73   
 74  1 c.sortOn("foobar", StatisticalMeasurement.DISPOSE_IGNORE);
 75   
 76  1 assertEquals("c.Name()", "foobar", c.getName());
 77  1 assertEquals("c.Direction()", MetricsComparator.DESCENDING, c.getDirection());
 78   
 79  1 c.sortOn("foobar", StatisticalMeasurement.DISPOSE_MINIMUM);
 80   
 81  1 assertEquals("c.Name()", "foobar", c.getName());
 82  1 assertEquals("c.Direction()", MetricsComparator.ASCENDING, c.getDirection());
 83    }
 84   
 85  1 public void testCompareTo() {
 86  1 Metrics m1 = new Metrics("m1");
 87  1 Metrics m2 = new Metrics("m2");
 88   
 89  1 m1.track("foo", new CounterMeasurement(null, null, null));
 90  1 m1.track("bar", new CounterMeasurement(null, null, null));
 91  1 m1.track("baz", new CounterMeasurement(null, null, null));
 92  1 m2.track("foo", new CounterMeasurement(null, null, null));
 93  1 m2.track("bar", new CounterMeasurement(null, null, null));
 94  1 m2.track("baz", new CounterMeasurement(null, null, null));
 95   
 96  1 m1.addToMeasurement("foo", 1);
 97  1 m1.addToMeasurement("bar", 2);
 98  1 m1.addToMeasurement("baz", 3);
 99  1 m2.addToMeasurement("foo", 3);
 100  1 m2.addToMeasurement("bar", 2);
 101  1 m2.addToMeasurement("baz", 1);
 102   
 103  1 MetricsComparator c1 = new MetricsComparator("foo");
 104  1 MetricsComparator c2 = new MetricsComparator("bar");
 105  1 MetricsComparator c3 = new MetricsComparator("baz");
 106   
 107  1 assertTrue(c1.compare(m1, m2) < 0);
 108  1 assertTrue(c2.compare(m1, m2) == 0);
 109  1 assertTrue(c3.compare(m1, m2) > 0);
 110   
 111  1 c1.reverse();
 112  1 c2.reverse();
 113  1 c3.reverse();
 114   
 115  1 assertTrue(c1.compare(m1, m2) > 0);
 116  1 assertTrue(c2.compare(m1, m2) == 0);
 117  1 assertTrue(c3.compare(m1, m2) < 0);
 118    }
 119   
 120  1 public void testCompareNaN() {
 121  1 Metrics m1 = new Metrics("m1");
 122  1 Metrics m2 = new Metrics("m2");
 123   
 124  1 m1.track("foo", new CounterMeasurement(null, null, null));
 125  1 m2.track("foo", new CounterMeasurement(null, null, null));
 126  1 m1.track("bar", new CounterMeasurement(null, null, null));
 127  1 m2.track("bar", new CounterMeasurement(null, null, null));
 128  1 m1.track("baz", new CounterMeasurement(null, null, null));
 129  1 m2.track("baz", new CounterMeasurement(null, null, null));
 130   
 131  1 m1.addToMeasurement("foo", Double.NaN);
 132  1 m2.addToMeasurement("foo", Double.NaN);
 133  1 m1.addToMeasurement("bar", Double.NaN);
 134  1 m2.addToMeasurement("bar", 1);
 135  1 m1.addToMeasurement("baz", 1);
 136  1 m2.addToMeasurement("baz", Double.NaN);
 137   
 138  1 MetricsComparator c1 = new MetricsComparator("foo");
 139  1 MetricsComparator c2 = new MetricsComparator("bar");
 140  1 MetricsComparator c3 = new MetricsComparator("baz");
 141   
 142  1 assertTrue(c1.compare(m1, m2) == 0);
 143  1 assertTrue(c2.compare(m1, m2) > 0);
 144  1 assertTrue(c3.compare(m1, m2) < 0);
 145   
 146  1 c1.reverse();
 147  1 c2.reverse();
 148  1 c3.reverse();
 149   
 150  1 assertTrue(c1.compare(m1, m2) == 0);
 151  1 assertTrue(c2.compare(m1, m2) > 0);
 152  1 assertTrue(c3.compare(m1, m2) < 0);
 153    }
 154    }