From 2d1481ce953a869b129bf2c98d7c084d7180f8a3 Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Wed, 18 Dec 2019 15:52:21 -0500 Subject: tested search and file functions; fixed relevant bugs --- space.js | 33 ++++++++++++++++++++------------- tests/space_file.js | 14 ++++++++++++++ tests/space_search.js | 16 ++++++++++++++++ 3 files changed, 50 insertions(+), 13 deletions(-) create mode 100644 tests/space_file.js create mode 100644 tests/space_search.js diff --git a/space.js b/space.js index 5eecf99..638734f 100644 --- a/space.js +++ b/space.js @@ -59,16 +59,24 @@ function Space(){ // CLASS return writes; } this.tofile = function(filename){ - fs.writeFile(filename, this.print(), (err)=>{console.log(err)}); + fs.writeFileSync(filename, this.print()); }; this.fromfile = function(filename){ //Reads an external file into internal data - this.adhoc(fs.readFileSync(filename)); + this.adhoc(fs.readFileSync(filename,'utf8')); } this.adhoc = function(text){ - this.data = text.split('\n').map(row => replace( row.replace(/\\(.)/g,'$1').split('') ,'&','' )); + text = text.split('\n') + text = text.map(row => row.split('')); + this.data = text.map(row => { + for (let i = 0; i replace(row,'','&').join('').replace(/\\|&/g, '\\$&')).join('\n'); + return this.data.map(row => replace(replace(replace(row,'&','\\&'),'\\','\\\\'),'','&').join('')).join('\n'); } this.comb = function(other, func, offset){ for (let row = offset[0]; row= this.data[row].length) this.data[row].push(''); - let otherchar = other.data[row][chr]; otherchar = (typeof(otherchar) == 'undefined') ? '' : otherchar; - this.data[row][chr] = func(this.data[row][chr], otherchar); + this.data[row][chr] = func(this.data[row][chr], other.data[row][chr] || ''); console.log(row,chr,this.data[row][chr]) }} } - this.search = function(other){ - loc = []; - for (let line=0; line<=this.data.length-other.data.length; line++) for (let chr=0; chr<=this.data[y].length-other.data[0].length; chr++){ - match = true; - for (var y=0; y