Skip to content

Commit 2aa4e5f

Browse files
nkbtTanya Butenko
authored andcommitted
2018-05-24 (#61)
* tests * 2018-05-24 Roman numbers
1 parent 7e2107c commit 2aa4e5f

File tree

4 files changed

+235
-1
lines changed

4 files changed

+235
-1
lines changed

2018/05-04-2018/berlin-clock-kata/test.js

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function fiveHoursStatus(hours){
1111
const a = Math.floor(hours / 5);
1212
if (a == 0)
1313
return "OOOO";
14-
else if (a == 1)
14+
else if (a == 1)
1515
return "ROOO";
1616
else if (a == 2)
1717
return "RROO";
@@ -21,6 +21,40 @@ function fiveHoursStatus(hours){
2121
return "RRRR";
2222
}
2323

24+
function oneHourStatus(hours) {
25+
const a = hours % 5;
26+
if(a == 1)
27+
return "ROOO";
28+
else if (a == 2)
29+
return "RROO";
30+
else if (a == 3)
31+
return "RRRO";
32+
else if (a == 4)
33+
return "RRRR";
34+
else
35+
return "OOOO";
36+
}
37+
38+
function fiveMinuteStatus(minutes) {
39+
const b = Math.floor(minutes /5);
40+
let string = "OOOOOOOOOOO";
41+
if (b ==12) {
42+
return string;
43+
} else {
44+
let array = string.split("");
45+
for (var i = 0; i < b; i++){
46+
if ((i+1)%3 == 0){
47+
array[i] = "R";
48+
} else {
49+
array[i] = "Y";
50+
}
51+
}
52+
return array.join("");
53+
}
54+
}
55+
56+
57+
2458
describe("Berlin Clock", () => {
2559

2660
it("Given a 1 second, returns OFF", () => {
@@ -38,19 +72,94 @@ describe("Berlin Clock", () => {
3872
it("Given 1 hour, returns OOOO", () => {
3973
assert.equal(fiveHoursStatus(1), "OOOO")
4074
});
75+
4176
it("Given 5 hour, returns ROOO", () => {
4277
assert.equal(fiveHoursStatus(5), "ROOO")
4378
});
79+
4480
it("Given 10 hour, returns RROO", () => {
4581
assert.equal(fiveHoursStatus(10), "RROO")
4682
});
83+
4784
it("Given 12 hour, returns RROO", () => {
4885
assert.equal(fiveHoursStatus(12), "RROO")
4986
});
87+
5088
it("Given 15 hour, returns RRRO", () => {
5189
assert.equal(fiveHoursStatus(15), "RRRO")
5290
});
91+
5392
it("Given 20 hour, returns RRRR", () => {
5493
assert.equal(fiveHoursStatus(20), "RRRR")
5594
});
95+
96+
it("Given 1 hour, returns ROOO", () => {
97+
assert.equal(oneHourStatus(1), "ROOO")
98+
});
99+
100+
it("Given 2 hours, returns RROO", () => {
101+
assert.equal(oneHourStatus(2), "RROO")
102+
});
103+
104+
it("Given 3 hours, returns RRRO", () => {
105+
assert.equal(oneHourStatus(3), "RRRO")
106+
});
107+
108+
it("Given 4 hours, returns RRRR", () => {
109+
assert.equal(oneHourStatus(4), "RRRR")
110+
});
111+
112+
it("Given 5 hours, returns OOOO", () => {
113+
assert.equal(oneHourStatus(5), "OOOO")
114+
});
115+
116+
it(" Given 5 minutes, returns YOOOOOOOOOO", ()=> {
117+
assert.equal(fiveMinuteStatus(5), "YOOOOOOOOOO")
118+
});
119+
120+
it(" Given 10 minutes, returns YYOOOOOOOOO", ()=> {
121+
assert.equal(fiveMinuteStatus(10), "YYOOOOOOOOO")
122+
});
123+
124+
it(" Given 15 minutes, returns YYROOOOOOOO", ()=> {
125+
assert.equal(fiveMinuteStatus(15), "YYROOOOOOOO")
126+
});
127+
128+
it(" Given 20 minutes, returns YYRYOOOOOOO", ()=> {
129+
assert.equal(fiveMinuteStatus(20), "YYRYOOOOOOO")
130+
});
131+
132+
it(" Given 25 minutes, returns YYRYYOOOOOO", ()=> {
133+
assert.equal(fiveMinuteStatus(25), "YYRYYOOOOOO")
134+
});
135+
136+
it(" Given 30 minutes, returns YYRYYROOOOO", ()=> {
137+
assert.equal(fiveMinuteStatus(30), "YYRYYROOOOO")
138+
});
139+
140+
it(" Given 35 minutes, returns YYRYYRYOOOO", ()=> {
141+
assert.equal(fiveMinuteStatus(35), "YYRYYRYOOOO")
142+
});
143+
144+
it(" Given 40 minutes, returns YYRYYRYYOOO", ()=> {
145+
assert.equal(fiveMinuteStatus(40), "YYRYYRYYOOO")
146+
});
147+
148+
it(" Given 45 minutes, returns YYRYYRYYROO", ()=> {
149+
assert.equal(fiveMinuteStatus(45), "YYRYYRYYROO")
150+
});
151+
152+
it(" Given 50 minutes, returns YYRYYRYYRYO", ()=> {
153+
assert.equal(fiveMinuteStatus(50), "YYRYYRYYRYO")
154+
});
155+
156+
it(" Given 55 minutes, returns YYRYYRYYRYY", ()=> {
157+
assert.equal(fiveMinuteStatus(55), "YYRYYRYYRYY")
158+
});
159+
160+
it(" Given 60 minutes, returns OOOOOOOOOOO", ()=> {
161+
assert.equal(fiveMinuteStatus(60), "OOOOOOOOOOO")
162+
});
163+
164+
56165
});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Roman Numerals
2+
3+
## Problem Description
4+
5+
The Romans were a clever bunch. They conquered most of Europe and ruled it for
6+
hundreds of years. They invented concrete and straight roads and even bikinis.
7+
One thing they never discovered though was the number zero. This made writing
8+
and dating extensive histories of their exploits slightly more challenging, but
9+
the system of numbers they came up with is still in use today. For example the
10+
BBC uses Roman numerals to date their programmes.
11+
12+
The Romans wrote numbers using letters - I, V, X, L, C, D, M. (notice these
13+
letters have lots of straight lines and are hence easy to hack into stone
14+
tablets).
15+
16+
The Kata says you should write a function to convert from normal numbers to
17+
Roman Numerals. E.g.:
18+
19+
1 -> I
20+
10 -> X
21+
7 -> VII
22+
23+
For a full description of how it works, take a look at
24+
https://en.wikipedia.org/wiki/Roman_numerals
25+
26+
There is no need to be able to convert numbers larger than about 3000 (the
27+
Romans themselves didn't tend to go any higher). Note that you can't write
28+
numerals like "IM" for 999. Wikipedia says: Modern Roman numerals (…) are
29+
written by expressing each digit separately starting with the left most digit
30+
and skipping any digit with a value of zero. To see this in practice, consider
31+
the (…) example of 1990. In Roman numerals 1990 is rendered: 1000=M, 900=CM,
32+
90=XC; resulting in MCMXC. 2008 is written as 2000=MM, 8=VIII; or MMVIII.
33+
34+
Here are a few more examples you can use as test cases:
35+
36+
1954 -> MCMLIV
37+
1990 -> MCMXC
38+
2014 -> MMXIV
39+
40+
# Extension:
41+
42+
Write a function to convert in the other direction, i.e. numeral to digit.
43+
44+
From: http://codingdojo.org/kata/RomanNumerals/
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "roman-numerals",
3+
"scripts": {
4+
"test": "mocha -w"
5+
},
6+
"devDependencies": {
7+
"mocha": "3.2.0"
8+
}
9+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
const assert = require('assert');
2+
3+
function convertToRoman(digital) {
4+
const numbers = {1: "I", 5: "V", 10: "X", 50: "L", 100: "C", 500: "D", 1000: "M"};
5+
if (numbers[digital]) {
6+
console.log(digital);
7+
console.log(numbers[digital]);
8+
return numbers[digital];
9+
} else {
10+
return "II";
11+
}
12+
13+
// switch (digital){
14+
// case 1:return "I";
15+
// break;
16+
// case 5:return "V";
17+
// break;
18+
// case 50:return "L";
19+
// break;
20+
// default: return "X";
21+
//}
22+
}
23+
24+
25+
describe('Roman Numerals', () => {
26+
27+
it('works', () => {
28+
const expected = true;
29+
const actual = true;
30+
31+
assert.equal(actual, expected);
32+
});
33+
34+
it('Should convert 1 to "I"', () => {
35+
const expected = 'I';
36+
const actual = convertToRoman(1);
37+
38+
assert.equal(actual, expected);
39+
});
40+
41+
it('Should convert 2 to "II"', () => {
42+
const expected = 'II';
43+
const actual = convertToRoman(2);
44+
assert.equal(actual, expected);
45+
});
46+
47+
it('Should convert 5 to "V"', () => {
48+
const expected = 'V';
49+
const actual = convertToRoman(5);
50+
51+
assert.equal(actual, expected);
52+
});
53+
54+
it('Should convert 10 to "X"', () => {
55+
assert.equal(convertToRoman(10), 'X');
56+
});
57+
58+
it('Should convert 50 to "L"', () => {
59+
assert.equal(convertToRoman(50), 'L');
60+
});
61+
it('Should convert 100 to "C"', () => {
62+
assert.equal(convertToRoman(100), 'C');
63+
});
64+
it('Should convert 500 to "D"', () => {
65+
assert.equal(convertToRoman(500), 'D');
66+
});
67+
it('Should convert 1000 to "M"', () => {
68+
assert.equal(convertToRoman(1000), 'M');
69+
});
70+
});
71+
72+

0 commit comments

Comments
 (0)