getfirstdecimal_spec.js
1.34 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
describe('#getFirstDecimal', function() {
beforeEach(function() {
this.el = Helper.create('#el');
});
afterEach(function() {
Helper.clear();
});
context('without decimal', function() {
it ('is zero', function() {
// given
var number = 0;
this.el.raty();
// when
var decimal = this.el.raty('_getFirstDecimal', number);
// then
expect(decimal).toEqual(0);
});
});
context('with one decimal', function() {
it ('is that one', function() {
// given
var number = 0.1;
this.el.raty();
// when
var decimal = this.el.raty('_getFirstDecimal', number);
// then
expect(decimal).toEqual(1);
});
});
context('with two decimal', function() {
it ('is the first decimal', function() {
// given
var number = 0.12;
this.el.raty();
// when
var decimal = this.el.raty('_getFirstDecimal', number);
// then
expect(decimal).toEqual(1);
});
});
context('with float round bug with more than three nines consecutives', function() {
it ('is the first decimal rounded', function() {
// given
var number = 0.1999999999999998;
this.el.raty();
// when
var decimal = this.el.raty('_getFirstDecimal', number);
// then
expect(decimal).toEqual(2);
});
});
});