From f90096c31eb318693a507be01822a6865dbbea7e Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Mon, 25 Sep 2017 23:30:48 -0400 Subject: [PATCH 1/3] test cases for toTwosComplement --- test/utils.toTwosComplement.js | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 test/utils.toTwosComplement.js diff --git a/test/utils.toTwosComplement.js b/test/utils.toTwosComplement.js new file mode 100644 index 00000000000..75e11bd2064 --- /dev/null +++ b/test/utils.toTwosComplement.js @@ -0,0 +1,3 @@ +/** + * Created by danielbruce on 2017-09-25. + */ From 29c29f33b78bf9250f20d41df225f84c3286993d Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Mon, 25 Sep 2017 23:31:34 -0400 Subject: [PATCH 2/3] test cases for to twos complement --- test/utils.toTwosComplement.js | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/test/utils.toTwosComplement.js b/test/utils.toTwosComplement.js index 75e11bd2064..3ef2c8f1cb4 100644 --- a/test/utils.toTwosComplement.js +++ b/test/utils.toTwosComplement.js @@ -1,3 +1,43 @@ /** * Created by danielbruce on 2017-09-25. */ + +/** + * Created by danielbruce on 2017-09-25. + */ +var chai = require('chai'); +var utils = require('../lib/utils/utils'); +var BigNumber = require('bignumber.js'); +var assert = chai.assert; + +var tests = [ + { value: 1, expected: new BigNumber(1).round() }, + { value: '1', expected: new BigNumber(1) }, + { value: '0x1', expected: new BigNumber(1) }, + { value: '15', expected: new BigNumber(15)}, + { value: '0xf', expected: new BigNumber(15)}, + { value: -1, expected: new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).plus(new BigNumber(-1)).plus(1)}, + { value: '-1', expected: new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).plus(new BigNumber(-1)).plus(1)}, + { value: '-0x1', expected: new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).plus(new BigNumber(-1)).plus(1)}, + { value: '-15', expected: new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).plus(new BigNumber(-15)).plus(1)}, + { value: '-0xf', expected: new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).plus(new BigNumber(-15)).plus(1)}, + { value: 0, expected: new BigNumber(0)}, + { value: '0', expected: new BigNumber(0)}, + { value: '0x0', expected: new BigNumber(0)}, + { value: -0, expected: new BigNumber(0)}, + { value: '-0', expected: new BigNumber(0)}, + { value: '-0x0', expected: new BigNumber(0)}, + { value: new BigNumber(15), expected: new BigNumber(15)} +]; + +describe('lib/utils/utils', function () { + describe('toTwosComplement', function () { + tests.forEach(function (test) { + items = []; + it('printing ' + test.value, function () { + assert(test.expected.equals(utils.toTwosComplement(test.value))); + }); + //console.log(items); + }); + }); +}); From e7721ff460d06cc185b559b4dab4ce2a6f59ffdf Mon Sep 17 00:00:00 2001 From: Daniel Bruce Date: Mon, 25 Sep 2017 23:52:15 -0400 Subject: [PATCH 3/3] removed unnecessary code --- test/utils.toTwosComplement.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/utils.toTwosComplement.js b/test/utils.toTwosComplement.js index 3ef2c8f1cb4..b1285de8d8a 100644 --- a/test/utils.toTwosComplement.js +++ b/test/utils.toTwosComplement.js @@ -33,11 +33,9 @@ var tests = [ describe('lib/utils/utils', function () { describe('toTwosComplement', function () { tests.forEach(function (test) { - items = []; it('printing ' + test.value, function () { assert(test.expected.equals(utils.toTwosComplement(test.value))); }); - //console.log(items); }); }); });