Skip to content

Commit

Permalink
Errors (#54)
Browse files Browse the repository at this point in the history
* removing console.log calls
  • Loading branch information
Beakerboy authored May 16, 2024
1 parent 6e11879 commit f01f06c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
15 changes: 7 additions & 8 deletions src/building.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ class Building {
}
this.addParts();
} else {
console.log('XML Not Valid');
window.printError('XML Not Valid');
throw new Error('invalid XML');
}
}

Expand Down Expand Up @@ -152,7 +153,6 @@ class Building {
if (part.tagName.toLowerCase() === 'way') {
this.parts.push(new BuildingPart(ref, this.fullXmlData, this.nodelist, this.outerElement.options));
} else {
console.log('Adding ' + part.tagName.toLowerCase() + ' ' + ref);
this.parts.push(new MultiBuildingPart(ref, this.fullXmlData, this.nodelist, this.outerElement.options));
}
}
Expand Down Expand Up @@ -225,8 +225,7 @@ class Building {
}
} else {
if (!buildingType) {
console.log('Outer way is not a building');
console.log(xmlData);
window.printError('Outer way is not a building');
return false;
}
ways.push(xmlData);
Expand All @@ -240,11 +239,11 @@ class Building {
const firstRef = nodes[0].getAttribute('ref');
const lastRef = nodes[nodes.length - 1].getAttribute('ref');
if (firstRef !== lastRef) {
console.log('Way ' + way.getAttribute('id') + ' is not a closed way. ' + firstRef + ' !== ' + lastRef + '.');
window.printError('Way ' + way.getAttribute('id') + ' is not a closed way. ' + firstRef + ' !== ' + lastRef + '.');
return false;
}
} else {
console.log('Way ' + way.getAttribute('id') + ' has no nodes.');
window.printError('Way ' + way.getAttribute('id') + ' has no nodes.');
return false;
}
} else {
Expand All @@ -256,7 +255,7 @@ class Building {
if (part) {
ways.push(this.fullXmlData.getElementById(ref));
} else {
console.log('Part ' + ref + ' is null.');
window.printError('Part ' + ref + ' is null.');
}
}
}
Expand Down Expand Up @@ -315,7 +314,7 @@ class Building {
}
}
} else {
console.log('"' + buildingType + '" is neither "way" nor "relation". Check that the id is correct.' + fullXmlData);
window.printError('"' + buildingType + '" is neither "way" nor "relation". Check that the id is correct.');
}
return extents;
}
Expand Down
5 changes: 4 additions & 1 deletion test/building.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,27 @@ const data = `

beforeEach(() => {
fetch.resetMocks();
errors = [];
});

test('Test Constructor', async() => {
const bldg = new Building('4', data);
expect(bldg.home).toBeDeepCloseTo([4.0005, 4.0005], 10);
expect(bldg.parts.length).toBe(0);
expect(errors.length).toBe(0);
});

test('Create Nodelist', () => {
let xmlData = new window.DOMParser().parseFromString(data, 'text/xml');
const list = Building.buildNodeList(xmlData);
expect(Object.keys(list).length).toBe(4);
expect(list['3']).toStrictEqual(['4', '4']);
expect(errors.length).toBe(0);
});

window.printError = printError;

const errors = [];
var errors = [];

function printError(txt) {
errors.push[txt];
Expand Down
7 changes: 6 additions & 1 deletion test/multipolygon.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,23 @@ const data = `
</way>
</osm>`;

beforeEach(() => {
errors = [];
});

test('Test Simple Multipolygon', () => {
let xmlData = new window.DOMParser().parseFromString(data, 'text/xml');
const nodelist = Building.buildNodeList(xmlData);
const shape = new MultiBuildingPart('4', xmlData, nodelist);
expect(shape.id).toBe('4');
expect(shape.shape).toBeInstanceOf(Shape);
// expect(shape.roof).toBeInstanceOf(Mesh);
expect(errors.length).toBe(0);
});

window.printError = printError;

const errors = [];
var errors = [];

function printError(txt) {
errors.push[txt];
Expand Down
7 changes: 6 additions & 1 deletion test/split_way_multipolygon.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,23 @@ const data = `
</way>
</osm>`;

beforeEach(() => {
errors = [];
});

test('Test Simple Multipolygon', () => {
let xmlData = new window.DOMParser().parseFromString(data, 'text/xml');
const nodelist = Building.buildNodeList(xmlData);
const shape = new MultiBuildingPart('5', xmlData, nodelist);
expect(shape.id).toBe('5');
expect(shape.shape).toBeInstanceOf(Shape);
// expect(shape.roof).toBeInstanceOf(Mesh);
expect(errors.length).toBe(0);
});

window.printError = printError;

const errors = [];
var errors = [];

function printError(txt) {
errors.push[txt];
Expand Down

0 comments on commit f01f06c

Please sign in to comment.