diff --git a/test/emptyTradeTimingStrategy.js b/test/emptyTradeTimingStrategy.js index 3444ff0..585329e 100644 --- a/test/emptyTradeTimingStrategy.js +++ b/test/emptyTradeTimingStrategy.js @@ -5,7 +5,7 @@ require('should'); const {TradeTimingStrategy} = require('../index.js'); let tradeAdvisor = null; -before(function(){ +beforeEach(function(){ tradeAdvisor = new TradeTimingStrategy(); }); it('is a (constructor) function', function(){ @@ -27,12 +27,14 @@ it('newPeriod() returns self', function(){ tradeAdvisor.newPeriod().should.equal(tradeAdvisor); }); it('newTrade() throws RangeError()', function(){ + tradeAdvisor.newPeriod(); function bad(){ tradeAdvisor.newTrade(); } bad.should.throw(RangeError); }); it('newTrade(-3) throws RangeError()', function(){ + tradeAdvisor.newPeriod(); function bad(){ tradeAdvisor.newTrade(-3); } @@ -42,30 +44,54 @@ it('has a method suggestedBid', function(){ tradeAdvisor.suggestedBid.should.be.a.Function(); }); it('.suggestedBid() throws RangeError', function(){ + tradeAdvisor.newPeriod(); function bad(){ tradeAdvisor.suggestedBid(); } bad.should.throw(RangeError); }); it('.suggestedBid(100) returns undefined', function(){ + tradeAdvisor.newPeriod(); assert.ok(tradeAdvisor.suggestedBid(100)===undefined); }); +it('.suggestedBid(100,{currentBid:10}) returns undefined', function(){ + tradeAdvisor.newPeriod(); + assert.ok(tradeAdvisor.suggestedBid(100,{currentBid:10})===undefined); +}); +it('.suggestedBid(100,{currentAsk:200}) returns undefined', function(){ + tradeAdvisor.newPeriod(); + assert.ok(tradeAdvisor.suggestedBid(100,{currentAsk:200})===undefined); +}); +it('.suggestedBid(100,{currentBid:10,smooth:0.001}) returns undefined', function(){ + tradeAdvisor.newPeriod(); + assert.ok(tradeAdvisor.suggestedBid(100,{currentBid:10,smooth:0.001})===undefined); +}); +it('.suggestedBid(100,{currentAsk:200,smooth:0.001}) returns undefined', function(){ + tradeAdvisor.newPeriod(); + assert.ok(tradeAdvisor.suggestedBid(100,{currentAsk:200,smooth:0.001})===undefined); +}); it('.suggestedBid(100,{currentBid:39,currentAsk:40,smooth:0.001}) returns 40', function(){ + tradeAdvisor.newPeriod(); tradeAdvisor.suggestedBid(100,{currentBid:39,currentAsk:40,smooth:0.001}).should.equal(40); }); it('.suggestedBid(100,{currentBid:38,currentAsk:40,smooth:0.001}) returns 40', function(){ + tradeAdvisor.newPeriod(); tradeAdvisor.suggestedBid(100,{currentBid:38,currentAsk:40,smooth:0.001}).should.equal(40); }); it('.suggestedBid(100,{currentBid:1,currentAsk:40,smooth:0.001}) returns 40', function(){ + tradeAdvisor.newPeriod(); tradeAdvisor.suggestedBid(100,{currentBid:1,currentAsk:40,smooth:0.001}).should.equal(40); }); it('.suggestedBid(100,{currentBid:10,currentAsk:70,smooth:0.001}) returns 55', function(){ + tradeAdvisor.newPeriod(); tradeAdvisor.suggestedBid(100,{currentBid:10,currentAsk:70,smooth:0.001}).should.equal(55); }); it('.suggestedBid(100,{currentBid:10,currentAsk:500,smooth:0.001}) returns 55', function(){ + tradeAdvisor.newPeriod(); tradeAdvisor.suggestedBid(100,{currentBid:10,currentAsk:500,smooth:0.001}).should.equal(55); }); it('has a method suggestedAsk',function(){ + tradeAdvisor.newPeriod(); tradeAdvisor.suggestedAsk.should.be.a.Function(); }); it('.suggestedAsk() throws RangeError', function(){ @@ -75,14 +101,18 @@ it('.suggestedAsk() throws RangeError', function(){ bad.should.throw(RangeError); }); it('.suggestedAsk(100) returns undefined', function(){ + tradeAdvisor.newPeriod(); assert.ok(tradeAdvisor.suggestedAsk(100)===undefined); }); it('.suggestedAsk(50,{currentBid:100,currentAsk:200,smooth:0.001}) returns 125', function(){ + tradeAdvisor.newPeriod(); tradeAdvisor.suggestedAsk(50,{currentBid:100,currentAsk:200,smooth:0.001}).should.equal(125); }); it('.suggestedAsk(80,{currentBid:100,currentAsk:119,smooth:0.001}) returns 100', function(){ + tradeAdvisor.newPeriod(); tradeAdvisor.suggestedAsk(80,{currentBid:100,currentAsk:119,smooth:0.001}).should.equal(100); }); it('.pricesWithProbabilities(1) returns []', function(){ + tradeAdvisor.newPeriod(); tradeAdvisor.pricesWithProbabilities(1).should.deepEqual([]); }); diff --git a/test/singlePeriodTradeTimingStrategy.js b/test/singlePeriodTradeTimingStrategy.js index 9a53176..f8d5461 100644 --- a/test/singlePeriodTradeTimingStrategy.js +++ b/test/singlePeriodTradeTimingStrategy.js @@ -17,6 +17,12 @@ describe('[single period, 4 trades: p=130,110,125,140]', function(){ .newTrade(140) .newPeriod(); }); + it('.pricesWithProbabilities(1,{sort:byPriceAscending, below:100, smooth:0.001}) should be []',function(){ + tradeAdvisor.pricesWithProbabilities(1,{sort:byPriceAscending, below:100, smooth:0.001}).should.deepEqual([]); + }); + it('.pricesWithProbabilities(1,{sort:byPriceAscending, above:200, smooth:0.001}) should be []',function(){ + tradeAdvisor.pricesWithProbabilities(1,{sort:byPriceAscending, below:100, smooth:0.001}).should.deepEqual([]); + }); it('.pricesWithProbabilities(1,{sort: byPriceAscending}) should be [[130,1]]', function(){ tradeAdvisor.pricesWithProbabilities(1,{sort:byPriceAscending}).should.deepEqual([[130,1]]); });