integrating the tests
This commit is contained in:
parent
710f014478
commit
93d7991960
|
@ -51,10 +51,17 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
var eq = function (x, y) { return x === y; };
|
||||||
|
var eqv = baselib.equality.eqv;
|
||||||
|
var equal = function (x, y) {
|
||||||
|
return baselib.equality.equals(x, y, new baselib.UnionFind());
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// Creates a low-level hashtable, following the interface of
|
// Creates a low-level hashtable, following the interface of
|
||||||
// http://www.timdown.co.uk/jshashtable/
|
// http://www.timdown.co.uk/jshashtable/
|
||||||
var makeLowLevelEqHash = function () {
|
var makeLowLevelEqHash = function () {
|
||||||
return new Hashtable(function (x) { return getEqHashCode(x); },
|
return new Hashtable(getEqHashCode,
|
||||||
function (x, y) { return x === y; });
|
function (x, y) { return x === y; });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -63,17 +70,17 @@
|
||||||
var makeEqHashtable = function() {
|
var makeEqHashtable = function() {
|
||||||
return new WhalesongHashtable(
|
return new WhalesongHashtable(
|
||||||
"hasheq",
|
"hasheq",
|
||||||
function (x) { return getEqHashCode(x); },
|
getEqHashCode,
|
||||||
function (x, y) { return x === y; });
|
eq,
|
||||||
|
new Hashtable(getEqHashCode, eq));
|
||||||
};
|
};
|
||||||
|
|
||||||
var makeEqualHashtable = function() {
|
var makeEqualHashtable = function() {
|
||||||
return new WhalesongHashtable(
|
return new WhalesongHashtable(
|
||||||
"hash",
|
"hash",
|
||||||
getEqualHashCode,
|
getEqualHashCode,
|
||||||
function (x, y) {
|
equal,
|
||||||
return baselib.equality.equals(x, y, new baselib.UnionFind());
|
new Hashtable(getEqualHashCode, equal));
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,7 +88,8 @@
|
||||||
return new WhalesongHashtable(
|
return new WhalesongHashtable(
|
||||||
"hasheqv",
|
"hasheqv",
|
||||||
getEqvHashCode,
|
getEqvHashCode,
|
||||||
baselib.equality.eqv);
|
baselib.equality.eqv,
|
||||||
|
new Hashtable(getEqvHashCode, baselib.equality.eqv));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -92,7 +100,7 @@
|
||||||
if (hx < hy) { return -1; }
|
if (hx < hy) { return -1; }
|
||||||
if (hx > hy) { return 1; }
|
if (hx > hy) { return 1; }
|
||||||
|
|
||||||
if eq(x, y) { return 0; }
|
if (eq(x, y)) { return 0; }
|
||||||
|
|
||||||
hx = getEqHashCode(x);
|
hx = getEqHashCode(x);
|
||||||
hy = getEqHashCode(y);
|
hy = getEqHashCode(y);
|
||||||
|
@ -109,11 +117,11 @@
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// Whalesong's Hashtables are a thin wrapper around the mutable Hashtable
|
// Whalesong's Hashtables are a thin wrapper around the mutable Hashtable
|
||||||
// class to make it printable and equatable.
|
// class to make it printable and equatable.
|
||||||
var WhalesongHashtable = function (type, hash_function, equality_function) {
|
var WhalesongHashtable = function (type, hash_function, equality_function, hash) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.hash_function = hash_function;
|
this.hash_function = hash_function;
|
||||||
this.equality_function = equality_function;
|
this.equality_function = equality_function;
|
||||||
this.hash = new Hashtable(hash_function, equality_function);
|
this.hash = hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
WhalesongHashtable.prototype.toWrittenString = function (cache) {
|
WhalesongHashtable.prototype.toWrittenString = function (cache) {
|
||||||
|
@ -272,15 +280,22 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
WhalesongImmutableHashtable.prototype.put = function(key, value) {
|
WhalesongImmutableHashtable.prototype.put = function(key, value) {
|
||||||
// this.hash.put(key, value);
|
throw new Error();
|
||||||
|
};
|
||||||
|
|
||||||
|
WhalesongImmutableHashtable.prototype.functionalPut = function(key, value) {
|
||||||
};
|
};
|
||||||
|
|
||||||
WhalesongImmutableHashtable.prototype.remove = function(key) {
|
WhalesongImmutableHashtable.prototype.remove = function(key) {
|
||||||
|
throw new Error();
|
||||||
|
};
|
||||||
|
|
||||||
|
WhalesongImmutableHashtable.prototype.functionalRemove = function(key) {
|
||||||
// this.hash.remove(key);
|
// this.hash.remove(key);
|
||||||
};
|
};
|
||||||
|
|
||||||
WhalesongImmutableHashtable.prototype.containsKey = function(key) {
|
WhalesongImmutableHashtable.prototype.containsKey = function(key) {
|
||||||
// return this.hash.containsKey(key);
|
return this.map.contains(key);
|
||||||
};
|
};
|
||||||
|
|
||||||
WhalesongImmutableHashtable.prototype.isImmutable = function() {
|
WhalesongImmutableHashtable.prototype.isImmutable = function() {
|
||||||
|
@ -312,11 +327,6 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Arbitrary magic number. We have to cut off the hashing at some point.
|
// Arbitrary magic number. We have to cut off the hashing at some point.
|
||||||
var MAX_HASH_DEPTH = 128;
|
var MAX_HASH_DEPTH = 128;
|
||||||
|
|
||||||
|
|
24
tests/more-tests/hash-code.expected
Normal file
24
tests/more-tests/hash-code.expected
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
"boxes"
|
||||||
|
1159182323
|
||||||
|
"bytes"
|
||||||
|
121827633
|
||||||
|
"chars"
|
||||||
|
1932714901
|
||||||
|
1932717986
|
||||||
|
"hashes"
|
||||||
|
1118728238
|
||||||
|
964361183
|
||||||
|
"lists"
|
||||||
|
448104403
|
||||||
|
1541271846
|
||||||
|
"strings"
|
||||||
|
801766744
|
||||||
|
"structs"
|
||||||
|
1930147392
|
||||||
|
402355443
|
||||||
|
"symbols"
|
||||||
|
22978968
|
||||||
|
721172405
|
||||||
|
"vectors"
|
||||||
|
1344488202
|
||||||
|
803618204
|
23
tests/more-tests/hashes.expected
Normal file
23
tests/more-tests/hashes.expected
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
false
|
||||||
|
false
|
||||||
|
true
|
||||||
|
true
|
||||||
|
true
|
||||||
|
true
|
||||||
|
true
|
||||||
|
true
|
||||||
|
#hash()
|
||||||
|
#hasheqv()
|
||||||
|
#hasheq()
|
||||||
|
#hash((4 . four) (3 . three) (2 . two) (1 . one))
|
||||||
|
#hasheqv((4 . four) (3 . three) (2 . two) (1 . one))
|
||||||
|
#hasheq((4 . four) (3 . three) (2 . two) (1 . one))
|
||||||
|
one
|
||||||
|
not-found
|
||||||
|
1
|
||||||
|
2
|
||||||
|
2
|
||||||
|
1
|
||||||
|
1
|
||||||
|
1
|
||||||
|
1
|
|
@ -32,7 +32,8 @@
|
||||||
(test "more-tests/earley.rkt")
|
(test "more-tests/earley.rkt")
|
||||||
(test "more-tests/view.rkt")
|
(test "more-tests/view.rkt")
|
||||||
(test "more-tests/weird-cc.rkt")
|
(test "more-tests/weird-cc.rkt")
|
||||||
|
(test "more-tests/hashes.rkt")
|
||||||
|
(test "more-tests/hash-code.rkt")
|
||||||
|
|
||||||
(test "more-tests/booleans-cs019.rkt")
|
(test "more-tests/booleans-cs019.rkt")
|
||||||
(test "more-tests/checking-cs019.rkt")
|
(test "more-tests/checking-cs019.rkt")
|
||||||
|
|
|
@ -6,4 +6,4 @@
|
||||||
|
|
||||||
(provide version)
|
(provide version)
|
||||||
(: version String)
|
(: version String)
|
||||||
(define version "1.59")
|
(define version "1.60")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user