-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing.rb
78 lines (71 loc) · 2.04 KB
/
testing.rb
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
module DFStock
# Every class of thing that appears in the stock menus
def self.testable_classes
constants.map {|x|
DFStock.const_get x
}.select {|x|
x.is_a?(Class) && x < DFStock::Thing
}.sort_by {|x|
x.to_s
}
end
# Every thing that exists in the stock menus
def self.testable_items
items = testable_classes.map(&:instances).flatten.uniq
end
# Every (added) way to compare two objects
def self.testable_comparators
Comparators.
instance_methods.
select {|mn|
Comparators.instance_method(mn).arity.zero?
}.
sort
end
# Creates abstract instance of each class
def self.test_all_classes
testable_classes.map {|k| k.instances.last }.compact.each {|x| p x }
true
end
# Enable only the first and last item in all categories in a pile
def self.test_all_categories pile
pile ||= pile_at_cursor
raise "Select a stockpile and enable all categories" unless pile
pile.categories.each {|cn,c|
begin
c.enable
rescue NotImplementedError
next p "Category #{cn} - unable to enable"
rescue
raise
end
# next unless (c.enable rescue false)
c.all_items.each {|i|
i.disable
}
next unless c.respond_to? :features # such as corpses, without any items or categories
c.features.select {|t,_,_,_| t == :array }.
each {|_,n1, n2, o|
sn = n2 || n1
i = c.send(sn)
next if i.empty?
f, l = i.first, i.last
[f,l].each &:enable
p [cn, sn, [f,l].map(&:name)]
}
}
true
end
# Calls all comparators on all abstract items
def self.test_all_comparators
items = testable_items
puts "Checking comparators against #{items.length}"
testable_comparators.each {|mn|
t = items.map(&mn).select {|x| !!x }.length
f = items.map(&mn).select {|x| x == false }.length
n = items.map(&mn).select {|x| x.nil? }.length
puts "Checking #{'%22s' % mn}, t: #{'%5d' % t}, f: #{'%5d' % f}, n: #{'%5d' % n}"
}
true
end
end