konacha-chai-matchers 0.1.4 → 0.1.5

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/VERSIONS CHANGED
@@ -3,12 +3,12 @@ sinon-chai: 2.4.0
3
3
  chai-as-promised: 3.3.1
4
4
  chai-jquery: 1.1.1
5
5
  chai-timers: 0.2.0
6
- chai-stats: 0.2.0
6
+ chai-stats: 0.3.0
7
7
  chai-null: 0.1.0
8
8
  chai-factories: 0.1.0
9
9
  chai-changes: 1.3.2
10
10
  chai-backbone: 0.9.2
11
- js-factories: 0.9.0
11
+ js-factories: 1.0.1
12
12
  mocha-as-promised: 1.4.0
13
13
  chai-things: 0.2.0
14
14
  chai-fuzzy: 1.3.0
@@ -1,7 +1,7 @@
1
1
  module Konacha
2
2
  module Chai
3
3
  module Matchers
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
6
6
  end
7
7
  end
@@ -105,6 +105,58 @@ exports.sdeviation = function (nums) {
105
105
  return Math.sqrt(davg);
106
106
  };
107
107
 
108
+ function tolerance(precision){
109
+ if(precision == null) precision = 7;
110
+ return 0.5 * Math.pow(10, -precision);
111
+ }
112
+
113
+ /**
114
+ *
115
+ * # almostEqual
116
+ *
117
+ * Returns true if the two arguments are equal within the given precision.
118
+ *
119
+ * @param {Number} a
120
+ * @param {Number} b
121
+ * @param {Number} precision. Optional: defaults to 7.
122
+ * @return {Boolean} true if the two arguments are equal with precision decimal places.
123
+ *
124
+ */
125
+
126
+ exports.almostEqual = function (a,b,precision){
127
+ return Math.abs(a - b) < tolerance(precision);
128
+ };
129
+
130
+ /**
131
+ *
132
+ * # deepAlmostEqual
133
+ *
134
+ * Returns true if all the objects are deeply equal, within the given precision.
135
+ *
136
+ * @param {Object} a
137
+ * @param {Object} b
138
+ * @param {Number} precision. Optional: defaults to 7.
139
+ * @return {Boolean} true if the two arguments are deeply equal with precision decimal places.
140
+ */
141
+
142
+ exports.deepAlmostEqual = function(a,b,precision){
143
+ var tol = tolerance(precision);
144
+ function deepEql (act, exp) {
145
+ if (Object(act) === act){
146
+ for (var k in act) {
147
+ if (!(deepEql(act[k], exp[k]))) {
148
+ return false;
149
+ }
150
+ }
151
+ return true;
152
+ } else {
153
+ return Math.abs(act - exp) < tol;
154
+ }
155
+ }
156
+
157
+ return deepEql(a,b);
158
+ };
159
+
108
160
  }); // module calc
109
161
 
110
162
 
