public
Description: A mimetic poly-alloy of the Quicksilver scoring algorithm, essentially LiquidMetal. </Schwarzenegger Voice>
Homepage:
Clone URL: git://github.com/rmm5t/liquidmetal.git
Click here to lend your support to: liquidmetal and make a donation at www.pledgie.com !
rmm5t (author)
Mon Jun 15 06:36:11 -0700 2009
commit  9584fa7c02b5bc4cae2b02cf74886a32a57dfd04
tree    97c00e07f64cb84c5de31de3f2f34b8736aa6bf7
parent  3a107592a5e59101048ee9838edfec19307c4e36
liquidmetal / test.html
100644 77 lines (67 sloc) 3.226 kb
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
<!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>