set_assertions 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +17 -3
- data/lib/set_assertions.rb +32 -4
- data/lib/set_assertions/version.rb +1 -1
- data/test/test_set_assertions.rb +50 -22
- metadata +13 -7
data/README.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
|
-
|
1
|
+
## SetAssertions
|
2
2
|
|
3
|
-
|
3
|
+
At the moment, the only test this gem provides is: assert_equal_set
|
4
4
|
|
5
|
-
|
5
|
+
This checks that, despite order, two arrays contain the same scalars and object references.
|
6
|
+
|
7
|
+
Why this assertion?
|
8
|
+
|
9
|
+
Because invariable I want to check that a set of values was added to a collection, but not need to know the order of them.
|
10
|
+
|
11
|
+
If you've ever had a fault like:
|
12
|
+
|
13
|
+
Expected [:a,:b] but got [:b,:a]
|
14
|
+
|
15
|
+
... then you know what I mean.
|
16
|
+
|
17
|
+
## Further Assertions
|
18
|
+
|
19
|
+
Want more? fork, add, make pull request OR add a ticket for it and I'll add it :D
|
data/lib/set_assertions.rb
CHANGED
@@ -2,13 +2,41 @@
|
|
2
2
|
require "set_assertions/version"
|
3
3
|
|
4
4
|
module SetAssertions
|
5
|
-
|
6
|
-
|
5
|
+
|
6
|
+
##
|
7
|
+
# Passes if +expected_set+ and +actual_set+ are equal sets.
|
8
|
+
# An equal set has the following properties.
|
9
|
+
# * Identical cardinality.
|
10
|
+
# * The same elements, without concern for order.
|
11
|
+
#
|
12
|
+
# Example:
|
13
|
+
# assert_equal_set [:a,:b], [:b,:a]
|
14
|
+
|
15
|
+
def assert_equal_set(expected_set, actual_set, message=nil)
|
16
|
+
full_message = build_message(message, "set <?> in any order was expected, got: \n<?>.\n", expected_set, actual_set)
|
17
|
+
assert_block(full_message) {
|
18
|
+
(expected_set.length == actual_set.length) &&
|
19
|
+
((expected_set & actual_set).length == actual_set.length)
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# Passes if +expected_set+ and +actual_set+ are inequal sets.
|
25
|
+
# An inequal set has the following properties.
|
26
|
+
# * Different cardinality.
|
27
|
+
# * The same cardinality, but different elements. (order does not matter)
|
28
|
+
#
|
29
|
+
# Example:
|
30
|
+
# assert_not_equal_set [:a,:b], [:a,:c]
|
31
|
+
|
32
|
+
def assert_not_equal_set(expected_set, actual_set, message=nil)
|
33
|
+
full_message = build_message(message, "any set other than <?> was expected, got the same: \n<?>.\n", expected_set, actual_set)
|
7
34
|
assert_block(full_message) {
|
8
|
-
(
|
9
|
-
((
|
35
|
+
(expected_set.length != actual_set.length) ||
|
36
|
+
((expected_set & actual_set).length != actual_set.length)
|
10
37
|
}
|
11
38
|
end
|
39
|
+
|
12
40
|
end
|
13
41
|
|
14
42
|
class Test::Unit::TestCase
|
data/test/test_set_assertions.rb
CHANGED
@@ -4,34 +4,62 @@ require 'test/unit'
|
|
4
4
|
require 'set_assertions'
|
5
5
|
|
6
6
|
class SetAssertionsTest < Test::Unit::TestCase
|
7
|
-
def test_two_empty_tests_pass
|
8
|
-
assert_equal_set([], [])
|
9
|
-
end
|
10
7
|
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
class EqualSetTest < Test::Unit::TestCase
|
9
|
+
def test_two_empty_tests_pass
|
10
|
+
assert_equal_set([], [])
|
11
|
+
end
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
13
|
+
def test_two_identical_unit_sets_pass
|
14
|
+
assert_equal_set([:a], [:a])
|
15
|
+
end
|
19
16
|
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
def test_an_empty_set_and_a_unit_set_fail
|
18
|
+
assert_fail_assertion { assert_equal_set([:a], []) }
|
19
|
+
assert_fail_assertion { assert_equal_set([], [:a]) }
|
20
|
+
end
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
def test_order_does_not_matter
|
23
|
+
assert_equal_set([:a, :b], [:b, :a])
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_same_cardinality_but_different_set_fails
|
27
|
+
assert_fail_assertion { assert_equal_set([:a, :b], [:c, :b]) }
|
28
|
+
end
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
+
def test_large_cardinality_passes
|
31
|
+
assert_equal_set([:a, :b, "c", 4, "f", :g, :h], [:a, :b, "c", 4, "f", :g, :h])
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_object_equality_passes
|
35
|
+
a = "foo"
|
36
|
+
b = {:foo => "bar"}
|
37
|
+
assert_equal_set([a, b], [b, a])
|
38
|
+
end
|
30
39
|
end
|
31
40
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
41
|
+
class NotEqualSetTest < Test::Unit::TestCase
|
42
|
+
def test_two_empty_tests_fail
|
43
|
+
assert_fail_assertion { assert_not_equal_set([], []) }
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_two_identical_unit_sets_fail
|
47
|
+
assert_fail_assertion { assert_not_equal_set([:a], [:a]) }
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_an_empty_set_and_a_unit_set_pass
|
51
|
+
assert_not_equal_set([:a], [])
|
52
|
+
assert_not_equal_set([], [:a])
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_same_cardinality_but_different_set_passes
|
56
|
+
assert_not_equal_set([:a, :b], [:c, :b])
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_object_equality_fails
|
60
|
+
a = "foo"
|
61
|
+
b = {:foo => "bar"}
|
62
|
+
assert_fail_assertion { assert_not_equal_set([a, b], [b, a]) }
|
63
|
+
end
|
36
64
|
end
|
37
65
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: set_assertions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-06-28 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: test-unit
|
16
|
-
requirement: &
|
16
|
+
requirement: &2153431920 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2153431920
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &2153431500 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2153431500
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: test-unit
|
38
|
-
requirement: &
|
38
|
+
requirement: &2153431080 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2153431080
|
47
47
|
description: Custom test-unit assertions for checking set equality and other set functions
|
48
48
|
email:
|
49
49
|
- squeedee@gmail.com
|
@@ -71,12 +71,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
71
|
- - ! '>='
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
version: '0'
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
hash: -3124136234441084457
|
74
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
78
|
none: false
|
76
79
|
requirements:
|
77
80
|
- - ! '>='
|
78
81
|
- !ruby/object:Gem::Version
|
79
82
|
version: '0'
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
hash: -3124136234441084457
|
80
86
|
requirements: []
|
81
87
|
rubyforge_project:
|
82
88
|
rubygems_version: 1.8.15
|