mug 0.2.8 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
data/lib/mug.rb CHANGED
@@ -12,6 +12,7 @@ require_relative 'mug/iterator/for'
12
12
  require_relative 'mug/iterator/method'
13
13
  require_relative 'mug/loop-with'
14
14
  require_relative 'mug/maybe'
15
+ require_relative 'mug/negativity'
15
16
  require_relative 'mug/rexproc'
16
17
  require_relative 'mug/self'
17
18
  require_relative 'mug/tau'
@@ -0,0 +1,44 @@
1
+
2
+ class Numeric
3
+
4
+ def negative?
5
+ self < 0 ? self : nil
6
+ end
7
+
8
+ def positive?
9
+ self > 0 ? self : nil
10
+ end
11
+
12
+ def nonnegative?
13
+ self < 0 ? nil : self
14
+ end
15
+
16
+ def nonpositive?
17
+ self > 0 ? nil : self
18
+ end
19
+
20
+ end
21
+
22
+ class Complex
23
+ undef :negative?
24
+ undef :positive?
25
+ undef :nonnegative?
26
+ undef :nonpositive?
27
+ end
28
+
29
+ =begin
30
+ Copyright (c) 2015, Matthew Kerwin <matthew@kerwin.net.au>
31
+
32
+ Permission to use, copy, modify, and/or distribute this software for any
33
+ purpose with or without fee is hereby granted, provided that the above
34
+ copyright notice and this permission notice appear in all copies.
35
+
36
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
37
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
38
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
39
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
40
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
41
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
42
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
43
+ =end
44
+
@@ -0,0 +1,56 @@
1
+ require 'test/unit'
2
+ $VERBOSE = true
3
+
4
+ require 'bigdecimal'
5
+
6
+ $neg = [ -1, -(2**65), -3.14, Rational(-1,2), BigDecimal.new('-1') ]
7
+ $pos = [ +1, +(2**65), +3.14, Rational(+1,2), BigDecimal.new('+1') ]
8
+ $zer = [ 0, 0.0, BigDecimal.new('0') ]
9
+ $err = [ Complex(1,1) ]
10
+
11
+ require_relative '../lib/mug/negativity'
12
+ class Test_negativity < Test::Unit::TestCase
13
+
14
+ alias :assert_true :assert
15
+ def assert_false val, msg=UNASSIGNED
16
+ assert !val, msg
17
+ end
18
+
19
+ def test_negative
20
+ $neg.each {|n| assert_true n.negative?, "#{n} should be negative" }
21
+ $pos.each {|n| assert_false n.negative?, "#{n} should not be negative" }
22
+ $zer.each {|n| assert_false n.negative?, "#{n} should not be negative" }
23
+ $err.each do |n|
24
+ assert_raise(NoMethodError) { n.negative? }
25
+ end
26
+ end
27
+
28
+ def test_positive
29
+ $neg.each {|n| assert_false n.positive?, "#{n} should not be positive" }
30
+ $pos.each {|n| assert_true n.positive?, "#{n} should be positive" }
31
+ $zer.each {|n| assert_false n.positive?, "#{n} should not be positive" }
32
+ $err.each do |n|
33
+ assert_raise(NoMethodError) { n.positive? }
34
+ end
35
+ end
36
+
37
+ def test_nonnegative
38
+ $neg.each {|n| assert_false n.nonnegative?, "#{n} should not be nonnegative" }
39
+ $pos.each {|n| assert_true n.nonnegative?, "#{n} should be nonnegative" }
40
+ $zer.each {|n| assert_true n.nonnegative?, "#{n} should be nonnegative" }
41
+ $err.each do |n|
42
+ assert_raise(NoMethodError) { n.nonnegative? }
43
+ end
44
+ end
45
+
46
+ def test_nonpositive
47
+ $neg.each {|n| assert_true n.nonpositive?, "#{n} should be nonpositive" }
48
+ $pos.each {|n| assert_false n.nonpositive?, "#{n} should not be nonpositive" }
49
+ $zer.each {|n| assert_true n.nonpositive?, "#{n} should be nonpositive" }
50
+ $err.each do |n|
51
+ assert_raise(NoMethodError) { n.nonpositive? }
52
+ end
53
+ end
54
+
55
+ end
56
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mug
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-23 00:00:00.000000000 Z
12
+ date: 2015-05-14 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! '== MUG: Matty''s Ultimate Gem
15
15
 
@@ -26,48 +26,50 @@ executables: []
26
26
  extensions: []
27
27
  extra_rdoc_files: []
28
28
  files:
