galaxy 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/.idea/.rakeTasks +7 -0
  4. data/.idea/encodings.xml +5 -0
  5. data/.idea/galaxy.iml +10 -0
  6. data/.idea/misc.xml +14 -0
  7. data/.idea/modules.xml +9 -0
  8. data/.idea/vcs.xml +8 -0
  9. data/.idea/workspace.xml +486 -0
  10. data/LICENSE +20 -0
  11. data/README.rdoc +36 -0
  12. data/Rakefile +62 -0
  13. data/VERSION +1 -0
  14. data/doc/plan.txt +5 -0
  15. data/doc/pseudo.txt +43 -0
  16. data/features/galaxy.feature +9 -0
  17. data/features/step_definitions/galaxy_steps.rb +0 -0
  18. data/features/support/env.rb +4 -0
  19. data/galaxy.gemspec +95 -0
  20. data/galaxy/.loadpath +5 -0
  21. data/galaxy/.project +17 -0
  22. data/galaxy/.settings/org.eclipse.mylyn.tasks.ui.prefs +4 -0
  23. data/galaxy/.settings/org.eclipse.wst.sse.core.prefs +5 -0
  24. data/galaxy/experiments.rb +26 -0
  25. data/lib/galaxy.rb +8 -0
  26. data/lib/galaxy/models/bombing.rb +64 -0
  27. data/lib/galaxy/models/fleet.rb +62 -0
  28. data/lib/galaxy/models/group.rb +178 -0
  29. data/lib/galaxy/models/models.rb +16 -0
  30. data/lib/galaxy/models/planet.rb +181 -0
  31. data/lib/galaxy/models/product.rb +84 -0
  32. data/lib/galaxy/models/race.rb +112 -0
  33. data/lib/galaxy/models/route.rb +60 -0
  34. data/lib/galaxy/order.rb +24 -0
  35. data/lib/galaxy/report.rb +176 -0
  36. data/lib/galaxy/section.rb +226 -0
  37. data/lib/galaxy/utils.rb +109 -0
  38. data/lib/galaxy/virtual_base.rb +165 -0
  39. data/spec/spec_helper.rb +9 -0
  40. data/test/test_helper.rb +4 -0
  41. data/test/unit/models_test.rb +1469 -0
  42. data/test/unit/report_test.rb +187 -0
  43. data/test/unit/utils_test.rb +421 -0
  44. data/test/unit/virtual_base_test.rb +224 -0
  45. metadata +123 -0
