Skip to content

Commit 20784e7

Browse files
committed
up
1 parent d7d25f4 commit 20784e7

File tree

48 files changed

+293
-388
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+293
-388
lines changed

1-js/03-code-quality/05-testing/3-pow-test-wrong/solution.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
Этот тест демонстрирует один из соблазнов, которые ожидают начинающего автора тестов.
1+
The test demonstrates one of temptations a developer meets when writing tests.
22

3-
Вместо того, чтобы написать три различных теста, он изложил их в виде одного потока вычислений, с несколькими `assert`.
3+
What we have here is actually 3 tests, but layed out as a single function with 3 asserts.
44

5-
Иногда так написать легче и проще, однако при ошибке в тесте гораздо менее очевидно, что же пошло не так.
5+
Sometimes it's easier to write this way, but if an error occurs, it's much less obvious what went wrong.
6+
7+
If an error happens inside a complex execution flow, then we'll have to figure out what was the data at that point.
8+
9+
TODO
610

711
Если в сложном тесте произошла ошибка где-то посередине потока вычислений, то придётся выяснять, какие конкретно были входные и выходные данные на этот момент, то есть по сути -- отлаживать код самого теста.
812

1-js/03-code-quality/05-testing/3-pow-test-wrong/task.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@ importance: 5
22

33
---
44

5-
# Что не так в тесте?
5+
# What's wrong in the test?
66

7-
Что не так в этом тесте функции `pow`?
7+
What's wrong in the test of `pow` below?
88

99
```js
10-
it("Возводит x в степень n", function() {
11-
var x = 5;
10+
it("Raises x to the power n", function() {
11+
let x = 5;
1212

13-
var result = x;
13+
let result = x;
1414
assert.equal(pow(x, 1), result);
1515

16-
var result *= x;
16+
result *= x;
1717
assert.equal(pow(x, 2), result);
1818

19-
var result *= x;
19+
result *= x;
2020
assert.equal(pow(x, 3), result);
2121
});
2222
```
2323

24-
P.S. Синтаксически он верен и работает, но спроектирован неправильно.
24+
P.S. Syntactically it's correct and passes.
Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
Да, возможны.
1+
Yes, it's possible.
22

3-
Они должны возвращать одинаковый объект. При этом если функция возвращает объект, то `this` не используется.
3+
If a function returns an object then `new` returns it instead of `this`.
44

5-
Например, они могут вернуть один и тот же объект `obj`, определённый снаружи:
5+
So thay can, for instance, return the same externally defined object `obj`:
66

77
```js run no-beautify
8-
var obj = {};
8+
let obj = {};
99

1010
function A() { return obj; }
1111
function B() { return obj; }
1212

13-
var a = new A;
14-
var b = new B;
15-
16-
alert( a == b ); // true
13+
alert( new A() == new B() ); // true
1714
```
18-

1-js/04-object-basics/06-constructor-new/1-two-functions-one-object/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 2
22

33
---
44

5-
# Две функции один объект
5+
# Two functions -- one object
66

7-
Возможны ли такие функции `A` и `B` в примере ниже, что соответствующие объекты `a,b` равны (см. код ниже)?
7+
Is it possible to create functions `A` and `B` such as `new A()==new B()`?
88

99
```js no-beautify
1010
function A() { ... }
@@ -16,4 +16,4 @@ var b = new B;
1616
alert( a == b ); // true
1717
```
1818

19-
Если да -- приведите пример кода с такими функциями.
19+
If it is, then provide an example of their code.
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
sinon.stub(window, "prompt")
2-
3-
prompt.onCall(0).returns("2");
4-
prompt.onCall(1).returns("3");
51

