Rubeuler 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rubeuler/problem.rb +7 -2
- data/lib/rubeuler/version.rb +1 -1
- data/lib/rubeuler.rb +2 -3
- data/rubeuler.gemspec +2 -1
- data/test/minitest_helper.rb +2 -1
- data/test/rubeuler/problem_test.rb +2 -2
- metadata +26 -9
- data/lib/rubeuler/base.rb +0 -13
- data/lib/rubeuler/result.rb +0 -21
data/lib/rubeuler/problem.rb
CHANGED
@@ -3,18 +3,23 @@ require 'benchmark'
|
|
3
3
|
module Rubeuler
|
4
4
|
include Solution
|
5
5
|
|
6
|
-
class Problem
|
6
|
+
class Problem
|
7
|
+
include PayDirt::UseCase
|
8
|
+
|
7
9
|
def initialize(options)
|
8
10
|
load_options(:number, :answer, options)
|
11
|
+
|
9
12
|
raise TypeError, ':answer should be a string' unless @answer.is_a?(String)
|
10
13
|
raise TypeError, ':number should be an integer' unless @number.is_a?(Fixnum)
|
14
|
+
|
15
|
+
|
11
16
|
end
|
12
17
|
|
13
18
|
def execute!
|
14
19
|
time = timed_answer
|
15
20
|
true_or_false = @data == solution ? true : false
|
16
21
|
|
17
|
-
return
|
22
|
+
return PayDirt::Result.new(success: true_or_false, problem: @number, data: data, runtime: time)
|
18
23
|
end
|
19
24
|
|
20
25
|
private
|
data/lib/rubeuler/version.rb
CHANGED
data/lib/rubeuler.rb
CHANGED
data/rubeuler.gemspec
CHANGED
@@ -16,8 +16,9 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
|
19
|
-
s.
|
19
|
+
s.add_runtime_dependency "pay_dirt"
|
20
20
|
|
21
|
+
s.add_development_dependency "minitest"
|
21
22
|
s.add_development_dependency "rake"
|
22
23
|
s.add_development_dependency "pry"
|
23
24
|
end
|
data/test/minitest_helper.rb
CHANGED
@@ -3,7 +3,7 @@ require "minitest_helper"
|
|
3
3
|
describe Rubeuler::Problem do
|
4
4
|
describe ".execute!" do
|
5
5
|
it "returns a result" do
|
6
|
-
Rubeuler::Problem.new(number: 1, answer: "0").execute!.must_be_kind_of(
|
6
|
+
Rubeuler::Problem.new(number: 1, answer: "0").execute!.must_be_kind_of(PayDirt::Result)
|
7
7
|
end
|
8
8
|
|
9
9
|
it "produces an error if :number is not provided" do
|
@@ -44,7 +44,7 @@ describe Rubeuler::Problem do
|
|
44
44
|
describe "#data" do
|
45
45
|
it "can track extra instance_variables" do
|
46
46
|
res = Rubeuler::Problem.new(number: 1, answer: "@foo, @baz = :bar, :bang; 111*0", tracked: {foo: "@foo", baz: "@bang"}).execute!
|
47
|
-
res.must_be_kind_of(
|
47
|
+
res.must_be_kind_of(PayDirt::Result)
|
48
48
|
res.data.keys.include?(:foo).must_equal(true)
|
49
49
|
res.data.keys.include?(:baz).must_equal(true)
|
50
50
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Rubeuler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-04-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: pay_dirt
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
14
30
|
- !ruby/object:Gem::Dependency
|
15
31
|
name: minitest
|
16
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -71,9 +87,7 @@ files:
|
|
71
87
|
- README.md
|
72
88
|
- Rakefile
|
73
89
|
- lib/rubeuler.rb
|
74
|
-
- lib/rubeuler/base.rb
|
75
90
|
- lib/rubeuler/problem.rb
|
76
|
-
- lib/rubeuler/result.rb
|
77
91
|
- lib/rubeuler/solution.rb
|
78
92
|
- lib/rubeuler/version.rb
|
79
93
|
- rubeuler.gemspec
|
@@ -92,20 +106,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
106
|
- - ! '>='
|
93
107
|
- !ruby/object:Gem::Version
|
94
108
|
version: '0'
|
109
|
+
segments:
|
110
|
+
- 0
|
111
|
+
hash: 384433139
|
95
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
113
|
none: false
|
97
114
|
requirements:
|
98
115
|
- - ! '>='
|
99
116
|
- !ruby/object:Gem::Version
|
100
117
|
version: '0'
|
118
|
+
segments:
|
119
|
+
- 0
|
120
|
+
hash: 384433139
|
101
121
|
requirements: []
|
102
122
|
rubyforge_project:
|
103
|
-
rubygems_version: 1.8.
|
123
|
+
rubygems_version: 1.8.25
|
104
124
|
signing_key:
|
105
125
|
specification_version: 3
|
106
126
|
summary: Evaluates whether a block produces a predefined response. Returns diagnostics
|
107
127
|
if the block's return value was expected.
|
108
|
-
test_files:
|
109
|
-
- test/minitest_helper.rb
|
110
|
-
- test/rubeuler/problem_test.rb
|
111
|
-
- test/rubeuler/solution_test.rb
|
128
|
+
test_files: []
|
data/lib/rubeuler/base.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
module Rubeuler
|
2
|
-
class Base
|
3
|
-
def load_option(option, options)
|
4
|
-
instance_variable_set("@#{option}", options.fetch(option.to_sym) { raise "Missing required option: #{option}" } )
|
5
|
-
end
|
6
|
-
|
7
|
-
def load_options(*option_names, options)
|
8
|
-
option_names.each{|o| load_option(o, options) }
|
9
|
-
|
10
|
-
option_names << instance_variable_set("@tracked", options[:tracked]) if options[:tracked]
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
data/lib/rubeuler/result.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
module Rubeuler
|
2
|
-
class Result
|
3
|
-
def initialize(options)
|
4
|
-
@success = options[:success]
|
5
|
-
@data = options[:data]
|
6
|
-
@runtime = options[:runtime]
|
7
|
-
end
|
8
|
-
|
9
|
-
def data
|
10
|
-
@data
|
11
|
-
end
|
12
|
-
|
13
|
-
def runtime
|
14
|
-
@runtime
|
15
|
-
end
|
16
|
-
|
17
|
-
def successful?
|
18
|
-
!!@success
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|