test.js 787 B

12345678910111213141516171819202122232425
  1. var sha1 = require('./sha1.js');
  2. var assert = require('assert');
  3. describe('sha1', function () {
  4. it ('should return the expected SHA-1 hash for "message"', function () {
  5. assert.equal('6f9b9af3cd6e8b8a73c2cdced37fe9f59226e27d', sha1('message'));
  6. });
  7. it('should not return the same hash for random numbers twice', function () {
  8. var msg1 = Math.floor((Math.random() * 100000) + 1) + (new Date).getTime();
  9. var msg2 = Math.floor((Math.random() * 100000) + 1) + (new Date).getTime();
  10. if (msg1 !== msg2)
  11. assert.notEqual(sha1(msg1), sha1(msg2));
  12. else
  13. assert.equal(sha1(msg1), sha1(msg1));
  14. });
  15. it('should node.js Buffer', function() {
  16. var buffer = new Buffer('hello, sha1', 'utf8');
  17. assert.equal(sha1(buffer), sha1('hello, sha1'));
  18. })
  19. });