2
0

index.spec.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright 2018 Scytl Secure Electronic Voting SA
  3. *
  4. * All rights reserved
  5. *
  6. * See our extended copyright notice in *file 'Copyright.txt' which is part of this source code package
  7. */
  8. /* jshint node:true, mocha:true */
  9. 'use strict';
  10. var bitwise = require('../lib/index.js');
  11. describe('The bitwise utility ...', function() {
  12. var BYTE_ARRAY_1 = [105, 73, 99];
  13. var BYTE_ARRAY_2 = [86, 43, 215];
  14. var BYTE_ARRAY_3 = [33, 163, 41];
  15. var BYTE = 0x05;
  16. var allBytesArray_;
  17. var prependedArray_;
  18. var appendedArray_;
  19. var bytes1_;
  20. var bytes2_;
  21. var bytes3_;
  22. var allBytes_;
  23. beforeAll(function() {
  24. allBytesArray_ = BYTE_ARRAY_1.concat(BYTE_ARRAY_2, BYTE_ARRAY_3);
  25. prependedArray_ = [BYTE].concat(allBytesArray_);
  26. appendedArray_ = allBytesArray_.concat([BYTE]);
  27. bytes1_ = new Uint8Array(BYTE_ARRAY_1);
  28. bytes2_ = new Uint8Array(BYTE_ARRAY_2);
  29. bytes3_ = new Uint8Array(BYTE_ARRAY_3);
  30. allBytes_ = new Uint8Array(allBytesArray_);
  31. });
  32. describe('should be able to ..', function() {
  33. it('concatenate some bytes to some existing bytes', function() {
  34. var concatenated = bitwise.concatenate(bytes1_, bytes2_, bytes3_);
  35. expect(Array.apply([], concatenated)).toEqual(allBytesArray_);
  36. });
  37. it('slice a subset of bytes from a concatenation of bytes', function() {
  38. var sliced = bitwise.slice(
  39. allBytes_, bytes1_.length, bytes1_.length + bytes2_.length);
  40. expect(Array.apply([], sliced)).toEqual(BYTE_ARRAY_2);
  41. sliced = bitwise.slice(allBytes_, bytes1_.length);
  42. expect(Array.apply([], sliced))
  43. .toEqual(BYTE_ARRAY_2.concat(BYTE_ARRAY_3));
  44. });
  45. it('prepend a byte to some existing bytes', function() {
  46. var prepended = bitwise.prepend(BYTE, allBytes_);
  47. expect(Array.apply([], prepended)).toEqual(prependedArray_);
  48. });
  49. it('apppend a byte to some existing bytes', function() {
  50. var appended = bitwise.append(allBytes_, BYTE);
  51. expect(Array.apply([], appended)).toEqual(appendedArray_);
  52. });
  53. });
  54. });