Permalink
Browse files

Bugfix: Stop using edge start->end as edge ID

Fixes: edges with different "predicates" were overwriting one another.
Also: google spreadsheet initial test; refactor edge tests
  • Loading branch information...
harlantwood committed Jan 7, 2017
1 parent 39b1675 commit aa982f9abebf7ce6f58100e40e51908f1e896207
@@ -1,6 +1,6 @@
request = require 'axios'
Promise = require 'bluebird'
{ log, p } = require 'lightsaber/lib/log'
{ log, d } = require 'lightsaber/lib/log'
{ camelCase, startsWith } = require 'lodash'
Sphere = require '../core/sphere'
View
@@ -9,8 +9,9 @@ class Edge extends Node
throw new Error "end must be of type Node, got #{json @end}" unless @end instanceof Node
throw new Error "Missing start [ID: #{@start?.id()}] and/or end [ID: #{@end?.id()}] in 'args' " unless @start? and @end?
@attrs = data
@setKey @attrs
id: -> "#{@start.id()} -> #{@end.id()}"
id: -> @_id
data: ->
map = {
@@ -0,0 +1,68 @@
{ expect } = require 'chai'
{ some, values } = require 'lodash'
{ d, pjson } = require 'lightsaber'
{ assertEdge } = require '../testHelpers'
Sphere = require '../../lib/core/sphere'
GoogleSpreadsheet = require '../../lib/adaptor/googleSpreadsheet'
describe 'GoogleSpreadsheet Adaptor', ->
describe '#sphere_from', ->
it 'builds a sphere from spreadsheet data', ->
gsheet = new GoogleSpreadsheet
gsheet.options = orientation: 'rows'
spreadsheet =
feed:
entry: [
{
id:
$t: '...R1C1'
content:
$t: ''
}
{
id:
$t: '...R1C2'
content:
$t: 'favorite color'
}
{
id:
$t: '...R1C3'
content:
$t: 'middle name'
}
{
id:
$t: '...R2C1'
content:
$t: 'Alice'
}
{
id:
$t: '...R2C2'
content:
$t: 'Violet'
}
{
id:
$t: '...R2C3'
content:
$t: 'Violet'
}
]
sphere = gsheet.sphere_from spreadsheet
expect(sphere).to.be.instanceof Sphere
edges = values sphere.edgesData()
assertEdge sphere,
subject: 'Alice'
predicate: {name: 'favorite color'}
object: 'Violet'
assertEdge sphere,
subject: 'Alice'
predicate: {name: 'middle name'}
object: 'Violet'
@@ -1,12 +1,12 @@
{ d, pjson } = require 'lightsaber'
{ d, json, pjson } = require 'lightsaber'
{ size } = require 'lodash'
{ should } = require 'chai'
{ expect } = require 'chai'
{ assertEdge } = require '../testHelpers'
Sphere = require '../../src/core/sphere'
multiply = require '../../src/algebra/multiply'
should() # make should available on everything
describe 'multiply', ->
makeEdge = ({start, end, data}) ->
@@ -33,10 +33,26 @@ describe 'multiply', ->
]
resultSphere = multiply contentSphere, filterSphere
edges = resultSphere.edges
edges["time poem -> the"].get('weight').should.equal 25 # check a sample: original edges are copied from content sphere
size(edges).should.equal size(contentSphere.edges) + 3, "expected result sphere to have 3 more edges than content sphere, but got: #{pjson edges}"
edges["time poem -> saturn"].get('weight').should.equal 3
edges["beauty poem -> venus"].get('weight').should.equal 2
edges["beauty poem -> saturn"].get('weight').should.equal .25
# check a sample: original edges are copied from content sphere
assertEdge resultSphere,
subject: 'time poem'
predicate: {weight: 25}
object: 'the'
expect(size(resultSphere.edges)).to.equal size(contentSphere.edges) + 3, "expected result sphere to have 3 more edges than content sphere, but got: #{pjson resultSphere.edges}"
assertEdge resultSphere,
subject: 'time poem'
predicate: {weight: 3}
object: 'saturn'
assertEdge resultSphere,
subject: 'beauty poem'
predicate: {weight: 2}
object: 'venus'
assertEdge resultSphere,
subject: 'beauty poem'
predicate: {weight: .25}
object: 'saturn'
View
@@ -0,0 +1,14 @@
{ d, json, pjson } = require 'lightsaber'
{ expect } = require 'chai'
{ isEqual, some, values } = require 'lodash'
class TestHelpers
@assertEdge: (sphere, {subject, predicate, object}) ->
edges = sphere.edgesData()
found = some edges, (edge) ->
edge.start.name is subject and
isEqual(edge.data, predicate) and
edge.end.name is object
expect(found).to.eq true, "Edge [ #{subject} -[#{json predicate}]-> #{object} ] not found in #{pjson edges}"
module.exports = TestHelpers

0 comments on commit aa982f9

Please sign in to comment.