Skip to content

Commit

Permalink
tests work
Browse files Browse the repository at this point in the history
  • Loading branch information
vogievetsky committed Jul 30, 2013
1 parent eab9ef7 commit 90d6312
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 37 deletions.
2 changes: 1 addition & 1 deletion dvl.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/core.coffee
Expand Up @@ -559,7 +559,7 @@ uniqById = (vs, allowConst) ->
return res

# Sorts the graph. Will sort nodes at levels [0, workers.length)
sortGraph = (from = 0) ->
dvl.sortGraph = sortGraph = (from = 0) ->
# L ← Empty list that will contain the sorted elements
# S ← Set of all nodes with no incoming edges
# while S is non-empty do
Expand Down
4 changes: 1 addition & 3 deletions test-run
@@ -1,4 +1,2 @@
#!/bin/bash
./node_modules/vows/bin/vows test/core/*
mocha --compilers coffee:coffee-script --reporter spec test/async/async.coffee
echo ''
mocha --compilers coffee:coffee-script --reporter spec test/*
5 changes: 1 addition & 4 deletions test/core/apply.coffee
Expand Up @@ -15,25 +15,22 @@ describe "dvl.apply", ->
runs++
return a * 7
invalid: invalid

}

it "correct initial run", ->
expect(runs).to.equal(1)
expect(b.value()).to.equal(21)


it "correct next run", ->
a.value(4)
expect(runs).to.equal(2)
expect(b.value()).to.equal(28)


it "correct invalid", ->
a.value(null)
expect(runs).to.equal(2)
expect(b.value()).to.equal(10)


it "correct on invalid change", ->
invalid.value(20)
expect(runs).to.equal(2)
Expand Down
99 changes: 71 additions & 28 deletions test/core/register.coffee
Expand Up @@ -2,6 +2,7 @@ chai = require("chai")
expect = chai.expect
dvl = require("../../dvl")


describe "dvl.register", ->

describe "basic register", ->
Expand All @@ -16,21 +17,21 @@ describe "dvl.register", ->
it "correct initial run", ->
expect(runs).to.equal(1)


it "correct next run", ->
a.value(4)
expect(runs).to.equal(2)


it "correct next run / same value", ->
a.value(4)
expect(runs).to.equal(2)


it "correct next run / notify", ->
a.notify()
expect(runs).to.equal(3)

it "maintains graph consistency", ->
expect(dvl.sortGraph).not.to.throw()


describe "basic register / const", ->
runs = 0
Expand All @@ -50,6 +51,9 @@ describe "dvl.register", ->
a.notify()
expect(runs).to.equal(1)

it "maintains graph consistency", ->
expect(dvl.sortGraph).not.to.throw()


describe "basic register / no init run", ->
runs = 0
Expand All @@ -68,6 +72,9 @@ describe "dvl.register", ->
a.value(4)
expect(runs).to.equal(1)

it "maintains graph consistency", ->
expect(dvl.sortGraph).not.to.throw()


describe "change and listen register", ->
runs = 0
Expand All @@ -91,6 +98,9 @@ describe "dvl.register", ->
expect(runs).to.equal(2)
expect(b.value()).to.equal(20)

it "maintains graph consistency", ->
expect(dvl.sortGraph).not.to.throw()


describe "double link", ->
runs = 0
Expand Down Expand Up @@ -125,6 +135,9 @@ describe "dvl.register", ->
a.value(4)
expect(runs).to.equal(2)

it "maintains graph consistency", ->
expect(dvl.sortGraph).not.to.throw()


describe "hasChanged works", ->
a = dvl(3)
Expand Down Expand Up @@ -153,28 +166,8 @@ describe "dvl.register", ->
b.value(14)
expect(status).to.equal('B')


describe "circular register", ->
runs = 0
a = dvl(3)
b = dvl(null)

dvl.register {
listen: a
change: b
fn: ->
b.value(a.value() * 5)
runs++
}

it "cant make circular", ->
expect(->
dvl.register {
listen: b
change: a
fn: -> "whatever"
}
).to.throw(Error)
it "maintains graph consistency", ->
expect(dvl.sortGraph).not.to.throw()


describe "addListen", ->
Expand Down Expand Up @@ -215,8 +208,11 @@ describe "dvl.register", ->
b.notify()
expect(status).to.equal('A')

it "maintains graph consistency", ->
expect(dvl.sortGraph).not.to.throw()

describe.skip "addChange", ->

describe "addChange", ->
a = dvl(3)
b = dvl(3)
changes = []
Expand Down Expand Up @@ -253,8 +249,11 @@ describe "dvl.register", ->
a.notify()
expect(status).to.equal('AB')

it "maintains graph consistency", ->
expect(dvl.sortGraph).not.to.throw()


describe.skip "remove basic", ->
describe "remove basic", ->
a = dvl(3)
status = ''

Expand All @@ -277,6 +276,9 @@ describe "dvl.register", ->
a.notify()
expect(status).to.equal('')

it "maintains graph consistency", ->
expect(dvl.sortGraph).not.to.throw()


describe "register order preserved - 1", ->
a = dvl(3)
Expand All @@ -294,6 +296,9 @@ describe "dvl.register", ->
a.notify()
expect(status).to.equal('ABC')

it "maintains graph consistency", ->
expect(dvl.sortGraph).not.to.throw()


describe "register order preserved - 2", ->
a = dvl(3)
Expand All @@ -312,6 +317,9 @@ describe "dvl.register", ->
dvl.notify(a, b)
expect(status).to.equal('ABC')

it "maintains graph consistency", ->
expect(dvl.sortGraph).not.to.throw()


describe "register order preserved - 3", ->
a = dvl(3)
Expand Down Expand Up @@ -339,6 +347,9 @@ describe "dvl.register", ->
dvl.notify(a)
expect(status).to.equal('AB')

it "maintains graph consistency", ->
expect(dvl.sortGraph).not.to.throw()


describe "register order preserved - 4", ->
a = dvl(3)
Expand All @@ -360,12 +371,14 @@ describe "dvl.register", ->
it "correct init run", ->
expect(status).to.equal('&ABC')


it "correct next run", ->
status = ''
a.notify()
expect(status).to.equal('&ABC')

it "maintains graph consistency", ->
expect(dvl.sortGraph).not.to.throw()


describe "register order preserved - 5", ->
source = dvl(1)
Expand Down Expand Up @@ -411,3 +424,33 @@ describe "dvl.register", ->
status = ''
source.value(2)
expect(status).to.equal('ABCDE#')



describe "dvl.register errors", ->
describe "circular register", ->
runs = 0
a = dvl(3)
b = dvl(null)

dvl.register {
listen: a
change: b
fn: ->
b.value(a.value() * 5)
runs++
}

it "cant make circular", ->
expect(->
dvl.register {
listen: b
change: a
fn: -> "whatever"
}
).to.throw(Error)

it "maintains graph consistency", ->
dvl.clearAll()
expect(dvl.sortGraph).not.to.throw()

0 comments on commit 90d6312

Please sign in to comment.