rubygoal 0.0.2 → 2.0.0

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 DELETED
@@ -1,104 +0,0 @@
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