Preset#matchTags -> Preset#matchScore

This commit is contained in:
John Firebaugh
2013-05-13 17:26:17 -07:00
parent bb8e91da31
commit 525d37c647
4 changed files with 10 additions and 10 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ iD.presets.Category = function(id, category, all) {
return category.geometry.indexOf(geometry) >= 0;
};
category.matchTags = function() { return false; };
category.matchScore = function() { return -1; };
category.name = function() {
return t('presets.categories.' + id + '.name', {'default': id});
+1 -1
View File
@@ -26,7 +26,7 @@ iD.presets.Collection = function(collection) {
match;
for (var i = 0; i < collection.length; i++) {
var score = collection[i].matchTags(entity);
var score = collection[i].matchScore(entity);
if (score > best) {
best = score;
match = collection[i];
+1 -1
View File
@@ -12,7 +12,7 @@ iD.presets.Preset = function(id, preset, fields) {
return preset.geometry.indexOf(geometry) >= 0;
};
preset.matchTags = function(entity) {
preset.matchScore = function(entity) {
var tags = preset.tags,
score = 0;
for (var t in tags) {
+7 -7
View File
@@ -50,23 +50,23 @@ describe('iD.presets.Preset', function() {
});
});
describe('#matchTags', function() {
describe('#matchScore', function() {
it("returns -1 if preset does not match tags", function() {
expect(p['highway/residential'].matchTags(w1)).to.equal(-1);
expect(p['highway/residential'].matchScore(w1)).to.equal(-1);
});
it("returns 0 for other preset (no match tags)", function() {
expect(p.other.matchTags(w1)).to.equal(0);
expect(p.other.matchScore(w1)).to.equal(0);
});
it("returns the number of matched tags", function() {
expect(p['highway/residential'].matchTags(w3)).to.equal(1);
expect(p['leisure/pitch/tennis'].matchTags(w2)).to.equal(2);
expect(p['highway/residential'].matchScore(w3)).to.equal(1);
expect(p['leisure/pitch/tennis'].matchScore(w2)).to.equal(2);
});
it("counts * as a match for any value", function() {
expect(p.building.matchTags(w4)).to.equal(0.5);
expect(p.building.matchTags(w5)).to.equal(-1);
expect(p.building.matchScore(w4)).to.equal(0.5);
expect(p.building.matchScore(w5)).to.equal(-1);
});
});