29
- - lib/mug/tau.rb
30
- - lib/mug/hash/operations.rb
31
- - lib/mug/hash/map.rb
32
- - lib/mug/top.rb
33
- - lib/mug/and-or.rb
34
- - lib/mug/bool.rb
35
29
  - lib/mug/iterator/for.rb
36
30
  - lib/mug/iterator/method.rb
37
- - lib/mug/rexproc.rb
38
- - lib/mug/hash.rb
39
- - lib/mug/maybe.rb
40
- - lib/mug/clamp.rb
41
31
  - lib/mug/self.rb
32
+ - lib/mug/bool.rb
33
+ - lib/mug/hashop.rb
42
34
  - lib/mug/array.rb
43
- - lib/mug/apply.rb
44
35
  - lib/mug/to_h.rb
45
- - lib/mug/array/extend.rb
46
- - lib/mug/loop-with.rb
36
+ - lib/mug/iterator_c.rb
37
+ - lib/mug/negativity.rb
47
38
  - lib/mug/fragile-method-chain.rb
39
+ - lib/mug/top.rb
40
+ - lib/mug/iterator.rb
48
41
  - lib/mug/hashmap.rb
42
+ - lib/mug/hash/map.rb
43
+ - lib/mug/hash/operations.rb
44
+ - lib/mug/array/extend.rb
45
+ - lib/mug/hash.rb
46
+ - lib/mug/loop-with.rb
49
47
  - lib/mug/counts.rb
50
- - lib/mug/iterator_c.rb
51
- - lib/mug/hashop.rb
52
- - lib/mug/iterator.rb
48
+ - lib/mug/clamp.rb
49
+ - lib/mug/apply.rb
50
+ - lib/mug/rexproc.rb
51
+ - lib/mug/and-or.rb
52
+ - lib/mug/tau.rb
53
+ - lib/mug/maybe.rb
53
54
  - lib/mug.rb
54
- - test/test-and-or.rb
55
- - test/test-hashop.rb
56
55
  - test/test-clamp.rb
56
+ - test/test-rexproc.rb
57
+ - test/test-tau.rb
58
+ - test/test-array-extend.rb
57
59
  - test/test-iterator-for.rb
60
+ - test/test-top.rb
61
+ - test/test-and-or.rb
62
+ - test/test-self.rb
63
+ - test/test-counts.rb
64
+ - test/test-negativity.rb
65
+ - test/test-bool.rb
58
66
  - test/test-hashmap.rb
59
- - test/test-tau.rb
60
67
  - test/test_apply.rb
61
- - test/test-bool.rb
62
- - test/test-top.rb
63
68
  - test/test-loop-with.rb
69
+ - test/test-maybe.rb
64
70
  - test/test-to_h.rb
65
- - test/test-rexproc.rb
66
- - test/test-array-extend.rb
67
- - test/test-self.rb
71
+ - test/test-hashop.rb
68
72
  - test/test-iterator-method.rb
69
- - test/test-maybe.rb
70
- - test/test-counts.rb
71
73
  - test/test-fragile-method-chain.rb
72
74
  homepage: http://phluid61.github.com/mug
73
75
  licenses:
@@ -95,22 +97,22 @@ signing_key:
95
97
  specification_version: 3
96
98
  summary: ! 'MUG: Matty''s Ultimate Gem'
97
99
  test_files:
98
- - test/test-and-or.rb
99
- - test/test-hashop.rb
100
100
  - test/test-clamp.rb
101
+ - test/test-rexproc.rb
102
+ - test/test-tau.rb
103
+ - test/test-array-extend.rb
101
104
  - test/test-iterator-for.rb
105
+ - test/test-top.rb
106
+ - test/test-and-or.rb
107
+ - test/test-self.rb
108
+ - test/test-counts.rb
109
+ - test/test-negativity.rb
110
+ - test/test-bool.rb
102
111
  - test/test-hashmap.rb
103
- - test/test-tau.rb
104
112
  - test/test_apply.rb
105
- - test/test-bool.rb
106
- - test/test-top.rb
107
113
  - test/test-loop-with.rb
114
+ - test/test-maybe.rb
108
115
  - test/test-to_h.rb
109
- - test/test-rexproc.rb
110
- - test/test-array-extend.rb
111
- - test/test-self.rb
116
+ - test/test-hashop.rb
112
117
  - test/test-iterator-method.rb
113
- - test/test-maybe.rb
114
- - test/test-counts.rb
115
118
  - test/test-fragile-method-chain.rb
116
- has_rdoc: true