rubygoal 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/test.rb ADDED
@@ -0,0 +1,104 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'timecop'
4
+
5
+ require 'rubygoal/game'
6
+
7
+ module Rubygoal
8
+ class GameTest < Game
9
+ def recorded_lines
10
+ lines = [
11
+ "Ball #{field.ball.position}",
12
+ "Score #{score_home} - #{score_away}",
13
+ ]
14
+ field.team_home.players.each_with_index do |p, i|
15
+ lines << "Team home: player #{i} #{p.position}"
16
+ end
17
+ field.team_away.players.each_with_index do |p, i|
18
+ lines << "Team away: player #{i} #{p.position}"
19
+ end
20
+ lines
21
+ end
22
+
23
+ def record
24
+ File.open(File.dirname(__FILE__) + '/record.txt', 'w') do |record_file|
25
+ init_time = Time.now
26
+ (60 * 300).times do |i|
27
+ Timecop.freeze(init_time + i/60) { update }
28
+ recorded_lines.each { |l| record_file.puts(l) }
29
+ end
30
+ end
31
+ end
32
+
33
+ def test
34
+ @success = true
35
+
36
+ File.open(File.dirname(__FILE__) + '/record.txt', 'r') do |record_file|
37
+ init_time = Time.now
38
+ (60 * 300).times do |i|
39
+ Timecop.freeze(init_time + i/60) { update }
40
+ recorded_lines.each do |line|
41
+ data = record_file.gets
42
+ @success &&= assert(data, line)
43
+ end
44
+ break unless @success
45
+ end
46
+ end
47
+
48
+ p "Caso de éxito!" if @success
49
+ end
50
+
51
+ private
52
+
53
+ def assert(expected, actual)
54
+ if actual == expected.chomp
55
+ true
56
+ else
57
+ p "ERROR: Expected \"#{expected}\" - Actual \"#{actual}\""
58
+ false
59
+ end
60
+ end
61
+ end
62
+
63
+ if ENV['mode'] == 'record'
64
+ class Random
65
+ def self.clear_random_list
66
+ @random_list = []
67
+ end
68
+
69
+ def self.rand(*args)
70
+ result = super(*args)
71
+ @random_list << result
72
+ result
73
+ end
74
+
75
+ def self.record
76
+ File.open(File.dirname(__FILE__) + '/random.txt', 'w') do |random_file|
77
+ @random_list.each { |n| random_file.puts n }
78
+ end
79
+ end
80
+ end
81
+
82
+ Random.clear_random_list
83
+ GameTest.new.record
84
+ Random.record
85
+ else
86
+ class Random
87
+ def self.load_random_list
88
+ @random_list = []
89
+ File.open(File.dirname(__FILE__) + '/random.txt', 'r') do |random_file|
90
+ while number = random_file.gets
91
+ @random_list << number.to_f
92
+ end
93
+ end
94
+ end
95
+
96
+ def self.rand(*args)
97
+ @random_list.shift
98
+ end
99
+ end
100
+
101
+ Random.load_random_list
102
+ GameTest.new.test
103
+ end
104
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubygoal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jorge Bejar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gosu
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: timecop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.7'
41
+ description: Rubygoal
42
+ email:
43
+ - jorge@wyeworks.com
44
+ executables:
45
+ - rubygoal
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - README.md
50
+ - MIT-LICENSE
51
+ - bin/rubygoal
52
+ - lib/rubygoal/ball.rb
53
+ - lib/rubygoal/coach.rb
54
+ - lib/rubygoal/coach_loader.rb
55
+ - lib/rubygoal/coaches/coach_away.rb
56
+ - lib/rubygoal/coaches/coach_home.rb
57
+ - lib/rubygoal/coaches/template.rb
58
+ - lib/rubygoal/config.rb
59
+ - lib/rubygoal/config_definitions.rb
60
+ - lib/rubygoal/coordinate.rb
61
+ - lib/rubygoal/field.rb
62
+ - lib/rubygoal/field_metrics.rb
63
+ - lib/rubygoal/formation.rb
64
+ - lib/rubygoal/game.rb
65
+ - lib/rubygoal/goal.rb
66
+ - lib/rubygoal/match.rb
67
+ - lib/rubygoal/moveable.rb
68
+ - lib/rubygoal/player.rb
69
+ - lib/rubygoal/players/average.rb
70
+ - lib/rubygoal/players/captain.rb
71
+ - lib/rubygoal/players/fast.rb
72
+ - lib/rubygoal/team.rb
73
+ - lib/rubygoal/version.rb
74
+ - lib/rubygoal.rb
75
+ - media/average_away.png
76
+ - media/average_home.png
77
+ - media/background.png
78
+ - media/ball.png
79
+ - media/captain_away.png
80
+ - media/captain_home.png
81
+ - media/fast_away.png
82
+ - media/fast_home.png
83
+ - media/goal.png
84
+ - test/formation_test.rb
85
+ - test/random.txt
86
+ - test/record.txt
87
+ - test/test.rb
88
+ homepage: https://github.com/wyeworks/rubygoal
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: 1.9.3
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.0.14
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Rubygoal
112
+ test_files:
113
+ - test/formation_test.rb
114
+ - test/random.txt
115
+ - test/record.txt
116
+ - test/test.rb