Skip to content

Commit

Permalink
examples of error in issue #1 confirmed in new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DrPaulBrewer committed Aug 21, 2020
1 parent 6119bd7 commit 02469d0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
32 changes: 31 additions & 1 deletion test/emptyTradeTimingStrategy.js
Expand Up @@ -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(){
Expand All @@ -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);
}
Expand All @@ -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(){
Expand All @@ -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([]);
});
6 changes: 6 additions & 0 deletions test/singlePeriodTradeTimingStrategy.js
Expand Up @@ -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]]);
});
Expand Down

0 comments on commit 02469d0

Please sign in to comment.