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
71
72
73
74
75
76
77
78
79
|
import { SFItem, derive, add, BaseComponents, get } from './deconstruct';
test('base returns 1', () => {
const item: SFItem = {
name: 'Iron Ingot',
id: 'iron_ingot',
type: 'base'
};
const expected = new Map([[item.id, 30]]);
expect(derive(item)).toMatchObject(expected);
});
test('add', () => {
const curr: BaseComponents = [['iron_ingot', 30]];
const val = add(['iron_ingot', 10], curr);
const expected = [['iron_ingot', 40]];
expect(val).toMatchObject(expected);
});
test('add2', () => {
const curr: BaseComponents = [['copper_ore', 10], ['iron_ingot', 30]];
const val = add(['iron_ingot', 10], curr);
const expected = [['copper_ore', 10], ['iron_ingot', 40]];
expect(val).toMatchObject(expected);
});
test('get undefined', () => {
const ITEMS: Array<SFItem> = [
{
name: 'Iron Ingot',
id: 'iron_ingot',
type: 'base'
},
];
const val = get('iron_plate', ITEMS);
const expected = undefined;
expect(val).toBe(expected);
});
test('get existing', () => {
const ITEMS: Array<SFItem> = [
{
name: 'Iron Ingot',
id: 'iron_ingot',
type: 'base'
},
];
const val = get('iron_ingot', ITEMS);
const expected = ITEMS[0];
expect(val).toMatchObject(expected);
});
test('level 1', () => {
const item: SFItem = {
name: 'Iron Plate',
id: 'iron_plate',
type: 'derived',
recipe: {
in: [['iron_ingot', 30]],
out: 20
}
};
const expected = [['iron_ingot', 30]];
expect(derive(item)).toMatchObject(expected);
});
test('level 2', () => {
const item: SFItem = {
name: 'Screw',
id: 'screw',
type: 'derived',
recipe: {
in: [['iron_rod', 10]],
out: 40
}
};
const expected = [['iron_ingot', 40]];
expect(derive(item)).toMatchObject(expected);
});
|