Skip to content

Commit

Permalink
add tests for LIMIT, OFFSET & DISTINCT modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
Callidon committed Sep 1, 2018
1 parent 586645e commit af2ed68
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 1 deletion.
110 changes: 110 additions & 0 deletions tests/modifiers/limit-offset-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/* file : limit-offset-test.js
MIT License
Copyright (c) 2018 Thomas Minier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

'use strict'

const expect = require('chai').expect
const { getGraph, TestEngine } = require('../utils.js')

describe('SPARQL queries with LIMIT/OFFSET', () => {
let engine = null
before(() => {
const g = getGraph('./tests/data/dblp.nt')
engine = new TestEngine(g)
})

const data = [
{
text: 'should evaluate SPARQL queries with OFFSET',
query: `
PREFIX dblp-pers: <https://dblp.org/pers/m/>
PREFIX dblp-rdf: <https://dblp.uni-trier.de/rdf/schema-2017-04-18#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?name ?article WHERE {
?s rdf:type dblp-rdf:Person .
?s dblp-rdf:primaryFullPersonName ?name .
?s dblp-rdf:authorOf ?article .
}
OFFSET 2`,
results: [
'https://dblp.org/rec/conf/esws/MinierSMV18',
'https://dblp.org/rec/conf/esws/MinierSMV18a',
'https://dblp.org/rec/journals/corr/abs-1806-00227'
]
},
{
text: 'should evaluate SPARQL queries with LIMIT',
query: `
PREFIX dblp-pers: <https://dblp.org/pers/m/>
PREFIX dblp-rdf: <https://dblp.uni-trier.de/rdf/schema-2017-04-18#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?name ?article WHERE {
?s rdf:type dblp-rdf:Person .
?s dblp-rdf:primaryFullPersonName ?name .
?s dblp-rdf:authorOf ?article .
}
LIMIT 2`,
results: [
'https://dblp.org/rec/conf/esws/MinierMSM17',
'https://dblp.org/rec/conf/esws/MinierMSM17a'
]
},
{
text: 'should evaluate SPARQL queries with LIMIT & OFFSET',
query: `
PREFIX dblp-pers: <https://dblp.org/pers/m/>
PREFIX dblp-rdf: <https://dblp.uni-trier.de/rdf/schema-2017-04-18#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?name ?article WHERE {
?s rdf:type dblp-rdf:Person .
?s dblp-rdf:primaryFullPersonName ?name .
?s dblp-rdf:authorOf ?article .
}
OFFSET 3
LIMIT 2`,
results: [
'https://dblp.org/rec/conf/esws/MinierSMV18',
'https://dblp.org/rec/conf/esws/MinierSMV18a'
]
}
]

data.forEach(d => {
it(d.text, done => {
const expectedCardinality = d.results.length
let nbResults = 0
const iterator = engine.execute(d.query)
iterator.on('error', done)
iterator.on('data', b => {
expect(b['?article']).to.be.oneOf(d.results)
d.results.splice(d.results.indexOf(b['?article']), 1)
nbResults++
})
iterator.on('end', () => {
expect(nbResults).to.equal(expectedCardinality)
done()
})
})
})
})
29 changes: 28 additions & 1 deletion tests/modifiers/select-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('SELECT SPARQL queries', () => {
})
})

it('should evaluate SELECT * SPARQL queries', done => {
it('should evaluate SELECT * queries', done => {
const query = `
PREFIX dblp-pers: <https://dblp.org/pers/m/>
PREFIX dblp-rdf: <https://dblp.uni-trier.de/rdf/schema-2017-04-18#>
Expand All @@ -79,4 +79,31 @@ describe('SELECT SPARQL queries', () => {
done()
})
})

it('should evaluate SELECT DISTINCT queries', done => {
const query = `
PREFIX dblp-pers: <https://dblp.org/pers/m/>
PREFIX dblp-rdf: <https://dblp.uni-trier.de/rdf/schema-2017-04-18#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT DISTINCT ?name WHERE {
{
?s rdf:type dblp-rdf:Person .
?s dblp-rdf:primaryFullPersonName ?name .
} UNION {
?s rdf:type dblp-rdf:Person .
?s dblp-rdf:primaryFullPersonName ?name .
}
}`
const results = []
const iterator = engine.execute(query)
iterator.on('error', done)
iterator.on('data', b => {
expect(b).to.have.keys('?name')
results.push(b)
})
iterator.on('end', () => {
expect(results.length).to.equal(1)
done()
})
})
})

0 comments on commit af2ed68

Please sign in to comment.