Skip to content

Commit 7f89e21

Browse files
author
Tymoteusz
authored
Merge pull request #12 from 403-html/blank-files-and-in-tests
Add blank files for writing and testing your own code
2 parents 8a6772e + 661a855 commit 7f89e21

15 files changed

Lines changed: 158 additions & 116 deletions

File tree

RandSum0/__tests__/randsum.spec.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
1-
const genSum = require('../index')
1+
const genSum = require('../randsum')
22

3-
const sumArrElems = (arr) => arr.reduce((a, b) => a + b)
4-
5-
test('Providing "0" as argument should give an array that\'s empty', () => {
3+
test.skip('Providing "0" as argument should give an array that\'s empty', () => {
64
const arrayLength = 0
7-
const randomArray = new genSum(arrayLength).array
5+
const randomArray = new genSum(arrayLength)
86

9-
expect(randomArray.length).toBe(arrayLength)
10-
expect(randomArray).toEqual([])
7+
expect(randomArray.array.length).toBe(arrayLength)
8+
expect(randomArray.sumArray()).toEqual([])
119
})
1210

13-
test('Providing "1" as argument should give an array that contains "0"', () => {
11+
test.skip('Providing "1" as argument should give an array that contains "0"', () => {
1412
const arrayLength = 1
15-
const randomArray = new genSum(arrayLength).array
13+
const randomArray = new genSum(arrayLength)
1614

17-
expect(randomArray.length).toBe(arrayLength)
18-
expect(randomArray[0]).toEqual(0)
15+
expect(randomArray.array.length).toBe(arrayLength)
16+
expect(randomArray.sumArray()).toEqual(0)
1917
})
2018

21-
test('Array should have length 4, and values should sum to 0', () => {
19+
test.skip('Array should have length 4, and values should sum to 0', () => {
2220
const arrayLength = 4
23-
const randomArray = new genSum(arrayLength).array
21+
const randomArray = new genSum(arrayLength)
2422

25-
expect(randomArray.length).toBe(arrayLength)
26-
expect(sumArrElems(randomArray)).toEqual(0)
23+
expect(randomArray.array.length).toBe(arrayLength)
24+
expect(randomArray.sumArray()).toEqual(0)
2725
})
2826

29-
test('Array should have length 17, and values should sum to 0', () => {
27+
test.skip('Array should have length 17, and values should sum to 0', () => {
3028
const arrayLength = 17
31-
const randomArray = new genSum(arrayLength).array
29+
const randomArray = new genSum(arrayLength)
3230

33-
expect(randomArray.length).toBe(arrayLength)
34-
expect(sumArrElems(randomArray)).toEqual(0)
31+
expect(randomArray.array.length).toBe(arrayLength)
32+
expect(randomArray.sumArray()).toEqual(0)
3533
})

RandSum0/randsum.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* Random numbers which always sum to 0 */
2+
3+
class genSum {
4+
constructor(n) {
5+
this.array = []
6+
}
7+
sumArray() {}
8+
}
9+
10+
// Don't delete export
11+
module.exports = genSum

binary-tree/__tests__/binary-tree.spec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,39 @@ const getTreeOf = (arr) => {
1111
return tree
1212
}
1313

14-
test('empty input should get empty obj', () => {
14+
test.skip('empty input should get empty obj', () => {
1515
expect(getTreeOf(fixtures.zero.input)).toEqual(fixtures.zero.output)
1616
})
1717

18-
test('one input should match output tree', () => {
18+
test.skip('one input should match output tree', () => {
1919
expect(getTreeOf(fixtures.one.input)).toEqual(fixtures.one.output)
2020
})
2121

22-
test('one-smaller input should match output tree', () => {
22+
test.skip('one-smaller input should match output tree', () => {
2323
expect(getTreeOf(fixtures['one-smaller'].input)).toEqual(
2424
fixtures['one-smaller'].output
2525
)
2626
})
2727

28-
test('one-greater input should match output tree', () => {
28+
test.skip('one-greater input should match output tree', () => {
2929
expect(getTreeOf(fixtures['one-greater'].input)).toEqual(
3030
fixtures['one-greater'].output
3131
)
3232
})
3333

34-
test('greater-and-lower input should match output tree', () => {
34+
test.skip('greater-and-lower input should match output tree', () => {
3535
expect(getTreeOf(fixtures['greater-and-lower'].input)).toEqual(
3636
fixtures['greater-and-lower'].output
3737
)
3838
})
3939

40-
test('inherit-greater input should match output tree', () => {
40+
test.skip('inherit-greater input should match output tree', () => {
4141
expect(getTreeOf(fixtures['inherit-greater'].input)).toEqual(
4242
fixtures['inherit-greater'].output
4343
)
4444
})
4545

46-
test('many-values input should match output tree', () => {
46+
test.skip('many-values input should match output tree', () => {
4747
expect(getTreeOf(fixtures['many-values'].input)).toEqual(
4848
fixtures['many-values'].output
4949
)

binary-tree/my_tree_solution.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
class Tree {
2+
constructor() {}
3+
addValue(value) {
4+
if (!this.number && value) {
5+
this.number = value
6+
this.nodeIndex = 0
7+
} else if (this.number && value) {
8+
if (this.valueIndex) this.valueIndex += 1
9+
else this.valueIndex = 1
10+
// right, higher
11+
if (value > this.number) {
12+
if (this.right) this.right.addValue(value, this.valueIndex)
13+
if (!this.right) this.right = new Branch(value, this.valueIndex)
14+
}
15+
// left, lower
16+
if (value < this.number) {
17+
if (this.left) this.left.addValue(value, this.valueIndex)
18+
if (!this.left) this.left = new Branch(value, this.valueIndex)
19+
}
20+
}
21+
}
22+
}
23+
24+
class Branch {
25+
constructor(value, index) {
26+
this.number = value
27+
this.nodeIndex = index
28+
}
29+
addValue(value, index) {
30+
// right, higher
31+
if (value > this.number) {
32+
if (!this.right) this.right = new Branch(value, index)
33+
if (this.right) this.right.addValue(value, index)
34+
}
35+
// left, lower
36+
if (value < this.number) {
37+
if (!this.left) this.left = new Branch(value, index)
38+
if (this.left) this.left.addValue(value, index)
39+
}
40+
}
41+
}
42+
43+
module.exports = Tree

binary-tree/tree.js

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,11 @@
1+
/* Binary tree challenge
2+
You need to use method `addValue` with `value` (or other name for it) argument so it's already provided
3+
*/
4+
15
class Tree {
26
constructor() {}
3-
addValue(value) {
4-
if (!this.number && value) {
5-
this.number = value
6-
this.nodeIndex = 0
7-
} else if (this.number && value) {
8-
if (this.valueIndex) this.valueIndex += 1
9-
else this.valueIndex = 1
10-
// right, higher
11-
if (value > this.number) {
12-
if (this.right) this.right.addValue(value, this.valueIndex)
13-
if (!this.right) this.right = new Branch(value, this.valueIndex)
14-
}
15-
// left, lower
16-
if (value < this.number) {
17-
if (this.left) this.left.addValue(value, this.valueIndex)
18-
if (!this.left) this.left = new Branch(value, this.valueIndex)
19-
}
20-
}
21-
}
22-
}
23-
24-
class Branch {
25-
constructor(value, index) {
26-
this.number = value
27-
this.nodeIndex = index
28-
}
29-
addValue(value, index) {
30-
// right, higher
31-
if (value > this.number) {
32-
if (!this.right) this.right = new Branch(value, index)
33-
if (this.right) this.right.addValue(value, index)
34-
}
35-
// left, lower
36-
if (value < this.number) {
37-
if (!this.left) this.left = new Branch(value, index)
38-
if (this.left) this.left.addValue(value, index)
39-
}
40-
}
7+
addValue(value) {}
418
}
429

10+
// Don't delete export
4311
module.exports = Tree

fizzbuzz/__tests__/fizzbuzz.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ const fs = require('fs')
33
const fizzbuzz = require('../fizzbuzz')
44
const fixtures = JSON.parse(fs.readFileSync(__dirname + '/fixtures.json'))
55

6-
test('0 fizzbuzz should answer empty array', () => {
6+
test.skip('0 fizzbuzz should answer empty array', () => {
77
expect(fizzbuzz(0)).toStrictEqual(fixtures.a0)
88
})
99

10-
test('2 fizzbuzz should answer proper array', () => {
10+
test.skip('2 fizzbuzz should answer proper array', () => {
1111
expect(fizzbuzz(2)).toStrictEqual(fixtures.a2)
1212
})
1313

14-
test('3 fizzbuzz should answer proper array', () => {
14+
test.skip('3 fizzbuzz should answer proper array', () => {
1515
expect(fizzbuzz(3)).toStrictEqual(fixtures.a3)
1616
})
1717

18-
test('5 fizzbuzz should answer proper array', () => {
18+
test.skip('5 fizzbuzz should answer proper array', () => {
1919
expect(fizzbuzz(5)).toStrictEqual(fixtures.a5)
2020
})
2121

22-
test('17 fizzbuzz should answer proper array', () => {
22+
test.skip('17 fizzbuzz should answer proper array', () => {
2323
expect(fizzbuzz(17)).toStrictEqual(fixtures.a17)
2424
})

fizzbuzz/fizzbuzz.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
1-
const isDividiedBy = (num, multiplier) => {
2-
if (num % multiplier == 0) {
3-
return true
4-
}
5-
}
1+
/* FizzBuzz */
62

73
const fizzbuzz = (n) => {
8-
return new Array(n).fill().map((val, index) => {
9-
if (isDividiedBy(index + 1, 3) && isDividiedBy(index + 1, 5)) {
10-
return 'FizzBuzz'
11-
} else if (isDividiedBy(index + 1, 3) || isDividiedBy(index + 1, 5)) {
12-
if (isDividiedBy(index + 1, 3)) return 'Fizz'
13-
if (isDividiedBy(index + 1, 5)) return 'Buzz'
14-
}
15-
return index + 1
16-
})
4+
return result
175
}
186

7+
// Don't delete export
198
module.exports = fizzbuzz

fizzbuzz/my_fizzbuzz_solution.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const isDividiedBy = (num, multiplier) => {
2+
if (num % multiplier == 0) {
3+
return true
4+
}
5+
}
6+
7+
const fizzbuzz = (n) => {
8+
return new Array(n).fill().map((val, index) => {
9+
if (isDividiedBy(index + 1, 3) && isDividiedBy(index + 1, 5)) {
10+
return 'FizzBuzz'
11+
} else if (isDividiedBy(index + 1, 3) || isDividiedBy(index + 1, 5)) {
12+
if (isDividiedBy(index + 1, 3)) return 'Fizz'
13+
if (isDividiedBy(index + 1, 5)) return 'Buzz'
14+
}
15+
return index + 1
16+
})
17+
}
18+
19+
module.exports = fizzbuzz
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
const feeding = require('../pigeons')
22

3-
test('0 wheat should last for 0 pigeons', () => {
3+
test.skip('0 wheat should last for 0 pigeons', () => {
44
expect(feeding(0)).toBe(0)
55
})
66

7-
test('1 wheat should last for 1 pigeons', () => {
7+
test.skip('1 wheat should last for 1 pigeons', () => {
88
expect(feeding(1)).toBe(1)
99
})
1010

11-
test('2 wheat should last for 1 pigeons', () => {
11+
test.skip('2 wheat should last for 1 pigeons', () => {
1212
expect(feeding(2)).toBe(1)
1313
})
1414

15-
test('17 wheat should last for 10 pigeons', () => {
15+
test.skip('17 wheat should last for 10 pigeons', () => {
1616
expect(feeding(17)).toBe(10)
1717
})
1818

19-
test('100 wheat should last for 28 pigeons', () => {
19+
test.skip('100 wheat should last for 28 pigeons', () => {
2020
expect(feeding(100)).toBe(28)
2121
})

0 commit comments

Comments
 (0)