inexact_equality_warning 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae03455fe61747ac2eb8451499e8f16f416e11dd
4
- data.tar.gz: 63bceb16e59cbd174328bbed7e065f7feff02e01
3
+ metadata.gz: ea8cdeed34206e0912c4358b86f589cb8e7ceb6a
4
+ data.tar.gz: bc341733ed61489d9306ae8edbd1578be2e1635c
5
5
  SHA512:
6
- metadata.gz: 4a7921d82180fb2d5487e68ea37233dfa31ca5748b4403e18ae8795dfd0d3d9efdf600ffaa3688c4bf473416c018ff52e800faebf7250584b5863871fe354d24
7
- data.tar.gz: 48e48d662db050e4b3ae8fef947d1aa4382c3d0a5a8979887d552b67df5cc851808e9e25d2e9a31c1ba38b931043a2ea3c65a50716375b5cc68926ece01e2796
6
+ metadata.gz: 486390cded551301cfd5ef1ef5aec45169a1dbc3849da13a28c0a0a11d5d4383077847a3e76439f30de15b0d29fae34273106f4c016949c96232a0ee5c901620
7
+ data.tar.gz: cb39f55449f5b519afa88f6abd43002a8d94a64593055abf7972a913ceae011b7210b2f91100418b1d759f2e4f61ac6f0e6045fb4b6fdf1ea8f080d18ae78bd6
data/README.md CHANGED
@@ -4,3 +4,16 @@ x == 0.0
4
4
  # WARNING: Testing for equality between inexact floats is ill-advised, when comparing -2.7755575615628914e-17 and 0 (/path/to/file.rb:123)
5
5
  # => false
6
6
  ```
7
+
8
+
9
+ ### Installation and usage
10
+
11
+ Gemfile:
12
+
13
+ ```ruby
14
+ gem "inexact_equality_warning"
15
+ ```
16
+
17
+ ```ruby
18
+ require "inexact_equality_warning"
19
+ ```
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "inexact_equality_warning"
3
- gem.version = "0.0.1"
3
+ gem.version = "0.0.2"
4
4
  gem.authors = ["Adam Prescott"]
5
5
  gem.email = ["adam@aprescott.com"]
6
6
  gem.description = "Warn when comparing floats for equality."
@@ -1,7 +1,7 @@
1
1
  # it would be good to use #inexact? here -- https://bugs.ruby-lang.org/issues/5321
2
2
  module EqualityWarning
3
3
  def ==(other)
4
- warn "WARNING: Testing for equality between inexact floats is ill-advised, when comparing #{self} and #{other} (#{caller.first})" if self.is_a?(Float) || other.is_a?(Float)
4
+ warn "WARNING: Testing for equality between inexact floats is ill-advised, when comparing #{self} and #{other} (#{caller.first})" if (self.is_a?(Numeric) && other.is_a?(Numeric)) && self.is_a?(Float) || other.is_a?(Float)
5
5
  super
6
6
  end
7
7
  end
@@ -19,23 +19,41 @@ RSpec.describe EqualityWarning do
19
19
  end
20
20
 
21
21
  [
22
- 1.0, 1.0,
23
- 1.0, 1.0,
24
22
  1.0, 1,
23
+ 1.0, 2**1000,
24
+ 1.0, Rational(1, 2),
25
+ 1.0, Complex(1, 2),
25
26
  1, 1.0,
26
- 1.0, Complex(1, 0),
27
- 1.0, Complex(0, 2),
28
- 1.0, 2**1000, # Bignum
27
+ Rational(1, 2), 1.0,
28
+ 2**1000, 1.0,
29
+ Complex(1, 2), 1.0,
29
30
  ].each_slice(2) do |x, y|
30
31
  specify { expect_warning(x, y) }
31
32
  end
32
33
 
33
34
  [
35
+ 1, 2**1000,
36
+ 1, Rational(1, 2),
37
+ 1, Complex(1, 2),
38
+ 1, "anything",
39
+ 2**1000, 1,
40
+ 2**1000, Rational(1, 2),
41
+ 2**1000, Complex(1, 2),
42
+ 2**1000, "anything",
43
+ Rational(1, 2), 1,
44
+ Rational(1, 2), 2**1000,
45
+ Rational(1, 2), Complex(1, 2),
46
+ Rational(1, 2), "anything",
47
+ Complex(1, 2), 1,
48
+ Complex(1, 2), 2**1000,
49
+ Complex(1, 2), Rational(1, 2),
50
+ Complex(1, 2), "anything",
51
+ "anything", 1,
52
+ "anything", 2**1000,
53
+ "anything", Rational(1, 2),
54
+ "anything", Complex(1, 2),
55
+ 1.0, "anything",
34
56
  "anything", 1.0,
35
- 1, 1,
36
- Complex(1, 0), Complex(0, 2),
37
- "anything", "anything",
38
- 2**1000, 2**1000, # Bignum
39
57
  ].each_slice(2) do |x, y|
40
58
  specify { expect_no_warning(x, y) }
41
59
  end
@@ -50,3 +68,21 @@ RSpec.describe EqualityWarning do
50
68
  expect(numeric_classes.reject { |klass| numeric_classes.any? { |other_class| other_class < klass } }).to eq(prepended_classes)
51
69
  end
52
70
  end
71
+
72
+ =begin
73
+ # test case permutations generation:
74
+
75
+ test_values = {
76
+ Fixnum => "1",
77
+ Float => "1.0",
78
+ Bignum => "2**1000",
79
+ Rational => "Rational(1, 2)",
80
+ Complex => "Complex(1, 2)",
81
+ String => %~"anything"~
82
+ }
83
+ [Float, Fixnum, Bignum, Rational, Complex, String].permutation(2).to_a.map do |x, y|
84
+ [test_values[x], test_values[y]]
85
+ end.each do |x, y|
86
+ puts "#{x}, #{y},"
87
+ end
88
+ =end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inexact_equality_warning
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Prescott