assay 0.4.0 → 0.4.1

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.
data/.ruby CHANGED
@@ -28,9 +28,10 @@ repositories:
28
28
  scm: git
29
29
  name: upstream
30
30
  resources:
31
- home: http://rubydoc.info/gems/assay
32
- docs: http://rubydoc.info/gems/assay
31
+ home: http://rubyworks.github.com/assay
32
+ docs: http://rubydoc.info/gems/assay/frames
33
33
  code: http://github.com/rubyworks/assay
34
+ bugs: http://github.com/rubyworks/assay/issues
34
35
  mail: http://groups.google.com/groups/rubyworks-mailinglist
35
36
  extra: {}
36
37
  load_path:
@@ -39,11 +40,12 @@ revision: 0
39
40
  created: '2009-08-21'
40
41
  summary: Class-based Assertions Framework
41
42
  title: Assay
42
- version: 0.4.0
43
+ version: 0.4.1
43
44
  name: assay
44
- description: ! 'The Assay project defines Assertions in the same way that Ruby defines
45
- Exceptions.
45
+ description: ! 'Assay defines assertions in the same way that Ruby defines exceptions.
46
46
 
47
- An asserition then simply becomes an extension to an Exception class.'
47
+ Each type of asserition, called an assay, is then a child of the base
48
+
49
+ Assertion class, which itself is a subclass of the Exception class.'
48
50
  organization: Rubyworks
49
- date: '2012-01-25'
51
+ date: '2012-01-27'
@@ -1,6 +1,17 @@
1
1
  = HISTORY
2
2
 
3
- == 0.4.0 | 1012-01-25
3
+ == 0.4.1 | 2012-01-27
4
+
5
+ This release adds CloseAssay for relative approxmation assertions on values,
6
+ where as the WithinAssay handles absolute difference.
7
+
8
+ Changes:
9
+
10
+ * Add CloseAssay for relative approximation.
11
+ * Use past tense for RescueAssay's assertive name, i.e. :rescued.
12
+
13
+
14
+ == 0.4.0 | 2012-01-25
4
15
 
5
16
  Version 0.4 is a very polished partial rewrite of the Assay project.
6
17
  This release sheds all ancillary code to separate projects. The
data/QED.rdoc CHANGED
@@ -440,6 +440,49 @@ This applies to any type of object that defines `#<=`, not just numbers.
440
440
  refute MoreEqualAssay.fail?('b', 'a')
441
441
 
442
442
 
443
+ ## CloseAssay
444
+
445
+ The `CloseAssay` class defines an assertion for matching that two values
446
+ are within a relative difference.
447
+
448
+ assert CloseAssay.pass?(1, 1, 0)
449
+ assert CloseAssay.pass?(1, 1.1, 0.1)
450
+
451
+ refute CloseAssay.pass?(1, 2, 0)
452
+ refute CloseAssay.pass?(1, 1.2, 0.1)
453
+
454
+ And conversely,
455
+
456
+ assert CloseAssay.fail?(1, 2, 0)
457
+ assert CloseAssay.fail?(1, 1.2, 0.1)
458
+
459
+ refute CloseAssay.fail?(1, 1, 0)
460
+ refute CloseAssay.fail?(1, 1.1, 0.1)
461
+
462
+ The object do not have to be numbers necessaity, just so long as they
463
+ are comparable and subtractable.
464
+
465
+ time = Time.now
466
+
467
+ assert CloseAssay.pass?(time, time+1, 2)
468
+
469
+ Making assertions,
470
+
471
+ assert CloseAssay.assert!(10, 11, 1)
472
+
473
+ expect ::CloseAssay do
474
+ CloseAssay.assert!(10, 15, 0.25)
475
+ end
476
+
477
+ And refutations,
478
+
479
+ assert CloseAssay.refute!(10, 11, 0.01)
480
+
481
+ expect ::CloseAssay do
482
+ CloseAssay.refute!(10, 11, 1)
483
+ end
484
+
485
+
443
486
  ## WithinAssay
444
487
 
445
488
  The `WithinAssay` class defines an assertion for matching that two values
@@ -28,9 +28,10 @@ repositories:
28
28
  scm: git
29
29
  name: upstream
30
30
  resources:
31
- home: http://rubydoc.info/gems/assay
32
- docs: http://rubydoc.info/gems/assay
31
+ home: http://rubyworks.github.com/assay
32
+ docs: http://rubydoc.info/gems/assay/frames
33
33
  code: http://github.com/rubyworks/assay
34
+ bugs: http://github.com/rubyworks/assay/issues
34
35
  mail: http://groups.google.com/groups/rubyworks-mailinglist
35
36
  extra: {}
36
37
  load_path:
