Import old forgotten tests
authorMatthew Mondor <mmondor@pulsar-zone.net>
Wed, 9 Sep 2015 23:53:43 +0000 (23:53 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Wed, 9 Sep 2015 23:53:43 +0000 (23:53 +0000)
mmsoftware/js/js-sh/src/markov.js [new file with mode: 0644]
mmsoftware/js/js-sh/src/test.js [new file with mode: 0644]

diff --git a/mmsoftware/js/js-sh/src/markov.js b/mmsoftware/js/js-sh/src/markov.js
new file mode 100644 (file)
index 0000000..f126a36
--- /dev/null
@@ -0,0 +1,33 @@
+File.prototype.readAll = function()
+{       
+       var data = '';
+
+       for (;;) {
+               try {
+                       data += this.read(1, 16384);
+               } catch (x if x.name == 'IOException') {
+                       if (!this.eof())
+                               throw x;
+                       break;
+               }
+       }
+
+       return data;
+}
+
+var words = stdin.readAll().split(/\ |\n|\t/);
+var dict = [];
+
+for (let w in words) {
+       let word = words[w];
+       if (word.length < 1)
+               continue;
+       if (dict[word] == undefined)
+               dict[word] = 1;
+       else
+               dict[word]++;
+}
+
+stdout.write("=======\n");
+for (i in dict)
+       stdout.write(i + " = " + dict[i] + "\n");
diff --git a/mmsoftware/js/js-sh/src/test.js b/mmsoftware/js/js-sh/src/test.js
new file mode 100644 (file)
index 0000000..cd4f7c9
--- /dev/null
@@ -0,0 +1,7 @@
+var o = {};
+for (;;) {
+       o.test = 'test';
+//     delete o.test;
+       o.test = undefined;
+//     CollectGarbage(); // simple call to JS_GC()
+}