set_specs 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README +16 -2
  2. data/lib/set_specs.rb +23 -1
  3. metadata +2 -2
data/README CHANGED
@@ -2,10 +2,24 @@ set_specs - A few useful RSpec matchers for making assertions about enumerables.
2
2
  ================================================================================
3
3
 
4
4
  Consists of:
5
- * intersects_with - asserts that one enumerable intersects with another
5
+ * intersect_with - asserts that one enumerable intersects with another
6
6
  * be_a_subset_of - asserts that one enumerable is a subset of another
7
7
  * be_a_proper_subset_of - asserts that one enumerable is a proper subset of another (ie, the two are not equivalent)
8
+ * partition - asserts that one enumerable, which is itself composed of enumerables, partitions another.
8
9
 
9
10
  Installation: gem install set_specs
10
11
 
11
- Enjoy!
12
+ Enjoy!
13
+
14
+
15
+
16
+ MIT License
17
+ ===========
18
+
19
+ (c) Tim Cowlishaw 2010
20
+
21
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
22
+
23
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
24
+
25
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/lib/set_specs.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  Spec::Matchers.define :intersect_with do |challenge_range|
2
2
 
3
- #based on http://gist.github.com/247669, but using Enumerable#select rather than '&', for compatibility with all enumerables (Enumerable doesn't implement &lo).
3
+ #based on http://gist.github.com/247669, but using Enumerable#select rather than '&', for compatibility with all enumerables (Enumerable doesn't implement &).
4
4
 
5
5
  match do |current_range|
6
6
  !current_range.select {|element| challenge_range.include?(element)}.empty?
@@ -62,3 +62,25 @@ Spec::Matchers.define :be_a_proper_subset_of do |challenge_range|
62
62
  end
63
63
 
64
64
  end
65
+
66
+
67
+ Spec::Matchers.define :partition do |partitioned_set|
68
+ match do |partitioning_sets|
69
+ entries = partitioning_sets.map {|s| s.entries}
70
+ entries.zip(entries[1..-1]).map {|a1,a2| a1.should_not intersect_with(a2 || []) }.inject(true) {|m, n| m && n }
71
+ all_entries = entries.inject([]) {|m, n| m + n}
72
+ all_entries.map {|e| partitioned_set.entries.include?(e) }.inject(true) {|m, n| m && n } && partitioned_set.entries.map {|e| all_entries.include?(e) }.inject(true) {|m, n| m && n }
73
+ end
74
+
75
+ failure_message_for_should do |partitioned_set|
76
+ "#{partitioning_sets.inspect} does not partition #{partitioned_set.inspect}"
77
+ end
78
+
79
+ failure_message_for_should_not do |partitioning_sets|
80
+ "#{partitioning_sets.inspect} partitions #{partitioned_set.inspect}"
81
+ end
82
+
83
+ description do
84
+ "assert that a set of sets partitions a second set"
85
+ end
86
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: set_specs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Cowlishaw
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-26 00:00:00 +00:00
12
+ date: 2010-02-18 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency