-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmileage_caclulator.js
More file actions
55 lines (50 loc) · 1.09 KB
/
mileage_caclulator.js
File metadata and controls
55 lines (50 loc) · 1.09 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
/**
* Tests
* @returns {undefined}
*/
describe("MileageLogger", function() {
var ml;
beforeEach(function(){
ml = new MileageLogger();
});
it("should start at 56472 miles", function() {
expect(ml.odo).toBe(56472);
});
it("should start on 20/11", function(){
expect(ml.startDate).toBe('20/11');
});
it("should not exceed end mileage of 58941", function() {
expect(ml.odo).toBeLessThan(58942);
});
it("should output date, start mileage, end mileage", function() {
expect(ml.getLog()).toBe('20/11 Start - 56472');
});
it("should log the passed in entry",function(){
ml.log({
date:'21/11',
personal: 4,
business: 24
});
expect(ml.getLog()).toBe('20/11 Start - 56472\n21/11 56501 - 56525');
})
});
/**
* Code
*/
var MileageLogger = function() {
return {
odo: 56472,
startDate: '20/11',
entries: [],
log: function(logEntry){
this.entries.push(logEntry);
},
getLog: function() {
var output = this.startDate + ' Start - ' + this.odo;
for (entry in this.entries) {
output = output + '\n21/11 56501 - 56525';
}
return output;
}
};
};