~ubuntu-branches/ubuntu/vivid/gmetrics/vivid

« back to all changes in this revision

Viewing changes to src/test/groovy/org/gmetrics/metric/cyclomatic/CyclomaticComplexityMetric_ClassTest.groovy

  • Committer: Package Import Robot
  • Author(s): Miguel Landaeta, Miguel Landaeta, tony mancill
  • Date: 2012-01-18 20:57:50 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120118205750-68fv86p7fs8xz470
Tags: 0.5-1
[Miguel Landaeta]
* New upstream release.
* Remove patch ftbfs_613266.diff since it was merged upstream.
* Update dates in copyright file.

[tony mancill]
* Set DMUA flag.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 * Tests for CyclomaticComplexityMetric - calculate aggregate metrics for a class
23
23
 *
24
24
 * @author Chris Mair
25
 
 * @version $Revision: 125 $ - $Date: 2010-07-17 21:39:11 -0400 (Sat, 17 Jul 2010) $
 
25
 * @version $Revision: 180 $ - $Date: 2011-11-27 21:56:48 -0500 (Sun, 27 Nov 2011) $
26
26
 */
27
27
class CyclomaticComplexityMetric_ClassTest extends AbstractMetricTestCase {
28
28
    static metricClass = CyclomaticComplexityMetric
53
53
        final SOURCE = """
54
54
            println 123     // this is a script; will generate main() and run() methods
55
55
        """
56
 
        assertApplyToClass(SOURCE, 1, 1, [run:1])
 
56
        assertApplyToClass(SOURCE, 1, 1, [(RUN_METHOD):1])
57
57
    }
58
58
 
59
59
    void testApplyToClass_ResultsForClassWithOneMethod() {
60
60
        final SOURCE = """
61
61
            class MyClass {
62
 
                def a() {
 
62
                String a() {
63
63
                    if (ready) { }
64
64
                }
65
65
            }
66
66
        """
67
 
        assertApplyToClass(SOURCE, 2, 2, [a:2])
 
67
        assertApplyToClass(SOURCE, 2, 2, ['String a()':2])
68
68
    }
69
69
 
70
70
    void testApplyToClass_ResultsForClassWithSeveralMethodsAndClosureFields() {
78
78
                    if (ready || started) { }
79
79
                    else { }
80
80
                }
81
 
                def c() {                   // 5
 
81
                String c() {                   // 5
82
82
                    switch(x) {
83
83
                        case 1: break
84
84
                        case 3: break
96
96
 
97
97
            }
98
98
        """
99
 
        assertApplyToClass(SOURCE, 14, scale(14/5), [(CONSTRUCTOR_NAME):3, b:3, c:5, d:1, e:2])
 
99
        assertApplyToClass(SOURCE, 14, scale(14/5), [(DEFAULT_CONSTRUCTOR):3, b:3, 'String c()':5, d:1, e:2])
100
100
    }
101
101
 
102
102
    void testApplyToClass_ResultsForClassWithOneClosureField() {
116
116
                if (x == 23) return 99 else return 0
117
117
            }
118
118
        """
119
 
        assertApplyToClass(SOURCE, 2, 2, [run:2])
 
119
        assertApplyToClass(SOURCE, 2, 2, [(RUN_METHOD):2])
120
120
    }
121
121
 
122
122
    void testApplyToPackage_ResultsForNoChildren() {