metric_configuration_test.rb
1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require "test_helper"
class MetricConfigurationTest < ActiveSupport::TestCase
def self.amloc_configuration
range1 = RangeTest.amloc_excellent
range2 = RangeTest.amloc_bad
amloc = Kalibro::Entities::MetricConfiguration.new
amloc.metric = NativeMetricTest.amloc
amloc.code = 'amloc'
amloc.weight = 1.0
amloc.aggregation_form = 'AVERAGE'
amloc.ranges = [range1, range2]
amloc
end
def self.sc_configuration
sc = Kalibro::Entities::MetricConfiguration.new
sc.metric = CompoundMetricTest.sc
sc.code = 'sc'
sc.weight = 1.0
sc.aggregation_form = 'AVERAGE'
sc
end
def self.amloc_configuration_hash
range1 = RangeTest.amloc_excellent_hash
range2 = RangeTest.amloc_bad_hash
{:metric => NativeMetricTest.amloc_hash,
:code => 'amloc', :weight => 1.0, :aggregation_form => 'AVERAGE',
:range => [range1, range2]}
end
def self.sc_configuration_hash
{:metric => CompoundMetricTest.sc_hash,
:code => 'sc', :weight => 1.0, :aggregation_form => 'AVERAGE'}
end
def setup
@hash = self.class.amloc_configuration_hash
@range = self.class.amloc_configuration
end
should 'create metric configuration from hash' do
assert_equal @range, Kalibro::Entities::MetricConfiguration.from_hash(@hash)
end
should 'convert metric configuration to hash' do
assert_equal @hash, @range.to_hash
end
should 'create appropriate metric type' do
assert self.class.amloc_configuration.metric.instance_of?(Kalibro::Entities::NativeMetric)
assert self.class.sc_configuration.metric.instance_of?(Kalibro::Entities::CompoundMetric)
end
end