Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Converted bert tests for float

  • Loading branch information...
commit cd3662d4819058bf3e0892e2991e2dcf84aebcb4 1 parent 0987526
@jhulten authored
Showing with 37 additions and 50 deletions.
  1. +0 −50 test/bert-test.js
  2. +37 −0 test/test_bert_float.js
View
50 test/bert-test.js
@@ -14,56 +14,6 @@ var encode = bert.encode,
var data = null,
obj = null;
-// BIG INTEGERS
-
-test('bert.encode(987654321)', function() {
- data = encode(987654321);
- assert_equal("<<131,110,4,0,177,104,222,58>>", bin(data));
-});
-
-test('bert.decode(987654321)', function() {
- obj = decode(data);
- assert_equal(987654321, obj);
-});
-
-test('bert.encode(-987654321)', function() {
- data = encode(-987654321);
- assert_equal("<<131,110,4,1,177,104,222,58>>", bin(data));
-});
-
-test('bert.decode(-987654321)', function() {
- obj = decode(data);
- assert_equal(-987654321, obj);
-});
-
-// FLOAT
-
-test('bert.encode(3.14159)', function() {
- data = encode(3.14159);
- assert_equal(
- "<<131,99,51,46,49,52,49,53,57,101,43,48,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0>>",
- bin(data)
- );
-});
-
-test('bert.decode(3.14159)', function() {
- obj = decode(data);
- assert_equal(3.14159, obj);
-});
-
-test('bert.encode(-3.14159)', function() {
- data = encode(-3.14159);
- assert_equal(
- "<<131,99,45,51,46,49,52,49,53,57,101,43,48,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0>>",
- bin(encode(-3.14159))
- );
-});
-
-test('bert.decode(-3.14159)', function() {
- obj = decode(data);
- assert_equal(-3.14159, obj);
-});
-
// LISTS
obj = [1, 2, 3]
View
37 test/test_bert_float.js
@@ -0,0 +1,37 @@
+var nodeunit = require('nodeunit');
+var util = require('util');
+var bert = require('../src/bert');
+
+exports.testFloatRepr = function(test) {
+ test.strictEqual(bert.repr(3.14159),'3.14159');
+ test.strictEqual(bert.repr(-3.14159),'-3.14159');
+ test.done();
+};
+
+var floatsEncoded = {};
+
+floatsEncoded[3.14159] = "<<131,99,51,46,49,52,49,53,57,101,43,48,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0>>";
+floatsEncoded[-3.14159] = "<<131,99,45,51,46,49,52,49,53,57,101,43,48,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0>>";
+
+exports.testFloatEncode = function(test) {
+ for (var number in floatsEncoded) {
+ if (floatsEncoded.hasOwnProperty(number)) {
+ // use the + notation to cast the strings in the hash key
+ // back to integers
+ var actual = bert.encode(+number);
+ test.strictEqual(bert.bin_repr(actual), floatsEncoded[number]);
+ }
+ }
+ test.done();
+};
+
+exports.testFloatDecode = function(test) {
+ for (var number in floatsEncoded) {
+ // use the + notation to cast the strings in the hash key
+ // back to integers
+ var actual = bert.decode(bert.encode(+number));
+ test.strictEqual(actual, +number);
+ }
+ test.done();
+};
+
Please sign in to comment.
Something went wrong with that request. Please try again.