-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathligth.test.ts
70 lines (55 loc) · 1.7 KB
/
ligth.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { Light, BrightLight } from './ligth';
describe("Ligth", () => {
test("init", () => {
const ligth = new Light();
expect(ligth.isOn).toBe(false);
})
test("turnOn should turn on", () => {
const ligth = new Light();
ligth.turnOn();
expect(ligth.isOn).toBe(true);
})
test("turnOff should turn off", () => {
const ligth = new Light();
ligth.turnOn();
ligth.turnOff();
expect(ligth.isOn).toBe(false);
})
test("toggle should turn on then off", () => {
const ligth = new Light();
ligth.toggle();
expect(ligth.isOn).toBe(true);
ligth.toggle();
expect(ligth.isOn).toBe(false);
})
})
describe("BrightLigth", () => {
test("init", () => {
const ligth = new BrightLight();
expect(ligth.brightness).toBe(0);
expect(ligth.isOn).toBe(false);
})
test("turnOn should increment brightness", () => {
const ligth = new BrightLight();
ligth.turnOn();
expect(ligth.brightness).toBe(1);
expect(ligth.isOn).toBe(true);
ligth.turnOn();
expect(ligth.brightness).toBe(2);
expect(ligth.isOn).toBe(true);
})
test("turnOff should decrement brightness with a minimum of 0", () => {
const ligth = new BrightLight();
ligth.turnOn();
ligth.turnOff();
expect(ligth.brightness).toBe(0);
expect(ligth.isOn).toBe(false);
ligth.turnOff();
expect(ligth.brightness).toBe(0);
})
test("toggle should increase brightness by 2", () => {
const ligth = new BrightLight();
ligth.toggle();
expect(ligth.brightness).toBe(2);
})
})