-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
73 lines (65 loc) · 1.89 KB
/
test.js
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
const { jHashCode, jUUIDHashCode } = require(".");
test_jHashCode = function () {
const testCases = [
{
"input": "java",
"hashCode": 3254818
},
{
"input": "javascript",
"hashCode": 188995949
},
{
"input": "ecmascript",
"hashCode": -948769283
}
]
testCases.forEach((testCase) => {
if (jHashCode(testCase["input"]) !== testCase["hashCode"]) {
throw EvalError("jHashCode generated hascode not consistent with Java hashcode")
}
});
}
test_jHashCode_returns_0_on_empty_string = function () {
if (jHashCode("") !== 0) {
throw EvalError("jHashCode generated hascode not consistent with Java hashcode");
}
}
test_jUUIDHashCode = function() {
const testCases = [
{
"input": "90903f27-e36e-4e6f-996a-124c58365b43",
"hashCode": -1297991609
},
{
"input": "20adfcb5-d0e7-4157-a94e-fcb749f25168",
"hashCode": 284561469
},
{
"input": "737de8e7-9ae9-4208-95c3-9514309c5032",
"hashCode": 1288400841
}
];
testCases.forEach((testCase) => {
if (jUUIDHashCode(testCase["input"]) !== testCase["hashCode"]) {
throw EvalError("jUUIDHashCode generated hascode not consistent with Java UUID hashcode")
}
});
}
test_jUUIDHashCode_throws_TypError_on_non_UUID = function() {
let exceptionThrown = false;
try {
jUUIDHashCode("foo")
} catch (error) {
if (error instanceof TypeError) {
exceptionThrown = true;
}
}
if (!exceptionThrown) {
throw EvalError("jUUIDHashCode did not throw TypeError on non UUID string")
}
}
test_jHashCode();
test_jHashCode_returns_0_on_empty_string();
test_jUUIDHashCode();
test_jUUIDHashCode_throws_TypError_on_non_UUID();