Skip to content

Commit 0850cec

Browse files
author
Jon Myrick
authored
Merge pull request CodewarsClone#88 from CodewarsClone/dataBaseEntry
Finished up most all work with testCtrl
2 parents 7b36c71 + 2060fff commit 0850cec

4 files changed

Lines changed: 67 additions & 85 deletions

File tree

KataParser.js

Lines changed: 36 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const _ = {
1818
return str
1919
},
2020

21+
22+
2123
cleanDesc(str) {
2224
str = str.replace(/\n/g, '\\n')
2325
.replace(/'/gi, `''`);
@@ -37,67 +39,58 @@ const _ = {
3739

3840
JSON(obj) {
3941
return JSON.stringify(obj)
40-
}
42+
},
43+
44+
cleanExample(str) {
45+
str = str.replace(/\n\s*\./g, `.`)
46+
.replace(/\n/g, ` \\n`)
47+
.replace(/"/gi, `'`)
48+
.replace(/'/gi, `''`);
49+
return JSON.stringify([
50+
{test: str}
51+
]).replace(/\\\\n/g, `\\n`)
52+
},
4153

4254
};
4355

4456
// Paste the languages into the array
4557
let languages = [
46-
`JavaScript`,
47-
`CoffeeScript`,
48-
`Crystal`,
49-
`Python`,
50-
`Ruby`
58+
``,
5159
];
5260
// Paste the tags into the array
5361
let tags = [
54-
`FUNDAMENTALS`,
55-
`STRINGS`,
62+
``,
5663
];
5764

5865
// Paste the Test Suite here
5966
let tests = [
6067
`
61-
Test.describe('tests', _ => {
62-
Test.it('fixed tests', _ => {
63-
Test.assertEquals(kebabize('myCamelCasedString'), 'my-camel-cased-string');
64-
Test.assertEquals(kebabize('myCamelHas3Humps'), 'my-camel-has-humps');
65-
});
66-
67-
Test.it('random tests', _ => {
68-
function fixture (str) {
69-
return str.replace(/\d/g,'')
70-
.split(/(?=[A-Z])/).map(s => s.toLowerCase()).join('-')
71-
}
72-
73-
for (let i = 0; i <= 100; i += 1) {
74-
let token = Test.randomToken();
75-
76-
let camel = token.split('').map(c => {
77-
const rand = Math.random();
78-
return rand > 0.9 ? c.toUpperCase() : c
79-
}).join('')
80-
81-
Test.assertEquals(kebabize(camel), fixture(camel));
82-
}
83-
});
84-
});
8568
`,
86-
8769
];
8870

8971

9072
// Paste the example script here
91-
let examples = [
92-
`Test.assertSimilar(generateRange(2, 10, 2), [2,4,6,8,10]);`,
93-
`Test.assertSimilar(generateRange(1, 10, 1), [1,2,3,4,5,6,7,8,9,10]);`,
94-
];
73+
let examples =
74+
`Test.describe("generateRange(2, 10, 2)", function() {
75+
Test.assertSimilar(generateRange(2, 10, 2), [2,4,6,8,10]);
76+
});`;
9577

9678
// Introduction to the Kata Here
9779
let description =
98-
`
99-
100-
`;
80+
`Implement a function named generateRange(min, max, step), which takes three arguments and generates a range of integers from min to max, with the step. The first integer is the minimum value, the second is the maximum of the range and the third is the step. (min < max)
81+
82+
Task
83+
84+
Implement a function named
85+
86+
generateRange(2, 10, 2) // should return array of [2,4,6,8,10]
87+
generateRange(1, 10, 3) // should return array of [1,4,7,10]
88+
, which takes three arguments and generates a range of integers from min to max, with given step. The first is minimum value, second is maximum of range and the third is step.
89+
90+
Note
91+
92+
min < max
93+
step > 0`;
10194
// Paste the starting script here
10295
let startScript = ``;
10396

@@ -107,11 +100,9 @@ let winScript = `
107100
108101
`;
109102

110-
103+
// Past a solution here and it will corrently parse it into the console for you
111104
let solution = `
112-
function descendingOrder(n){
113-
return parseInt(n.toString().split('').sort((a, b) => b - a).join(''));
114-
}
105+
115106
116107
`
117108

@@ -131,7 +122,7 @@ console.log(_.cleanStr(startScript));
131122
console.log('\nDescription');
132123
console.log(_.cleanDesc(description));
133124
console.log('\n\n\nExampes');
134-
console.log(_.testObjectify(examples));
125+
console.log(_.cleanExample(examples));
135126
console.log('\nTests');
136127
console.log(_.testObjectify(tests));
137128

controllers/testCtrl.js

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const util = require('util');
1717
function timeParser(str) {
1818
str = str.replace(/<COMPLETEDIN::>/, '');
1919
if (!parseInt(str)) {
20-
return 0
20+
return 1
2121
} else {
2222
return parseInt(str)
2323
}
@@ -69,42 +69,32 @@ function objectifer(arr) {
6969

7070

7171

72-
function nester(arr) {
73-
let count = 0;
72+
function nester(array) {
7473
let testCount = 0;
7574
let passCount = 0;
76-
console.log(arr.length);
77-
for (let i = arr.length - 1; i >= 0; i--) {
78-
if (arr[i]) {
79-
if (arr[i].type == 'test') {
75+
for (let i = array.length - 1; i >= 0; i--) {
76+
if (array[i]) {
77+
if (array[i].type == 'test') {
8078
testCount += 1;
81-
if (arr[i].passed == true) passCount += 1
79+
if (array[i].passed == true) passCount += 1
8280
}
83-
if (arr[i].type === 'describe' || arr[i].type === 'it') {
84-
count += 1;
81+
if (array[i].type === 'describe' || array[i].type === 'it') {
8582
let j = i + 1;
8683
let recurs = true;
8784
while (recurs) {
88-
if (arr[j].type !== 'completed') {
89-
if (arr[j].type == 'it') count += 1;
90-
arr[i].nest.push(arr.splice(j, 1)[0])
85+
if (array[j].type !== 'completed') {
86+
array[i].nest.push(array.splice(j, 1)[0])
9187
} else {
92-
count -= 1;
93-
arr.splice(j, 1);
88+
array[i].time = array[j].time;
89+
array.splice(j, 1);
9490
recurs = false
9591
}
9692
}
9793
}
98-
} else {
99-
100-
101-
console.log('didn\'t have type');
102-
console.log(arr[i]);
10394
}
104-
10595
}
10696
return {
107-
nest: arr,
97+
nest: array,
10898
testCount: testCount,
10999
passCount: passCount
110100
}
@@ -115,7 +105,6 @@ function nester(arr) {
115105
function testRunner(script, test) {
116106
let defer = Q.defer();
117107

118-
119108
exec(`docker run --rm codewars/node-runner run -l javascript -c "${script}" -t cw -f "${test}"`,
120109
(err, stdOut, stdErr) => {
121110
if (err) console.log(err);
@@ -126,6 +115,7 @@ function testRunner(script, test) {
126115
let output = stdOut.split(/\n/g);
127116
for (let i = output.length - 1; i >= 0; i--) if (output[i] === '') output.splice(i, 1);
128117
let newArr = objectifer(output);
118+
// console.log(output);
129119
newArr = nester(newArr);
130120
defer.resolve(newArr);
131121
return
@@ -148,19 +138,18 @@ module.exports = {
148138

149139
testRunner(body.script, test).then((response) => {
150140
res.json(response);
151-
console.log(util.inspect(response, false, null));
141+
// console.log(util.inspect(response, false, null));
152142
return
153143
});
154144
});
155145
},
156146

157147
testExamplesKata: (req, res, next) => {
158148
let body = req.body;
159-
console.log(body.script);
160149

161150
testRunner(body.script, body.examples).then((response) => {
162151
res.json(response);
163-
console.log(util.inspect(response, false, null));
152+
// console.log(util.inspect(response, false, null));
164153
return
165154
});
166155
}

0 commit comments

Comments
 (0)