jeka 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/bin/jeka CHANGED
@@ -29,7 +29,7 @@ def build(folder)
29
29
  init(folder) do |dir|
30
30
  begin
31
31
  make = Jeka::Make.new(dir)
32
- puts "jeka: building #{dir}"
32
+ puts "[build] #{dir}"
33
33
  make.build
34
34
  rescue
35
35
  end
@@ -41,11 +41,10 @@ def test(folder)
41
41
  init(folder) do |dir|
42
42
  begin
43
43
  make = Jeka::Make.new(dir)
44
- make.test do |implementation, input, output, result|
44
+ make.test do |i, t, r|
45
45
  ok = "error"
46
- ok = "ok" if result
47
- puts "jeka: testing #{implementation.folder} with #{input}...#{ok}"
48
- return unless result
46
+ ok = "ok" if r
47
+ puts "[test] #{i.algorithm.name} - #{i.language} - #{t.name}: #{ok}"
49
48
  end
50
49
  rescue
51
50
  end
@@ -56,10 +55,14 @@ end
56
55
  def benchmark(folder)
57
56
  init(folder) do |dir|
58
57
  begin
58
+ ok = false
59
59
  make = Jeka::Make.new(dir)
60
- puts "jeka: benchmarking #{dir}"
60
+ print "[benchmark] #{dir}... "
61
+ ok = true
61
62
  make.benchmark(10)
63
+ puts "ok"
62
64
  rescue
65
+ puts "error" if ok
63
66
  end
64
67
  benchmark(dir)
65
68
  end
@@ -67,7 +70,7 @@ end
67
70
 
68
71
  def site(folder)
69
72
  build(folder)
70
- test(folder)
73
+ benchmark(folder)
71
74
 
72
75
  Dir.mkdir("_jeka") unless Dir.exists?("_jeka")
73
76
  Dir.mkdir("_jeka/algorithms") unless Dir.exists?("_jeka/algorithms")
@@ -82,14 +85,13 @@ def _site(folder)
82
85
  init(folder) do |dir|
83
86
  begin
84
87
  make = Jeka::Make.new(dir)
85
- puts "jeka: generating #{dir}"
86
- make.generate_site(10) do |algorithm, implementations, date|
87
- falgorithm = File.new(File.join("_jeka/algorithms/_posts", "#{algorithm[1]["date"].to_s}-#{algorithm[1]["name"].gsub(" ", "_")}.textile"), "w")
88
- falgorithm.write(algorithm[0])
89
- implementations.each do |imp|
90
- fimplementation = File.new(File.join("_jeka/implementations/_posts", "#{algorithm[1]["date"].to_s}-#{imp[1].gsub(" ", "_")}.textile"), "w")
91
- fimplementation.write(imp[0])
92
- end
88
+ puts "[site] #{dir}"
89
+ algorithm, implementations = make.generate_site
90
+ falgorithm = File.new(File.join("_jeka/algorithms/_posts", "2011-01-01-#{algorithm[0].name.gsub(" ", "_")}.textile"), "w")
91
+ falgorithm.write(algorithm[1])
92
+ implementations.each do |imp|
93
+ fimplementation = File.new(File.join("_jeka/implementations/_posts", "2011-01-01-#{imp[0].comment.gsub(" ", "_")}.textile"), "w")
94
+ fimplementation.write(imp[1])
93
95
  end
94
96
  rescue
95
97
  end
