Skip to content

Commit db1f866

Browse files
committed
started chapter examples
1 parent a323274 commit db1f866

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function processor(transmission) {
2+
if (transmission.indexOf("::") < 0) {
3+
// Data is invalid
4+
return -1;
5+
}
6+
let parts = transmission.split("::");
7+
let rawData = parts[1];
8+
if (rawData[0] !== "<") {
9+
rawData = -1;
10+
}
11+
return {
12+
id: Number(parts[0]),
13+
rawData: rawData
14+
};
15+
}
16+
17+
module.exports = processor;
Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
1+
const processor = require('./processor.js');
2+
13
describe("transmission processor", function() {
24

3-
// TODO: put tests here
4-
5-
});
5+
test("takes a string returns an object", function() {
6+
let result = processor("9701::<489584872710>");
7+
expect(typeof result).toBe("object");
8+
});
9+
10+
test("returns -1 if '::' not found", function() {
11+
let result = processor("9701<489584872710>");
12+
expect(result).toBe(-1);
13+
});
14+
15+
test("returns id in object", function() {
16+
let result = processor("9701::<489584872710>");
17+
expect(result.id).not.toBeUndefined();
18+
});
19+
20+
test("converts id to a number", function() {
21+
let result = processor("9701::<489584872710>");
22+
expect(result.id).toBe(9701);
23+
});
24+
25+
test("returns rawData in object", () => {
26+
let result = processor("9701::<487297403495720912>");
27+
expect(result.rawData).not.toBeUndefined();
28+
});
29+
30+
test("returns -1 for rawData if missing < at position 0", function() {
31+
let result = processor("9701::487297403495720912>");
32+
expect(result.rawData).toBe(-1);
33+
});
34+
35+
36+
});

0 commit comments

Comments
 (0)