1 | require File.dirname(__FILE__) + '/../../../../../spec_helper'
|
---|
2 |
|
---|
3 | include OpenEHR::RM::DataStructures::ItemStructure
|
---|
4 | include OpenEHR::RM::DataStructures::ItemStructure::Representation
|
---|
5 | include OpenEHR::RM::DataTypes::Text
|
---|
6 |
|
---|
7 | def row(args)
|
---|
8 | return args.collect do |n|
|
---|
9 | Element.new(:name => DvText.new(:value => n),
|
---|
10 | :archetype_node_id => 'test')
|
---|
11 | end
|
---|
12 | end
|
---|
13 |
|
---|
14 | def cluster_builder(name,rows)
|
---|
15 | return Cluster.new(:name => DvText.new(:value => name),
|
---|
16 | :archetype_node_id => 'test',
|
---|
17 | :items => rows)
|
---|
18 | end
|
---|
19 |
|
---|
20 | describe ItemTable do
|
---|
21 | before(:each) do
|
---|
22 | row1 = row(%w{one two three})
|
---|
23 | row2 = row(%w{four five six})
|
---|
24 | rows = [row1, row2].collect{|r| cluster_builder('cluster',r)}
|
---|
25 | @item_table = ItemTable.new(:name => DvText.new(:value => 'item table'),
|
---|
26 | :archetype_node_id => 'test',
|
---|
27 | :rows => rows)
|
---|
28 | end
|
---|
29 |
|
---|
30 | it 'should be an instance of ItemTable' do
|
---|
31 | @item_table.should be_an_instance_of ItemTable
|
---|
32 | end
|
---|
33 |
|
---|
34 | it 's row count should be 2' do
|
---|
35 | @item_table.row_count.should be_equal 2
|
---|
36 | end
|
---|
37 |
|
---|
38 | it 's row_count should be 0 when rows are nil' do
|
---|
39 | @item_table.rows = nil
|
---|
40 | @item_table.row_count.should be_equal 0
|
---|
41 | end
|
---|
42 |
|
---|
43 | it 's column_count should be 3' do
|
---|
44 | @item_table.column_count.should be_equal 3
|
---|
45 | end
|
---|
46 |
|
---|
47 | it 'column_count should be 0 when @rows == nil' do
|
---|
48 | @item_table.rows = nil
|
---|
49 | @item_table.column_count.should be_equal 0
|
---|
50 | end
|
---|
51 |
|
---|
52 | it 's row_names should be cluster cluster' do
|
---|
53 | @item_table.row_names.should == %w{cluster cluster}.collect{|n|
|
---|
54 | DvText.new(:value => n)}
|
---|
55 | end
|
---|
56 |
|
---|
57 | it 's row_names should be empty when items are nil' do
|
---|
58 | @item_table.rows = nil
|
---|
59 | @item_table.row_names.should == []
|
---|
60 | end
|
---|
61 |
|
---|
62 | it 's column_names should one two three' do
|
---|
63 | @item_table.column_names.should == %w{one two three}.collect{|s|
|
---|
64 | DvText.new(:value => s)}
|
---|
65 | end
|
---|
66 |
|
---|
67 | it 's column_names should empty when items aer nil' do
|
---|
68 | @item_table.rows = nil
|
---|
69 | @item_table.column_names.should == []
|
---|
70 | end
|
---|
71 |
|
---|
72 | it 's ith_row(integer) should be ith row' do
|
---|
73 | @item_table.ith_row(2).items[1].name.value.should == 'five'
|
---|
74 | end
|
---|
75 |
|
---|
76 | it 'should be invalid index under 0' do
|
---|
77 | lambda {@item_table.ith_row(0) }.should raise_error(ArgumentError)
|
---|
78 | end
|
---|
79 |
|
---|
80 | it 'should be true because it has_row_with_name cluster' do
|
---|
81 | @item_table.has_row_with_name?('one').should be_true
|
---|
82 | end
|
---|
83 |
|
---|
84 | it 'should be true because it does not have_row_with_name key' do
|
---|
85 | @item_table.has_row_with_name?('two').should_not be_true
|
---|
86 | end
|
---|
87 |
|
---|
88 | it 'should raise argument error key is nil' do
|
---|
89 | lambda {@item_table.has_row_with_name?(nil)
|
---|
90 | }.should raise_error(ArgumentError)
|
---|
91 | end
|
---|
92 |
|
---|
93 | it 'should raise argument error key is empty' do
|
---|
94 | lambda {@item_table.has_row_with_name?('')
|
---|
95 | }.should raise_error(ArgumentError)
|
---|
96 | end
|
---|
97 |
|
---|
98 | it 'should be true because it has_column_with_name one' do
|
---|
99 | @item_table.has_column_with_name?('one').should be_true
|
---|
100 | end
|
---|
101 |
|
---|
102 | it 'should be false it has_column with name ten' do
|
---|
103 | @item_table.has_column_with_name?('ten').should be_false
|
---|
104 | end
|
---|
105 |
|
---|
106 | it 'second row should be named_row four' do
|
---|
107 | @item_table.named_row('four').items[1].name.value = 'five'
|
---|
108 | end
|
---|
109 |
|
---|
110 | it 'should be true if row has key' do
|
---|
111 | @item_table.has_row_with_key?(Set['one','two']).should be_true
|
---|
112 | end
|
---|
113 |
|
---|
114 | it 'should not be true if row has not key' do
|
---|
115 | @item_table.has_row_with_key?(Set['two','five']).should be_false
|
---|
116 | end
|
---|
117 |
|
---|
118 | it 'should be a first row that has one' do
|
---|
119 | @item_table.row_with_key(Set['one', 'two']).items[0].name.value.should =='one'
|
---|
120 | end
|
---|
121 |
|
---|
122 | it 'should raise argument error if row has no key' do
|
---|
123 | lambda {
|
---|
124 | @item_table.row_with_key(Set['two','five'])}.should raise_error(ArgumentError)
|
---|
125 | end
|
---|
126 |
|
---|
127 | it 'should be element at cell ij' do
|
---|
128 | @item_table.element_at_cell_ij(2,2).name.value.should == 'five'
|
---|
129 | end
|
---|
130 |
|
---|
131 | it 'should not be element at cell with wrong ij' do
|
---|
132 | @item_table.element_at_cell_ij(2,3).name.value.should_not == 'five'
|
---|
133 | end
|
---|
134 |
|
---|
135 | it 'should be two element at named cell by row column' do
|
---|
136 | @item_table.element_at_named_cell('cluster', 'three').name.value == 'three'
|
---|
137 | end
|
---|
138 |
|
---|
139 | it 'should return nil when rows are nil' do
|
---|
140 | @item_table.rows = nil
|
---|
141 | @item_table.row_count.should be_equal 0
|
---|
142 | end
|
---|
143 |
|
---|
144 | it 'should be first row as hierachy' do
|
---|
145 | @item_table.as_hierarchy.name.value.should == 'cluster'
|
---|
146 | end
|
---|
147 | end
|
---|