data/jeka.gemspec ADDED
@@ -0,0 +1,91 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{jeka}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Igor Bonadio"]
12
+ s.date = %q{2011-07-16}
13
+ s.default_executable = %q{jeka}
14
+ s.description = %q{Jeka is an awesome build/test/benchmarking tool}
15
+ s.email = %q{igorbonadio@gmail.com}
16
+ s.executables = ["jeka"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "bin/jeka",
30
+ "jeka.gemspec",
31
+ "lib/jeka.rb",
32
+ "lib/jeka/algorithm.rb",
33
+ "lib/jeka/implementation.rb",
34
+ "lib/jeka/jeka_helper.rb",
35
+ "lib/jeka/make.rb",
36
+ "lib/jeka/test.rb",
37
+ "test/example/01_bubble_sort/_algorithm.yaml",
38
+ "test/example/01_bubble_sort/_description.textile",
39
+ "test/example/01_bubble_sort/_references.textile",
40
+ "test/example/01_bubble_sort/_tests/test_01.yaml",
41
+ "test/example/01_bubble_sort/_tests/test_02.yaml",
42
+ "test/example/01_bubble_sort/cpp/_implementation.yaml",
43
+ "test/example/01_bubble_sort/cpp/bubble.cpp",
44
+ "test/example/01_bubble_sort/ruby/_implementation.yaml",
45
+ "test/example/01_bubble_sort/ruby/bubble.rb",
46
+ "test/helper.rb",
47
+ "test/site/algorithm.textile",
48
+ "test/site/cpp.textile",
49
+ "test/site/ruby.textile",
50
+ "test/test_algorithm.rb",
51
+ "test/test_implementation.rb",
52
+ "test/test_make.rb",
53
+ "test/test_test.rb"
54
+ ]
55
+ s.homepage = %q{http://github.com/igorbonadio/jeka}
56
+ s.licenses = ["MIT"]
57
+ s.require_paths = ["lib"]
58
+ s.rubygems_version = %q{1.3.7}
59
+ s.summary = %q{Jeka is an awesome build/test/benchmarking tool}
60
+ s.test_files = [
61
+ "test/example/01_bubble_sort/ruby/bubble.rb",
62
+ "test/helper.rb",
63
+ "test/test_algorithm.rb",
64
+ "test/test_implementation.rb",
65
+ "test/test_make.rb",
66
+ "test/test_test.rb"
67
+ ]
68
+
69
+ if s.respond_to? :specification_version then
70
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
71
+ s.specification_version = 3
72
+
73
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
74
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
75
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
76
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
77
+ s.add_development_dependency(%q<rcov>, [">= 0"])
78
+ else
79
+ s.add_dependency(%q<shoulda>, [">= 0"])
80
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
81
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
82
+ s.add_dependency(%q<rcov>, [">= 0"])
83
+ end
84
+ else
85
+ s.add_dependency(%q<shoulda>, [">= 0"])
86
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
87
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
88
+ s.add_dependency(%q<rcov>, [">= 0"])
89
+ end
90
+ end
91
+
@@ -0,0 +1,38 @@
1
+ require 'yaml'
2
+
3
+ module Jeka
4
+
5
+ class Algorithm < JekaHelper
6
+
7
+ jeka_reader :name
8
+ jeka_reader :type
9
+ jeka_reader :complexity
10
+ jeka_reader :description
11
+ jeka_reader :references
12
+
13
+ def initialize(folder)
14
+ super(File.join(folder, "_algorithm.yaml"))
15
+ @implementations = nil
16
+ @tests = nil
17
+ end
18
+
19
+ def tests
20
+ return @tests = Test::test_set(File.join(@folder, "_tests")) unless @tests
21
+ return @tests
22
+ end
23
+
24
+ def implementations
25
+ unless @implementations
26
+ @implementations = []
27
+ @jeka["implementations"].each do |i|
28
+ imp = Implementation.new(File.join(@folder, i))
29
+ imp.algorithm = self
30
+ @implementations << imp
31
+ end
32
+ end
33
+ return @implementations
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -1,57 +1,111 @@
1
1
  require 'yaml'
2
+ require 'benchmark'
2
3
 
3
4
  module Jeka
4
5
 
5
- class Implementation
6
- attr_reader :folder
7
- attr_reader :info
6
+ class Implementation < JekaHelper
7
+
8
+ jeka_reader :language
9
+ jeka_reader :source
10
+ jeka_reader :comment
11
+
12
+ attr_accessor :algorithm
8
13
 
9
14
  def initialize(folder)
10
- if folder[-1] == "/"
11
- @folder = folder
12
- else
13
- @folder = "#{folder}/"
14
- end
15
- _load
15
+ super(File.join(folder, "_implementation.yaml"))
16
16
  end
17
17
 
18
- def _load
19
- @info = YAML::load(File.open(File.join(@folder, '_info.yaml'))) if File.exists?(File.join(@folder, '_info.yaml'))
20
- @run = YAML::load(File.open(File.join(@folder, '_run.yaml'))) if File.exists?(File.join(@folder, '_run.yaml'))
21
- @build = YAML::load(File.open(File.join(@folder, '_build.yaml'))) if File.exists?(File.join(@folder, '_build.yaml'))
18
+ def source_code
19
+ f = File.open(File.join(@folder, source), "r")
20
+ return f.readlines.join()
22
21
  end
23
22
 
24
- def run(output, input)
25
- out = []
26
- arg = nil
27
- arg = File.join(@folder, @run['arguments']) if @run['arguments']
28
- command = @run['command']
29
- new_command = @run['command'].sub("$", @folder)
30
- while not new_command == command
31
- command = new_command
32
- new_command = new_command.sub("$", @folder)
23
+ def build
24
+ if @jeka["build"]
25
+ command = @jeka["build"]["command"].gsub("$", @folder)
26
+ system(command)
33
27
  end
34
- if output
35
- system("#{command} #{arg if arg} #{"< #{input}" if input}")
28
+ end
29
+
30
+ def run(input, verbose)
31
+ command = "#{@jeka["run"]["command"].gsub("$", @folder)} #{"< #{input}" if input}"
32
+ if verbose
33
+ system(command)
36
34
  else
37
- IO.popen("#{command} #{arg if arg} #{"< #{input}" if input}") do |io|
35
+ out = ""
36
+ IO.popen(command) do |io|
38
37
  out = io.readlines
39
38
  end
39
+ return out.join("")
40
40
  end
41
- return out.join("\n")
42
41
  end
43
42
 
44
- def build
45
- if @build
46
- command = @build["command"]
47
- new_command = @build["command"].sub("$", @folder)
48
- while not new_command == command
49
- command = new_command
50
- new_command = new_command.sub("$", @folder)
43
+ def benchmark(input, n)
44
+ b = Benchmark.measure {run(input, false)}.to_a
45
+ bench = Hash.new
46
+ bench[:user_cpu_time] = b[1]
47
+ bench[:system_cpu_time] = b[2]
48
+ bench[:childrens_use_cpu_time] = b[3]
49
+ bench[:childrens_system_cpu_time] = b[4]
50
+ bench[:elapsed_real_time] = b[5]
51
+ (n-1).times do
52
+ b = Benchmark.measure {run(input, false)}.to_a
53
+ bench[:user_cpu_time] += b[1]
54
+ bench[:system_cpu_time] += b[2]
55
+ bench[:childrens_use_cpu_time] += b[3]
56
+ bench[:childrens_system_cpu_time] += b[4]
57
+ bench[:elapsed_real_time] += b[5]
58
+ end
59
+ bench[:user_cpu_time] /= n
60
+ bench[:system_cpu_time] /= n
61
+ bench[:childrens_use_cpu_time] /= n
62
+ bench[:childrens_system_cpu_time] /= n
63
+ bench[:elapsed_real_time] /= n
64
+
65
+ filename = File.join(@folder, File.basename(input).gsub(/\..*/, ".benchmark"))
66
+ f = File.open(filename, "w")
67
+ f.write(bench)
68
+ f.close
69
+
70
+ return bench
71
+ end
72
+
73
+ def benchmark_results
74
+ benchmarks = []
75
+ n = 0
76
+ dir = Dir.new(@folder)
77
+ dir.each do |d|
78
+ if d.index(/^test_.*\.benchmark$/)
79
+ f = File.open(File.join(@folder, d), "r")
80
+ benchmarks << eval(f.readlines.join(""))
81
+ n += 1
51
82
  end
52
- system(new_command)
53
83
  end
84
+
85
+ bench = Hash.new
86
+ bench[:language] = language
87
+ bench[:comment] = comment
88
+ bench[:user_cpu_time] = 0
89
+ bench[:system_cpu_time] = 0
90
+ bench[:childrens_use_cpu_time] = 0
91
+ bench[:childrens_system_cpu_time] = 0
92
+ bench[:elapsed_real_time] = 0
93
+ benchmarks.each do |b|
94
+ bench[:user_cpu_time] += b[:user_cpu_time]
95
+ bench[:system_cpu_time] += b[:system_cpu_time]
96
+ bench[:childrens_use_cpu_time] += b[:childrens_use_cpu_time]
97
+ bench[:childrens_system_cpu_time] += b[:childrens_system_cpu_time]
98
+ bench[:elapsed_real_time] += b[:elapsed_real_time]
99
+ end
100
+ bench[:user_cpu_time] /= n
101
+ bench[:system_cpu_time] /= n
102
+ bench[:childrens_use_cpu_time] /= n
103
+ bench[:childrens_system_cpu_time] /= n
104
+ bench[:elapsed_real_time] /= n
105
+
106
+ return bench
54
107
  end
108
+
55
109
  end
56
110
 
57
111
  end
@@ -0,0 +1,16 @@
1
+ module Jeka
2
+ class JekaHelper
3
+
4
+ def initialize(path)
5
+ @folder = "#{File.dirname(path)}/"
6
+ @jeka = YAML::load(File.open(path))
7
+ end
8
+
9
+ def self.jeka_reader(name)
10
+ define_method(name) do
11
+ return @jeka[name.to_s] unless @jeka[name.to_s].kind_of? Hash
12
+ return File.open(File.join(@folder, @jeka[name.to_s]["file"])).readlines.join("")
13
+ end
14
+ end
15
+ end
16
+ end
data/lib/jeka/make.rb CHANGED
@@ -1,162 +1,80 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'yaml'
4
-
5
4
  require 'benchmark'
5
+ require 'uri'
6
6
 
7
7
  module Jeka
8
8
 
9
9
  class Make
10
- attr_reader :jeka
11
- attr_reader :folder
12
10
 
13
11
  def initialize(folder)
14
- @folder = folder
15
- _load
16
- end
17
-
18
- def _load
19
- @jeka = YAML::load(File.open(File.join(@folder, '_jeka.yaml')))
20
- @implementations = []
21
- @jeka["implementations"].each do |implementation|
22
- @implementations << Implementation.new(File.join(@folder, implementation))
23
- end
24
- @test_set = TestSet.new(File.join(@folder, @jeka["tests"]))
25
- end
26
-
27
- def test(&block)
28
- return _test_all unless block
29
- @implementations.each do |implementation|
30
- @test_set.each do |input, output|
31
- block.call(implementation, input, output, implementation.run(false, input) == File.open(output).readlines.join("\n"))
32
- end
33
- end
34
- end
35
-
36
- def _test_all
37
- @implementations.each do |implementation|
38
- @test_set.each do |input, output|
39
- return false unless implementation.run(false, input) == File.open(output).readlines.join("\n")
40
- end
41
- end
42
- return true
12
+ @algorithm = Algorithm.new(folder)
43
13
  end
44
14
 
45
15
  def build
46
- @implementations.each do |implementation|
47
- implementation.build
16
+ @algorithm.implementations.each do |i|
17
+ i.build
48
18
  end
49
19
  end
50
20
 
51
- def benchmark(n, &block)
52
- @implementations.each do |implementation|
53
- @test_set.each do |input, output|
54
- results = []
55
- n.times do
56
- results << Benchmark.measure { implementation.run(true, input) }
57
- end
58
- analysis = _benchmark_analysis(results, implementation.folder, input[input.rindex("/")+1..-7])
59
- block.call(implementation, input, output, analysis) if block
21
+ def test
22
+ @algorithm.implementations.each do |i|
23
+ @algorithm.tests.each do |t|
24
+ out = i.run(t.generate, false)
25
+ yield i, t, out == "#{t.output}\n"
60
26
  end
61
27
  end
62
28
  end
63
29
 
64
- def _benchmark_analysis(results, folder, test)
65
- analysis = [0, 0, 0, 0, 0, 0]
66
- count = 0;
67
- results.each do |r|
68
- r = r.to_a
69
- 5.times do |i|
70
- analysis[i+1] += r[i+1]
30
+ def benchmark(n)
31
+ @algorithm.implementations.each do |i|
32
+ @algorithm.tests.each do |t|
33
+ i.benchmark(t.generate, n)
71
34
  end
72
- count += 1
73
35
  end
74
- analysis.map! {|a| a/count}
75
- analysis[0] = "##{test}"
76
- f = File.new(File.join(folder, "#{test}.benchmark"), "w")
77
- f.write(analysis)
78
- return analysis
79
36
  end
80
37
 
81
- def generate_site(n, &block)
82
- algorithm = ""
83
- implementations = []
84
-
85
- result_alg = {}
86
- benchmark(n) do |implementation, input, output, analysis|
87
- if result_alg[implementation.info["language"]]
88
- a = result_alg[implementation.info["language"]][1]
89
- a << analysis[1..-1]
90
- result_alg[implementation.info["language"]][1] = a
91
- else
92
- result_alg[implementation.info["language"]] = [implementation.info["comment"], [analysis[1..-1]], File.join(implementation.folder, implementation.info["source"])]
93
- end
38
+ def generate_site
39
+ bench = []
40
+ @algorithm.implementations.each do |i|
41
+ bench << i.benchmark_results
94
42
  end
95
- algorithm, implementations = _generete_site(result_alg)
96
- #puts algorithm
97
- block.call([algorithm, @jeka], implementations) if block
43
+ bench = _sort_bench(bench)
44
+ _generete_site(bench)
98
45
  end
99
46
 
100
- def _generete_site(result)
47
+ def _generete_site(bench)
101
48
  implementations = []
102
49
  page = "---\n"
103
50
  page += "layout: algorithm\n"
104
- page += "title: #{@jeka["name"]}\n"
51
+ page += "title: #{@algorithm.name}\n"
105
52
  page += "---\n\n"
106
- page += "h1. #{@jeka["name"]}\n\n"
107
- page += "h2. #{@jeka["type"]}\n\n"
53
+ page += "h1. #{@algorithm.name}\n\n"
54
+ page += "h2. #{@algorithm.type}\n\n"
108
55
  page += "h3. Descrição\n\n"
109
- file = File.new(File.join(@folder, "_description.textile"), "r")
110
- description = file.readlines
111
- page += "#{description.join("")}\n\n"
56
+ page += "#{@algorithm.description}\n\n"
112
57
  page += "h3. Complexidade\n\n"
113
- page += "#{@jeka["complexity"]}\n\n"
58
+ page += "#{@algorithm.complexity}\n\n"
114
59
  page += "h3. Referências\n\n"
115
- file = File.new(File.join(@folder, "_references.textile"), "r")
116
- references = file.readlines
117
- page += "#{references.join()}\n\n"
60
+ page += "#{@algorithm.references}\n\n"
118
61
  page += "h3. Implementações\n\n"
119
62
  page += "|_. Linguagem |_. Comentário |_. Código fonte |_. Tempo de execução médio |\n"
120
- imp = []
121
- result.each do |lang, result|
122
- implementations << [_generate_source_page(File.join(result[2]), "ruby"), result[0]]
123
- total = [0,0,0,0,0]
124
- total_index = 0
125
- result[1].each do |r|
126
- total_index += 1
127
- r.each_with_index do |v, i|
128
- total[i] += v
129
- end
130
- end
131
- total.each_with_index do |v, i|
132
- total[i] = total[i]/total_index
133
- end
134
- imp << ["| #{lang} | #{result[0]} | \"ver\":#{URI.escape("../../../../implementations/#{@jeka["date"].year}/#{'%02d' % @jeka["date"].month}/#{'%02d' % @jeka["date"].day}/#{result[0].gsub(" ", "_")}.html")} | #{total[3]}s |\n", total[3]]
135
- end
136
- imp = sort_imp(imp)
137
- imp.each do |i|
138
- page += i[0]
63
+ bench.each do |b|
64
+ page += "| #{b[:language]} | #{b[:comment]} | \"ver\":#{
65
+ URI.escape("../../../../implementations/2011/01/01/#{b[:comment].gsub(" ", "_")
66
+ }.html")} | #{b[:elapsed_real_time]}s |\n"
139
67
  end
140
68
  page += "\n"
141
- return page, implementations
142
- end
143
-
144
- def sort_imp(imp)
145
- for i in 0..(imp.size-1) do
146
- for j in (i+1)..(imp.size-1) do
147
- if imp[i][1] > imp[j][1]
148
- temp = imp[i]
149
- imp[i] = imp[j]
150
- imp[j] = temp
151
- end
152
- end
69
+
70
+ @algorithm.implementations.each do |i|
71
+ implementations << [i, _generate_source_page(i.source_code, "ruby")]
153
72
  end
154
- return imp
73
+
74
+ return [@algorithm, page], implementations
155
75
  end
156
76
 
157
- def _generate_source_page(file, lang)
158
- f = File.new(file, "r")
159
- src = f.readlines.join()
77
+ def _generate_source_page(src, lang)
160
78
  page = "---\n"
161
79
  page += "layout: implementation\n"
162
80
  page += "title: Bubble Sort\n"
@@ -167,6 +85,19 @@ module Jeka
167
85
  return page
168
86
  end
169
87
 
88
+ def _sort_bench(bench)
89
+ for i in 0..(bench.size-1) do
90
+ for j in (i+1)..(bench.size-1) do
91
+ if bench[i][:elapsed_real_time] > bench[j][:elapsed_real_time]
92
+ temp = bench[i]
93
+ bench[i] = bench[j]
94
+ bench[j] = temp
95
+ end
96
+ end
97
+ end
98
+ return bench
99
+ end
100
+
170
101
  end
171
102
 
172
103
  end
data/lib/jeka/test.rb ADDED
@@ -0,0 +1,38 @@
1
+ require 'yaml'
2
+
3
+ module Jeka
4
+
5
+ class Test < JekaHelper
6
+
7
+ jeka_reader :name
8
+ jeka_reader :input
9
+ jeka_reader :output
10
+
11
+ def initialize(file)
12
+ super(file)
13
+ @file = file
14
+ @generated = false
15
+ end
16
+
17
+ def generate
18
+ filename = "#{@file}.input"
19
+ unless @generated
20
+ ftest = File.open(filename, "w")
21
+ ftest.write(input)
22
+ ftest.close
23
+ end
24
+ return filename
25
+ end
26
+
27
+ end
28
+
29
+ def Test.test_set(folder)
30
+ tests = []
31
+ test_dir = Dir.new(folder)
32
+ test_dir.each do |d|
33
+ tests << Test.new(File.join(folder, d)) if d.index(/test_.*\.yaml$/) == 0
34
+ end
35
+ return tests
36
+ end
37
+
38
+ end
data/lib/jeka.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  ROOT_PATH = File.expand_path(File.dirname(__FILE__))
2
2
 
3
+ require File.join(ROOT_PATH, '/jeka/jeka_helper')
4
+ require File.join(ROOT_PATH, '/jeka/algorithm')
5
+ require File.join(ROOT_PATH, '/jeka/test')
3
6
  require File.join(ROOT_PATH, '/jeka/implementation')
4
7
  require File.join(ROOT_PATH, '/jeka/make')
5
- require File.join(ROOT_PATH, '/jeka/test_set')
@@ -0,0 +1,12 @@
1
+ name: Bubble Sort
2
+ type: Sorting
3
+ description: {
4
+ file: _description.textile
5
+ }
6
+ references: {
7
+ file: _references.textile
8
+ }
9
+ complexity: O(n^2)
10
+ implementations:
11
+ - ruby
12
+ - cpp
@@ -0,0 +1,3 @@
1
+ name: Sequencia decrescente
2
+ input: 9 9 8 7 6 5 4 3 2 1
3
+ output: 1 2 3 4 5 6 7 8 9
@@ -0,0 +1,3 @@
1
+ name: Sequencia aleatoria
2
+ input: 9 8 9 1 3 4 7 6 2 5
3
+ output: 1 2 3 4 5 6 7 8 9
@@ -0,0 +1,9 @@
1
+ language: c++
2
+ source: bubble.cpp
3
+ comment: Implementação simples em C++
4
+ build: {
5
+ command: g++ -o $bubble $bubble.cpp
6
+ }
7
+ run: {
8
+ command: ./$bubble
9
+ }
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ source: bubble.rb
3
+ comment: Implementação simples em Ruby
4
+ run: {
5
+ command: ruby $bubble.rb
6
+ }
@@ -0,0 +1,20 @@
1
+ require 'helper'
2
+
3
+ class TestAlgorithm < Test::Unit::TestCase
4
+
5
+ context "The example" do
6
+
7
+ should "open the bubble sort algorithms" do
8
+ algorithm = Jeka::Algorithm.new(File.join(File.dirname(__FILE__), "example", "01_bubble_sort"))
9
+ assert_equal algorithm.name, "Bubble Sort"
10
+ assert_equal algorithm.type, "Sorting"
11
+ assert_equal algorithm.description, File.open(File.join(File.dirname(__FILE__), "example", "01_bubble_sort", "_description.textile")).readlines.join("")
12
+ assert_equal algorithm.references, File.open(File.join(File.dirname(__FILE__), "example", "01_bubble_sort", "_references.textile")).readlines.join("")
13
+ assert_equal algorithm.complexity, "O(n^2)"
14
+ assert_equal algorithm.tests.length, 2
15
+ assert_equal algorithm.implementations.length, 2
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ require 'helper'
4
+
5
+ class TestImplementation < Test::Unit::TestCase
6
+
7
+ context "The example" do
8
+
9
+ should "open the bubble sort implementation" do
10
+ implementation = Jeka::Implementation.new(File.join(File.dirname(__FILE__), "example", "01_bubble_sort", "cpp"))
11
+ assert_equal implementation.language, "c++"
12
+ assert_equal implementation.source, "bubble.cpp"
13
+ assert_equal implementation.comment, "Implementação simples em C++"
14
+ end
15
+
16
+ end
17
+
18
+ end
data/test/test_make.rb CHANGED
@@ -7,8 +7,8 @@ class TestMake < Test::Unit::TestCase
7
7
  should "pass all the tests" do
8
8
  make = Jeka::Make.new(File.join(File.dirname(__FILE__), "example", "01_bubble_sort"))
9
9
  make.build
10
- make.test do |implementation, input, output, result|
11
- assert result
10
+ make.test do |i, t, r|
11
+ assert r
12
12
  end
13
13
  end
14
14
 
@@ -22,11 +22,11 @@ class TestMake < Test::Unit::TestCase
22
22
  fruby = fruby.readlines.join()
23
23
  make = Jeka::Make.new(File.join(File.dirname(__FILE__), "example", "01_bubble_sort"))
24
24
  make.build
25
- make.generate_site(1) do |algorithm, implementations|
26
- assert_equal falgorithm, algorithm[0].gsub(/(\d)*\.(\d)*s/, "*")
27
- assert_equal fruby, implementations[0][0]
28
- assert_equal fcpp, implementations[1][0]
29
- end
25
+ make.benchmark(1)
26
+ algorithm, implementations = make.generate_site
27
+ assert_equal falgorithm, algorithm[1].gsub(/(\d)*\.(\d)*s/, "*")
28
+ assert_equal fruby, implementations[0][1]
29
+ assert_equal fcpp, implementations[1][1]
30
30
  end
31
31
 
32
32
  end
data/test/test_test.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'helper'
2
+
3
+ class TestTest < Test::Unit::TestCase
4
+
5
+ context "The example" do
6
+
7
+ should "open the bubble sort tests" do
8
+ test = Jeka::Test.new(File.join(File.dirname(__FILE__), "example", "01_bubble_sort", "_tests", "test_01.yaml"))
9
+ assert_equal test.name, "Sequencia decrescente"
10
+ assert_equal test.input, "9 9 8 7 6 5 4 3 2 1"
11
+ assert_equal test.output, "1 2 3 4 5 6 7 8 9"
12
+ end
13
+
14
+ end
15
+
16
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Igor Bonadio
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-07-03 00:00:00 -03:00
17
+ date: 2011-07-16 00:00:00 -03:00
18
18
  default_executable: jeka
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -91,29 +91,30 @@ files:
91
91
  - Rakefile
92
92
  - VERSION
93
93
  - bin/jeka
94
+ - jeka.gemspec
94
95
  - lib/jeka.rb
96
+ - lib/jeka/algorithm.rb
95
97
  - lib/jeka/implementation.rb
98
+ - lib/jeka/jeka_helper.rb
96
99
  - lib/jeka/make.rb
97
- - lib/jeka/test_set.rb
100
+ - lib/jeka/test.rb
101
+ - test/example/01_bubble_sort/_algorithm.yaml
98
102
  - test/example/01_bubble_sort/_description.textile
99
- - test/example/01_bubble_sort/_jeka.yaml
100
103
  - test/example/01_bubble_sort/_references.textile
101
- - test/example/01_bubble_sort/_tests/1.input
102
- - test/example/01_bubble_sort/_tests/1.output
103
- - test/example/01_bubble_sort/_tests/2.input
104
- - test/example/01_bubble_sort/_tests/2.output
105
- - test/example/01_bubble_sort/cpp/_build.yaml
106
- - test/example/01_bubble_sort/cpp/_info.yaml
107
- - test/example/01_bubble_sort/cpp/_run.yaml
104
+ - test/example/01_bubble_sort/_tests/test_01.yaml
105
+ - test/example/01_bubble_sort/_tests/test_02.yaml
106
+ - test/example/01_bubble_sort/cpp/_implementation.yaml
108
107
  - test/example/01_bubble_sort/cpp/bubble.cpp
109
- - test/example/01_bubble_sort/ruby/_info.yaml
110
- - test/example/01_bubble_sort/ruby/_run.yaml
108
+ - test/example/01_bubble_sort/ruby/_implementation.yaml
111
109
  - test/example/01_bubble_sort/ruby/bubble.rb
112
110
  - test/helper.rb
113
111
  - test/site/algorithm.textile
114
112
  - test/site/cpp.textile
115
113
  - test/site/ruby.textile
114
+ - test/test_algorithm.rb
115
+ - test/test_implementation.rb
116
116
  - test/test_make.rb
117
+ - test/test_test.rb
117
118
  has_rdoc: true
118
119
  homepage: http://github.com/igorbonadio/jeka
119
120
  licenses:
@@ -128,7 +129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
129
  requirements:
129
130
  - - ">="
130
131
  - !ruby/object:Gem::Version
131
- hash: 2111267639951866997
132
+ hash: -2500968058579272860
132
133
  segments:
133
134
  - 0
134
135
  version: "0"
@@ -150,4 +151,7 @@ summary: Jeka is an awesome build/test/benchmarking tool
150
151
  test_files:
151
152
  - test/example/01_bubble_sort/ruby/bubble.rb
152
153
  - test/helper.rb
154
+ - test/test_algorithm.rb
155
+ - test/test_implementation.rb
153
156
  - test/test_make.rb
157
+ - test/test_test.rb
data/lib/jeka/test_set.rb DELETED
@@ -1,27 +0,0 @@
1
- module Jeka
2
-
3
- class TestSet
4
- def initialize(folder)
5
- @folder = folder
6
- _load
7
- end
8
-
9
- def _load
10
- tests_dir = Dir.new(@folder)
11
- @input = []
12
- @output = []
13
- tests_dir.each do |test|
14
- @input << File.join(@folder, test) if test.include?(".input")
15
- @output << File.join(@folder, test) if test.include?(".output")
16
- end
17
- end
18
-
19
- def each
20
- @test = []
21
- @input.each_with_index do |input, i|
22
- yield input, @output[i]
23
- end
24
- end
25
- end
26
-
27
- end
@@ -1,8 +0,0 @@
1
- name: Bubble Sort
2
- type: Sorting
3
- tests: _tests
4
- date: 2011-01-01
5
- complexity: O(n^2)
6
- implementations:
7
- - ruby
8
- - cpp
@@ -1 +0,0 @@
1
- 9 9 8 7 6 5 4 3 2 1
@@ -1 +0,0 @@
1
- 1 2 3 4 5 6 7 8 9
@@ -1 +0,0 @@
1
- 9 9 1 8 2 7 3 6 4 5
@@ -1 +0,0 @@
1
- 1 2 3 4 5 6 7 8 9
@@ -1 +0,0 @@
1
- command: g++ -o $bubble $bubble.cpp
@@ -1,3 +0,0 @@
1
- language: c++
2
- source: bubble.cpp
3
- comment: Implementação simples em C++
@@ -1 +0,0 @@
1
- command: ./$bubble
@@ -1,3 +0,0 @@
1
- language: ruby
2
- source: bubble.rb
3
- comment: Implementação simples em Ruby
@@ -1 +0,0 @@
1
- command: ruby $bubble.rb