Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

77 lines (67 sloc) 3.226 kB
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>liquidmetal tests</title>
<style>
.pass { display: inline; color: green; }
.fail { display: block; color: red; }
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js" type="text/javascript"></script>
<script src="liquidmetal.js" type="text/javascript"></script>
<script type="text/javascript">
function log(message) { if (console && console.log) console.log(message); }
$(document).ready(function() {
function shouldScore(charScores, string, abbreviation) {
var sum = 0.0;
for (var s in charScores) { sum += charScores[s]; }
var expectedScore = Math.round(sum / charScores.length * 1000) / 1000;
var score = LiquidMetal.score(string, abbreviation);
var scoreArray = LiquidMetal.buildScoreArray(string, abbreviation);
var roundedScore = Math.round(score*1000)/1000;
var pass = (expectedScore == roundedScore);
var result = (pass) ? "pass" : "fail";
log(string + " ~ " + abbreviation + " : " + scoreArray);
var desc = "."
if (!pass) {
desc = "LiquidMetal.score('" + string + "', '" + abbreviation + "') should match " + expectedScore + " but was " + score;
}
$("body").append($("<div></div>").addClass(result).text(desc));
}
var n = 0.0; // no match
var m = 1.0; // match
var t = 0.8; // trailing
var s = 0.9; // special trailing
var b = 0.85; // buffer
shouldScore([t], "", "");
shouldScore([n], "", "a");
shouldScore([t], "a", "");
shouldScore([n], "a", "toolong");
shouldScore([m], "a", "a");
shouldScore([n], "a", "b");
shouldScore([t,t,t], "abc", "");
shouldScore([m,s,s], "abc", "a");
shouldScore([n,m,t], "abc", "b");
shouldScore([n,n,m], "abc", "c");
shouldScore([n,n,n], "abc", "d");
shouldScore([m], "A", "a");
shouldScore([n], "A", "b");
shouldScore([t,t,t,t,t,t], "FooBar", "");
shouldScore([m,m,m,s,s,s], "FooBar", "foo");
shouldScore([m,b,b,m,s,s], "FooBar", "fb");
shouldScore([b,b,b,m,t,t], "FooBar", "b");
shouldScore([n,m,m,n,m,m], "FooBar", "ooar");
shouldScore([n,n,n,n,n,n], "FooBar", "bab");
shouldScore([t,t,t,t,t,t,t], "Foo Bar", "");
shouldScore([m,m,m,s,s,s,s], "Foo Bar", "foo");
shouldScore([m,b,b,m,m,s,s], "Foo Bar", "fb");
shouldScore([b,b,b,m,m,t,t], "Foo Bar", "b");
shouldScore([n,m,m,n,n,m,m], "Foo Bar", "ooar");
shouldScore([n,n,n,n,n,n,n], "Foo Bar", "bab");
});
</script>
</head>
<body>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.