Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Vegard Bakke authored and Vegard Bakke committed Dec 30, 2017
1 parent 244de2e commit 798a934
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
17 changes: 17 additions & 0 deletions src/trytes.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ function _shiftTrytes(fromArray, sizeFrom, sizeTo) {
}


/**
* Convert a tryte string (9+A-Z), to an array of tryte3 values (0-26)
*
* @param {*} tryte3Str a tryte string, e.g. "KB0Z"
*
* @returns Array of tryte3 valules, e.g. [11, 2, 0, 26]
*
*/
function convertTryte3CharsToValues(tryte3Str) {
let tryte3Values = new Array(tryte3Str.length);
for (let i = 0; i < tryte3Str.length; i++) {
Expand All @@ -144,6 +152,15 @@ function convertTryte3CharsToValues(tryte3Str) {
}
return tryte3Values;
}

/**
* Convert an array of tryte3 values (0-26) to a tryte string (9+A-Z)
*
* @param {*} tryte3Values Array of tryte3 valules, e.g. [11, 2, 0, 26]
*
* @returns a tryte string, e.g. "KB0Z"
*
*/
function convertTryte3ValuesToChars(tryte3Values) {
let tryte3Str = "";
let value = 0;
Expand Down
12 changes: 7 additions & 5 deletions test/tests.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
var chai = require('chai');
var assert = chai.assert;
var Trytes = require('../src/trytes.js');

Trytes.decodeTryteStringFromBytes('KB');
var Trytes = require('../index.js');


describe('Various lengths of Z trytes', function () {
Expand All @@ -13,12 +11,14 @@ describe('Various lengths of Z trytes', function () {
var trytes = str.substr(0, i);
var bytes = Trytes.encodeTryteStringAsBytes(trytes);
var reverted = Trytes.decodeTryteStringFromBytes(bytes);
//console.log('Converted '+trytes+'-'+reverted+', via '+bytes.toString());
console.log('Converted '+trytes+'-'+reverted+', via '+bytes.toString());
assert.equal(trytes, reverted);
}
});
});



describe('Various length of 9 trytes', function () {
it('should convert tryte strings of 0 to 6, to byte and back', function () {

Expand All @@ -27,12 +27,14 @@ describe('Various length of 9 trytes', function () {
var trytes = str.substr(0, i);
var bytes = Trytes.encodeTryteStringAsBytes(trytes);
var reverted = Trytes.decodeTryteStringFromBytes(bytes);
//console.log('Converted '+trytes+'-'+reverted+', via '+bytes.toString());
console.log('Converted '+trytes+'-'+reverted+', via '+bytes.toString());
assert.equal(trytes, reverted);
}
});
});



describe('Encode and decode seeds and addresses', function () {
let testTrytes = [
'',
Expand Down

0 comments on commit 798a934

Please # to comment.