-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.js
More file actions
140 lines (106 loc) · 4.94 KB
/
Copy pathtest.js
File metadata and controls
140 lines (106 loc) · 4.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
'use strict';
/**
* Module dependencies.
*/
var should = require( 'should' ),
Odds = require( './index' ),
chalk = require( 'chalk' );
/**
* Unit tests
*/
describe( 'Conversion function', function () {
var tests = [
[ 1, 1, 2, 100, 0.5 ],
[ 4, 1, 5, 400, 0.2 ],
[ 1, 2, 1.5, -200, 0.67 ],
[ 1, 4, 1.25, -400, 0.8 ]
];
tests.forEach( function ( test ) {
var numerator = test[ 0 ];
var denominator = test[ 1 ];
var decimal = test[ 2 ];
var american = test[ 3 ];
var percent = test[ 4 ];
it( 'Convert fraction ' + numerator + '/' + denominator + ' to ' + (percent * 100) + '%', function () {
Odds.fractionToPercent( numerator, denominator ).should.eql( percent );
} );
it( 'Convert fraction ' + numerator + '/' + denominator + ' to decimal ' + decimal, function () {
Odds.fractionToDecimal( numerator, denominator ).should.eql( decimal );
} );
it( 'Convert fraction ' + numerator + '/' + denominator + ' to GBP ' + american, function () {
Odds.fractionToAmerican( numerator, denominator ).should.eql( american );
} );
it( 'Convert decimal ' + decimal + ' to fraction ' + numerator + '/' + denominator, function () {
Odds.decimalToFraction( decimal ).should.eql( numerator + '/' + denominator );
} );
it( 'Convert decimal ' + decimal + ' to percent ' + (percent * 100) + '%', function () {
Odds.decimalToPercent( decimal ).should.eql( percent );
} );
it( 'Convert decimal ' + decimal + ' to american GBP ' + (american), function () {
Odds.decimalToAmerican( decimal ).should.eql( american );
} );
it( 'Convert percent ' + (percent * 100) + '% to fraction ' + numerator + '/' + denominator, function () {
Odds.percentToFraction( percent ).should.eql( numerator + '/' + denominator );
} );
it( 'Convert percent ' + (percent * 100) + '% to ' + decimal, function () {
Odds.percentToDecimal( percent ).should.approximately( decimal, 0.02 );
} );
it( 'Convert percent ' + (percent * 100) + '% to american GBP ' + american, function () {
Odds.percentToAmerican( percent ).should.approximately( american, 5 );
} );
it( 'Convert american GBP ' + american + '% to decimal ' + decimal, function () {
Odds.americanToDecimal( american ).should.eql( decimal );
} );
it( 'Convert american GBP ' + american + '% to fraction ' + numerator + '/' + denominator, function () {
Odds.americanToFraction( american ).should.eql( numerator + '/' + denominator );
} );
it( 'Convert american GBP ' + american + '% to percent ' + (percent * 100) + '%', function () {
Odds.americanToPercent( american ).should.eql( percent );
} );
it( 'Parse string "' + numerator + '/' + denominator + '" to decimal ' + decimal, function () {
Odds.parse( numerator + '/' + denominator ).should.eql( decimal );
} );
it( 'Parse string "' + decimal + '" to decimal ' + decimal, function () {
Odds.parse( '' + decimal ).should.eql( decimal );
} );
it( 'Parse string "' + (decimal * 100) + ':100" to decimal ' + decimal, function () {
Odds.parse( (decimal * 100) + ':100' ).should.eql( decimal );
} );
it( 'Parse string ' + (percent * 100) + '% to decimal ' + decimal, function () {
Odds.parse( (percent * 100) + '%' ).should.approximately( decimal, 0.02 );
} );
} );
} );
describe( 'Operations', function () {
it( 'WinSingle', function () {
Odds.winSingle( Odds.fractionToDecimal( 9, 2 ), 100 ).should.eql( 550 );
Odds.winSingle( '9/2', 100 ).should.eql( 550 );
} );
it('OddsEachWAy', function() {
var odds = Odds.oddsEachWaySingle('11/4',0.2 );
odds.oddsWin.should.eql(3.75);
odds.oddsPlace.should.eql(1.55);
var odds = Odds.oddsEachWaySingle('11/4','1:5' );
odds.oddsWin.should.eql(3.75);
odds.oddsPlace.should.eql(1.55);
});
it( 'WinEachWaySingle', function () {
Odds.winEachWaySingle(
'11/4',
0.2,
100,
100
).should.eql( 530 );
} );
it('CombinedOddsEachWay', function() {
var odds = Odds.combinedOddsEachWay([[ '1/1', '1:4' ], [ '11/8', '1:5' ], [ '5/4', '1:4' ], [ '1/2', '1' ], [ '3/1', '1:5' ]] );
odds.win.should.approximately(64.25,0.02);
odds.place.should.approximately(5.024,0.02);
});
it('CombineOdds', function() {
Odds.combineOdds(['1/1','11/8','5/4','1/2','3/1']).should.approximately(64.25,0.02);
});
it( 'WinAccumulator', function () {
Odds.winAccumulator( 100, 100, [ '1/1', '1:4' ], [ '11/8', '1:5' ], [ '5/4', '1:4' ], [ '1/2', '1' ], [ '3/1', '1:5' ] ).should.eql( 6928.42 )
} );
} );