-
Notifications
You must be signed in to change notification settings - Fork 200
Expand file tree
/
Copy pathCarsTest.js
More file actions
66 lines (46 loc) · 1.91 KB
/
CarsTest.js
File metadata and controls
66 lines (46 loc) · 1.91 KB
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
import Cars from '../src/domain/Cars.js';
import Car from '../src/domain/Car.js';
describe('Cars 클래스 테스트', () => {
test('이름 배열로 여러 자동차를 생성한다', () => {
const names = ['pobi', 'woni', 'jun'];
const cars = new Cars(names);
expect(cars.getCars()).toHaveLength(3);
});
test('모든 자동차를 한 번씩 이동시킨다', () => {
const cars = new Cars(['pobi', 'woni']);
cars.moveAll([4, 3]);
const carsList = cars.getCars();
expect(carsList[0].getPosition()).toBe(1);
expect(carsList[1].getPosition()).toBe(0);
});
test('각 자동차에 다른 무작위 값을 적용한다', () => {
const cars = new Cars(['pobi', 'woni', 'jun']);
cars.moveAll([5, 2, 8]);
const carsList = cars.getCars();
expect(carsList[0].getPosition()).toBe(1);
expect(carsList[1].getPosition()).toBe(0);
expect(carsList[2].getPosition()).toBe(1);
});
test('최대 위치를 가진 자동차들을 찾는다 - 단독 우승자', () => {
const cars = new Cars(['pobi', 'woni', 'jun']);
cars.moveAll([5, 4, 3]);
cars.moveAll([6, 3, 2]);
const winners = cars.getWinners();
expect(winners).toHaveLength(1);
expect(winners[0].getName()).toBe('pobi');
});
test('최대 위치를 가진 자동차들을 찾는다 - 공동 우승자', () => {
const cars = new Cars(['pobi', 'woni', 'jun']);
cars.moveAll([5, 6, 3]);
cars.moveAll([6, 5, 2]);
const winners = cars.getWinners();
expect(winners).toHaveLength(2);
expect(winners.map(car => car.getName())).toEqual(expect.arrayContaining(['pobi', 'woni']));
});
test('모든 자동차가 같은 위치면 모두 우승자다', () => {
const cars = new Cars(['pobi', 'woni', 'jun']);
cars.moveAll([3, 3, 3]);
const winners = cars.getWinners();
expect(winners).toHaveLength(3);
});
});