forked from NebulaSS13/Nebula
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatmospherics_tests.dm
More file actions
418 lines (351 loc) · 14.2 KB
/
atmospherics_tests.dm
File metadata and controls
418 lines (351 loc) · 14.2 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
/*
Unit tests for ATMOSPHERICS primitives
*/
/datum/unit_test/atmos_machinery
abstract_type = /datum/unit_test/atmos_machinery
var/list/test_cases = list()
/datum/unit_test/atmos_machinery/proc/create_gas_mixes(gas_mix_data)
var/list/gas_mixes = list()
for(var/mix_name in gas_mix_data)
var/list/mix_data = gas_mix_data[mix_name]
var/datum/gas_mixture/gas_mix = new (CELL_VOLUME, mix_data["temperature"])
var/list/initial_gas = mix_data["initial_gas"]
if(initial_gas.len)
for(var/gasid in initial_gas)
gas_mix.adjust_gas(gasid, initial_gas[gasid], FALSE)
gas_mix.update_values()
gas_mixes[mix_name] = gas_mix
return gas_mixes
/datum/unit_test/atmos_machinery/proc/gas_amount_changes(var/list/before_gas_mixes, var/list/after_gas_mixes)
var/list/result = list()
for(var/mix_name in before_gas_mixes & after_gas_mixes)
var/change = list()
var/datum/gas_mixture/before = before_gas_mixes[mix_name]
var/datum/gas_mixture/after = after_gas_mixes[mix_name]
var/list/all_gases = before.gas | after.gas
for(var/gasid in all_gases)
change[gasid] = after.get_gas(gasid) - before.get_gas(gasid)
result[mix_name] = change
return result
/datum/unit_test/atmos_machinery/proc/check_moles_conserved(var/case_name, var/list/before_gas_mixes, var/list/after_gas_mixes)
var/failed = FALSE
for(var/gasid in get_filterable_material_types())
var/before = 0
for(var/gasmix in before_gas_mixes)
var/datum/gas_mixture/G = before_gas_mixes[gasmix]
before += G.get_gas(gasid)
var/after = 0
for(var/gasmix in after_gas_mixes)
var/datum/gas_mixture/G = after_gas_mixes[gasmix]
after += G.get_gas(gasid)
if(abs(before - after) > ATMOS_PRECISION)
fail("[case_name]: expected [before] moles of [gasid], found [after] moles.")
failed |= TRUE
if(!failed)
pass("[case_name]: conserved moles of each gas ID.")
/datum/unit_test/atmos_machinery/conserve_moles
abstract_type = /datum/unit_test/atmos_machinery/conserve_moles
test_cases = list(
uphill = list(
source = list(
initial_gas = list(
/decl/material/gas/oxygen = 5,
/decl/material/gas/nitrogen = 10,
/decl/material/gas/carbon_dioxide = 5,
/decl/material/gas/chlorine = 10,
/decl/material/gas/nitrous_oxide = 5
),
temperature = T20C - 5,
),
sink = list(
initial_gas = list(
/decl/material/gas/oxygen = 10,
/decl/material/gas/nitrogen = 20,
/decl/material/gas/carbon_dioxide = 10,
/decl/material/gas/chlorine = 20,
/decl/material/gas/nitrous_oxide = 10
),
temperature = T20C + 5,
)
),
downhill = list(
source = list(
initial_gas = list(
/decl/material/gas/oxygen = 10,
/decl/material/gas/nitrogen = 20,
/decl/material/gas/carbon_dioxide = 10,
/decl/material/gas/chlorine = 20,
/decl/material/gas/nitrous_oxide = 10
),
temperature = T20C + 5,
),
sink = list(
initial_gas = list(
/decl/material/gas/oxygen = 5,
/decl/material/gas/nitrogen = 10,
/decl/material/gas/carbon_dioxide = 5,
/decl/material/gas/chlorine = 10,
/decl/material/gas/nitrous_oxide = 5
),
temperature = T20C - 5,
),
),
flat = list(
source = list(
initial_gas = list(
/decl/material/gas/oxygen = 10,
/decl/material/gas/nitrogen = 20,
/decl/material/gas/carbon_dioxide = 10,
/decl/material/gas/chlorine = 20,
/decl/material/gas/nitrous_oxide = 10
),
temperature = T20C,
),
sink = list(
initial_gas = list(
/decl/material/gas/oxygen = 10,
/decl/material/gas/nitrogen = 20,
/decl/material/gas/carbon_dioxide = 10,
/decl/material/gas/chlorine = 20,
/decl/material/gas/nitrous_oxide = 10
),
temperature = T20C,
),
),
vacuum_sink = list(
source = list(
initial_gas = list(
/decl/material/gas/oxygen = 10,
/decl/material/gas/nitrogen = 20,
/decl/material/gas/carbon_dioxide = 10,
/decl/material/gas/chlorine = 20,
/decl/material/gas/nitrous_oxide = 10
),
temperature = T20C,
),
sink = list(
initial_gas = list(),
temperature = 0,
),
),
vacuum_source = list(
source = list(
initial_gas = list(),
temperature = 0,
),
sink = list(
initial_gas = list(
/decl/material/gas/oxygen = 10,
/decl/material/gas/nitrogen = 20,
/decl/material/gas/carbon_dioxide = 10,
/decl/material/gas/chlorine = 20,
/decl/material/gas/nitrous_oxide = 10
),
temperature = T20C,
),
),
)
/datum/unit_test/atmos_machinery/conserve_moles/pump_gas
name = "ATMOS MACHINERY: pump_gas() Conserves Moles"
/datum/unit_test/atmos_machinery/conserve_moles/pump_gas/start_test()
for(var/case_name in test_cases)
var/gas_mix_data = test_cases[case_name]
var/list/before_gas_mixes = create_gas_mixes(gas_mix_data)
var/list/after_gas_mixes = create_gas_mixes(gas_mix_data)
pump_gas(null, after_gas_mixes["source"], after_gas_mixes["sink"], null, INFINITY)
check_moles_conserved(case_name, before_gas_mixes, after_gas_mixes)
return 1
/datum/unit_test/atmos_machinery/conserve_moles/pump_gas_passive
name = "ATMOS MACHINERY: pump_gas_passive() Conserves Moles"
/datum/unit_test/atmos_machinery/conserve_moles/pump_gas_passive/start_test()
for(var/case_name in test_cases)
var/gas_mix_data = test_cases[case_name]
var/list/before_gas_mixes = create_gas_mixes(gas_mix_data)
var/list/after_gas_mixes = create_gas_mixes(gas_mix_data)
pump_gas_passive(null, after_gas_mixes["source"], after_gas_mixes["sink"], null)
check_moles_conserved(case_name, before_gas_mixes, after_gas_mixes)
return 1
/datum/unit_test/atmos_machinery/conserve_moles/scrub_gas
name = "ATMOS MACHINERY: scrub_gas() Conserves Moles"
/datum/unit_test/atmos_machinery/conserve_moles/scrub_gas/start_test()
var/list/filtering = get_filterable_material_types(as_list = TRUE)
for(var/case_name in test_cases)
var/gas_mix_data = test_cases[case_name]
var/list/before_gas_mixes = create_gas_mixes(gas_mix_data)
var/list/after_gas_mixes = create_gas_mixes(gas_mix_data)
scrub_gas(null, filtering, after_gas_mixes["source"], after_gas_mixes["sink"], null, INFINITY)
check_moles_conserved(case_name, before_gas_mixes, after_gas_mixes)
return 1
/datum/unit_test/atmos_machinery/conserve_moles/filter_gas
name = "ATMOS MACHINERY: filter_gas() Conserves Moles"
/datum/unit_test/atmos_machinery/conserve_moles/filter_gas/start_test()
var/list/filtering = get_filterable_material_types(as_list = TRUE)
for(var/case_name in test_cases)
var/gas_mix_data = test_cases[case_name]
var/list/before_gas_mixes = create_gas_mixes(gas_mix_data)
var/list/after_gas_mixes = create_gas_mixes(gas_mix_data)
filter_gas(null, filtering, after_gas_mixes["source"], after_gas_mixes["sink"], after_gas_mixes["source"], null, INFINITY)
check_moles_conserved(case_name, before_gas_mixes, after_gas_mixes)
return 1
/datum/unit_test/atmos_machinery/conserve_moles/filter_gas_multi
name = "ATMOS MACHINERY: filter_gas_multi() Conserves Moles"
/datum/unit_test/atmos_machinery/conserve_moles/filter_gas_multi/start_test()
for(var/case_name in test_cases)
var/gas_mix_data = test_cases[case_name]
var/list/before_gas_mixes = create_gas_mixes(gas_mix_data)
var/list/after_gas_mixes = create_gas_mixes(gas_mix_data)
var/list/filtering = list()
for(var/gasid in get_filterable_material_types())
filtering[gasid] = after_gas_mixes["sink"] //just filter everything to sink
filter_gas_multi(null, filtering, after_gas_mixes["source"], after_gas_mixes["sink"], null, INFINITY)
check_moles_conserved(case_name, before_gas_mixes, after_gas_mixes)
return 1
/datum/unit_test/atmos_machinery/conserve_moles/mix_gas
name = "ATMOS MACHINERY: mix_gas() Conserves Moles"
/datum/unit_test/atmos_machinery/conserve_moles/mix_gas/start_test()
for(var/case_name in test_cases)
var/gas_mix_data = test_cases[case_name]
var/list/before_gas_mixes = create_gas_mixes(gas_mix_data)
var/list/after_gas_mixes = create_gas_mixes(gas_mix_data)
var/list/mix_sources = list()
var/list/all_gasses = get_filterable_material_types(as_list = TRUE)
var/gas_count = length(all_gasses)
for(var/gasid in all_gasses)
var/datum/gas_mixture/mix_source = after_gas_mixes["sink"]
mix_sources[mix_source] = 1.0/gas_count //doesn't work as a macro for some reason
mix_gas(null, mix_sources, after_gas_mixes["sink"], null, INFINITY)
check_moles_conserved(case_name, before_gas_mixes, after_gas_mixes)
return 1
/datum/unit_test/pipes_shall_belong_to_unique_pipelines
name = "ATMOS MACHINERY: all pipes shall belong to a unique pipeline"
/datum/unit_test/pipes_shall_belong_to_unique_pipelines/start_test()
var/list/checked_pipes = list()
var/list/bad_pipelines = list()
for(var/datum/pipeline/P)
for(var/thing in P.members)
var/obj/machinery/atmospherics/pipe/pipe = thing
if(!checked_pipes[thing])
checked_pipes[thing] = P
continue
LAZYDISTINCTADD(bad_pipelines[P], pipe)
LAZYDISTINCTADD(bad_pipelines[checked_pipes[thing]], pipe) // Missed it the first time; thought it was good.
if(length(bad_pipelines))
for(var/datum/pipeline/badboy in bad_pipelines)
var/info = list()
for(var/bad_pipe in bad_pipelines[badboy])
info += log_info_line(bad_pipe)
log_bad("A pipeline with overlapping members contained the following overlapping pipes: [english_list(info)]")
fail("Some pipes were in multiple pipelines at once.")
else
pass("All pipes belonged to a unique pipeline.")
return 1
/datum/unit_test/pipelines_shall_belong_to_unique_pipenets
name = "ATMOS MACHINERY: all pipelines shall belong to a unique pipenet"
/datum/unit_test/pipelines_shall_belong_to_unique_pipenets/start_test()
var/list/checked_pipelines = list()
var/list/bad_pipenets = list()
for(var/datum/pipe_network/network)
for(var/thing in network.line_members)
if(!checked_pipelines[thing])
checked_pipelines[thing] = network
continue
LAZYDISTINCTADD(bad_pipenets[network], thing)
LAZYDISTINCTADD(bad_pipenets[checked_pipelines[thing]], thing)
if(length(bad_pipenets))
fail("There were [length(bad_pipenets)] which shared at least one pipeline with another pipenet.")
else
pass("All pipelines belonged to a unique pipenet.")
return 1
/datum/unit_test/atmos_machinery_shall_not_have_conflicting_connections
name = "ATMOS MACHINERY: all mapped atmos machinery shall not have more than one connection of each type per dir."
/datum/unit_test/atmos_machinery_shall_not_have_conflicting_connections/start_test()
var/fail = FALSE
for(var/obj/machinery/atmospherics/machine in SSmachines.machinery)
for(var/obj/machinery/atmospherics/M in machine.loc)
if(M == machine)
continue
if(!machine.check_connect_types(M, machine))
continue
if(M.initialize_directions & machine.initialize_directions)
log_bad("[log_info_line(machine)] has conflicting connections.")
fail = TRUE
if(fail)
fail("Some pipes had conflicting connections.")
else
pass("All pipes were mapped properly.")
return 1
/datum/unit_test/atmos_machinery_node_reciprocity
name = "ATMOS MACHINERY: all atmos machines shall be nodes of their nodes."
/datum/unit_test/atmos_machinery_node_reciprocity/start_test()
var/fail = FALSE
for(var/obj/machinery/atmospherics/machine in SSmachines.machinery)
for(var/obj/machinery/atmospherics/node as anything in machine.nodes_to_networks)
if(node == machine)
log_bad("[log_info_line(machine)] was its own node.")
fail = TRUE
if(!(machine in node.nodes_to_networks))
log_bad("[log_info_line(machine)] has [log_info_line(node)] in its nodes list, but not vice versa.")
fail = TRUE
if(fail)
fail("Some machines failed to have reciprocal node connections.")
else
pass("All machines had reciprocal node connections.")
return 1
/datum/unit_test/atmos_machinery_construction_inheritance
name = "ATMOS MACHINERY: all atmos machines shall deconstruct and reconstruct themselves."
/datum/unit_test/atmos_machinery_construction_inheritance/proc/check_machine(var/obj/machinery/atmospherics/machine, var/obj/item/pipe/pipe)
. = FALSE
if(!machine.construct_state)
return
var/pipe_class = machine.pipe_class
var/rotate_class = machine.rotate_class
var/connect_types = machine.connect_types
var/dir = machine.dir
if(pipe_class != pipe.pipe_class)
log_bad("Machine of type [machine.type] had pipe with class [pipe.pipe_class]; was expecting [pipe_class].")
. = TRUE
if(rotate_class != pipe.rotate_class)
log_bad("Machine of type [machine.type] had pipe with rotate class [pipe.rotate_class]; was expecting [rotate_class].")
. = TRUE
if(connect_types != pipe.connect_types)
log_bad("Machine of type [machine.type] had pipe with connect type [pipe.connect_types]; was expecting [connect_types].")
. = TRUE
if(dir != pipe.dir)
log_bad("Machine of type [machine.type] had pipe with dir [pipe.dir]; was expecting [dir].")
. = TRUE
/datum/unit_test/atmos_machinery_construction_inheritance/start_test()
var/fail = FALSE
// make a place to test
SSmapping.increment_world_z_size(/datum/level_data/unit_test)
for(var/turf/T as anything in block(1, 1, world.maxz, 3, 3, world.maxz))
T.ChangeTurf(/turf/floor)
var/turf/T = locate(2, 2, world.maxz)
// first, every spawnable machine ("mapped" behavior)
for(var/type in subtypesof(/obj/machinery/atmospherics))
var/obj/machinery/atmospherics/machine = new type(T)
var/obj/item/pipe/pipe = machine.dismantle()
if(!istype(pipe))
qdel(pipe)
continue
fail |= check_machine(machine, pipe)
qdel(pipe)
if(!fail)
// then, pipes from machine datums are used to spawn machines ("player-built" behavior)
for(var/type in subtypesof(/datum/fabricator_recipe/pipe))
var/datum/fabricator_recipe/pipe/recipe = new type()
var/list/stuff = recipe.build(T, new/datum/fabricator_build_order(recipe) )
var/obj/item/pipe/pipe = locate() in stuff
if(pipe)
stuff -= pipe
var/obj/machinery/atmospherics/machine = pipe.construct_pipe(T)
if(!istype(machine))
qdel(machine)
else
fail |= check_machine(machine, pipe) // compare to a newly built machine
qdel(machine)
QDEL_NULL_LIST(stuff) // clean up just in case
if(fail)
fail("Some atmos machines failed to rebuild themselves from pipes.")
else
pass("All atmos machines rebuilt themselves from pipes.")
return 1