                     if start < 500
                         expect(end).to.be.above 499
 
-                    else if end > 700
-                        expect(start).to.be.below 701
+                    else if end > 510
+                        expect(start).to.be.below 511
 
                     else
-                        expect(start).within 500, 700
-                        expect(end).within 500, 700
-
+                        expect(start).within 500, 510
+                        expect(end).within 500, 510
 
                 else
-                    expect(start > 700 or end < 500).to.be.true
+                    expect(start > 510 or end < 500).to.be.true
 
 
 


        @iTree = new IntervalTree(500)

        @intervals = (createRandomInterval(1000, i) for i in [0...100])

        for interval in @intervals

            @iTree.add interval.start, interval.end, interval.id


    describe 'search', ->

        it 'runs point search when one argument is given', ->


    describe 'pointSearch', ->

        it 'searches intervals by point', ->

            results = @iTree.search(500)

            resultIds = (result.id for result in results)

            for interval in @intervals

                { start, end, id } = interval

                if id in resultIds

                    expect(start).to.be.below 501
                    expect(end).to.be.above 499

                else if start < 500
                    expect(end).to.be.below 500

                else
                    expect(start).to.be.above 500


    describe 'rangeSearch', ->

        it 'searches intervals by range', ->

            results = @iTree.search(500, 700)

            resultIds = (result.id for result in results)

            for interval in @intervals

                { start, end, id } = interval



        it 'removes an interval by id', ->

            @iTree.add 498, 499, 'foo'
            @iTree.add 498, 499, 'bar'

            id = 'foo'

            interval = @iTree.intervalsById[id]
            node = @iTree.nodesById[id]
            count = node.count()

            @iTree.remove id

            expect(@iTree.intervalsById[id]).to.not.exist
            expect(@iTree.nodesById[id]).to.not.exist
