keso 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'keso'
5
+ require 'spec'
6
+ require 'spec/autorun'
7
+
8
+ Spec::Runner.configure do |config|
9
+
10
+ end
@@ -0,0 +1,155 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Tuple do
4
+
5
+ #
6
+ # {:a => 4,:b => 4 ,:c => 4} + {:y => 4} == {:a => 4,:b => 4,:c => 4,:y => 4}
7
+ # {:a => 4,:b => 4 ,:c => 4}.add y == {a,b,c,y}
8
+ # {:a => 4,:b => 4 ,:c => 4}.add [y,t] == {a,b,c,y,t}
9
+ # {:a => 4,:b => 4 ,:c => 4} - c == {a,b}
10
+ # {:a => 4,:b => 4 ,:c => 4}.remove c == {a,b}
11
+ # {:a => 4,:b => 4 ,:c => 4}.remove [a,c] == {b}
12
+ # {x,y}.eql? {x,y}
13
+ # {x,y} == {x,y}
14
+ # {x,y}.heading == {x,y}.heading
15
+ # {x,y}.count == 2
16
+ #
17
+
18
+ describe :heading do
19
+ it 'retuns the heading of the tuple' do
20
+ Tuple.new({'a' => :b,'c' => :y}).heading.should be_an_instance_of Heading
21
+ Tuple.new({'a' => :b,'c' => :y}).heading.should eql(Heading.new.add(:name => 'a', :type => Symbol).add(:name => 'c', :type => Symbol))
22
+ end
23
+ end
24
+
25
+ describe :[] do
26
+ it 'returns the value of the named attribute' do
27
+ Tuple.new({:c => 3})[:c].should eql 3
28
+ Tuple.new({:name => 'Bjorn'})[:name].should eql 'Bjorn'
29
+ end
30
+
31
+ it 'returns the value of the named attribute' do
32
+ Tuple.new({:c => 3})[:c].should eql 3
33
+ Tuple.new({:name => 'Bjorn'})[Attribute.new(:name => 'name', :type => String)].should eql 'Bjorn'
34
+ Tuple.new({:name => 'Bjorn'})[Attribute.new(:name => 'name', :type => Fixnum)].should_not eql 'Bjorn'
35
+ end
36
+ end
37
+
38
+ describe :count do
39
+ it 'returns the amount of values that are part of the tuple' do
40
+ Tuple.new({:a => :b,:c => :y}).count.should eql(2)
41
+ Tuple.new({:a => :b,:c => :y,:g => 'ee',:htn => 21}).count.should eql(4)
42
+ end
43
+ end
44
+
45
+ describe :new do
46
+ it 'returns a new tuple value of suplied values' do
47
+ Tuple.new({:a => "b",:c => "ue"}).should be_an_instance_of Tuple
48
+ Tuple.new({:c => 3}).should be_an_instance_of Tuple
49
+ end
50
+
51
+ it 'should accept a attribute as a key' do
52
+ Tuple.new({Attribute.new(:name => 'name', :type => String) => "Bjorn"}).should eql(Tuple.new({:name => "Bjorn"}))
53
+ end
54
+
55
+ it 'should throw an exception when i try to add a value that is not of the type represented by the attribute' do
56
+ lambda {Tuple.new({Attribute.new(:name => 'name', :type => String) => 13})}.should raise_error(ArgumentError)
57
+ end
58
+ end
59
+
60
+ describe :add do
61
+ it 'returns a new value of current value plus the supplied value' do
62
+ Tuple.new({:b => 4,:c => 4, :d => 4}).add({:g => 32}).should eql(Tuple.new(:b => 4,:c => 4, :d => 4,:g => 32))
63
+ Tuple.new({:b => 4,:c => 4, :d => 4}).add(:g => 32,:gd => 32).should eql(Tuple.new(:b => 4,:c => 4, :d => 4,:g => 32,:gd => 32))
64
+ end
65
+
66
+ it 'returns a new tuple with the attributes of both' do
67
+ Tuple.new({:b => 4,:c => 4, :d => 4}).add(Tuple.new({:test => "Hi this is my test"})).should eql(Tuple.new({:b => 4,:c => 4, :d => 4,:test => "Hi this is my test"}))
68
+ end
69
+
70
+ it 'should throw an exception' do
71
+ lambda {Tuple.new({:b => 4,:c => 4, :d => 4}).add(Tuple.new({:d => "Hi this is my test"}))}.should raise_error(ArgumentError)
72
+ end
73
+
74
+ it 'should accept a relation as a value' do
75
+ relation_value = Relation.new(Tuple.new({:name => 'Bjorn',:age => 29})).add(Tuple.new({:name => 'Emma',:age => 30}))
76
+
77
+ Tuple.new({:b => 4,:c => 4, :d => 4}).add({:persons => relation_value}).should eql(Tuple.new(:b => 4,:c => 4, :d => 4,:persons => relation_value))
78
+ end
79
+
80
+ it 'should accept a attribute as a key' do
81
+ Tuple.new.add({Attribute.new(:name => 'name', :type => String) => "Bjorn"}).should eql(Tuple.new({:name => "Bjorn"}))
82
+ end
83
+
84
+ it 'should throw an exception when i try to add a value that is not of the type represented by the attribute' do
85
+ lambda {Tuple.new.add({Attribute.new(:name => 'name', :type => String) => 13})}.should raise_error(ArgumentError)
86
+ end
87
+
88
+ it 'should not accept a null value' do
89
+ lambda {Tuple.new.add({Attribute.new(:name => 'name', :type => String) => nil})}.should raise_error(ArgumentError)
90
+ lambda {Tuple.new.add({Attribute.new(:name => 'name', :type => nil) => nil})}.should raise_error(ArgumentError)
91
+ end
92
+ end
93
+
94
+ describe :remove do
95
+ it 'returns a new value of current values minus the supplied values' do
96
+ Tuple.new({:a => :b,:c => :y,:g => 'ee',:htn => 21}).remove(:htn => 21).count.should eql 3
97
+ Tuple.new({:a => :b,:c => :y,:g => 'ee',:htn => 21}).remove(:htn => 21).should eql(Tuple.new(:a => :b,:c => :y,:g => 'ee'))
98
+ Tuple.new(:a => :b,:c => :y,:g => 'ee').remove(:g => 'ee',:a => :b).should eql(Tuple.new({:c => :y}))
99
+ Tuple.new({:g => 'ee',:htn => 21}).remove({:g => 'ee',:htn => 21}).should eql(Tuple.new())
100
+ Tuple.new(:g => 'ee',:htn => 21).remove(:g => 'ee',:htn => 21).should_not eql(Tuple.new(:g => 'ee',:htn => 21))
101
+ Tuple.new({:g => 'ee',:htn => 21}).remove(:g).should eql(Tuple.new(:htn => 21))
102
+ Tuple.new({:g => 'ee',:htn => 21}).remove(:g,:htn).should eql(Tuple.new())
103
+ Tuple.new({:g => 'ee',:htn => 21}).remove([:g,:htn]).should eql(Tuple.new())
104
+ end
105
+ end
106
+
107
+ describe :hash do
108
+ it 'returns the same hash for the same value' do
109
+
110
+ Tuple.new(:g => 'ee',:htn => 21).hash.should eql(Tuple.new(:g => 'ee',:htn => 21).hash)
111
+ Tuple.new(:g => 'ee',:htn => 21).hash.should_not eql(Tuple.new(:g => 'ee',:htn => 22).hash)
112
+
113
+ end
114
+ end
115
+
116
+ describe :each do
117
+ it 'iterates over all the attributes in the tuple' do
118
+
119
+ new_tuple = Tuple.new
120
+
121
+ Tuple.new(:g => 'ee',:htn => 21).each do |attribute,value|
122
+ new_tuple = new_tuple.add attribute,value
123
+ end
124
+
125
+ new_tuple.should eql(Tuple.new(:g => 'ee',:htn => 21))
126
+ end
127
+ end
128
+
129
+ describe :rename do
130
+ it 'changes the name of a attribute' do
131
+ Tuple.new(:g => 'ee',:htn => 21).rename(:g,:d).should eql(Tuple.new(:d => 'ee',:htn => 21))
132
+ end
133
+
134
+ it 'should throw an exception' do
135
+ lambda { Tuple.new(:g => 'ee',:htn => 21).rename(:missing,:d) }.should raise_error(ArgumentError)
136
+ lambda { Tuple.new(:g => 'ee',:htn => 21).rename(:g,:htn) }.should raise_error(ArgumentError)
137
+ end
138
+ end
139
+
140
+ describe :eql? do
141
+ it 'returns true if the supplied value is equal to this one' do
142
+ Tuple.new().eql?(Tuple.new()).should be_true
143
+
144
+ Tuple.new(:g => 'ee',:htn => 21).eql?(Tuple.new(:g => 'ee').add(:htn => 21)).should be_true
145
+
146
+ Tuple.new({:g => 'ee',:htn => 21}).eql?(Tuple.new({:g => 'ee',:htn => 21})).should be_true
147
+
148
+ Tuple.new(:g => 'ee',:htn => 21).eql?(Tuple.new(:g => 'ee',:htn => 22)).should be_false
149
+ end
150
+ end
151
+
152
+
153
+ end
154
+
155
+
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: keso
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 3
9
+ version: 0.1.3
10
+ platform: ruby
11
+ authors:
12
+ - Darwin
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-29 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 2
31
+ - 9
32
+ version: 1.2.9
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: Cottage cheees with lots of relational theory. Or mabye not so much theory =(
36
+ email: darwin@markkonsulter.se
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - keso.gemspec
52
+ - lib/keso.rb
53
+ - lib/realvar.rb
54
+ - lib/values/attribute.rb
55
+ - lib/values/heading.rb
56
+ - lib/values/immutable_hash.rb
57
+ - lib/values/immutable_set.rb
58
+ - lib/values/relation.rb
59
+ - lib/values/tuple.rb
60
+ - spec/attribute_spec.rb
61
+ - spec/heading_spec.rb
62
+ - spec/immutable_hash_spec.rb
63
+ - spec/immutable_set_spec.rb
64
+ - spec/relation_spec.rb
65
+ - spec/spec.opts
66
+ - spec/spec_helper.rb
67
+ - spec/tuple_spec.rb
68
+ has_rdoc: true
69
+ homepage: http://github.com/bjornblomqvist/keso
70
+ licenses: []
71
+
72
+ post_install_message:
73
+ rdoc_options:
74
+ - --charset=UTF-8
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ requirements: []
94
+
95
+ rubyforge_project:
96
+ rubygems_version: 1.3.7
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: Cottage cheees with lots of relational theory
100
+ test_files:
101
+ - spec/attribute_spec.rb
102
+ - spec/heading_spec.rb
103
+ - spec/immutable_hash_spec.rb
104
+ - spec/immutable_set_spec.rb
105
+ - spec/relation_spec.rb
106
+ - spec/spec_helper.rb
107
+ - spec/tuple_spec.rb