Rubeuler 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +8 -0
- data/README.md +1 -1
- data/lib/rubeuler/base.rb +2 -0
- data/lib/rubeuler/problem.rb +15 -4
- data/lib/rubeuler/result.rb +12 -0
- data/lib/rubeuler/solution.rb +1 -1
- data/lib/rubeuler/version.rb +1 -1
- data/test/rubeuler/problem_test.rb +22 -4
- data/test/rubeuler/solution_test.rb +18 -0
- metadata +3 -1
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
1
|
0.0.1 - Initial release, allows you to initialize an instance of Rubeuler::Problem with required options `:number` (int) and `:answer` (string of ruby code). Answer is evaluated and compared to answer predefined in Rubeuler::Problem#solutions method. Result is returned indicating success/failure and the time elapsed when running the code in `:answer`
|
2
|
+
|
2
3
|
0.0.2 - Fixed Rakefile (gave myself the ability to use `rake release`); Updated description in gemspec
|
4
|
+
|
3
5
|
0.0.3 - Moved Rubeuler::Problem#solutions to Rubeuler::Solution#for_problem to make the intended use more intuitive
|
6
|
+
|
7
|
+
0.0.4 - Add tests using minitest
|
8
|
+
|
9
|
+
0.0.5 - Feature: Track other variables... the options `tracked: {foo: @foo}` would track a variable set as `@foo` in Rubeuler::Problem's `:answer` argument
|
10
|
+
Improve on tests, improve timer by moving Benchmark closer to code being evaluated,
|
11
|
+
|
data/README.md
CHANGED
data/lib/rubeuler/base.rb
CHANGED
data/lib/rubeuler/problem.rb
CHANGED
@@ -7,22 +7,33 @@ module Rubeuler
|
|
7
7
|
def initialize(options)
|
8
8
|
load_options(:number, :answer, options)
|
9
9
|
raise TypeError, ':answer should be a string' unless @answer.is_a?(String)
|
10
|
+
raise TypeError, ':number should be an integer' unless @number.is_a?(Fixnum)
|
10
11
|
end
|
11
12
|
|
12
13
|
def execute!
|
13
|
-
time =
|
14
|
+
time = timed_answer
|
14
15
|
true_or_false = @data == solution ? true : false
|
15
16
|
|
16
|
-
return Rubeuler::Result.new(success: true_or_false, problem: @number, data:
|
17
|
+
return Rubeuler::Result.new(success: true_or_false, problem: @number, data: data, runtime: time)
|
17
18
|
end
|
18
19
|
|
19
20
|
private
|
20
|
-
def
|
21
|
-
|
21
|
+
def timed_answer
|
22
|
+
timer_endpoints = ["Benchmark.measure { @data =", "}.real"]
|
23
|
+
instance_eval(timer_endpoints.join(@answer.gsub("\n",";")))
|
22
24
|
end
|
23
25
|
|
24
26
|
def solution
|
25
27
|
Rubeuler::Solution.for_problem(@number)
|
26
28
|
end
|
29
|
+
|
30
|
+
def data
|
31
|
+
result_data = {
|
32
|
+
solution: @data
|
33
|
+
}
|
34
|
+
@tracked.each { |k,v| result_data.merge!({ k => instance_eval(v.to_s) }) } if @tracked
|
35
|
+
|
36
|
+
result_data
|
37
|
+
end
|
27
38
|
end
|
28
39
|
end
|
data/lib/rubeuler/result.rb
CHANGED
data/lib/rubeuler/solution.rb
CHANGED
data/lib/rubeuler/version.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
require "minitest_helper"
|
2
|
-
require "rubeuler"
|
3
2
|
|
4
3
|
describe Rubeuler::Problem do
|
5
|
-
describe ".
|
4
|
+
describe ".execute!" do
|
6
5
|
it "returns a result" do
|
7
6
|
Rubeuler::Problem.new(number: 1, answer: "0").execute!.must_be_kind_of(Rubeuler::Result)
|
8
7
|
end
|
@@ -25,10 +24,29 @@ describe Rubeuler::Problem do
|
|
25
24
|
|
26
25
|
it "complains if :answer is not a string" do
|
27
26
|
begin
|
28
|
-
|
27
|
+
Rubeuler::Problem.new(number: 1, answer: 0)
|
29
28
|
rescue => e
|
30
|
-
e
|
29
|
+
error = e
|
31
30
|
end
|
31
|
+
error.must_be_kind_of(TypeError)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "complains if :number is not an integer" do
|
35
|
+
begin
|
36
|
+
Rubeuler::Problem.new(number: :the_letter_a, answer: "0")
|
37
|
+
rescue => e
|
38
|
+
error = e
|
39
|
+
end
|
40
|
+
error.must_be_kind_of(TypeError)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#data" do
|
45
|
+
it "can track extra instance_variables" do
|
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(Rubeuler::Result)
|
48
|
+
res.data.keys.include?(:foo).must_equal(true)
|
49
|
+
res.data.keys.include?(:baz).must_equal(true)
|
32
50
|
end
|
33
51
|
end
|
34
52
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "minitest_helper"
|
2
|
+
|
3
|
+
describe Rubeuler::Problem do
|
4
|
+
describe ".execute!" do
|
5
|
+
it "returns a solution if predefined" do
|
6
|
+
Rubeuler::Solution.for_problem(1).must_be_kind_of(Numeric)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "produces an error if key for the problem specified is not defined" do
|
10
|
+
begin
|
11
|
+
@problem = Rubeuler::Solution.for_problem(:orange)
|
12
|
+
rescue => e
|
13
|
+
e.must_be_kind_of(RuntimeError)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
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.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- rubeuler.gemspec
|
80
80
|
- test/minitest_helper.rb
|
81
81
|
- test/rubeuler/problem_test.rb
|
82
|
+
- test/rubeuler/solution_test.rb
|
82
83
|
homepage: http://github.com/rthbound/rubeuler
|
83
84
|
licenses: []
|
84
85
|
post_install_message:
|
@@ -107,3 +108,4 @@ summary: Evaluates whether a block produces a predefined response. Returns diagn
|
|
107
108
|
test_files:
|
108
109
|
- test/minitest_helper.rb
|
109
110
|
- test/rubeuler/problem_test.rb
|
111
|
+
- test/rubeuler/solution_test.rb
|