From 2f4fd395c3226afba081d156af6421bca136112b Mon Sep 17 00:00:00 2001 From: nisstyre56 Date: Fri, 28 Mar 2014 14:40:29 -0400 Subject: [PATCH 1/5] testing stuff for new types --- test.js | 24 +++++++++++++++++++++++- tokenize.js | 1 - 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/test.js b/test.js index a360582..201c329 100755 --- a/test.js +++ b/test.js @@ -9,6 +9,7 @@ var errors = require("./errors.js"); var tokens = require("./tokenize.js"); var tools = require("./tools.js"); var typecheck = require("./typecheck.js"); +var representation = require("./representation.js"); var _ = require("underscore"); var qc = require("quickcheck"); @@ -16,6 +17,26 @@ var assert = require("assert"); /* my own generators */ + +function arbIdentifier(construct) { + var result = qc.arbString(); + if (_.size(result) > 0 && + tokens.isIdentifier(result[0])) { + return new construct(result); + } + else { + return arbIdentifier(); + } +} + +function arbName() { + return arbIdentifier(representation.Name); +} + +function arbTypeOp() { + return arbIdentifier(representation.TypeOp); +} + function arbArray(gen) { return qc.arbArray(gen); } @@ -108,4 +129,5 @@ function toolsTests() { } -toolsTests(); +//toolsTests(); +console.log(arbTypeOp()); diff --git a/tokenize.js b/tokenize.js index 23e226f..744d71f 100755 --- a/tokenize.js +++ b/tokenize.js @@ -423,6 +423,5 @@ function tokenizeFull(input) { return tokenizeHelp(input, matchop, true); } - module.exports = {tokenize : tokenizeFull, isIdentifier : isIdentifier}; From 6dd014e824765a3f16c9ee40280590d568c6dbbc Mon Sep 17 00:00:00 2001 From: nisstyre56 Date: Fri, 28 Mar 2014 14:59:27 -0400 Subject: [PATCH 2/5] more testing code --- test.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test.js b/test.js index 201c329..6b3f1db 100755 --- a/test.js +++ b/test.js @@ -29,12 +29,23 @@ function arbIdentifier(construct) { } } +function randomInt(min, max) { + return Math.floor(Math.random() * (max - min + 1)) + min; +} + +function arbCapital() { + return String.fromCharCode(randomInt(65, 90)); +} + function arbName() { return arbIdentifier(representation.Name); } function arbTypeOp() { - return arbIdentifier(representation.TypeOp); + var result = arbIdentifier(representation.TypeOp); + result.name = arbCapital()+result.name; + result.val = result.name; + return result; } function arbArray(gen) { From 319e099297f0fb960e5578189294aabee7735bde Mon Sep 17 00:00:00 2001 From: nisstyre56 Date: Fri, 28 Mar 2014 16:18:15 -0400 Subject: [PATCH 3/5] generate arbitrary strings with different character ranges for quickcheck --- test.js | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/test.js b/test.js index 6b3f1db..3d1e3f5 100755 --- a/test.js +++ b/test.js @@ -18,36 +18,39 @@ var assert = require("assert"); /* my own generators */ -function arbIdentifier(construct) { - var result = qc.arbString(); - if (_.size(result) > 0 && - tokens.isIdentifier(result[0])) { - return new construct(result); - } - else { - return arbIdentifier(); - } +function arbChars(n, max, min) { + return function () { + return _.invoke(_.times(randomInt(1, n), + _.partial(arbChar, max, min)), + "call"); + }; } -function randomInt(min, max) { - return Math.floor(Math.random() * (max - min + 1)) + min; +function arbChar(max, min) { + return function() { + return String.fromCharCode(randomInt(max, min)); + }; } -function arbCapital() { - return String.fromCharCode(randomInt(65, 90)); +function arbCharRanges(ranges, max) { + return function() { + return _.flatten( + _.map(ranges, + function(bound) { + return arbChars(max, bound[0], bound[1])(); + })).join(""); + }; } -function arbName() { - return arbIdentifier(representation.Name); -} -function arbTypeOp() { - var result = arbIdentifier(representation.TypeOp); - result.name = arbCapital()+result.name; - result.val = result.name; - return result; + + +function randomInt(min, max) { + return Math.floor(Math.random() * (max - min + 1)) + min; } +var arbCapital = arbChar(65, 90); + function arbArray(gen) { return qc.arbArray(gen); } @@ -141,4 +144,3 @@ function toolsTests() { //toolsTests(); -console.log(arbTypeOp()); From 754da9d966173389584a978b1fb779d27feeae70 Mon Sep 17 00:00:00 2001 From: nisstyre56 Date: Fri, 28 Mar 2014 16:21:31 -0400 Subject: [PATCH 4/5] switch to underscore.js random function --- test.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/test.js b/test.js index 3d1e3f5..63c4e41 100755 --- a/test.js +++ b/test.js @@ -20,7 +20,7 @@ var assert = require("assert"); function arbChars(n, max, min) { return function () { - return _.invoke(_.times(randomInt(1, n), + return _.invoke(_.times(_.random(1, n), _.partial(arbChar, max, min)), "call"); }; @@ -28,7 +28,7 @@ function arbChars(n, max, min) { function arbChar(max, min) { return function() { - return String.fromCharCode(randomInt(max, min)); + return String.fromCharCode(_.random(max, min)); }; } @@ -45,10 +45,6 @@ function arbCharRanges(ranges, max) { -function randomInt(min, max) { - return Math.floor(Math.random() * (max - min + 1)) + min; -} - var arbCapital = arbChar(65, 90); function arbArray(gen) { From bb0a91b6874ef808e288692b49bd223df9ad8bd7 Mon Sep 17 00:00:00 2001 From: nisstyre56 Date: Fri, 28 Mar 2014 17:01:32 -0400 Subject: [PATCH 5/5] tweaks for identifier generation --- test.js | 17 ++++++++++++----- tokenize.js | 4 +++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/test.js b/test.js index 63c4e41..3507792 100755 --- a/test.js +++ b/test.js @@ -35,15 +35,22 @@ function arbChar(max, min) { function arbCharRanges(ranges, max) { return function() { return _.flatten( - _.map(ranges, + _.shuffle( + _.map(ranges, function(bound) { - return arbChars(max, bound[0], bound[1])(); - })).join(""); + return _.sample(arbChars(max, bound[0], bound[1])(), + bound[1] - bound[0]); + }))).join(""); }; } - +var arbName = arbCharRanges([[33, 33], + [35, 39], + [42,43], + [45, 122], + [124, 126]], + 200); var arbCapital = arbChar(65, 90); @@ -138,5 +145,5 @@ function toolsTests() { //assert.equal(true, qc.forAll(opMatchProp, arbStrings)); } - +console.log(arbName()); //toolsTests(); diff --git a/tokenize.js b/tokenize.js index 744d71f..3789446 100755 --- a/tokenize.js +++ b/tokenize.js @@ -43,7 +43,9 @@ function isIdentifier(c) { code !== 123 && code !== 93 && code !== 91 && - code !== 44); + code !== 44 && + code !== 34 && + code > 32); } function isUpper(c) {