@@ -0,0 +1,109 @@
1
+
2
+ # Array extension that supports both Integer index and Hash-like 'key'
3
+ # Objects put into HashArray might respond to key, key=, idx, idx= methods
4
+ # Class Interfaces:
5
+ # a = HashArray.new; b = HashArray[1,2,3,4,5]; c = HashArray.new(15, 'blah') - Initialize array
6
+ # a[idx] = obj. Insert object (by idx). If obj responds to 'key' method, key is automatically created
7
+ # a[key] = obj. Insert object(by key). If obj responds to 'idx' method, it is placed at a[idx]
8
+ # a[idx, key] = obj. Insert object by both idx and key. Both key and idx are created, object updated using 'key=','idx=' methods
9
+ # a << obj; a[] = obj. Add object. If obj responds to 'key' method, key is automatically created. If obj responds to 'idx' method, it is placed at a[idx]
10
+ # a >> obj. Remove object from array and kill all keys pointing to it
11
+ # Multiple keys can be assigned to obj by repeatedly adding it to HashArray with different keys.
12
+ # Deleting object from HashArray deletes all key references to it
13
+ # All other Array methods are not redefined and therefore return simple Arrays, not HashArrays
14
+ # (for example, if you add two HashArrays, @hashmap values will be all wrong)
15
+
16
+ class HashArray < Array
17
+ attr_reader :hashmap
18
+
19
+ def HashArray.[] *args
20
+ new args
21
+ end
22
+
23
+ def initialize *args
24
+ @hashmap = {} # Hash map that holds key=>idx pairs
25
+ super *args
26
+ temp = self.map{|x| x}
27
+ clear
28
+ temp.each {|x| self << x}
29
+ end
30
+
31
+ def >> (obj)
32
+ # Remove object by idx
33
+ idx = obj.idx if obj.respond_to? :idx # Assign idx from obj.idx if it is not given
34
+ key = obj.key if obj.respond_to? :key # Assign key from obj.key if it is not given
35
+ key = key.to_sym if key and String === key #Transparently convert String keys into Symbols
36
+ if idx and self[idx] and self[idx].eql? obj
37
+ self[idx,nil]=nil
38
+ elsif key and self[key] and self[key].eql? obj
39
+ self[nil,key]=nil
40
+ elsif idx = self.index(obj)
41
+ self[idx,nil]=nil
42
+ else
43
+ raise ArgumentError, "Unable to delete #{obj}"
44
+ end
45
+ self
46
+ end #[]
47
+
48
+ def [](*args)
49
+ case args.size
50
+ when 2 then super *args # [3,3] slice access
51
+ when 1 then
52
+ case args[0]
53
+ when Range then super args[0]
54
+ when Integer then super args[0]
55
+ when String then self[args[0].to_sym]
56
+ else
57
+ return nil unless @hashmap[args[0]]
58
+ super @hashmap[args[0]]
59
+ end #case
60
+ else
61
+ raise ArgumentError
62
+ end #case
63
+ end #[]
64
+
65
+ # Also with 3 arguments (key, idx, obj) and without arguments
66
+ def []=(*args)
67
+ case args.size
68
+ when 1 then self[nil,nil] = *args # Assign obj given its idx and key
69
+ when 2 then
70
+ keyidx, obj = args
71
+ case keyidx
72
+ when Range then raise IndexError # TODO Implement Range access operation
73
+ when Integer then self[keyidx, nil] = obj
74
+ else self[nil, keyidx] = obj #keyidx is not Integer or Range, consider it a key
75
+ end #case
76
+
77
+ when 3 # Assign obj to HashArray using given key and idx (main logics here)
78
+ idx, key, obj = args
79
+ idx ||= obj.idx if obj.respond_to? :idx # Assign idx from obj.idx if it is not given
80
+ key ||= obj.key if obj.respond_to? :key # Assign key from obj.key if it is not given
81
+ key = key.to_sym if String === key #Transparently convert String keys into Symbols
82
+
83
+ #return self if self.include? obj and # Is this object already in HashArray?
84
+ return self[self.size,key]=obj unless idx or obj.nil? # If no idx, add new element at the end of HashArray
85
+
86
+ old_obj = idx ? self[idx] : self[key]
87
+ if obj.nil?
88
+ old_obj.idx = nil if old_obj.respond_to? :idx=
89
+ old_obj.key = nil if old_obj.respond_to? :key=
90
+ @hashmap.reject! {|k,v| v == idx} # Delete all key references to this object from hashmap
91
+ else
92
+ self >> old_obj if old_obj and not old_obj.eql? obj # Another object uses this idx, remove previous object
93
+ self >> self[key] if self[key] and not self[key].eql? obj # Another object uses this key, remove previous object
94
+ @hashmap[key] = idx if key
95
+ obj.idx = idx if obj.respond_to? :idx=
96
+ obj.key = key if obj.respond_to? :key=
97
+ end
98
+ super(idx, obj)
99
+ else
100
+ raise ArgumentError
101
+ end #case
102
+ end
103
+
104
+ def <<(obj)
105
+ self[]=obj
106
+ self
107
+ end
108
+ end
109
+
@@ -0,0 +1,165 @@
1
+ module ActiveRecord
2
+ module VirtualBase
3
+
4
+ def self.included(base)
5
+ # 'base' is assumed to be ActiveRecord::Base
6
+ base.extend(TablelessClassMethods)
7
+ base.extend(VirtualClassMethods)
8
+ end
9
+
10
+ module VirtualClassMethods
11
+ # Model class that invokes this macro becomes "virtual" - uses dataset instead of DB connection
12
+ def virtual
13
+ include ActiveRecord::VirtualBase::VirtualInstanceMethods
14
+ include ActiveRecord::VirtualBase::YourMethods
15
+ include Comparable
16
+
17
+ # Should be part of a separate macro, but let's leave them here for now
18
+ attr_accessor :idx # To keep track of Model position in container HashArray
19
+ @@dataset ||= nil
20
+
21
+ #self.extend(VirtualMetaMethods)
22
+ end
23
+
24
+ def has_many_linked( association_id, options = {}, &extension )
25
+ #puts "#{self} has_many_linked #{association_id} with options: #{options}"
26
+ #Standard has_many_linked, add standard before and after callback methods
27
+
28
+ owner_reference = if options[:foreign_key] then options[:foreign_key].split('_')[0] else self.name.downcase end
29
+
30
+ add_method = "add_linked_#{association_id}".to_sym
31
+ define_method(add_method) do |association|
32
+ #p association_id, association, self, owner_reference
33
+ owner = association.send(owner_reference.to_sym)
34
+ if owner != self
35
+ # If association already has another current_owner, delete it it from current_owner's collection
36
+ owner.send(association_id.to_sym).delete association if owner
37
+ association.send( (owner_reference+'=').to_sym, self)
38
+ end
39
+ end
40
+
41
+ remove_method = "remove_linked_#{association_id}".to_sym
42
+ define_method(remove_method) do |association|
43
+ owner = association.send(owner_reference.to_sym)
44
+ raise ActiveRecordError if owner and owner != self # Something wrong, association is not pointing back to us
45
+ association.send( (owner_reference+'=').to_sym, nil)
46
+ end
47
+
48
+ before = if options[:before_add] then [options[:before_add], add_method] else add_method end
49
+ after = if options[:after_remove] then [options[:after_remove], remove_method] else remove_method end
50
+ has_many association_id, options.merge(:before_add => before, :after_remove => after), &extension
51
+ end
52
+
53
+ #TODO Add methods for work with data set (save!, delete!, find, find_all, etc...)
54
+
55
+ # Establish dataset to run add/lookup/kill (redefined save/find/delete?) operations against
56
+ def establish_dataset( dataset )
57
+ #print 'Dataset established: ', dataset.name if dataset.respond_to? :name and dataset.name
58
+ @@dataset = dataset
59
+ end
60
+
61
+ # Return dataset proper for add/lookup/kill operations
62
+ def dataset
63
+ @@dataset
64
+ end
65
+
66
+ # Lookup objects of this Class in the dataset - analog of find()
67
+ def lookup(*args)
68
+ return nil unless dataset # Dataset is not established, unable to lookup
69
+ # options = args.extract_options!
70
+ case args.first
71
+ when :first then dataset.send(table_name.to_sym).find{|m| m}
72
+ when :last then dataset.send(table_name.to_sym).compact[-1]
73
+ when :all then dataset.send(table_name.to_sym).compact
74
+ else dataset.send(table_name.to_sym)[*args]
75
+ end
76
+ end
77
+
78
+ # Delete objects from the dataset - analog of delete()
79
+ def kill(*args)
80
+ obj = self.lookup(*args)
81
+ case obj
82
+ when nil then false
83
+ when Array then obj.each {|o| o.kill}
84
+ else obj.kill
85
+ end
86
+ end
87
+
88
+ # Pass through method that calls new (called on each found Section record)
89
+ # Model should redefine this method for meaningful result (like Planets.new_or_update)
90
+ def new_or_update *args
91
+ new *args
92
+ end
93
+ end
94
+
95
+ module VirtualInstanceMethods
96
+ def add key = nil
97
+ return false unless self.class.dataset
98
+ self.class.dataset.send(self.class.table_name.to_sym) << self
99
+ self.class.dataset.send(self.class.table_name.to_sym)[key] = self if key
100
+ true
101
+ end
102
+
103
+ def kill
104
+ return false unless self.class.dataset
105
+
106
+ self.class.dataset.send(self.class.table_name.to_sym) >> self rescue false
107
+ end
108
+
109
+ end
110
+
111
+ module YourMethods
112
+ def your? ; race and race.your? end
113
+ alias yours? your?
114
+ alias controlled? your?
115
+ alias my? your?
116
+ alias me? your?
117
+ alias mine? your?
118
+ end
119
+
120
+ module TablelessClassMethods
121
+ def tableless( options = {} )
122
+ include ActiveRecord::VirtualBase::TablelessInstanceMethods
123
+
124
+ self.extend(TablelessMetaMethods)
125
+
126
+ #raise "No columns defined" unless options.has_key?(:columns) && !options[:columns].empty?
127
+ for column_args in options[:columns]
128
+ column( *column_args )
129
+ end
130
+ end
131
+ end
132
+
133
+ module TablelessMetaMethods
134
+ def columns()
135
+ @columns ||= []
136
+ end
137
+
138
+ def column(name, sql_type = nil, default = nil, null = true)
139
+ columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
140
+ reset_column_information
141
+ end
142
+
143
+ # Do not reset @columns
144
+ def reset_column_information
145
+ generated_methods.each { |name| undef_method(name) }
146
+ @column_names = @columns_hash = @content_columns = @dynamic_methods_hash = @read_methods = nil
147
+ end
148
+ end
149
+
150
+ module TablelessInstanceMethods
151
+ def create_or_update
152
+ errors.empty?
153
+ end
154
+
155
+ def saved!(with_id = 1)
156
+ self.id = with_id
157
+
158
+ def self.new_record?
159
+ false
160
+ end
161
+ end
162
+ alias_method :exists!, :saved!
163
+ end
164
+ end
165
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'galaxy'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'spec/test/unit'
4
+ require 'galaxy'
@@ -0,0 +1,1469 @@
1
+ #TAG models_test.rb tasks are on
2
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
+ #require 'report.rb'
4
+
5
+ class M_RaceTest < Test::Unit::TestCase
6
+ def setup
7
+ rep = Report.new 'rep/ArVit187.rep'
8
+ @data = ActiveRecord::Base.establish_dataset(rep)
9
+ @data.owner='ArVitallian'
10
+ end
11
+
12
+ def test_fail
13
+ assert_equal 1, 0
14
+ end
15
+
16
+ def test_order #Tests new Order functionality
17
+ av = Race.new %w[ArVitallian 13.00 11.61 11.08 5.48 2276614.82 2028341.13 2515 - 2276.61],{:game=>'research3', :turn=>187}
18
+ rip = Race.new %w[Krot_RIP 6.54 4.22 3.45 1.83 0.00 0.00 0 War 0.00],{}
19
+ text = "#order research3 ArVitallian_zelikaka turn 187\n#end\n"
20
+ text1 = "#order research3 ArVitallian_zelikaka turn 187\n#Test line\n#end\n"
21
+
22
+ puts av.order.text
23
+ assert_nil rip.order, 'Newly created race should have default Order'
24
+ assert_equal text, av.order.text, 'Newly created race should have empty Order'
25
+
26
+ av.order.add_line '#Test line'
27
+ puts av.order.text
28
+ assert_equal text1, av.order.text, 'Newly created race should have empty Order'
29
+ end
30
+
31
+ def test_init
32
+ av = Race.new %w[ArVitallian 13.00 11.61 11.08 5.48 2276614.82 2028341.13 2515 - 2276.61],{}
33
+ m = Race.new %w[Krot_RIP 6.54 4.22 3.45 1.83 0.00 0.00 0 War 0.00],{}
34
+
35
+ assert_equal "ArVitallian", av.key, 'Key accessor wrong'
36
+ assert_equal "ArVitallian", av.name, 'Name attribute wrong'
37
+ assert_equal 13.0, av.drive, 'Drive attribute wrong'
38
+ assert_equal 11.61, av.weapons, 'Weapons attribute wrong'
39
+ assert_equal 11.08, av.shields, 'Shields attribute wrong'
40
+ assert_equal 5.48, av.cargo, 'Cargo attribute wrong'
41
+ assert_equal 2276614.82, av.pop, 'Pop attribute wrong'
42
+ assert_equal 2028341.13, av.ind, 'Ind attribute wrong'
43
+ assert_equal 2515, av.num_planets, 'Number of planets wrong'
44
+ assert_equal "-", av.relation, 'Relation attribute wrong'
45
+
46
+ # Assert Boolean Methods
47
+ assert m.rip?, 'Rip method wrong'
48
+ assert ! av.rip? , 'Rip method wrong'
49
+ assert m.war? , 'War method wrong'
50
+ assert av.peace? , 'War method wrong'
51
+ assert ! m.ally? , 'War method wrong'
52
+ assert av.friend? , 'War method wrong'
53
+ end
54
+
55
+ def test_boolean_methods
56
+ m1 = Race.new %w[ArVitallian 13.00 11.61 11.08 5.48 2276614.82 2028341.13 2515 - 2276.61],{}
57
+ m2 = Race.new %w[1eadgen 10.00 9.94 9.31 7.75 226543.97 224300.00 166 Peace 0.00],{}
58
+ m3 = Race.new %w[Beast 10.97 10.38 9.41 4.24 25295.06 24196.83 16 War 0.00],{}
59
+ m4 = Race.new %w[Ace 1.00 1.00 1.00 1.00 0.00 0.00 0 War 60.53],{}
60
+ m5 = Race.new %w[Duck_RIP 6.96 7.62 7.61 2.60 0.00 0.00 0 War 0.00],{}
61
+
62
+ assert !m1.rip? , 'Boolean method failed'
63
+ assert !m1.enemy? , 'Boolean method failed'
64
+ assert m1.friend? , 'Boolean method failed'
65
+ assert m1.your? , 'Boolean method failed'
66
+
67
+ assert !m2.rip? , 'Boolean method failed'
68
+ assert !m2.enemy? , 'Boolean method failed'
69
+ assert m2.friend? , 'Boolean method failed'
70
+ assert !m2.your? , 'Boolean method failed'
71
+
72
+ assert !m3.rip? , 'Boolean method failed'
73
+ assert m3.enemy? , 'Boolean method failed'
74
+ assert !m3.friend? , 'Boolean method failed'
75
+ assert !m3.your? , 'Boolean method failed'
76
+
77
+ assert !m4.rip? , 'Boolean method failed'
78
+ assert m4.enemy? , 'Boolean method failed'
79
+ assert !m4.friend? , 'Boolean method failed'
80
+ assert !m4.your? , 'Boolean method failed'
81
+
82
+ assert m5.rip? , 'Boolean method failed'
83
+ assert m5.enemy? , 'Boolean method failed'
84
+ assert !m5.friend? , 'Boolean method failed'
85
+ assert !m5.your? , 'Boolean method failed'
86
+ end
87
+
88
+ def test_comparisons
89
+ m1 = Race.new %w[ArVitallian 13.00 11.61 11.08 5.48 2276614.82 2028341.13 2515 - 2276.61],{}
90
+ m2 = Race.new %w[1eadgen 10.00 9.94 9.31 7.75 226543.97 224300.00 166 Peace 0.00],{}
91
+ m3 = Race.new %w[Beast 10.97 10.38 9.41 4.24 25295.06 24196.83 16 War 0.00],{}
92
+ m4 = Race.new %w[Ace 1.00 1.00 1.00 1.00 0.00 0.00 0 War 60.53],{}
93
+ m5 = Race.new %w[Duck_RIP 6.96 7.62 7.61 2.60 0.00 0.00 0 War 0.00],{}
94
+
95
+ assert m1==m1, 'Self-equality failed'
96
+ assert m1>m2, 'GT model comparison failed'
97
+ assert m3<m2, 'LT model comparison failed'
98
+ assert m2>=m4, 'GTE model comparison failed'
99
+ assert m4<=m3, 'LTE model comparison failed'
100
+
101
+ assert m4>nil, 'nil comparison failed'
102
+ assert m2>30, 'Integer comparison failed'
103
+ assert m3==16, 'Integer comparison failed'
104
+
105
+ assert m1=='ArVitallian', 'String comparison failed'
106
+ assert m5=='RIP', 'String comparison failed'
107
+ assert m5=='Duck', 'String comparison failed'
108
+
109
+ assert m1==:alive, 'Symbol comparison failed'
110
+ assert m3==:enemy, 'Symbol comparison failed'
111
+ assert m4==:ace, 'Symbol comparison failed'
112
+ assert m5==:duck, 'Symbol comparison failed'
113
+ assert m5==:dead, 'Symbol comparison failed'
114
+ end
115
+ end
116
+
117
+ class M_ProductTest < Test::Unit::TestCase
118
+ def setup
119
+ rep = Report.new 'rep/ArVit187.rep'
120
+ @data = ActiveRecord::Base.establish_dataset(rep)
121
+ @data.owner='ArVitallian'
122
+ @av = Race.new %w[ArVitallian 13.00 11.61 11.08 5.48 2276614.82 2028341.13 2515 - 2276.61],{}
123
+ @ace = Race.new %w[Ace 1.00 1.00 1.00 1.00 0.00 0.00 0 War 60.53],{}
124
+ @ster = Race.new %w[Ace 1.00 1.00 1.00 1.00 0.00 0.00 0 War 60.53],{}
125
+ end
126
+
127
+ def test_init_science
128
+ m = Product.new %w[MoveTo_6300_12504 6299.55 12503.99 0 0],{:race=>@av}
129
+ assert_equal "ArVitallian.MoveTo_6300_12504_Research", m.key, 'Key accessor wrong'
130
+ assert_equal "MoveTo_6300_12504", m.name, 'Name attribute wrong'
131
+ assert_equal 6299.55, m.drive, 'Drive attribute wrong'
132
+ assert_equal 12503.99, m.weapons, 'Weapons attribute wrong'
133
+ assert_equal 0, m.shields, 'Shields attribute wrong'
134
+ assert_equal 0, m.cargo, 'Cargo attribute wrong'
135
+ assert_equal 'research', m.prod_type, 'Cargo attribute wrong'
136
+
137
+ assert_equal @av, m.race, 'Race association wrong'
138
+ assert_equal m, @av.products.first, 'Race association wrong'
139
+ assert_equal m, @av.sciences.first, 'Race association wrong'
140
+ end
141
+
142
+ def test_init_ship
143
+ m = Product.new %w[MAK-113-11x13 218.28 11 13.70 35.24 0.00 335.72],{:race=>@av}
144
+ assert_equal "ArVitallian.MAK-113-11x13", m.key, 'Key accessor wrong'
145
+ assert_equal "MAK-113-11x13", m.name, 'Name attribute wrong'
146
+ assert_equal 218.28, m.drive, 'Drive attribute wrong'
147
+ assert_equal 11, m.guns, 'Guns attribute wrong'
148
+ assert_equal 13.70, m.weapons, 'Weapons attribute wrong'
149
+ assert_equal 35.24, m.shields, 'Shields attribute wrong'
150
+ assert_equal 0.00, m.cargo, 'Cargo attribute wrong'
151
+ assert_equal 335.72, m.mass, 'Mass attribute wrong'
152
+ assert_equal 'ship', m.prod_type, 'Cargo attribute wrong'
153
+
154
+ assert_equal @av, m.race, 'Race association wrong'
155
+ assert_equal m, @av.products.first, 'Race association wrong'
156
+ assert_equal m, @av.designs.first, 'Race association wrong'
157
+ end
158
+
159
+ def test_race_association
160
+ s1 = Product.new %w[MoveTo_6300_12504 6299.55 12503.99 0 0],{:race=>@av}
161
+ s2 = Product.new %w[MoveTo_300_2504 300.00 2503.99 0 0],{}
162
+ s3 = Product.new %w[MoveTo_3000_2504 3000.00 2503.99 0 0],{:race=>@ster}
163
+
164
+ # Delete Model from its Race's collection
165
+ s1.race.products.delete s1
166
+ assert_equal [], @av.products, 'Delete association failed'
167
+ assert_nil s1.race, 'Delete association failed'
168
+
169
+ # Add no-race Model to Race collection
170
+ @av.products << s2
171
+ assert_equal s2, @av.products.first, 'Add association failed'
172
+ assert_equal @av, s2.race, 'Add association failed'
173
+
174
+ # Clearing collection
175
+ @av.products.clear
176
+ assert_nil @av.products.first, 'Add association failed'
177
+ assert_nil s2.race, 'Add association failed'
178
+
179
+ # Add Model to another Race's collection
180
+ @av.products << s3
181
+ assert_equal s3, @av.products.first, 'Add association failed'
182
+ assert_equal @av, s3.race, 'Add association failed'
183
+ assert_equal [], @ster.products, 'Add association failed'
184
+ end
185
+
186
+ def test_compare_ships
187
+ m1 = Product.new %w[N310.f134h 30.90 1 20.00 450.00 0.00 500.90],{:race=>@ace}
188
+ m2 = Product.new %w[MAK-113-11x13 18.28 11 13.70 35.24 0.00 335.72],{:race=>@av}
189
+ m3 = Product.new %w[z17-.2x2 11.66 1 2.00 2.00 1.00 16.66],{:race=>@ster}
190
+ m4 = Product.new %w[z17-2orro 11.66 1 2.00 1.00 2.00 16.66],{:race=>@ster}
191
+
192
+ assert m1==m1, 'Self-equality failed'
193
+ assert m1!=m2, 'Non-equal comparison failed'
194
+ assert m3!=m4, 'Non-equal comparison failed, equal mass ships'
195
+ assert m2<m1, 'LT model comparison failed'
196
+ assert m2>=m3, 'GTE model comparison failed'
197
+
198
+ assert m1>nil, 'nil comparison failed'
199
+ assert m2=='MAK-113-11x13', 'String comparison failed'
200
+ assert m2=='ArVitallian.MAK-113-11x13', 'String comparison failed'
201
+ end
202
+
203
+ def test_compare_sciences
204
+ m1 = Product.new %w[MoveTo_300_2504 300.00 2503.99 0 0],{:race=>@ace}
205
+ m2 = Product.new %w[MoveTo_6300_12504 6299.55 12503.99 0 0],{:race=>@av}
206
+ m3 = Product.new %w[MoveTo_3000_2504 3000.00 2503.99 0 0],{:race=>@ster}
207
+
208
+ assert m1==m1, 'Self-equality failed'
209
+ assert m1!=m2, 'Non-equal comparison failed'
210
+ assert m3<m2, 'LT model comparison failed'
211
+ assert m2>=m3, 'GTE model comparison failed'
212
+ end
213
+
214
+ def test_compare_ships_and_sciences
215
+ m0 = Product.new %w[_TerraForming 1.00 0.00 0 0],{:race=>@ace}
216
+ m1 = Product.new %w[MoveTo_300_2504 300.00 2503.99 0 0],{:race=>@ace}
217
+ m2 = Product.new %w[MAK-113-11x13 218.28 11 13.70 35.24 0.00 335.72],{:race=>@av}
218
+ m3 = Product.new %w[DPOH 1.00 0 0.00 0.00 0.00 1.00],{:race=>@av}
219
+ drive = Product.new [], {:name=>'Drive', :prod_type=>'research'}
220
+ wea = Product.new [], {:name=>'Weapons', :prod_type=>'research'}
221
+ shi = Product.new [], {:name=>'Shields', :prod_type=>'research'}
222
+ car = Product.new [], {:name=>'Cargo', :prod_type=>'research'}
223
+ cap = Product.new [], {:name=>'Capital', :prod_type=>'cap'}
224
+ mat = Product.new [], {:name=>'Materials', :prod_type=>'mat'}
225
+
226
+ assert m1!=m2, 'Non-equal comparison failed'
227
+ assert m2!=m1, 'Non-equal comparison failed'
228
+ assert m1!=drive, 'Non-equal comparison failed'
229
+ assert m1!=wea, 'Non-equal comparison failed'
230
+ assert shi!=m2, 'Non-equal comparison failed'
231
+ assert car!=shi, 'Non-equal comparison failed'
232
+ assert m1!=cap, 'Non-equal comparison failed'
233
+ assert cap!=m2, 'Non-equal comparison failed'
234
+ assert mat!=m1, 'Non-equal comparison failed'
235
+ assert mat!=car, 'Non-equal comparison failed'
236
+
237
+ assert cap!=:col, 'Symbol comparison failed'
238
+ assert cap==:cap, 'Symbol comparison failed'
239
+ assert cap==:capital, 'Symbol comparison failed'
240
+ assert mat==:mat, 'Symbol comparison failed'
241
+ assert mat==:materials, 'Symbol comparison failed'
242
+ assert drive==:research, 'Symbol comparison failed'
243
+ assert drive==:drive, 'Symbol comparison failed'
244
+ assert wea==:weapons, 'Symbol comparison failed'
245
+ assert shi==:shields, 'Symbol comparison failed'
246
+ assert car==:cargo, 'Symbol comparison failed'
247
+ assert m0 == :research, 'Symbol comparison failed'
248
+ assert m0 == :terraform, 'Symbol comparison failed'
249
+ assert m1==:research, 'Symbol comparison failed'
250
+ assert m1==:tech, 'Symbol comparison failed'
251
+ assert m1==:science, 'Symbol comparison failed'
252
+ assert m1==:move, 'Symbol comparison failed'
253
+ assert m1==:moveto, 'Symbol comparison failed'
254
+ assert m1== :"300", 'Symbol comparison failed'
255
+ assert m2 == :mak, 'Symbol comparison failed'
256
+ assert m3 == :ship, 'Symbol comparison failed'
257
+ assert m3 == :dron, 'Symbol comparison failed'
258
+
259
+ assert cap=='Capital', 'String comparison failed'
260
+ assert mat=='Materials', 'String comparison failed'
261
+ assert m2 == "MAK", 'String comparison failed'
262
+ assert shi=='Shield', 'String comparison failed'
263
+ end
264
+
265
+ def test_compare_all
266
+ m0 = Product.new %w[_TerraForming 1.00 0.00 0 0],{:race=>@ace}
267
+ m1 = Product.new %w[MoveTo_300_2504 300.00 2503.99 0 0],{:race=>@ace}
268
+ m2 = Product.new %w[MAK-113-11x13 218.28 11 13.70 35.24 0.00 335.72],{:race=>@av}
269
+ m3 = Product.new %w[DPOH 1.00 0 0.00 0.00 0.00 1.00],{:race=>@av}
270
+ drive = Product.new [], {:name=>'Drive', :prod_type=>'research'}
271
+ cap = Product.new [], {:name=>'Capital', :prod_type=>'cap'}
272
+ mat = Product.new [], {:name=>'Materials', :prod_type=>'mat'}
273
+
274
+ p1 = Planet.new %w[9802 10483.56 10512.20 N-A4 2500.00 2349.00 2200.00 0.03 DPOH 49.75 5214.30 2005.14 2300.00], {:race=>@av}
275
+ p2 = Planet.new %w[7261 15768.34 11160.36], {} #MoveTo_300_2504
276
+
277
+ b = Bombing.new %w[Ace ArVitallian 7261 #7261 0.01 0.01 DPOH 3.19 1.75 0.09 26.82 Wiped],{}
278
+
279
+ assert m0 > nil, 'nil comparison failed'
280
+ assert m1 == m1, 'Self-equality failed'
281
+ assert m1 != m3, 'Equality failed'
282
+ assert m2 > m3, 'GT model comparison failed'
283
+ assert m1 != drive, 'LTE model comparison failed'
284
+ assert m1 != cap, 'LTE model comparison failed'
285
+ assert m1 != mat, 'LTE model comparison failed'
286
+
287
+ assert m2 == @av, 'Race comparison failed'
288
+ assert m1 != @av, 'Race comparison failed'
289
+ assert m3 == p1, 'Planet comparison failed'
290
+ assert m0 != p1, 'Planet comparison failed'
291
+ assert m3 == b, 'Bombing comparison failed'
292
+ assert m2 != b, 'Bombing comparison failed'
293
+ assert m1 > b, 'Bombing comparison failed'
294
+ # Add group comparison
295
+
296
+ assert m2 > 300, 'Integer comparison failed'
297
+ assert m2 > 335.7, 'Float comparison failed'
298
+ assert drive > 30000, 'Integer comparison failed'
299
+ assert m3 == 1, 'Integer comparison failed'
300
+ assert m2 == 'ArVitallian', 'String comparison failed'
301
+ assert m1 == 'research', 'String comparison failed'
302
+ assert m1 != :ship, 'Symbol comparison failed'
303
+ assert m0 != :move, 'Symbol comparison failed'
304
+ assert m0 == :terraform, 'Symbol comparison failed'
305
+ end
306
+
307
+ def test_boolean_methods
308
+ m0 = Product.new %w[_TerraForming 1.00 0.00 0 0],{:race=>@ace}
309
+ m1 = Product.new %w[MoveTo_300_2504 300.00 2503.99 0 0],{:race=>@ace}
310
+ m2 = Product.new %w[MAK-113-11x13 218.28 11 13.70 35.24 0.00 335.72],{:race=>@av}
311
+ m3 = Product.new %w[DPOH 1.00 0 0.00 0.00 0.00 1.00],{:race=>@av}
312
+ drive = Product.new [], {:name=>'Drive', :prod_type=>'research'}
313
+ wea = Product.new [], {:name=>'Weapons', :prod_type=>'research'}
314
+ shi = Product.new [], {:name=>'Shields', :prod_type=>'research'}
315
+ car = Product.new [], {:name=>'Cargo', :prod_type=>'research'}
316
+ cap = Product.new [], {:name=>'Capital', :prod_type=>'cap'}
317
+ mat = Product.new [], {:name=>'Materials', :prod_type=>'mat'}
318
+
319
+ p = Planet.new %w[9802 10483.56 10512.20 N-A4 2500.00 2349.00 2200.00 0.03 DPOH 49.75 5214.30 2005.14 2300.00], {:race=>@av}
320
+ b = Bombing.new %w[Ace ArVitallian 7261 #7261 0.01 0.01 DPOH 3.19 1.75 0.09 26.82 Wiped], {}
321
+ [p,b] #weird way to say that p, b are "used" without using them
322
+
323
+ assert cap.cap?, 'Boolean method failed'
324
+ assert !cap.mat?, 'Boolean method failed'
325
+ assert !cap.research?, 'Boolean method failed'
326
+ assert !cap.terraforming?, 'Boolean method failed'
327
+ assert !cap.moving?, 'Boolean method failed'
328
+ assert !cap.ship?, 'Boolean method failed'
329
+ assert !cap.drone?, 'Boolean method failed'
330
+ assert !cap.your?, 'Boolean method failed'
331
+ assert !cap.in_use?, 'Boolean method failed'
332
+
333
+ assert !mat.cap?, 'Boolean method failed'
334
+ assert mat.mat?, 'Boolean method failed'
335
+ assert !mat.research?, 'Boolean method failed'
336
+ assert !mat.terraforming?, 'Boolean method failed'
337
+ assert !mat.moving?, 'Boolean method failed'
338
+ assert !mat.ship?, 'Boolean method failed'
339
+ assert !mat.drone?, 'Boolean method failed'
340
+ assert !mat.your?, 'Boolean method failed'
341
+ assert !mat.in_use?, 'Boolean method failed'
342
+
343
+ assert !m0.cap?, 'Boolean method failed'
344
+ assert !m0.mat?, 'Boolean method failed'
345
+ assert m0.research?, 'Boolean method failed'
346
+ assert m0.terraforming?, 'Boolean method failed'
347
+ assert !m0.moving?, 'Boolean method failed'
348
+ assert !m0.ship?, 'Boolean method failed'
349
+ assert !m0.drone?, 'Boolean method failed'
350
+ assert !m0.your?, 'Boolean method failed'
351
+ assert !m0.in_use?, 'Boolean method failed'
352
+
353
+ assert !m1.cap?, 'Boolean method failed'
354
+ assert !m1.mat?, 'Boolean method failed'
355
+ assert m1.research?, 'Boolean method failed'
356
+ assert !m1.terraforming?, 'Boolean method failed'
357
+ assert m1.moving?, 'Boolean method failed'
358
+ assert !m1.ship?, 'Boolean method failed'
359
+ assert !m1.drone?, 'Boolean method failed'
360
+ assert !m1.your?, 'Boolean method failed'
361
+ assert !m1.in_use?, 'Boolean method failed'
362
+
363
+ assert !m2.cap?, 'Boolean method failed'
364
+ assert !m2.mat?, 'Boolean method failed'
365
+ assert !m2.research?, 'Boolean method failed'
366
+ assert !m2.terraforming?, 'Boolean method failed'
367
+ assert !m2.moving?, 'Boolean method failed'
368
+ assert m2.ship?, 'Boolean method failed'
369
+ assert !m2.drone?, 'Boolean method failed'
370
+ assert m2.your?, 'Boolean method failed'
371
+ assert !m2.in_use?, 'Boolean method failed'
372
+
373
+ assert !m3.cap?, 'Boolean method failed'
374
+ assert !m3.mat?, 'Boolean method failed'
375
+ assert !m3.research?, 'Boolean method failed'
376
+ assert !m3.terraforming?, 'Boolean method failed'
377
+ assert !m3.moving?, 'Boolean method failed'
378
+ assert m3.ship?, 'Boolean method failed'
379
+ assert m3.drone?, 'Boolean method failed'
380
+ assert m3.your?, 'Boolean method failed'
381
+ assert m3.in_use?, 'Boolean method failed'
382
+
383
+ assert !drive.cap?, 'Boolean method failed'
384
+ assert !drive.mat?, 'Boolean method failed'
385
+ assert drive.research?, 'Boolean method failed'
386
+ assert !drive.terraforming?, 'Boolean method failed'
387
+ assert !drive.moving?, 'Boolean method failed'
388
+ assert !drive.ship?, 'Boolean method failed'
389
+ assert !drive.drone?, 'Boolean method failed'
390
+ assert !drive.your?, 'Boolean method failed'
391
+ assert !drive.in_use?, 'Boolean method failed'
392
+
393
+ assert !wea.cap?, 'Boolean method failed'
394
+ assert !wea.mat?, 'Boolean method failed'
395
+ assert wea.research?, 'Boolean method failed'
396
+ assert !wea.terraforming?, 'Boolean method failed'
397
+ assert !wea.moving?, 'Boolean method failed'
398
+ assert !wea.ship?, 'Boolean method failed'
399
+ assert !wea.drone?, 'Boolean method failed'
400
+ assert !wea.your?, 'Boolean method failed'
401
+ assert !wea.in_use?, 'Boolean method failed'
402
+
403
+ assert !shi.cap?, 'Boolean method failed'
404
+ assert !shi.mat?, 'Boolean method failed'
405
+ assert shi.research?, 'Boolean method failed'
406
+ assert !shi.terraforming?, 'Boolean method failed'
407
+ assert !shi.moving?, 'Boolean method failed'
408
+ assert !shi.ship?, 'Boolean method failed'
409
+ assert !shi.drone?, 'Boolean method failed'
410
+ assert !shi.your?, 'Boolean method failed'
411
+ assert !shi.in_use?, 'Boolean method failed'
412
+
413
+ assert !car.cap?, 'Boolean method failed'
414
+ assert !car.mat?, 'Boolean method failed'
415
+ assert car.research?, 'Boolean method failed'
416
+ assert !car.terraforming?, 'Boolean method failed'
417
+ assert !car.moving?, 'Boolean method failed'
418
+ assert !car.ship?, 'Boolean method failed'
419
+ assert !car.drone?, 'Boolean method failed'
420
+ assert !car.your?, 'Boolean method failed'
421
+ assert !car.in_use?, 'Boolean method failed'
422
+ end
423
+ end
424
+
425
+ class M_RouteTest < Test::Unit::TestCase
426
+ def setup
427
+ rep = Report.new 'rep/ArVit187.rep'
428
+ @data = ActiveRecord::Base.establish_dataset(rep)
429
+ @data.owner='ArVitallian'
430
+ @av = Race.new %w[ArVitallian 13.00 11.61 11.08 5.48 2276614.82 2028341.13 2515 - 2276.61],{}
431
+ @q = Product.new %w[QAK 1.00 0 0.00 2.33 0.00 3.33],{:race=>@av}
432
+ @p1 = Planet.new %w[9802 10483.56 10512.20 N-A4 2500.00 2349.00 2200.00 0.03 QAK 49.75 5214.30 2005.14 2300.00], {:race=>@av}
433
+ @p2 = Planet.new %w[7346 13906.25 17458.86 CYB 2500.00 0.07 0.00 3819.89], {}
434
+ @p3 = Planet.new %w[7261 15768.34 11160.36], {}
435
+ end
436
+
437
+ def test_init
438
+ m = Route.new %w[N-A4 - CYB - -], {:owner=>'ArVitallian'}
439
+
440
+ assert_equal '9802.7346.mat', m.key, 'Route key wrong'
441
+ assert_equal @p1, m.planet, 'Source accessor wrong'
442
+ assert_equal @p2, m.target, 'Target accessor wrong'
443
+ assert_equal 'mat', m.cargo, 'Cargo accessor wrong'
444
+ assert m.planet == :arvitallian, 'Source accessor wrong'
445
+ assert m.target == 'CYB', 'Target accessor wrong'
446
+
447
+ assert_equal m, @p1.routes.first, 'Route association wrong'
448
+ assert_equal @p2, @p1.targets.first, 'Route association wrong'
449
+ assert_equal m, @p2.incoming_routes.first, 'Route association wrong'
450
+ assert_equal @p1, @p2.suppliers.first, 'Route association wrong'
451
+ assert_equal m, @av.routes.first, 'Route association wrong'
452
+ assert_equal @av, m.race, 'Route association wrong'
453
+ end
454
+
455
+ def test_replace
456
+ m = Route.new %w[N-A4 - - CYB -], {:owner=>'ArVitallian'}
457
+ # Establishing new col Route starting from the same Planet (should replace previous Route)
458
+ m1 = Route.new %w[N-A4 - - #7261 -], {:owner=>'ArVitallian'}
459
+
460
+ # Assert nil on former col Route association
461
+ assert_nil @p2.suppliers.first, 'Route association wrong'
462
+ assert_nil @p2.incoming_routes.first, 'Route association wrong'
463
+ assert_nil m.planet, 'Source accessor wrong'
464
+ assert_nil m.target, 'Target accessor wrong'
465
+ assert_nil m.race, 'Route association wrong'
466
+ assert_equal 'col', m.cargo, 'Cargo accessor wrong'
467
+
468
+ # Assert equality of new col Route
469
+ assert_equal @p1, m1.planet, 'Source accessor wrong'
470
+ assert_equal @p3, m1.target, 'Target accessor wrong'
471
+ assert_equal 'col', m1.cargo, 'Cargo accessor wrong'
472
+ assert_equal m1, @p1.routes.first, 'Route association wrong'
473
+ assert_equal @p3, @p1.targets.first, 'Route association wrong'
474
+ assert_equal m1, @p3.incoming_routes.first, 'Route association wrong'
475
+ assert_equal @p1, @p3.suppliers.first, 'Route association wrong'
476
+ assert m1.planet == :arvitallian, 'Source accessor wrong'
477
+ assert m1.target == :unidentified, 'Target accessor wrong'
478
+ assert m1.target == 7261, 'Target accessor wrong'
479
+ assert_equal @av, m1.race, 'Route association wrong'
480
+ assert_equal m1, @av.routes.first, 'Route association wrong'
481
+ end
482
+
483
+ def test_compare
484
+ m1 = Route.new %w[CYB - - #7261 -], {:owner=>'ArVitallian'}
485
+ m2 = Route.new %w[N-A4 - CYB - -], {:owner=>'ArVitallian'}
486
+
487
+ assert m1 > nil, 'Nil Comparison wrong'
488
+ assert m1 == m1, 'Self Comparison wrong'
489
+ assert m1 != m2, 'Route Comparison wrong'
490
+ assert m1 == @av, 'Race Comparison wrong'
491
+ assert m1 == @p2, 'Planet Comparison wrong'
492
+ assert m1 == @p3, 'Planet Comparison wrong'
493
+ assert m2 == @p1, 'Planet Comparison wrong'
494
+ assert m2 == @p2, 'Planet Comparison wrong'
495
+ assert m1 < 1, 'Route Distance Comparison wrong' # Should be implemented in Planet
496
+ assert m1 < 1.0, 'Route Distance Comparison wrong' # Should be implemented in Planet
497
+ assert m1 == :arvitallian, 'Symbol Comparison wrong'
498
+ assert m1 == :unidentified, 'Symbol Comparison wrong'
499
+ assert m1 == 'CYB', 'String Comparison wrong'
500
+ assert m2 == 'CYB'.downcase.to_sym, 'Symbol Comparison wrong'
501
+ assert m2 == 'N-A4', 'String Comparison wrong'
502
+ assert m1 != 'Erunda', 'String Comparison wrong'
503
+ assert m1 == :col, 'Symbol Comparison wrong'
504
+ assert m2 == 'MAT', 'String Comparison wrong'
505
+ assert m2 != :erunda, 'Symbol Comparison wrong'
506
+ end
507
+
508
+ def test_delete
509
+ # Delete from planet side
510
+ m = Route.new %w[N-A4 - - CYB -], {:owner=>'ArVitallian'}
511
+ @p1.routes.delete m
512
+
513
+ assert_nil @p1.routes.first, 'Route association wrong'
514
+ assert_nil @p1.targets.first, 'Route association wrong'
515
+ assert_nil @p2.incoming_routes.first, 'Route association wrong'
516
+ assert_nil @p2.suppliers.first, 'Route association wrong'
517
+ assert_nil m.planet, 'Source accessor wrong'
518
+ assert_nil m.target, 'Target accessor wrong'
519
+ assert_equal 'col', m.cargo, 'Cargo accessor wrong'
520
+
521
+ # Delete from target side
522
+ m = Route.new %w[N-A4 - - CYB -], {:owner=>'ArVitallian'}
523
+ @p2.incoming_routes.delete m
524
+
525
+ assert_nil @p1.routes.first, 'Route association wrong'
526
+ assert_nil @p1.targets.first, 'Route association wrong'
527
+ assert_nil @p2.incoming_routes.first, 'Route association wrong'
528
+ assert_nil @p2.suppliers.first, 'Route association wrong'
529
+ assert_nil m.race, 'Route association wrong'
530
+ assert_nil @av.routes.first, 'Route association wrong'
531
+ assert_nil m.planet, 'Source accessor wrong'
532
+ assert_nil m.target, 'Target accessor wrong'
533
+ assert_equal 'col', m.cargo, 'Cargo accessor wrong'
534
+ end
535
+
536
+ end
537
+
538
+ class M_FleetTest < Test::Unit::TestCase
539
+ def setup
540
+ rep = Report.new 'rep/ArVit187.rep'
541
+ @data = ActiveRecord::Base.establish_dataset(rep)
542
+ @data.owner='ArVitallian'
543
+ @av = Race.new %w[ArVitallian 13.00 11.61 11.08 5.48 2276614.82 2028341.13 2515 - 2276.61],{}
544
+ @q = Product.new %w[QAK 1.00 0 0.00 2.33 0.00 3.33],{:race=>@av}
545
+ @p1 = Planet.new %w[9802 10483.56 10512.20 N-A4 2500.00 2349.00 2200.00 0.03 QAK 49.75 5214.30 2005.14 2300.00], {:race=>@av}
546
+ @p2 = Planet.new %w[7346 13906.25 17458.86 CYB 2500.00 0.07 0.00 3819.89], {}
547
+ @p3 = Planet.new %w[7261 15768.34 11160.36], {}
548
+ end
549
+
550
+ def test_init
551
+ m1 = Fleet.new %w[1 fgtr5 6 N-A4 - 0.00 112.50 In_Orbit], {:owner=>'ArVitallian'}
552
+ m2 = Fleet.new %w[10 sv11 17 CYB #7261 91.69 153.45 In_Space], {:owner=>'ArVitallian'}
553
+
554
+ assert_equal 'ArVitallian.fgtr5', m1.key, 'Fleet key wrong'
555
+ assert_equal @p1, m1.planet, 'Fleet planet wrong'
556
+ assert_nil m1.from, 'Fleet planet wrong'
557
+ assert_equal 1, m1.num, 'Fleet accessor wrong'
558
+ assert_equal 'fgtr5', m1.name, 'Fleet accessor wrong'
559
+ assert_equal 6, m1.num_groups, 'Fleet accessor wrong'
560
+ assert_equal 0, m1.range, 'Fleet accessor wrong'
561
+ assert_equal 112.50, m1.speed, 'Fleet accessor wrong'
562
+ assert_equal 'In_Orbit', m1.status, 'Fleet accessor wrong'
563
+ assert_in_delta 0.0, m1.eta, 0.00001, 'ETA calculation wrong'
564
+
565
+ assert_equal 'ArVitallian.sv11', m2.key, 'Fleet key wrong'
566
+ assert_equal @p2, m2.planet, 'Fleet planet wrong'
567
+ assert_equal @p3, m2.from, 'Fleet planet wrong'
568
+ assert_equal 'sv11', m2.name, 'Fleet accessor wrong'
569
+ assert_equal 17, m2.num_groups, 'Fleet accessor wrong'
570
+ assert_equal 91.69, m2.range, 'Fleet accessor wrong'
571
+ assert_equal 153.45, m2.speed, 'Fleet accessor wrong'
572
+ assert_equal 'In_Space', m2.status, 'Fleet accessor wrong'
573
+ assert_in_delta 0.597523, m2.eta, 0.00001, 'ETA calculation wrong'
574
+
575
+ assert_equal m1, @p1.fleets.first, 'Fleet association wrong'
576
+ assert_equal m2, @p2.fleets.first, 'Fleet association wrong'
577
+ assert_equal m2, @p3.sent_fleets.first, 'Fleet association wrong'
578
+ assert_equal @av, m1.race, 'Fleet association wrong'
579
+ assert_equal m1, @av.fleets.first, 'Fleet association wrong'
580
+ assert_equal @av, m2.race, 'Fleet association wrong'
581
+ assert_equal m2, @av.fleets.last, 'Fleet association wrong'
582
+ end
583
+
584
+ def test_compare
585
+ m1 = Fleet.new %w[1 fgtr5 6 N-A4 - 0.00 112.50 In_Orbit], {:owner=>'ArVitallian'}
586
+ m2 = Fleet.new %w[10 sv11 17 CYB #7261 91.69 153.45 In_Space], {:owner=>'ArVitallian'}
587
+
588
+ assert m1 > nil, 'Nil Comparison wrong'
589
+ assert m1 == m1, 'Self Comparison wrong'
590
+ assert m1 != m2, 'Fleet Comparison wrong'
591
+ assert m1 == @p1, 'Planet Comparison wrong'
592
+ assert m2 == @p3, 'Planet Comparison wrong'
593
+ # assert group comparison
594
+ assert m1 < 7, 'Num groups Comparison wrong'
595
+ assert m2 >= 13, 'Num groups Comparison wrong'
596
+ assert m1 == :in_orbit, 'Comparison wrong'
597
+ assert m1 == 'Orbit', 'Comparison wrong'
598
+ assert m1 == 'fgtr5', 'Comparison wrong'
599
+ assert m2 == 'sv11', 'Comparison wrong'
600
+ assert m1 == :arvitallian, 'Comparison wrong'
601
+ assert m1 != 'Erunda', 'String Comparison wrong'
602
+ assert m2 != :erunda, 'Symbol Comparison wrong'
603
+ end
604
+
605
+ def test_change_sent_fleet_collection #weird way to test VirtualBase::has_many_linked method generator
606
+ m1 = Fleet.new %w[1 fgtr5 6 N-A4 - 0.00 112.50 In_Orbit], {:owner=>'ArVitallian'}
607
+ m2 = Fleet.new %w[10 sv11 17 CYB #7261 91.69 153.45 In_Space], {:owner=>'ArVitallian'}
608
+
609
+ @p1.sent_fleets << m2
610
+
611
+ assert_equal 'ArVitallian.fgtr5', m1.key, 'Fleet key wrong'
612
+ assert_equal @p1, m1.planet, 'Fleet planet wrong'
613
+ assert_nil m1.from, 'Fleet planet wrong'
614
+ assert_equal 1, m1.num, 'Fleet accessor wrong'
615
+ assert_equal 'fgtr5', m1.name, 'Fleet accessor wrong'
616
+ assert_equal 6, m1.num_groups, 'Fleet accessor wrong'
617
+ assert_equal 0, m1.range, 'Fleet accessor wrong'
618
+ assert_equal 112.50, m1.speed, 'Fleet accessor wrong'
619
+ assert_equal 'In_Orbit', m1.status, 'Fleet accessor wrong'
620
+ assert_in_delta 0.0, m1.eta, 0.00001, 'ETA calculation wrong'
621
+
622
+ assert_equal 'ArVitallian.sv11', m2.key, 'Fleet key wrong'
623
+ assert_equal @p2, m2.planet, 'Fleet planet wrong'
624
+ assert_equal @p1, m2.from, 'Fleet planet wrong'
625
+ assert_equal 'sv11', m2.name, 'Fleet accessor wrong'
626
+ assert_equal 17, m2.num_groups, 'Fleet accessor wrong'
627
+ assert_equal 91.69, m2.range, 'Fleet accessor wrong'
628
+ assert_equal 153.45, m2.speed, 'Fleet accessor wrong'
629
+ assert_equal 'In_Space', m2.status, 'Fleet accessor wrong'
630
+ assert_in_delta 0.597523, m2.eta, 0.00001, 'ETA calculation wrong'
631
+
632
+ assert_equal m1, @p1.fleets.first, 'Fleet association wrong'
633
+ assert_equal m2, @p2.fleets.first, 'Fleet association wrong'
634
+ assert_equal m2, @p1.sent_fleets.first, 'Fleet association wrong'
635
+ assert_nil @p3.sent_fleets.first, 'Fleet association wrong'
636
+ assert_equal @av, m1.race, 'Fleet association wrong'
637
+ assert_equal @av, m2.race, 'Fleet association wrong'
638
+ assert_equal m1, @av.fleets.first, 'Fleet association wrong'
639
+ assert_equal m2, @av.fleets.last, 'Fleet association wrong'
640
+
641
+ end
642
+
643
+ end
644
+
645
+ class M_BombingTest < Test::Unit::TestCase
646
+ def setup
647
+ rep = Report.new 'rep/ArVit187.rep'
648
+ @data = ActiveRecord::Base.establish_dataset(rep)
649
+ @data.owner='ArVitallian'
650
+ @av = Race.new %w[ArVitallian 13.00 11.61 11.08 5.48 2276614.82 2028341.13 2515 - 2276.61],{}
651
+ @vd = Race.new %w[Vildok 10.33 1.00 1.00 6.07 2035.74 0.00 1 War 0.00], {}
652
+ @raz = Product.new %w[raz 1.00 0 0.00 0.00 0.00 1.00],{:race=>@vd}
653
+ @move = Product.new %w[Move6SUN 15741.00 8699.00 0 0],{:race=>@av}
654
+ @p1 = Planet.new %w[10190 NOVA], {}
655
+ @p2 = Planet.new ['#3191'], {}
656
+ end
657
+
658
+ def test_init
659
+ m1 = Bombing.new %w[ArVitallian Vildok 10190 NOVA 2500.00 268.75 raz 0.00 44877.92 0.00 615.06 Damaged], {}
660
+ m2 = Bombing.new %w[Vildok ArVitallian 3191 #3191 0.01 0.01 Move6SUN 3.19 1.75 0.09 26.82 Wiped], {}
661
+
662
+ assert_equal 'ArVitallian.Vildok.10190', m1.key, 'Bombing planet wrong'
663
+ assert_equal 2500.00, m1.pop, 'Bombing planet wrong'
664
+ assert_equal 268.75, m1.ind, 'Bombing planet wrong'
665
+ assert_equal 0, m1.cap, 'Bombing planet wrong'
666
+ assert_equal 44877.92, m1.mat, 'Bombing planet wrong'
667
+ assert_equal 0, m1.col, 'Bombing planet wrong'
668
+ assert_equal 615.06, m1.attack, 'Bombing planet wrong'
669
+ assert_equal 'Damaged', m1.status, 'Bombing planet wrong'
670
+ assert_equal @raz, m1.product, 'Bombing planet wrong'
671
+ assert_equal @p1, m1.planet, 'Bombing planet wrong'
672
+ assert_equal @av, m1.race, 'Bombing planet wrong'
673
+ assert_equal @vd, m1.victim, 'Bombing planet wrong'
674
+
675
+ assert_equal 'Vildok.ArVitallian.3191', m2.key, 'Bombing planet wrong'
676
+ assert_equal 0.01, m2.pop, 'Bombing planet wrong'
677
+ assert_equal 0.01, m2.ind, 'Bombing planet wrong'
678
+ assert_equal 3.19, m2.cap, 'Bombing planet wrong'
679
+ assert_equal 1.75, m2.mat, 'Bombing planet wrong'
680
+ assert_equal 0.09, m2.col, 'Bombing planet wrong'
681
+ assert_equal 26.82, m2.attack, 'Bombing planet wrong'
682
+ assert_equal 'Wiped', m2.status, 'Bombing planet wrong'
683
+ assert_equal @move, m2.product, 'Bombing planet wrong'
684
+ assert_equal @p2, m2.planet, 'Bombing planet wrong'
685
+ assert_equal @vd, m2.race, 'Bombing planet wrong'
686
+ assert_equal @av, m2.victim, 'Bombing planet wrong'
687
+
688
+ #Assert associations
689
+ assert_equal m1, @p1.bombings.first, 'Bombing association wrong'
690
+ assert_equal m1, @av.bombings.first, 'Bombing association wrong'
691
+ assert_equal m1, @vd.incoming_bombings.first, 'Bombing association wrong'
692
+ assert_equal m1, @raz.bombings.first, 'Bombing association wrong'
693
+
694
+ assert_equal m2, @p2.bombings.first, 'Bombing association wrong'
695
+ assert_equal m2, @av.incoming_bombings.first, 'Bombing association wrong'
696
+ assert_equal m2, @vd.bombings.first, 'Bombing association wrong'
697
+ assert_equal m2, @move.bombings.first, 'Bombing association wrong'
698
+ end
699
+
700
+ def test_compare
701
+ m1 = Bombing.new %w[ArVitallian Vildok 10190 NOVA 2500.00 268.75 raz 0.00 44877.92 0.00 615.06 Damaged],
702
+ {:planet=>@p1, :race=>@av, :victim=>@vd, :product=>@raz}
703
+ m2 = Bombing.new %w[Vildok ArVitallian 3191 #3191 0.01 0.01 Move6SUN 3.19 1.75 0.09 26.82 Wiped],
704
+ {:planet=>@p2, :race=>@vd, :victim=>@av, :product=>@move}
705
+
706
+ assert m1 > nil, 'Comparison wrong'
707
+ assert m1 == @p1, 'Comparison wrong'
708
+ assert m1 != @p2, 'Comparison wrong'
709
+ assert m1 == @raz, 'Comparison wrong'
710
+ assert m1 != @move, 'Comparison wrong'
711
+ assert m1 == @av, 'Comparison wrong'
712
+ assert m1 == @vd, 'Comparison wrong'
713
+ assert m1 > 600, 'Comparison wrong'
714
+ assert m1 == 'nova', 'Comparison wrong'
715
+ assert m1 == :arvitallian, 'Comparison wrong'
716
+ assert m1 == 'raz', 'Comparison wrong'
717
+ assert m1 == 'Vildok', 'Comparison wrong'
718
+ assert m1 == :damaged, 'Comparison wrong'
719
+ assert m2 != m1, 'Comparison wrong'
720
+ assert m2 <= 100, 'Comparison wrong'
721
+ assert m2 == :move, 'Comparison wrong'
722
+ assert m2 == :research, 'Comparison wrong'
723
+ end
724
+ end
725
+
726
+ class M_PlanetTest < Test::Unit::TestCase
727
+ def setup
728
+ rep = Report.new 'rep/ArVit187.rep'
729
+ @data = ActiveRecord::Base.establish_dataset(rep)
730
+ @data.owner='ArVitallian'
731
+ @av = Race.new %w[ArVitallian 13.00 11.61 11.08 5.48 2276614.82 2028341.13 2515 - 2276.61],{}
732
+ @vd = Race.new %w[Vildok 10.33 1.00 1.00 6.07 2035.74 0.00 1 War 0.00], {}
733
+ @q = Product.new %w[QAK 1.00 0 0.00 2.33 0.00 3.33],{:race=>@av}
734
+ end
735
+
736
+ def test_init_your
737
+ m = Planet.new %w[9802 10483.56 10512.20 N-A4 2500.00 2349.00 2200.00 0.03 QAK 49.75 5214.30 2005.14 2300.00], {:race=>@av}
738
+ assert_equal "N-A4", m.key, 'Key accessor wrong'
739
+ assert_equal 0, m.idx, 'Idx accessor wrong'
740
+ assert_equal 9802, m.num, 'Num attribute wrong'
741
+ assert_equal 10483.56, m.x, 'X attribute wrong'
742
+ assert_equal 10512.20, m.y, 'Y attribute wrong'
743
+ assert_equal "N-A4", m.name, 'Name attribute wrong'
744
+ assert_equal 2500.00, m.size, 'Size attribute wrong'
745
+ assert_equal 2349.00, m.pop, 'Pop attribute wrong'
746
+ assert_equal 2200.00, m.ind, 'Ind attribute wrong'
747
+ assert_equal 0.03, m.res, 'Res attribute wrong'
748
+ assert_equal 49.75, m.cap, 'Cap attribute wrong'
749
+ assert_equal 5214.30, m.mat, 'Mat attribute wrong'
750
+ assert_equal 2005.14, m.col, 'Col attribute wrong'
751
+ assert_equal 2300.00, m.l, 'L attribute wrong'
752
+ assert ! m.uninhabited?, 'Method wrong'
753
+ assert ! m.unidentified?, 'Method wrong'
754
+
755
+ assert_equal @av, m.race, 'Race association wrong'
756
+ assert_equal m, @av.planets.first, 'Race association wrong'
757
+ assert_equal m, @q.planets.first, 'Product association wrong'
758
+ assert_equal @q, m.product, 'Product association wrong'
759
+ end
760
+
761
+ def test_init_uninhabited
762
+ m = Planet.new %w[7346 13906.25 17458.86 HOLY_TERRA 2500.00 0.07 0.00 3819.89], {}
763
+ assert_equal "HOLY_TERRA", m.key, 'Key accessor wrong'
764
+ #assert_equal 7346, m.idx, 'Idx accessor wrong'
765
+ assert_equal 7346, m.num, 'Num attribute wrong'
766
+ assert_equal 13906.25, m.x, 'X attribute wrong'
767
+ assert_equal 17458.86, m.y, 'Y attribute wrong'
768
+ assert_equal "HOLY_TERRA", m.name, 'Name attribute wrong'
769
+ assert_equal 2500.00, m.size, 'Size attribute wrong'
770
+ assert_nil m.pop, 'Pop attribute wrong'
771
+ assert_nil m.ind, 'Ind attribute wrong'
772
+ assert_equal 0.07, m.res, 'Res attribute wrong'
773
+ assert_nil m.product, 'Production attribute wrong'
774
+ assert_equal 0.00, m.cap, 'Cap attribute wrong'
775
+ assert_equal 3819.89, m.mat, 'Mat attribute wrong'
776
+ assert_nil m.col, 'Col attribute wrong'
777
+ assert_nil m.l, 'L attribute wrong'
778
+ assert m.uninhabited?, 'Method wrong'
779
+ assert ! m.unidentified?, 'Method wrong'
780
+
781
+ assert_nil m.race, 'Race association wrong'
782
+ end
783
+
784
+ def test_init_unidentified
785
+ m = Planet.new %w[7261 15768.34 11160.36], {}
786
+ assert_equal "#7261", m.key, 'Key accessor wrong'
787
+ #assert_equal 7261, m.idx, 'Idx accessor wrong'
788
+ assert_equal 7261, m.num, 'Num attribute wrong'
789
+ assert_equal 15768.34, m.x, 'X attribute wrong'
790
+ assert_equal 11160.36, m.y, 'Y attribute wrong'
791
+ assert_nil m.name, 'Name attribute wrong'
792
+ assert_nil m.size, 'Size attribute wrong'
793
+ assert_nil m.pop, 'Pop attribute wrong'
794
+ assert_nil m.ind, 'Ind attribute wrong'
795
+ assert_nil m.res, 'Res attribute wrong'
796
+ assert_nil m.product, 'Production attribute wrong'
797
+ assert_nil m.cap, 'Cap attribute wrong'
798
+ assert_nil m.mat, 'Mat attribute wrong'
799
+ assert_nil m.col, 'Col attribute wrong'
800
+ assert_nil m.l, 'L attribute wrong'
801
+ assert m.unidentified?, 'Method wrong'
802
+ assert ! m.uninhabited?, 'Method wrong'
803
+
804
+ assert_nil m.race, 'Race association wrong'
805
+ end
806
+
807
+ def test_init_battle
808
+ m = Planet.new %w[9032 A-S83], {}
809
+ assert_equal "A-S83", m.key, 'Key accessor wrong'
810
+ #assert_equal 9032, m.idx, 'Idx accessor wrong'
811
+ assert_equal 9032, m.num, 'Num attribute wrong'
812
+ assert_nil m.x, 'X attribute wrong'
813
+ assert_nil m.y, 'Y attribute wrong'
814
+ assert_equal "A-S83", m.name, 'Name attribute wrong'
815
+ assert_nil m.size, 'Size attribute wrong'
816
+ assert_nil m.pop, 'Pop attribute wrong'
817
+ assert_nil m.ind, 'Ind attribute wrong'
818
+ assert_nil m.res, 'Res attribute wrong'
819
+ assert_nil m.product, 'Production attribute wrong'
820
+ assert_nil m.cap, 'Cap attribute wrong'
821
+ assert_nil m.mat, 'Mat attribute wrong'
822
+ assert_nil m.col, 'Col attribute wrong'
823
+ assert_nil m.l, 'L attribute wrong'
824
+ assert m.unidentified?, 'Method wrong'
825
+ assert !m.uninhabited?, 'Method wrong'
826
+
827
+ assert_nil m.race, 'Race association wrong'
828
+ end
829
+
830
+ def test_update_planet
831
+ # Update with your planet
832
+ m = Planet.new %w[9802 N-A4], {}
833
+ m.update_planet %w[9802 10483.56 10512.20 N-A4 2500.00 2349.00 2200.00 0.03 QAK 49.75 5214.30 2005.14 2300.00], {:race=>@av, :product=>@q}
834
+ assert_equal "N-A4", m.key, 'Key accessor wrong'
835
+ #assert_equal 9802, m.idx, 'Idx accessor wrong'
836
+ assert_equal 9802, m.num, 'Num attribute wrong'
837
+ assert_equal 10483.56, m.x, 'X attribute wrong'
838
+ assert_equal 10512.20, m.y, 'Y attribute wrong'
839
+ assert_equal "N-A4", m.name, 'Name attribute wrong'
840
+ assert_equal 2500.00, m.size, 'Size attribute wrong'
841
+ assert_equal 2349.00, m.pop, 'Pop attribute wrong'
842
+ assert_equal 2200.00, m.ind, 'Ind attribute wrong'
843
+ assert_equal 0.03, m.res, 'Res attribute wrong'
844
+ assert_equal 49.75, m.cap, 'Cap attribute wrong'
845
+ assert_equal 5214.30, m.mat, 'Mat attribute wrong'
846
+ assert_equal 2005.14, m.col, 'Col attribute wrong'
847
+ assert_equal 2300.00, m.l, 'L attribute wrong'
848
+ assert ! m.uninhabited?, 'Method wrong'
849
+ assert ! m.unidentified?, 'Method wrong'
850
+
851
+ assert_equal @av, m.race, 'Race association wrong'
852
+ assert_equal m, @av.planets.first, 'Race association wrong'
853
+ assert_equal @q, m.product, 'Product association wrong'
854
+ assert_equal m, @q.planets.first, 'Product association wrong'
855
+
856
+ # Update with unidentified planet
857
+ m = Planet.new '#7261', {}
858
+ m.update_planet %w[7261 15768.34 11160.36], {}
859
+ assert_equal "#7261", m.key, 'Key accessor wrong' #should @planets['key'] position also change once a planet.key changes?!
860
+ assert_equal 1, m.idx, 'Idx accessor wrong'
861
+ assert_equal 7261, m.num, 'Num attribute wrong'
862
+ assert_equal 15768.34, m.x, 'X attribute wrong'
863
+ assert_equal 11160.36, m.y, 'Y attribute wrong'
864
+ assert_nil m.name, 'Name attribute wrong'
865
+ assert_nil m.size, 'Size attribute wrong'
866
+ assert_nil m.pop, 'Pop attribute wrong'
867
+ assert_nil m.ind, 'Ind attribute wrong'
868
+ assert_nil m.res, 'Res attribute wrong'
869
+ assert_nil m.product, 'Production attribute wrong'
870
+ assert_nil m.cap, 'Cap attribute wrong'
871
+ assert_nil m.mat, 'Mat attribute wrong'
872
+ assert_nil m.col, 'Col attribute wrong'
873
+ assert_nil m.l, 'L attribute wrong'
874
+ assert m.unidentified?, 'Method wrong'
875
+ assert ! m.uninhabited?, 'Method wrong'
876
+
877
+ assert_nil m.race, 'Race association wrong'
878
+ end
879
+
880
+ def test_update_production
881
+ m = Planet.new %w[9802 10483.56 10512.20 N-A4 33.3 33.3 33.3 0.03 QAK 49.75 5214.30 100.14 33.3], {:race=>@av}
882
+ match = %w[9802 N-A4 QAK 33.30 15.00 33.3]
883
+ Planet.new_or_update match, {}
884
+
885
+ assert_in_delta 0.45045045, m.progress, 0.001, 'Progress calculation wrong'
886
+ assert_in_delta 0.45045045, m.produced, 0.001, 'Progress calculation wrong'
887
+ assert_in_delta 0.45045045, m.produced_full_mat, 0.001, 'Progress calculation wrong'
888
+ assert_equal "N-A4", m.key, 'Key accessor wrong'
889
+ assert_equal 0, m.idx, 'Idx accessor wrong'
890
+ assert_equal 9802, m.num, 'Num attribute wrong'
891
+ assert_equal 10483.56, m.x, 'X attribute wrong'
892
+ assert_equal 10512.20, m.y, 'Y attribute wrong'
893
+ assert_equal "N-A4", m.name, 'Name attribute wrong'
894
+ assert_equal 33.3, m.size, 'Size attribute wrong'
895
+ assert_equal 33.3, m.pop, 'Pop attribute wrong'
896
+ assert_equal 33.3, m.ind, 'Ind attribute wrong'
897
+ assert_equal 0.03, m.res, 'Res attribute wrong'
898
+ assert_equal 49.75, m.cap, 'Cap attribute wrong'
899
+ assert_equal 5214.30, m.mat, 'Mat attribute wrong'
900
+ assert_equal 100.14, m.col, 'Col attribute wrong'
901
+ assert_equal 33.3, m.l, 'L attribute wrong'
902
+ assert ! m.uninhabited?, 'Method wrong'
903
+ assert ! m.unidentified?, 'Method wrong'
904
+ assert_equal @av, m.race, 'Race association wrong'
905
+ assert_equal m, @av.planets.first, 'Race association wrong'
906
+ assert_equal @q, m.product, 'Product association wrong'
907
+ assert_equal m, @q.planets.first, 'Product association wrong'
908
+
909
+ m = Planet.new %w[9802 10483.56 10512.20 N-A4 2500.00 2349.00 2200.00 0.03 QAK 49.75 0 2005.14 2300.00], {:race=>@av}
910
+ match = %w[9802 N-A4 QAK 33.30 15.00 2500.00]
911
+ Planet.new_or_update match, {}
912
+
913
+ assert_in_delta 0.159066808, m.produced, 0.001, 'Progress calculation wrong'
914
+ assert_in_delta 0.45045045, m.progress, 0.001, 'Progress calculation wrong'
915
+ assert_in_delta 0.45045045, m.produced_full_mat, 0.001, 'Progress calculation wrong'
916
+ end
917
+
918
+ def test_compare
919
+ m1 = Planet.new %w[9802 10483.56 10512.20 N-A4 2500.00 2349.00 2200.00 0.03 QAK 49.75 5214.30 2005.14 2300.00], {:race=>@av}
920
+ m2 = Planet.new %w[7346 13906.25 17458.86 HOLY_TERRA 2500.00 0.07 0.00 3819.89], {}
921
+ m3 = Planet.new %w[7261 15768.34 11160.36], {}
922
+ m4 = Planet.new %w[32 A-S83], {}
923
+
924
+ @move = Product.new %w[Move6SUN 15741.00 8699.00 0 0],{:race=>@av}
925
+ b = Bombing.new %w[Vildok ArVitallian 7261 #7261 0.01 0.01 Move6SUN 3.19 1.75 0.09 26.82 Wiped],
926
+ {:planet=>m3, :race=>@vd, :victim=>@av, :product=>@move}
927
+ f = Fleet.new %w[1 fgtr5 6 N-A4 - 0.00 112.50 In_Orbit], {:owner=>'ArVitallian'}
928
+ r = Route.new %w[N-A4 - HOLY_TERRA - -], {:owner=>'ArVitallian'}
929
+
930
+ assert m2 > nil, 'nil comparison failed'
931
+ assert m1 == m1, 'Self-equality failed'
932
+ assert m1 > m2, 'GT model comparison failed'
933
+ assert m3 < m2, 'LT model comparison failed'
934
+ assert m2 >= m4, 'GTE model comparison failed'
935
+ assert m4 <= m3, 'LTE model comparison failed'
936
+
937
+ assert m1 == @av, 'Race comparison failed'
938
+ assert m2 != @av, 'Race comparison failed'
939
+ assert m1 == @q, 'Product comparison failed'
940
+ assert m1 != b, 'Bombing comparison failed'
941
+ assert m3 == b, 'Bombing comparison failed'
942
+ assert m2 > b, 'Bombing comparison failed'
943
+ assert m1 == r, 'Route comparison failed'
944
+ assert m2 == r, 'Route comparison failed'
945
+ assert m4 > r, 'Route comparison failed'
946
+ assert m1 == f, 'Fleet comparison failed'
947
+ assert m4 > f, 'Fleet comparison failed'
948
+ # Add group comparison
949
+
950
+ assert m4 > 30, 'Integer comparison failed'
951
+ assert m3 == 7261, 'Integer comparison failed'
952
+ assert m1 == 'ArVitallian', 'String comparison failed'
953
+ assert m1 == 'N-A4', 'String comparison failed'
954
+ assert m1 != :aster, 'Symbol comparison failed'
955
+ assert m1 == :max, 'Symbol comparison failed'
956
+ assert m1 == :'n-a4', 'Symbol comparison failed'
957
+ assert m1 == :q, 'Symbol comparison failed'
958
+ end
959
+
960
+ def test_race_association
961
+ p1 = Planet.new %w[9802 10483.56 10512.20 N-A4 2500.00 2349.00 2200.00 0.03 QAK 49.75 5214.30 2005.14 2300.00], {:race=>@av}
962
+ p3 = Planet.new %w[7261 15768.34 11160.36], {:race=>@vd}
963
+
964
+ # Delete planet from its race's collection
965
+ p1.race.planets.delete p1
966
+ assert_equal [], @av.planets, 'Delete association failed'
967
+ assert_nil p1.race, 'Delete association failed'
968
+
969
+ # Add planet to another race's collection
970
+ @av.planets << p3
971
+ assert_equal p3, @av.planets.first, 'Add association failed'
972
+ assert_equal @av, p3.race, 'Add association failed'
973
+ assert_equal [], @vd.planets, 'Add association failed'
974
+ end
975
+ end
976
+
977
+ class M_GroupTest < Test::Unit::TestCase
978
+ def setup
979
+ rep = Report.new 'rep/ArVit187.rep'
980
+ @data = ActiveRecord::Base.establish_dataset(rep)
981
+ @data.owner='ArVitallian'
982
+ @av = Race.new %w[ArVitallian 13.00 11.61 11.08 5.48 2276614.82 2028341.13 2515 - 2276.61],{}
983
+ @vd = Race.new %w[Vildok 10.33 1.00 1.00 6.07 2035.74 0.00 1 War 0.00], {}
984
+ @homo = Race.new %w[Homo_galaktikus 8.10 6.04 6.04 4.50 39760.96 39026.32 45 Peace 0.00], {}
985
+ @raz = Product.new %w[raz 1.00 0 0.00 0.00 0.00 1.00],{:race=>@vd}
986
+ @q = Product.new %w[QAK 1.00 0 0.00 2.33 0.00 3.33],{:race=>@av}
987
+ @dron = Product.new %w[DPOH 1.00 0 0.00 0.00 0.00 1.00],{:race=>@av}
988
+ @mark = Product.new %w[MAPKEP 8.00 0 0.00 0.00 1.00 9.00],{:race=>@av}
989
+ @def = Product.new %w[Def 9.17 1 6.32 15.00 1.00 31.49],{:race=>@homo}
990
+ @p1 = Planet.new %w[9802 10483.56 10512.20 N-A4 2500.00 2349.00 2200.00 0.03 QAK 49.75 5214.30 2005.14 2300.00], {:race=>@av}
991
+ @p2 = Planet.new %w[7346 13906.25 17458.86 CYB 2500.00 0.07 0.00 3819.89], {}
992
+ @p3 = Planet.new %w[7261 15768.34 11160.36], {}
993
+ @p4 = Planet.new %w[9219 A-019], {}
994
+ @f1 = Fleet.new %w[1 fgtr5 6 N-A4 - 0.00 112.50 In_Orbit], {:owner=>'ArVitallian'}
995
+ @f2 = Fleet.new %w[10 sv11 17 CYB #7261 91.69 153.45 In_Space], {:owner=>'ArVitallian'}
996
+ end
997
+
998
+ def test_compare
999
+ m1 = Group.new %w[15768.34 11160.36], {}
1000
+ m2 = Group.new %w[#9219 N-A4 828.88 69.00 1.00], {}
1001
+ m3 = Group.new %w[CYB N-A4 1420.78 50.56 2000.00], {}
1002
+ m4 = Group.new %w[13 DPOH 11.80 0.00 0 0.00 - 0.00 10 In_Battle], {:race=>@av, :planet=>@p2, :battles=>1}
1003
+ m5 = Group.new %w[1 raz 8.05 0 0 0 - 0 1 Out_Battle], {:race=>@vd, :planet=>@p4, :battles=>2}
1004
+ m6 = Group.new %w[0 1 MAPKEP 2.22 0.00 0.00 1.00 COL 0.03 N-A4 - 0.00 39.34 9.03 - In_Orbit], {:race=>@av}
1005
+ m7 = Group.new %w[6830 1170 QAK 13.00 0.00 9.99 0.00 - 0.00 N-A4 - 0.00 78.08 3.33 fgtr5 In_Orbit], {:race=>@av}
1006
+ m8 = Group.new %w[62 raz 2.22 0 0 0 - 0 N-A4 44.40 1], {:race=>@vd}
1007
+ m9 = Group.new %w[1 Def 8.05 6.04 6.04 4.27 COL 4.48 CYB 45.37 32.54], {:race=>@homo}
1008
+
1009
+ all = [m1,m2,m3,m4,m5,m6,m7,m8,m9]
1010
+
1011
+ all.each do |m|
1012
+ assert m > nil, 'Nil Comparison wrong'
1013
+ assert m == m, 'Self Comparison wrong'
1014
+ assert m != @av, 'Race comparison failed' unless [m4,m6,m7].include? m
1015
+ assert m != @vd, 'Race comparison failed' unless [m5,m8].include? m
1016
+ assert m != @homo, 'Race comparison failed' unless m == m9
1017
+ assert m != @p1, 'Planet comparison failed' unless [m2,m3,m8,m6,m7].include? m
1018
+ assert m != @p2, 'Planet comparison failed' unless [m3,m4, m9].include? m
1019
+ assert m != @p3, 'Planet comparison failed'
1020
+ assert m != @p4, 'Planet comparison failed' unless [m2,m5].include? m
1021
+ assert m != @q, 'Product comparison failed' unless [m7].include? m
1022
+ assert m != @def, 'Product comparison failed' unless [m9].include? m
1023
+ assert m != @f1, 'Fleet comparison failed' unless [m7].include? m
1024
+ assert m != @f2, 'Fleet comparison failed'
1025
+ assert m != 122, 'Integer comparison failed'
1026
+ assert m == :active, 'Symbol comparison failed' unless [m4,m5].include? m
1027
+ assert m != :battle, 'Symbol comparison failed' unless [m4,m5].include? m
1028
+ assert m != :incoming, 'Symbol comparison failed' unless [m2,m3].include? m
1029
+ assert m != :unknown, 'Symbol comparison failed' unless [m1,m2,m3].include? m
1030
+ assert m != :homo, 'Symbol comparison failed' unless [m9].include? m
1031
+ assert m != :dron, 'Symbol comparison failed' unless [m4,m5,m8].include? m
1032
+ assert m != :cyb, 'Symbol comparison failed' unless [m3,m4,m9].include? m
1033
+ assert m != :orbit, 'Symbol comparison failed' unless [m6,m7].include? m
1034
+ assert m != :'6830', 'Symbol comparison failed' unless [m7].include? m
1035
+
1036
+ (all-[m]).each do |mm|
1037
+ assert m != mm, 'Group Comparison wrong'
1038
+ assert mm != m, 'Group Comparison wrong'
1039
+ end
1040
+ assert m != 'Erunda', 'String Comparison wrong'
1041
+ assert m != :erunda, 'Symbol Comparison wrong'
1042
+ end
1043
+ assert m8 > m6, 'Group Comparison wrong'
1044
+ assert m4 == @av, 'Race comparison failed'
1045
+ assert m5 == @vd, 'Race comparison failed'
1046
+ assert m9 == @homo, 'Race comparison failed'
1047
+ assert m2 == @p1, 'Planet comparison failed'
1048
+ assert m3 == @p2, 'Planet comparison failed'
1049
+ assert m5 == @p4, 'Planet comparison failed'
1050
+ assert m9 == @def, 'Product comparison failed'
1051
+ assert m6 == @mark, 'Product comparison failed'
1052
+ assert m5 == @raz, 'Product comparison failed'
1053
+ assert m7 == @f1, 'Fleet comparison failed'
1054
+ assert m6 == 1, 'Integer comparison failed'
1055
+ assert m8 == 62, 'Integer comparison failed'
1056
+ assert m9 <10, 'Integer comparison failed'
1057
+ assert m1 <0, 'Integer comparison failed'
1058
+ assert m4 != :active, 'Symbol comparison failed'
1059
+ assert m5 == :battle, 'Symbol comparison failed'
1060
+ assert m2 == :incoming, 'Symbol comparison failed'
1061
+ assert m3 == :unknown, 'Symbol comparison failed'
1062
+ assert m9 == :homo, 'Symbol comparison failed'
1063
+ assert m5 == :dron, 'Symbol comparison failed'
1064
+ assert m4 == :cyb, 'Symbol comparison failed'
1065
+ assert m7 == :orbit, 'Symbol comparison failed'
1066
+ assert m7 == :'6830', 'Symbol comparison failed'
1067
+ end
1068
+
1069
+ def test_booleans
1070
+ m1 = Group.new %w[15768.34 11160.36], {}
1071
+ m2 = Group.new %w[#9219 N-A4 828.88 69.00 1.00], {}
1072
+ m3 = Group.new %w[CYB N-A4 1420.78 50.56 2000.00], {}
1073
+ m4 = Group.new %w[13 DPOH 11.80 0.00 0 0.00 - 0.00 10 In_Battle], {:race=>@av, :planet=>@p2, :battles=>1}
1074
+ m5 = Group.new %w[1 raz 8.05 0 0 0 - 0 1 Out_Battle], {:race=>@vd, :planet=>@p4, :battles=>2}
1075
+ m6 = Group.new %w[0 1 MAPKEP 2.22 0.00 0.00 1.00 COL 0.03 N-A4 - 0.00 39.34 9.03 - In_Orbit], {:race=>@av}
1076
+ m7 = Group.new %w[6830 1170 QAK 13.00 0.00 9.99 0.00 - 0.00 N-A4 - 0.00 78.08 3.33 fgtr5 In_Orbit], {:race=>@av}
1077
+ m8 = Group.new %w[62 raz 2.22 0 0 0 - 0 N-A4 44.40 1], {:race=>@vd}
1078
+ m9 = Group.new %w[1 Def 8.05 6.04 6.04 4.27 COL 4.48 CYB 45.37 32.54], {:race=>@homo}
1079
+
1080
+ assert !m9.from_battle?, 'Boolean wrong'
1081
+ assert !m9.incoming?, 'Boolean wrong'
1082
+ assert !m9.unidentified?, 'Boolean wrong'
1083
+ assert m9.active?, 'Boolean wrong'
1084
+ assert !m9.your?, 'Boolean wrong'
1085
+ assert !m9.your_active?, 'Boolean wrong'
1086
+ assert !m9.drone?, 'Boolean wrong'
1087
+
1088
+ assert !m8.from_battle?, 'Boolean wrong'
1089
+ assert !m8.incoming?, 'Boolean wrong'
1090
+ assert !m8.unidentified?, 'Boolean wrong'
1091
+ assert m8.active?, 'Boolean wrong'
1092
+ assert !m8.your?, 'Boolean wrong'
1093
+ assert !m8.your_active?, 'Boolean wrong'
1094
+ assert m8.drone?, 'Boolean wrong'
1095
+
1096
+ assert !m7.from_battle?, 'Boolean wrong'
1097
+ assert !m7.incoming?, 'Boolean wrong'
1098
+ assert !m7.unidentified?, 'Boolean wrong'
1099
+ assert m7.active?, 'Boolean wrong'
1100
+ assert m7.your?, 'Boolean wrong'
1101
+ assert m7.your_active?, 'Boolean wrong'
1102
+ assert !m7.drone?, 'Boolean wrong'
1103
+
1104
+ assert !m6.from_battle?, 'Boolean wrong'
1105
+ assert !m6.incoming?, 'Boolean wrong'
1106
+ assert !m6.unidentified?, 'Boolean wrong'
1107
+ assert m6.active?, 'Boolean wrong'
1108
+ assert m6.your?, 'Boolean wrong'
1109
+ assert m6.your_active?, 'Boolean wrong'
1110
+ assert !m6.drone?, 'Boolean wrong'
1111
+
1112
+ assert m5.from_battle?, 'Boolean wrong'
1113
+ assert !m5.incoming?, 'Boolean wrong'
1114
+ assert !m5.unidentified?, 'Boolean wrong'
1115
+ assert !m5.active?, 'Boolean wrong'
1116
+ assert !m5.your?, 'Boolean wrong'
1117
+ assert !m5.your_active?, 'Boolean wrong'
1118
+ assert m5.drone?, 'Boolean wrong'
1119
+
1120
+ assert m4.from_battle?, 'Boolean wrong'
1121
+ assert !m4.incoming?, 'Boolean wrong'
1122
+ assert !m4.unidentified?, 'Boolean wrong'
1123
+ assert !m4.active?, 'Boolean wrong'
1124
+ assert m4.your?, 'Boolean wrong'
1125
+ assert !m4.your_active?, 'Boolean wrong'
1126
+ assert m4.drone?, 'Boolean wrong'
1127
+
1128
+ assert !m3.from_battle?, 'Boolean wrong'
1129
+ assert m3.incoming?, 'Boolean wrong'
1130
+ assert m3.unidentified?, 'Boolean wrong'
1131
+ assert m3.active?, 'Boolean wrong'
1132
+ assert !m3.your?, 'Boolean wrong'
1133
+ assert !m3.your_active?, 'Boolean wrong'
1134
+ assert !m3.drone?, 'Boolean wrong'
1135
+
1136
+ assert !m2.from_battle?, 'Boolean wrong'
1137
+ assert m2.incoming?, 'Boolean wrong'
1138
+ assert m2.unidentified?, 'Boolean wrong'
1139
+ assert m2.active?, 'Boolean wrong'
1140
+ assert !m2.your?, 'Boolean wrong'
1141
+ assert !m2.your_active?, 'Boolean wrong'
1142
+ assert m2.drone?, 'Boolean wrong'
1143
+
1144
+ assert !m1.from_battle?, 'Boolean wrong'
1145
+ assert !m1.incoming?, 'Boolean wrong'
1146
+ assert m1.unidentified?, 'Boolean wrong'
1147
+ assert m1.active?, 'Boolean wrong'
1148
+ assert !m1.your?, 'Boolean wrong'
1149
+ assert !m1.your_active?, 'Boolean wrong'
1150
+ assert !m1.drone?, 'Boolean wrong'
1151
+
1152
+ end
1153
+
1154
+ def test_init_unidentified
1155
+ m1 = Group.new %w[15768.34 11160.36], {}
1156
+
1157
+ assert_nil m1.key, 'Group key wrong'
1158
+ assert_nil m1.race, 'Group race wrong'
1159
+ assert_nil m1.product, 'Group product wrong'
1160
+ assert_nil m1.planet, 'Group planet wrong'
1161
+ assert_nil m1.from, 'Group planet wrong'
1162
+ assert_nil m1.fleet, 'Group fleet wrong'
1163
+ assert_nil m1.num, 'Group accessor wrong'
1164
+ assert_equal 15768.34, m1.x, 'Group accessor wrong'
1165
+ assert_equal 11160.36, m1.y, 'Group accessor wrong'
1166
+ assert_nil m1.num_ships, 'Group accessor wrong'
1167
+ assert_nil m1.battles, 'Group key wrong'
1168
+ assert_nil m1.num_before, 'Group accessor wrong'
1169
+ assert_nil m1.drive, 'Group accessor wrong'
1170
+ assert_nil m1.weapons, 'Group accessor wrong'
1171
+ assert_nil m1.shields, 'Group accessor wrong'
1172
+ assert_nil m1.cargo, 'Group accessor wrong'
1173
+ assert_nil m1.cargo_type, 'Group accessor wrong'
1174
+ assert_nil m1.qty, 'Group accessor wrong'
1175
+ assert_nil m1.range, 'Group accessor wrong'
1176
+ assert_nil m1.speed, 'Group accessor wrong'
1177
+ assert_nil m1.mass, 'Group accessor wrong'
1178
+ assert_nil m1.status, 'Group accessor wrong'
1179
+ assert_in_delta 0, m1.eta, 0.00001, 'ETA calculation wrong'
1180
+ end
1181
+
1182
+ def test_init_incoming
1183
+ m1 = Group.new %w[#9219 N-A4 828.88 69.00 1.00], {}
1184
+ m2 = Group.new %w[CYB N-A4 1420.78 50.56 2000.00], {}
1185
+
1186
+ assert_nil m2.key, 'Group key wrong'
1187
+ assert_nil m2.race, 'Group race wrong'
1188
+ assert_nil m2.product, 'Group product wrong'
1189
+ assert_equal @p1, m2.planet, 'Group planet wrong'
1190
+ assert_equal @p2, m2.from, 'Group planet wrong'
1191
+ assert_nil m2.fleet, 'Group fleet wrong'
1192
+ assert_nil m2.num, 'Group accessor wrong'
1193
+ assert_equal 0, m2.x, 'Group accessor wrong'
1194
+ assert_equal 0, m2.y, 'Group accessor wrong'
1195
+ assert_nil m2.num_ships, 'Group accessor wrong'
1196
+ assert_nil m2.battles, 'Group key wrong'
1197
+ assert_nil m2.num_before, 'Group accessor wrong'
1198
+ assert_nil m2.drive, 'Group accessor wrong'
1199
+ assert_nil m2.weapons, 'Group accessor wrong'
1200
+ assert_nil m2.shields, 'Group accessor wrong'
1201
+ assert_nil m2.cargo, 'Group accessor wrong'
1202
+ assert_nil m2.cargo_type, 'Group accessor wrong'
1203
+ assert_nil m2.qty, 'Group accessor wrong'
1204
+ assert_equal 1420.78, m2.range, 'Group accessor wrong'
1205
+ assert_equal 50.56, m2.speed, 'Group accessor wrong'
1206
+ assert_equal 2000.00, m2.mass, 'Group accessor wrong'
1207
+ assert_nil m2.status, 'Group accessor wrong'
1208
+ assert_in_delta 28.10087, m2.eta, 0.00001, 'ETA calculation wrong'
1209
+ assert_equal m2, @p1.groups[1], 'Group association wrong'
1210
+ assert_equal m2, @p2.sent_groups[0], 'Group association wrong'
1211
+
1212
+ assert_nil m1.key, 'Group key wrong'
1213
+ assert_nil m1.race, 'Group race wrong'
1214
+ assert_nil m1.product, 'Group product wrong'
1215
+ assert_equal @p1, m1.planet, 'Group planet wrong'
1216
+ assert_equal @p4, m1.from, 'Group planet wrong'
1217
+ assert_nil m1.fleet, 'Group fleet wrong'
1218
+ assert_nil m1.num, 'Group accessor wrong'
1219
+ assert_equal 0, m1.x, 'Group accessor wrong'
1220
+ assert_equal 0, m1.y, 'Group accessor wrong'
1221
+ assert_nil m1.num_ships, 'Group accessor wrong'
1222
+ assert_nil m1.battles, 'Group key wrong'
1223
+ assert_nil m1.num_before, 'Group accessor wrong'
1224
+ assert_nil m1.drive, 'Group accessor wrong'
1225
+ assert_nil m1.weapons, 'Group accessor wrong'
1226
+ assert_nil m1.shields, 'Group accessor wrong'
1227
+ assert_nil m1.cargo, 'Group accessor wrong'
1228
+ assert_nil m1.cargo_type, 'Group accessor wrong'
1229
+ assert_nil m1.qty, 'Group accessor wrong'
1230
+ assert_equal 828.88, m1.range, 'Group accessor wrong'
1231
+ assert_equal 69.00, m1.speed, 'Group accessor wrong'
1232
+ assert_equal 1, m1.mass, 'Group accessor wrong'
1233
+ assert_nil m1.status, 'Group accessor wrong'
1234
+ assert_in_delta 12.0127536, m1.eta, 0.00001, 'ETA calculation wrong'
1235
+ assert_equal m1, @p1.groups[0], 'Group association wrong'
1236
+ assert_equal m1, @p4.sent_groups[0], 'Group association wrong'
1237
+ end
1238
+
1239
+ def test_init_battle
1240
+ m1 = Group.new %w[13 DPOH 11.80 0.00 0 0.00 - 0.00 10 In_Battle], {:race=>@av, :planet=>@p4, :battles=>1}
1241
+ m2 = Group.new %w[1 raz 8.05 0 0 0 - 0 1 Out_Battle], {:race=>@vd, :planet=>@p4, :battles=>2}
1242
+
1243
+ assert_nil m2.key, 'Group key wrong'
1244
+ assert_equal @vd, m2.race, 'Group race wrong'
1245
+ assert_equal @raz, m2.product, 'Group product wrong'
1246
+ assert_equal @p4, m2.planet, 'Group planet wrong'
1247
+ assert_nil m2.from, 'Group planet wrong'
1248
+ assert_nil m2.fleet, 'Group fleet wrong'
1249
+ assert_nil m2.num, 'Group accessor wrong'
1250
+ assert_nil m2.x, 'Group accessor wrong'
1251
+ assert_nil m2.y, 'Group accessor wrong'
1252
+ assert_equal 1, m2.num_ships, 'Group accessor wrong'
1253
+ assert_equal 2, m2.battles, 'Group key wrong'
1254
+ assert_equal 1, m2.num_before, 'Group accessor wrong'
1255
+ assert_equal 8.05, m2.drive, 'Group accessor wrong'
1256
+ assert_equal 0, m2.weapons, 'Group accessor wrong'
1257
+ assert_equal 0, m2.shields, 'Group accessor wrong'
1258
+ assert_equal 0, m2.cargo, 'Group accessor wrong'
1259
+ assert_equal '-', m2.cargo_type, 'Group accessor wrong'
1260
+ assert_equal 0, m2.qty, 'Group accessor wrong'
1261
+ assert_nil m2.range, 'Group accessor wrong'
1262
+ assert_nil m2.speed, 'Group accessor wrong'
1263
+ assert_nil m2.mass, 'Group accessor wrong'
1264
+ assert_equal 'Out_Battle', m2.status, 'Group accessor wrong'
1265
+ assert_in_delta 0, m2.eta, 0.00001, 'ETA calculation wrong'
1266
+ assert_equal m2, @p4.groups[1], 'Group association wrong'
1267
+ assert_equal m2, @vd.groups[0], 'Group association wrong'
1268
+ assert_equal m2, @raz.groups.first, 'Group association wrong'
1269
+
1270
+ assert_nil m1.key, 'Group key wrong'
1271
+ assert_equal @av, m1.race, 'Group race wrong'
1272
+ assert_equal @dron, m1.product, 'Group product wrong'
1273
+ assert_equal @p4, m1.planet, 'Group planet wrong'
1274
+ assert_nil m1.from, 'Group planet wrong'
1275
+ assert_nil m1.fleet, 'Group fleet wrong'
1276
+ assert_nil m1.num, 'Group accessor wrong'
1277
+ assert_nil m1.x, 'Group accessor wrong'
1278
+ assert_nil m1.y, 'Group accessor wrong'
1279
+ assert_equal 10, m1.num_ships, 'Group accessor wrong'
1280
+ assert_equal 1, m1.battles, 'Group key wrong'
1281
+ assert_equal 13, m1.num_before, 'Group accessor wrong'
1282
+ assert_equal 11.80, m1.drive, 'Group accessor wrong'
1283
+ assert_equal 0, m1.weapons, 'Group accessor wrong'
1284
+ assert_equal 0, m1.shields, 'Group accessor wrong'
1285
+ assert_equal 0, m1.cargo, 'Group accessor wrong'
1286
+ assert_equal '-', m1.cargo_type, 'Group accessor wrong'
1287
+ assert_equal 0, m1.qty, 'Group accessor wrong'
1288
+ assert_nil m1.range, 'Group accessor wrong'
1289
+ assert_nil m1.speed, 'Group accessor wrong'
1290
+ assert_nil m1.mass, 'Group accessor wrong'
1291
+ assert_equal 'In_Battle', m1.status, 'Group accessor wrong'
1292
+ assert_in_delta 0, m1.eta, 0.00001, 'ETA calculation wrong'
1293
+ assert_equal m1, @p4.groups[0], 'Group association wrong'
1294
+ assert_equal m1, @av.groups[0], 'Group association wrong'
1295
+ assert_equal m1, @dron.groups.first, 'Group association wrong'
1296
+
1297
+ end
1298
+
1299
+ def test_init_yours
1300
+ m1 = Group.new %w[0 1 MAPKEP 2.22 0.00 0.00 1.00 COL 0.03 N-A4 - 0.00 39.34 9.03 - In_Orbit], {:race=>@av}
1301
+ m2 = Group.new %w[6830 1170 QAK 13.00 0.00 9.99 0.00 - 0.00 N-A4 - 0.00 78.08 3.33 fgtr5 In_Orbit], {:race=>@av}
1302
+ m3 = Group.new %w[14 1 DPOH 2.62 0.00 0.00 0.00 - 0.00 CYB #7261 396.10 52.40 1.00 - In_Space], {:race=>@av}
1303
+ m4 = Group.new %w[133 1 DPOH 12.62 0.00 0.00 0.00 - 0.00 CYB #7261 4796.57 52.40 1.00 sv11 In_Space], {:race=>@av}
1304
+
1305
+ assert_equal 'ArVitallian.133', m4.key, 'Group key wrong'
1306
+ assert_equal @av, m4.race, 'Group race wrong'
1307
+ assert_equal @dron, m4.product, 'Group product wrong'
1308
+ assert_equal @p2, m4.planet, 'Group planet wrong'
1309
+ assert_equal @p3, m4.from, 'Group planet wrong'
1310
+ assert_equal @f2, m4.fleet, 'Group fleet wrong'
1311
+ assert_equal 133, m4.num, 'Group accessor wrong'
1312
+ assert_equal 0, m4.x, 'Group accessor wrong'
1313
+ assert_equal 0, m4.y, 'Group accessor wrong'
1314
+ assert_equal 1, m4.num_ships, 'Group accessor wrong'
1315
+ assert_nil m4.num_before, 'Group accessor wrong'
1316
+ assert_equal 12.62, m4.drive, 'Group accessor wrong'
1317
+ assert_equal 0, m4.weapons, 'Group accessor wrong'
1318
+ assert_equal 0, m4.shields, 'Group accessor wrong'
1319
+ assert_equal 0, m4.cargo, 'Group accessor wrong'
1320
+ assert_equal '-', m4.cargo_type, 'Group accessor wrong'
1321
+ assert_equal 0, m4.qty, 'Group accessor wrong'
1322
+ assert_equal 4796.57, m4.range, 'Group accessor wrong'
1323
+ assert_equal 52.40, m4.speed, 'Group accessor wrong'
1324
+ assert_equal 1, m4.mass, 'Group accessor wrong'
1325
+ assert_equal 'In_Space', m4.status, 'Group accessor wrong'
1326
+ assert_in_delta 91.537595419, m4.eta, 0.00001, 'ETA calculation wrong'
1327
+ assert_equal m4, @p2.groups[1], 'Group association wrong'
1328
+ assert_equal m4, @p3.sent_groups[1], 'Group association wrong'
1329
+ assert_equal m4, @av.groups[3], 'Group association wrong'
1330
+ assert_equal m4, @dron.groups.last, 'Group association wrong'
1331
+
1332
+ assert_equal 'ArVitallian.14', m3.key, 'Group key wrong'
1333
+ assert_equal @av, m3.race, 'Group race wrong'
1334
+ assert_equal @dron, m3.product, 'Group product wrong'
1335
+ assert_equal @p2, m3.planet, 'Group planet wrong'
1336
+ assert_equal @p3, m3.from, 'Group planet wrong'
1337
+ assert_nil m3.fleet, 'Group fleet wrong'
1338
+ assert_equal 14, m3.num, 'Group accessor wrong'
1339
+ assert_equal 0, m3.x, 'Group accessor wrong'
1340
+ assert_equal 0, m3.y, 'Group accessor wrong'
1341
+ assert_equal 1, m3.num_ships, 'Group accessor wrong'
1342
+ assert_nil m3.num_before, 'Group accessor wrong'
1343
+ assert_equal 2.62, m3.drive, 'Group accessor wrong'
1344
+ assert_equal 0, m3.weapons, 'Group accessor wrong'
1345
+ assert_equal 0, m3.shields, 'Group accessor wrong'
1346
+ assert_equal 0, m3.cargo, 'Group accessor wrong'
1347
+ assert_equal '-', m3.cargo_type, 'Group accessor wrong'
1348
+ assert_equal 0, m3.qty, 'Group accessor wrong'
1349
+ assert_equal 396.10, m3.range, 'Group accessor wrong'
1350
+ assert_equal 52.40, m3.speed, 'Group accessor wrong'
1351
+ assert_equal 1, m3.mass, 'Group accessor wrong'
1352
+ assert_equal 'In_Space', m3.status, 'Group accessor wrong'
1353
+ assert_in_delta 7.559160305, m3.eta, 0.00001, 'ETA calculation wrong'
1354
+ assert_equal m3, @p2.groups[0], 'Group association wrong'
1355
+ assert_equal m3, @p3.sent_groups[0], 'Group association wrong'
1356
+ assert_equal m3, @av.groups[2], 'Group association wrong'
1357
+ assert_equal m3, @dron.groups.first, 'Group association wrong'
1358
+
1359
+ assert_equal 'ArVitallian.6830', m2.key, 'Group key wrong'
1360
+ assert_equal @av, m2.race, 'Group race wrong'
1361
+ assert_equal @q, m2.product, 'Group product wrong'
1362
+ assert_equal @p1, m2.planet, 'Group planet wrong'
1363
+ assert_nil m2.from, 'Group planet wrong'
1364
+ assert_equal @f1, m2.fleet, 'Group fleet wrong'
1365
+ assert_equal 6830, m2.num, 'Group accessor wrong'
1366
+ assert_equal 10483.56, m2.x, 'Group accessor wrong'
1367
+ assert_equal 10512.20, m2.y, 'Group accessor wrong'
1368
+ assert_equal 1170, m2.num_ships, 'Group accessor wrong'
1369
+ assert_nil m2.num_before, 'Group accessor wrong'
1370
+ assert_equal 13.00, m2.drive, 'Group accessor wrong'
1371
+ assert_equal 0, m2.weapons, 'Group accessor wrong'
1372
+ assert_equal 9.99, m2.shields, 'Group accessor wrong'
1373
+ assert_equal 0, m2.cargo, 'Group accessor wrong'
1374
+ assert_equal '-', m2.cargo_type, 'Group accessor wrong'
1375
+ assert_equal 0, m2.qty, 'Group accessor wrong'
1376
+ assert_equal 0, m2.range, 'Group accessor wrong'
1377
+ assert_equal 78.08, m2.speed, 'Group accessor wrong'
1378
+ assert_equal 3.33, m2.mass, 'Group accessor wrong'
1379
+ assert_equal 'In_Orbit', m2.status, 'Group accessor wrong'
1380
+ assert_in_delta 0.0, m2.eta, 0.00001, 'ETA calculation wrong'
1381
+ assert_equal m2, @p1.groups[1], 'Group association wrong'
1382
+ assert_equal m2, @av.groups[1], 'Group association wrong'
1383
+ assert_equal m2, @q.groups.first, 'Group association wrong'
1384
+
1385
+ assert_equal 'ArVitallian.0', m1.key, 'Group key wrong'
1386
+ assert_equal @av, m1.race, 'Group race wrong'
1387
+ assert_equal @mark, m1.product, 'Group product wrong'
1388
+ assert_equal @p1, m1.planet, 'Group planet wrong'
1389
+ assert_nil m1.from, 'Group planet wrong'
1390
+ assert_nil m1.fleet, 'Group fleet wrong'
1391
+ assert_equal 0, m1.num, 'Group accessor wrong'
1392
+ assert_equal 10483.56, m1.x, 'Group accessor wrong'
1393
+ assert_equal 10512.20, m1.y, 'Group accessor wrong'
1394
+ assert_equal 1, m1.num_ships, 'Group accessor wrong'
1395
+ assert_nil m1.num_before, 'Group accessor wrong'
1396
+ assert_equal 2.22, m1.drive, 'Group accessor wrong'
1397
+ assert_equal 0, m1.weapons, 'Group accessor wrong'
1398
+ assert_equal 0, m1.shields, 'Group accessor wrong'
1399
+ assert_equal 1, m1.cargo, 'Group accessor wrong'
1400
+ assert_equal 'COL', m1.cargo_type, 'Group accessor wrong'
1401
+ assert_equal 0.03, m1.qty, 'Group accessor wrong'
1402
+ assert_equal 0, m1.range, 'Group accessor wrong'
1403
+ assert_equal 39.34, m1.speed, 'Group accessor wrong'
1404
+ assert_equal 9.03, m1.mass, 'Group accessor wrong'
1405
+ assert_equal 'In_Orbit', m1.status, 'Group accessor wrong'
1406
+ assert_in_delta 0.0, m1.eta, 0.00001, 'ETA calculation wrong'
1407
+ assert_equal m1, @p1.groups.first, 'Group association wrong'
1408
+ assert_equal m1, @av.groups.first, 'Group association wrong'
1409
+ assert_equal m1, @mark.groups.first, 'Group association wrong'
1410
+ end
1411
+
1412
+ def test_init_other
1413
+ m1 = Group.new %w[62 raz 2.22 0 0 0 - 0 N-A4 44.40 1], {:race=>@vd}
1414
+ m2 = Group.new %w[1 Def 8.05 6.04 6.04 4.27 COL 4.48 CYB 45.37 32.54], {:race=>@homo}
1415
+
1416
+ assert_nil m1.key, 'Group key wrong'
1417
+ assert_equal @vd, m1.race, 'Group race wrong'
1418
+ assert_equal @raz, m1.product, 'Group product wrong'
1419
+ assert_equal @p1, m1.planet, 'Group planet wrong'
1420
+ assert_nil m1.from, 'Group planet wrong'
1421
+ assert_nil m1.fleet, 'Group fleet wrong'
1422
+ assert_nil m1.num, 'Group accessor wrong'
1423
+ assert_equal 10483.56, m1.x, 'Group accessor wrong'
1424
+ assert_equal 10512.20, m1.y, 'Group accessor wrong'
1425
+ assert_equal 62, m1.num_ships, 'Group accessor wrong'
1426
+ assert_nil m1.num_before, 'Group accessor wrong'
1427
+ assert_equal 2.22, m1.drive, 'Group accessor wrong'
1428
+ assert_equal 0, m1.weapons, 'Group accessor wrong'
1429
+ assert_equal 0, m1.shields, 'Group accessor wrong'
1430
+ assert_equal 0, m1.cargo, 'Group accessor wrong'
1431
+ assert_equal '-', m1.cargo_type, 'Group accessor wrong'
1432
+ assert_equal 0, m1.qty, 'Group accessor wrong'
1433
+ assert_nil m1.range, 'Group accessor wrong'
1434
+ assert_equal 44.40, m1.speed, 'Group accessor wrong'
1435
+ assert_equal 1, m1.mass, 'Group accessor wrong'
1436
+ assert_nil m1.status, 'Group accessor wrong'
1437
+ assert_in_delta 0, m1.eta, 0.00001, 'ETA calculation wrong'
1438
+ assert_equal m1, @p1.groups[0], 'Group association wrong'
1439
+ assert_equal m1, @vd.groups[0], 'Group association wrong'
1440
+ assert_equal m1, @raz.groups.first, 'Group association wrong'
1441
+
1442
+ assert_nil m2.key, 'Group key wrong'
1443
+ assert_equal @homo, m2.race, 'Group race wrong'
1444
+ assert_equal @def, m2.product, 'Group product wrong'
1445
+ assert_equal @p2, m2.planet, 'Group planet wrong'
1446
+ assert_nil m2.from, 'Group planet wrong'
1447
+ assert_nil m2.fleet, 'Group fleet wrong'
1448
+ assert_nil m2.num, 'Group accessor wrong'
1449
+ assert_equal 13906.25, m2.x, 'Group accessor wrong'
1450
+ assert_equal 17458.86, m2.y, 'Group accessor wrong'
1451
+ assert_equal 1, m2.num_ships, 'Group accessor wrong'
1452
+ assert_nil m2.num_before, 'Group accessor wrong'
1453
+ assert_equal 8.05, m2.drive, 'Group accessor wrong'
1454
+ assert_equal 6.04, m2.weapons, 'Group accessor wrong'
1455
+ assert_equal 6.04, m2.shields, 'Group accessor wrong'
1456
+ assert_equal 4.27, m2.cargo, 'Group accessor wrong'
1457
+ assert_equal 'COL', m2.cargo_type, 'Group accessor wrong'
1458
+ assert_equal 4.48, m2.qty, 'Group accessor wrong'
1459
+ assert_nil m2.range, 'Group accessor wrong'
1460
+ assert_equal 45.37, m2.speed, 'Group accessor wrong'
1461
+ assert_equal 32.54, m2.mass, 'Group accessor wrong'
1462
+ assert_nil m2.status, 'Group accessor wrong'
1463
+ assert_in_delta 0, m2.eta, 0.00001, 'ETA calculation wrong'
1464
+ assert_equal m2, @p2.groups[0], 'Group association wrong'
1465
+ assert_equal m2, @homo.groups[0], 'Group association wrong'
1466
+ assert_equal m2, @def.groups.first, 'Group association wrong'
1467
+ end
1468
+ end
1469
+