保誠-保戶業務員媒合平台
HelenHuang
2022-06-09 9bdb95c9e34cef640534e5e5a1e2225a80442000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
'use strict';
 
var _ = require('lodash');
var test = require('tape');
var sum = require('./');
 
test('creates unique hashes', function (t) {
  var cases = [];
 
  test_case([0,1,2,3]);
  test_case({0:0,1:1,2:2,3:3});
  test_case({0:0,1:1,2:2,3:3,length:4});
  test_case({url:12});
  test_case({headers:12});
  test_case({headers:122});
  test_case({headers:'122'});
  test_case({headers:{accept:'text/plain'}});
  test_case({payload:[0,1,2,3],headers:[{a:'b'}]});
  test_case({a:function () {}});
  test_case({b:function () {}});
  test_case({b:function (a) {}});
  test_case(function () {});
  test_case(function (a) {});
  test_case(function (b) {});
  test_case(function (a) { return a;});
  test_case(function (a) {return a;});
  test_case('', '\'\'');
  test_case('null', '\'null\'');
  test_case('false', '\'false\'');
  test_case('true', '\'true\'');
  test_case('0', '\'0\'');
  test_case('1', '\'1\'');
  test_case('void 0', '\'void 0\'');
  test_case('undefined', '\'undefined\'');
  test_case(null);
  test_case(false);
  test_case(true);
  test_case(Infinity);
  test_case(-Infinity);
  test_case(NaN);
  test_case(0);
  test_case(1);
  test_case(void 0);
  test_case({});
  test_case({a:{},b:{}});
  test_case({valueOf(){return 1}});
  test_case({valueOf(){return 2}});
  test_case([]);
  test_case(new Date());
  test_case(new Date(2019, 5, 28));
  test_case(new Date(1988, 5, 9));
  test_case(global, 'global');
 
  const uniqCases = _.uniqBy(cases, 'hash')
  _.uniqBy(cases, 'hash').forEach(function (expected) {
    var matches = _.filter(cases, { hash: expected.hash })
    t.equal(matches.length, 1, expected.hash + ': ' + _.map(matches, 'value').join(' '))
  })
 
  t.end();
 
  function test_case(value, name) {
    var hash = sum(value);
    cases.push({ value, hash });
    console.log('%s from:', hash, name || value);
  }
});
 
test('hashes clash if same properties', function (t) {
  equals(function () {}, function () {});
  equals(function (a) {}, function (a) {});
  equals({a:'1'},{a:'1'});
  equals({a:'1',b:1},{b:1,a:'1'});
  equals({valueOf(){return 1}},{valueOf(){return 1}});
  t.end();
 
  function equals (a, b) {
    t.equal(sum(a), sum(b));
  }
});