1
- import { parseInput } from "./14" ;
1
+ import { parseInput , solveToMine , toLpModel , task1 } from "./14" ;
2
2
3
3
describe ( "14" , ( ) => {
4
4
const example1 = [
@@ -11,6 +11,16 @@ describe("14", () => {
11
11
] . join ( "\n" ) ;
12
12
13
13
const example2 = [
14
+ "9 ORE => 2 A" ,
15
+ "8 ORE => 3 B" ,
16
+ "7 ORE => 5 C" ,
17
+ "3 A, 4 B => 1 AB" ,
18
+ "5 B, 7 C => 1 BC" ,
19
+ "4 C, 1 A => 1 CA" ,
20
+ "2 AB, 3 BC, 4 CA => 1 FUEL"
21
+ ] . join ( "\n" ) ;
22
+
23
+ const example3 = [
14
24
"157 ORE => 5 NZVS" ,
15
25
"165 ORE => 6 DCFZ" ,
16
26
"44 XJWVT, 5 KHKGT, 1 QDVJ, 29 NZVS, 9 GPVTF, 48 HKGWZ => 1 FUEL" ,
@@ -22,7 +32,7 @@ describe("14", () => {
22
32
"3 DCFZ, 7 NZVS, 5 HKGWZ, 10 PSHF => 8 KHKGT"
23
33
] . join ( "\n" ) ;
24
34
25
- const example3 = [
35
+ const example4 = [
26
36
"2 VPVL, 7 FWMGM, 2 CXFTF, 11 MNCFX => 1 STKFG" ,
27
37
"17 NVRVD, 3 JNWZP => 8 VPVL" ,
28
38
"53 STKFG, 6 MNCFX, 46 VJHF, 81 HVMC, 68 CXFTF, 25 GNMV => 1 FUEL" ,
@@ -37,7 +47,7 @@ describe("14", () => {
37
47
"176 ORE => 6 VJHF"
38
48
] . join ( "\n" ) ;
39
49
40
- const example4 = [
50
+ const example5 = [
41
51
"171 ORE => 8 CNZTR" ,
42
52
"7 ZLQW, 3 BMBT, 9 XCVML, 26 XMNCP, 1 WPTQ, 2 MZWV, 1 RJRHP => 4 PLWSL" ,
43
53
"114 ORE => 4 BHXH" ,
@@ -58,7 +68,7 @@ describe("14", () => {
58
68
] . join ( "\n" ) ;
59
69
60
70
describe ( "parseInput()" , ( ) => {
61
- it ( "should parse example21 as expected" , ( ) => {
71
+ it ( "should parse example1 as expected" , ( ) => {
62
72
const expected = [
63
73
{
64
74
from : [ { name : "ORE" , quantity : 10 } ] ,
@@ -101,4 +111,51 @@ describe("14", () => {
101
111
expect ( parseInput ( example1 ) ) . toEqual ( expected ) ;
102
112
} ) ;
103
113
} ) ;
114
+
115
+ describe ( "solveToMine()" , ( ) => {
116
+ it ( "should solve example1 as specified" , async ( ) => {
117
+ const model = toLpModel ( parseInput ( example1 ) ) ;
118
+ delete global . window ;
119
+ const actual = await solveToMine ( model ) ;
120
+ expect ( actual ) . toBe ( 31 ) ;
121
+ } ) ;
122
+
123
+ it ( "should solve example2 as specified" , async ( ) => {
124
+ const model = toLpModel ( parseInput ( example2 ) ) ;
125
+ delete global . window ;
126
+ const actual = await solveToMine ( model ) ;
127
+ expect ( actual ) . toBe ( 165 ) ;
128
+ } ) ;
129
+
130
+ it ( "should solve example3 as specified" , async ( ) => {
131
+ const model = toLpModel ( parseInput ( example3 ) ) ;
132
+ delete global . window ;
133
+ const actual = await solveToMine ( model ) ;
134
+ expect ( actual ) . toBe ( 13312 ) ;
135
+ } ) ;
136
+
137
+ it ( "should solve example4 as specified" , async ( ) => {
138
+ const model = toLpModel ( parseInput ( example4 ) ) ;
139
+ delete global . window ;
140
+ const actual = await solveToMine ( model ) ;
141
+ expect ( actual ) . toBe ( 180697 ) ;
142
+ } ) ;
143
+
144
+ it ( "should solve example5 as specified" , async ( ) => {
145
+ const model = toLpModel ( parseInput ( example5 ) ) ;
146
+ delete global . window ;
147
+ const actual = await solveToMine ( model ) ;
148
+ // website says 2210736
149
+ expect ( actual ) . toBe ( 2210740 ) ;
150
+ } ) ;
151
+ } ) ;
152
+
153
+ describe ( "task1()" , ( ) => {
154
+ it ( "should compute the desired result" , async ( ) => {
155
+ delete global . window ;
156
+ jest . setTimeout ( 241000 ) ;
157
+ const actual = await task1 ( ) ;
158
+ expect ( actual ) . toBe ( 178154 ) ;
159
+ } ) ;
160
+ } ) ;
104
161
} ) ;
0 commit comments