@@ -39,11 +40,12 @@ revision: 0
39
40
  created: '2009-08-21'
40
41
  summary: Class-based Assertions Framework
41
42
  title: Assay
42
- version: 0.4.0
43
+ version: 0.4.1
43
44
  name: assay
44
- description: ! 'The Assay project defines Assertions in the same way that Ruby defines
45
- Exceptions.
45
+ description: ! 'Assay defines assertions in the same way that Ruby defines exceptions.
46
46
 
47
- An asserition then simply becomes an extension to an Exception class.'
47
+ Each type of asserition, called an assay, is then a child of the base
48
+
49
+ Assertion class, which itself is a subclass of the Exception class.'
48
50
  organization: Rubyworks
49
- date: '2012-01-25'
51
+ date: '2012-01-27'
@@ -0,0 +1,42 @@
1
+ require_relative 'compare_assay'
2
+
3
+ # Relative approximation, sometimes refered to as *within epsilon*.
4
+ #
5
+ class CloseAssay < CompareAssay
6
+
7
+ register :close
8
+
9
+ #
10
+ # Check assertion.
11
+ #
12
+ def self.pass?(subject, criterion, epsilon)
13
+ #if [subject, criterion, epsilon].all?{ |v| Numeric === v }
14
+ a, b, e = subject.to_f, criterion.to_f, epsilon.to_f
15
+ #else
16
+ # a, b, e = subject, criterion, epsilon
17
+ #end
18
+
19
+ #(a - b).abs / [a.abs, b.abs].max <= e
20
+
21
+ d = b * e # [a.abs,b.abs].max * e
22
+
23
+ (b - d) <= a && (b + d) >= a
24
+ end
25
+
26
+ #
27
+ # Failed assertion message.
28
+ #
29
+ def self.assert_message(subject, criterion, delta)
30
+ a = subject.inspect
31
+ b = criterion.inspect
32
+ e = delta.inspect
33
+
34
+ if [a, b, e].any?{ |e| e.to_s.size > SIZE_LIMIT }
35
+ "b(1 - e) <= a <= b(1 + e)\na) #{a}\nb) #{b}\nd) #{d}"
36
+ else
37
+ "#{b}(1 - #{e}) <= #{a} <= #{b}(1 + #{e})"
38
+ end
39
+ end
40
+
41
+ end
42
+
@@ -5,7 +5,7 @@ require_relative 'assertion'
5
5
  #
6
6
  class RescueAssay < Assertion
7
7
 
8
- register :rescue
8
+ register :rescued
9
9
 
10
10
  #
11
11
  # Check assertion.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-25 00:00:00.000000000 Z
12
+ date: 2012-01-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ansi
16
- requirement: &18939580 !ruby/object:Gem::Requirement
16
+ requirement: &14053100 !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: :runtime
23
23
  prerelease: false
24
- version_requirements: *18939580
24
+ version_requirements: *14053100
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: brass
27
- requirement: &18936100 !ruby/object:Gem::Requirement
27
+ requirement: &15234940 !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: :runtime
34
34
  prerelease: false
35
- version_requirements: *18936100
35
+ version_requirements: *15234940
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: detroit
38
- requirement: &19011100 !ruby/object:Gem::Requirement
38
+ requirement: &15232900 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *19011100
46
+ version_requirements: *15232900
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: qed
49
- requirement: &19008540 !ruby/object:Gem::Requirement
49
+ requirement: &15230160 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,11 +54,12 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *19008540
58
- description: ! 'The Assay project defines Assertions in the same way that Ruby defines
59
- Exceptions.
57
+ version_requirements: *15230160
58
+ description: ! 'Assay defines assertions in the same way that Ruby defines exceptions.
60
59
 
61
- An asserition then simply becomes an extension to an Exception class.'
60
+ Each type of asserition, called an assay, is then a child of the base
61
+
62
+ Assertion class, which itself is a subclass of the Exception class.'
62
63
  email:
63
64
  - transfire@gmail.com
64
65
  executables: []
@@ -77,6 +78,7 @@ files:
77
78
  - lib/assay/assertor.rb
78
79
  - lib/assay/boolean_assay.rb
79
80
  - lib/assay/case_assay.rb
81
+ - lib/assay/close_assay.rb
80
82
  - lib/assay/compare_assay.rb
81
83
  - lib/assay/core_ext/kernel.rb
82
84
  - lib/assay/core_ext/na.rb
@@ -142,7 +144,7 @@ files:
142
144
  - README.rdoc
143
145
  - QED.rdoc
144
146
  - COPYING.rdoc
145
- homepage: http://rubydoc.info/gems/assay
147
+ homepage: http://rubyworks.github.com/assay
146
148
  licenses:
147
149
  - BSD-2-Clause
148
150
  post_install_message: