codejam 0.1.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.
@@ -0,0 +1,4 @@
1
+ module CodeJam
2
+ autoload :Runner, 'codejam/runner'
3
+ autoload :TestCase, 'codejam/testcase'
4
+ end
@@ -0,0 +1,19 @@
1
+ module CodeJam
2
+
3
+ class Runner
4
+ attr_reader :testcases
5
+
6
+ def initialize(input, caseclass)
7
+ num, *lines = input.split("\n")
8
+ raise "Invalid input: wrong number of testcases" if num.to_i != lines.size
9
+ @testcases = lines.map {|n| caseclass.new(n)}
10
+ end
11
+
12
+ def run
13
+ testcases.each_with_index.inject("") do |r, (n, i)|
14
+ r + (i+1==1 ? "" : "\n") + "Case ##{i+1}: #{n.run}"
15
+ end
16
+ end
17
+ end # /class
18
+
19
+ end
@@ -0,0 +1,23 @@
1
+ module CodeJam
2
+
3
+ class TestCase
4
+ attr_reader :input
5
+
6
+ def initialize(input)
7
+ @input = input
8
+ end
9
+
10
+ def run
11
+ fun
12
+ end
13
+
14
+ def fun
15
+ input #default behaviour is echo
16
+ end
17
+
18
+ def ==(other)
19
+ self.input == other.input
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,3 @@
1
+ module CodeJam
2
+ VERSION = "0.1.0" unless defined?(::CodeJam::VERSION)
3
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codejam
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Stefano Pigozzi
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-05-07 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Runner library for Google's Codejam
22
+ email: stefano.pigozzi@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/codejam/runner.rb
31
+ - lib/codejam/testcase.rb
32
+ - lib/codejam/version.rb
33
+ - lib/codejam.rb
34
+ has_rdoc: true
35
+ homepage: https://github.com/pigoz/codejam
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ segments:
49
+ - 0
50
+ version: "0"
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ requirements: []
60
+
61
+ rubyforge_project:
62
+ rubygems_version: 1.3.7
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Runs codejam test cases
66
+ test_files: []
67
+