Skip to content

Commit

Permalink
test: fix tests for CentralEuropeanStreetNameClassifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Joxit committed May 4, 2020
1 parent 9b94b48 commit dd24aaf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
9 changes: 4 additions & 5 deletions classifier/CentralEuropeanStreetNameClassifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ const StreetClassification = require('../classification/StreetClassification')

class CentralEuropeanStreetNameClassifier extends SectionClassifier {
each (section) {
// there must be excactly two childen in this section
// note: we may wish to relax/expand on this later
if (section.graph.length('child') !== 2) { return }
// there must at least two childen in this section
if (section.graph.length('child') < 2) { return }

// get first and last child
let children = section.graph.findAll('child')
let first = _.first(children)
let last = _.last(children)
let next = first.graph.findOne('next')

// section must end with a HouseNumberClassification
if (!last.classifications.hasOwnProperty('HouseNumberClassification')) { return }
if (!next || next.end !== section.end || !next.classifications.hasOwnProperty('HouseNumberClassification')) { return }

// other elements cannot contain any public classifications
if (_.some(first.classifications, (c) => c.public)) { return }
Expand Down
33 changes: 23 additions & 10 deletions classifier/CentralEuropeanStreetNameClassifier.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,26 @@ const classifier = new CentralEuropeanStreetNameClassifier()

module.exports.tests = {}
module.exports.tests.classify = (test) => {
let foo = new Span('Foo')
let fooHouseNum = new Span('1', 4).classify(new HouseNumberClassification(1.0))
foo.graph.add('next', fooHouseNum)

let bar = new Span('Bar')
let barHouseNum = new Span('2137', 4).classify(new HouseNumberClassification(1.0))
bar.graph.add('next', barHouseNum)

let baz = new Span('Baz')
let bazHouseNum0 = new Span('152/160', 4).classify(new HouseNumberClassification(1.0))
let bazHouseNum1 = new Span('152', 4).classify(new HouseNumberClassification(1.0))
let bazHouseNum2 = new Span('160', 8).classify(new HouseNumberClassification(1.0))
baz.graph.add('next', bazHouseNum0)
baz.graph.add('next', bazHouseNum1)
bazHouseNum1.graph.add('next', bazHouseNum2)

let valid = [
new Span('Foo 1').setChildren([
new Span('Foo'),
new Span('1').classify(new HouseNumberClassification(1.0))
]),
new Span('Bar 2137').setChildren([
new Span('Bar'),
new Span('2137').classify(new HouseNumberClassification(1.0))
])
new Span('Foo 1').setChildren([foo, fooHouseNum]),
new Span('Bar 2137').setChildren([bar, barHouseNum]),
new Span('Baz 152/160').setChildren([baz, bazHouseNum0, bazHouseNum1, bazHouseNum2])
]

valid.forEach(s => {
Expand All @@ -32,8 +43,10 @@ module.exports.tests.classify = (test) => {
})

// last child was unchanged
t.deepEqual(_.last(children).classifications, {
HouseNumberClassification: new HouseNumberClassification(1)
_.tail(children).forEach(c => {
t.deepEqual(c.classifications, {
HouseNumberClassification: new HouseNumberClassification(1)
})
})

t.end()
Expand Down

0 comments on commit dd24aaf

Please sign in to comment.