@@ -139,10 +191,10 @@ module.exports = function (chai, _) {
139
191
  Assertion.overwriteMethod('equal', function(_super) {
140
192
  return function equal (exp, precision) {
141
193
  if (flag(this, 'almost')) {
142
- var act = flag(this, 'object')
143
- if (null == precision) precision = 7;
194
+ var act = flag(this, 'object');
195
+ if(precision == null) precision = 7;
144
196
  this.assert(
145
- Math.abs(act - exp) < 0.5 * Math.pow(10, -precision)
197
+ calc.almostEqual(exp,act,precision)
146
198
  , "expected #{this} to equal #{exp} up to " + _.inspect(precision) + " decimal places"
147
199
  , "expected #{this} to not equal #{exp} up to " + _.inspect(precision) + " decimal places"
148
200
  , exp
@@ -177,25 +229,10 @@ module.exports = function (chai, _) {
177
229
  Assertion.overwriteMethod('eql', function (_super) {
178
230
  return function eql (exp, precision) {
179
231
  if (flag(this, 'almost')) {
180
- if (null == precision) precision = 7;
181
- var act = flag(this, 'object')
182
- , tol = 0.5 * Math.pow(10, -precision);
183
-
184
- function deepEql (act, exp) {
185
- if (Object(act) === act){
186
- for (var k in act) {
187
- if (!(deepEql(act[k], exp[k]))) {
188
- return false;
189
- }
190
- }
191
- return true;
192
- } else {
193
- return Math.abs(act - exp) < tol;
194
- }
195
- };
196
-
232
+ var act = flag(this, 'object') ;
233
+ if(precision == null) precision = 7;
197
234
  this.assert(
198
- deepEql(act, exp)
235
+ calc.deepAlmostEqual(act,exp,precision)
199
236
  , "expected #{this} to equal #{exp} up to " + _.inspect(precision) + ' decimal places'
200
237
  , "expected #{this} to not equal #{exp} up to " + _.inspect(precision) + ' decimal places'
201
238
  , exp
@@ -279,6 +316,11 @@ module.exports = function (chai, _) {
279
316
  Assertion.addProperty('deviation', deviation);
280
317
  };
281
318
 
319
+ for(var i in calc){
320
+ if(calc.hasOwnProperty(i)){
321
+ module.exports[i] = calc[i];
322
+ }
323
+ }
282
324
  }); // module stats
283
325
  return require('stats');
284
326
  });
@@ -1,4 +1,4 @@
1
- // Generated by CoffeeScript 1.3.3
1
+ // Generated by CoffeeScript 1.6.3
2
2
  (function() {
3
3
  var __slice = [].slice;
4
4
 
@@ -76,6 +76,15 @@
76
76
  obj = null;
77
77
  return r;
78
78
  },
79
+ createList: function() {
80
+ var amount, args, i, _i, _results;
81
+ amount = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
82
+ _results = [];
83
+ for (i = _i = 1; 1 <= amount ? _i <= amount : _i >= amount; i = 1 <= amount ? ++_i : --_i) {
84
+ _results.push(this.create.apply(this, args));
85
+ }
86
+ return _results;
87
+ },
79
88
  resetFactories: function() {
80
89
  return this.factories = [];
81
90
  }
metadata CHANGED
@@ -1,23 +1,28 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: konacha-chai-matchers
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.4
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease:
5
+ version: 0.1.5
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Matthijs Groen
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-24 00:00:00.000000000 Z
12
+
13
+ date: 2013-09-20 00:00:00 Z
13
14
  dependencies: []
15
+
14
16
  description: A set of Chai.js libraries ready to use for Konacha
15
- email:
17
+ email:
16
18
  - matthijs.groen@gmail.com
17
19
  executables: []
20
+
18
21
  extensions: []
22
+
19
23
  extra_rdoc_files: []
20
- files:
24
+
25
+ files:
21
26
  - .gitignore
22
27
  - .gitmodules
23
28
  - Gemfile
@@ -47,29 +52,32 @@ files:
47
52
  - vendor/assets/javascripts/mocha-as-promised.js
48
53
  - vendor/assets/javascripts/sinon-chai.js
49
54
  - vendor/assets/javascripts/sinon.js
50
- homepage: ''
51
- licenses:
55
+ homepage: ""
56
+ licenses:
52
57
  - MIT
53
58
  post_install_message:
54
59
  rdoc_options: []
55
- require_paths:
60
+
61
+ require_paths:
56
62
  - lib
57
- required_ruby_version: !ruby/object:Gem::Requirement
63
+ required_ruby_version: !ruby/object:Gem::Requirement
58
64
  none: false
59
- requirements:
60
- - - ! '>='
61
- - !ruby/object:Gem::Version
62
- version: '0'
63
- required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
70
  none: false
65
- requirements:
66
- - - ! '>='
67
- - !ruby/object:Gem::Version
68
- version: '0'
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
69
75
  requirements: []
76
+
70
77
  rubyforge_project: konacha-chai-matchers
71
- rubygems_version: 1.8.24
78
+ rubygems_version: 1.8.5
72
79
  signing_key:
73
80
  specification_version: 3
74
81
  summary: Chai.js plugins collection for Konacha
75
82
  test_files: []
83
+