| 1 |
package t::Analizo::GlobalMetric::ChangeCost; |
| 2 |
use strict; |
| 3 |
use warnings; |
| 4 |
use parent qw(Test::Analizo::Class); |
| 5 |
use Test::More; |
| 6 |
use Analizo::Model; |
| 7 |
use vars qw($model $metric); |
| 8 |
|
| 9 |
BEGIN { |
| 10 |
use_ok 'Analizo::GlobalMetric::ChangeCost'; |
| 11 |
} |
| 12 |
|
| 13 |
sub setup : Test(setup) { |
| 14 |
$model = Analizo::Model->new; |
| 15 |
$metric = Analizo::GlobalMetric::ChangeCost->new(model => $model); |
| 16 |
} |
| 17 |
|
| 18 |
sub has_model : Tests { |
| 19 |
is($metric->model, $model); |
| 20 |
} |
| 21 |
|
| 22 |
sub description : Tests { |
| 23 |
is($metric->description, "Change Cost"); |
| 24 |
} |
| 25 |
|
| 26 |
sub calculate_for_an_empty_callgraph : Tests { |
| 27 |
is($metric->calculate, undef, 'no change cost'); |
| 28 |
} |
| 29 |
|
| 30 |
sub calculate : Tests { |
| 31 |
$model->declare_module('a', 'src/a.c'); |
| 32 |
$model->declare_module('b', 'src/b.c'); |
| 33 |
$model->declare_module('c', 'src/c.c'); |
| 34 |
$model->declare_module('d', 'src/d.c'); |
| 35 |
$model->declare_module('e', 'src/e.c'); |
| 36 |
$model->declare_module('f', 'src/f.c'); |
| 37 |
$model->declare_function('a', 'a::name()'); |
| 38 |
$model->declare_function('b', 'b::name()'); |
| 39 |
$model->declare_function('c', 'c::name()'); |
| 40 |
$model->declare_function('d', 'd::name()'); |
| 41 |
$model->declare_function('e', 'e::name()'); |
| 42 |
$model->declare_function('f', 'f::name()'); |
| 43 |
$model->add_call('a::name()', 'b::name()'); |
| 44 |
$model->add_call('a::name()', 'c::name()'); |
| 45 |
$model->add_call('b::name()', 'd::name()'); |
| 46 |
$model->add_call('c::name()', 'e::name()'); |
| 47 |
$model->add_call('e::name()', 'f::name()'); |
| 48 |
is($metric->calculate, 0.42); |
| 49 |
} |
| 50 |
|
| 51 |
__PACKAGE__->runtests; |