62
describe("calculator", function() {
7-
var calculator;
3+
let calculator;
84
before(function() {
5+
sinon.stub(window, "prompt")
6+
7+
prompt.onCall(0).returns("2");
8+
prompt.onCall(1).returns("3");
9+
910
calculator = new Calculator();
1011
calculator.read();
1112
});
1213

13-
it("при вводе 2 и 3 сумма равна 5", function() {
14+
it("when 2 and 3 are entered, the sum is 5", function() {
1415
assert.equal(calculator.sum(), 5);
1516
});
1617

17-
it("при вводе 2 и 3 произведение равно 6", function() {
18+
it("when 2 and 3 are entered, the product is 6", function() {
1819
assert.equal(calculator.mul(), 6);
1920
});
2021

22+
after(function() {
23+
prompt.restore();
24+
});
2125
});
22-
23-
after(function() {
24-
prompt.restore();
25-
});

1-js/04-object-basics/06-constructor-new/2-calculator-constructor/solution.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ function Calculator() {
1717
};
1818
}
1919

20-
var calculator = new Calculator();
20+
let calculator = new Calculator();
2121
calculator.read();
2222

23-
alert( "Сумма=" + calculator.sum() );
24-
alert( "Произведение=" + calculator.mul() );
23+
alert( "Sum=" + calculator.sum() );
24+
alert( "Mul=" + calculator.mul() );
2525
```
26-

1-js/04-object-basics/06-constructor-new/2-calculator-constructor/task.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,22 @@ importance: 5
22

33
---
44

5-
# Создать Calculator при помощи конструктора
5+
# Create new Calculator
66

7-
Напишите *функцию-конструктор* `Calculator`, которая создает объект с тремя методами:
7+
Create a constructor function `Calculator` that creates objects with 3 methods:
88

9-
- Метод `read()` запрашивает два значения при помощи `prompt` и запоминает их в свойствах объекта.
10-
- Метод `sum()` возвращает сумму запомненных свойств.
11-
- Метод `mul()` возвращает произведение запомненных свойств.
9+
- `read()` asks for two values using `prompt` and remembers them in object properties.
10+
- `sum()` returns the sum of these properties.
11+
- `mul()` returns the multiplication product of these properties.
1212

13-
Пример использования:
13+
For instance:
1414

1515
```js
16-
var calculator = new Calculator();
16+
let calculator = new Calculator();
1717
calculator.read();
1818

19-
alert( "Сумма=" + calculator.sum() );
20-
alert( "Произведение=" + calculator.mul() );
19+
alert( "Sum=" + calculator.sum() );
20+
alert( "Mul=" + calculator.mul() );
2121
```
2222

2323
[demo]
24-

1-js/04-object-basics/06-constructor-new/3-accumulator/_js.view/solution.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ function Accumulator(startingValue) {
22
this.value = startingValue;
33

44
this.read = function() {
5-
this.value += +prompt('Сколько добавлять будем?', 0);
5+
this.value += +prompt('How much to add?', 0);
66
};
77

8-
}
8+
}
Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
describe("Accumulator(1)", function() {
2-
var accumulator;
3-
before(function() {
4-
accumulator = new Accumulator(1);
5-
});
1+
describe("Accumulator", function() {
62

73
beforeEach(function() {
84
sinon.stub(window, "prompt")
@@ -12,26 +8,23 @@ describe("Accumulator(1)", function() {
128
prompt.restore();
139
});
1410

15-
it("начальное значение 1", function() {
11+
it("initial value is the argument of the constructor", function() {
12+
let accumulator = new Accumulator(1);
13+
1614
assert.equal(accumulator.value, 1);
1715
});
1816

19-
it("после ввода 0 значение 1", function() {
17+
it("after reading 0, the value is 1", function() {
18+
let accumulator = new Accumulator(1);
2019
prompt.returns("0");
2120
accumulator.read();
2221
assert.equal(accumulator.value, 1);
2322
});
2423

25-
it("после ввода 1 значение 2", function() {
24+
it("after reading 1, the value is 2", function() {
25+
let accumulator = new Accumulator(1);
2626
prompt.returns("1");
2727
accumulator.read();
2828
assert.equal(accumulator.value, 2);
2929
});
30-
31-
it("после ввода 2 значение 4", function() {
32-
prompt.returns("2");
33-
accumulator.read();
34-
assert.equal(accumulator.value, 4);
35-
});
36-
37-
});
30+
});

1-js/04-object-basics/06-constructor-new/3-accumulator/solution.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ function Accumulator(startingValue) {
55
this.value = startingValue;
66

77
this.read = function() {
8-
this.value += +prompt('Сколько добавлять будем?', 0);
8+
this.value += +prompt('How much to add?', 0);
99
};
1010

1111
}
1212

13-
var accumulator = new Accumulator(1);
13+
let accumulator = new Accumulator(1);
1414
accumulator.read();
1515
accumulator.read();
16-
alert( accumulator.value );
16+
alert(accumulator.value);
1717
```
18-

0 commit comments

Comments
 (0)