jeka 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +20 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +53 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/bin/jeka +115 -0
- data/lib/jeka/implementation.rb +57 -0
- data/lib/jeka/make.rb +172 -0
- data/lib/jeka/test_set.rb +27 -0
- data/lib/jeka.rb +5 -0
- data/test/example/01_bubble_sort/_description.textile +1 -0
- data/test/example/01_bubble_sort/_jeka.yaml +8 -0
- data/test/example/01_bubble_sort/_references.textile +1 -0
- data/test/example/01_bubble_sort/_tests/1.input +1 -0
- data/test/example/01_bubble_sort/_tests/1.output +1 -0
- data/test/example/01_bubble_sort/_tests/2.input +1 -0
- data/test/example/01_bubble_sort/_tests/2.output +1 -0
- data/test/example/01_bubble_sort/cpp/_build.yaml +1 -0
- data/test/example/01_bubble_sort/cpp/_info.yaml +3 -0
- data/test/example/01_bubble_sort/cpp/_run.yaml +1 -0
- data/test/example/01_bubble_sort/cpp/bubble.cpp +39 -0
- data/test/example/01_bubble_sort/ruby/_info.yaml +3 -0
- data/test/example/01_bubble_sort/ruby/_run.yaml +1 -0
- data/test/example/01_bubble_sort/ruby/bubble.rb +21 -0
- data/test/helper.rb +18 -0
- data/test/site/algorithm.textile +27 -0
- data/test/site/cpp.textile +46 -0
- data/test/site/ruby.textile +28 -0
- data/test/test_make.rb +34 -0
- metadata +153 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.5.2"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
git (1.2.5)
|
5
|
+
jeweler (1.5.2)
|
6
|
+
bundler (~> 1.0.0)
|
7
|
+
git (>= 1.2.5)
|
8
|
+
rake
|
9
|
+
rake (0.8.7)
|
10
|
+
rcov (0.9.9)
|
11
|
+
shoulda (2.11.3)
|
12
|
+
|
13
|
+
PLATFORMS
|
14
|
+
ruby
|
15
|
+
|
16
|
+
DEPENDENCIES
|
17
|
+
bundler (~> 1.0.0)
|
18
|
+
jeweler (~> 1.5.2)
|
19
|
+
rcov
|
20
|
+
shoulda
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Ígor Bonadio
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
= Jeka v0.1.0
|
2
|
+
|
3
|
+
Jeka is an awesome build/test/benchmarking tool.
|
4
|
+
|
5
|
+
It uses Jekyll (https://github.com/mojombo/jekyll) to create a website with informations about algorithms.
|
6
|
+
|
7
|
+
== Applications
|
8
|
+
|
9
|
+
* Repository of algorithms and problems
|
10
|
+
* Comparison of algorithms and their implementations
|
11
|
+
* Studies about analysis of algorithms
|
12
|
+
|
13
|
+
== Creating a Jeka Repository
|
14
|
+
|
15
|
+
See an example here[link:https://github.com/igorbonadio/jeka/tree/master/test/example]
|
16
|
+
|
17
|
+
== Using
|
18
|
+
|
19
|
+
Building a Jeka repository:
|
20
|
+
|
21
|
+
$ jeka build <dir>
|
22
|
+
|
23
|
+
Testing implementations:
|
24
|
+
|
25
|
+
$ jeka test <dir>
|
26
|
+
|
27
|
+
Benchmarking implementations:
|
28
|
+
|
29
|
+
$ jeka benchmark <dir>
|
30
|
+
|
31
|
+
Creating a Jekyll site:
|
32
|
+
|
33
|
+
$ jeka site <dir>
|
34
|
+
|
35
|
+
== For the future
|
36
|
+
|
37
|
+
* Jeka will be used in my next project which is a repository of algorithms and their implementations in several languages. It will be released soon.
|
38
|
+
|
39
|
+
== Contributing to jeka
|
40
|
+
|
41
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
42
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
43
|
+
* Fork the project
|
44
|
+
* Start a feature/bugfix branch
|
45
|
+
* Commit and push until you are happy with your contribution
|
46
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
47
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
48
|
+
|
49
|
+
== Copyright
|
50
|
+
|
51
|
+
Copyright (c) 2011 Ígor Bonadio. See LICENSE.txt for
|
52
|
+
further details.
|
53
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "jeka"
|
16
|
+
gem.homepage = "http://github.com/igorbonadio/jeka"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{Jeka is an awesome build/test/benchmarking tool}
|
19
|
+
gem.description = %Q{Jeka is an awesome build/test/benchmarking tool}
|
20
|
+
gem.email = "igorbonadio@gmail.com"
|
21
|
+
gem.authors = ["Igor Bonadio"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
Rake::TestTask.new(:test) do |test|
|
31
|
+
test.libs << 'lib' << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'rcov/rcovtask'
|
37
|
+
Rcov::RcovTask.new do |test|
|
38
|
+
test.libs << 'test'
|
39
|
+
test.pattern = 'test/**/test_*.rb'
|
40
|
+
test.verbose = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "jeka #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/jeka
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '/../lib/jeka')
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
def help
|
8
|
+
puts "Usage: p-lang [option] folder"
|
9
|
+
puts " options:"
|
10
|
+
puts " build"
|
11
|
+
puts " test"
|
12
|
+
puts " benchmark"
|
13
|
+
puts " site"
|
14
|
+
puts " Example:"
|
15
|
+
puts " jeka build test/example/01_bubble_sort/"
|
16
|
+
end
|
17
|
+
|
18
|
+
def init(folder)
|
19
|
+
jeka_dir = Dir.new(folder)
|
20
|
+
jeka_dir.each do |d|
|
21
|
+
dir = File.join(folder, d)
|
22
|
+
if (File.directory?(dir) and d != "." and d != "..")
|
23
|
+
yield dir
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def build(folder)
|
29
|
+
init(folder) do |dir|
|
30
|
+
begin
|
31
|
+
make = Jeka::Make.new(dir)
|
32
|
+
puts "jeka: building #{dir}"
|
33
|
+
make.build
|
34
|
+
rescue
|
35
|
+
end
|
36
|
+
build(dir)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test(folder)
|
41
|
+
init(folder) do |dir|
|
42
|
+
begin
|
43
|
+
make = Jeka::Make.new(dir)
|
44
|
+
make.test do |implementation, input, output, result|
|
45
|
+
ok = "error"
|
46
|
+
ok = "ok" if result
|
47
|
+
puts "jeka: testing #{implementation.folder} with #{input}...#{ok}"
|
48
|
+
return unless result
|
49
|
+
end
|
50
|
+
rescue
|
51
|
+
end
|
52
|
+
test(dir)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def benchmark(folder)
|
57
|
+
init(folder) do |dir|
|
58
|
+
begin
|
59
|
+
make = Jeka::Make.new(dir)
|
60
|
+
puts "jeka: benchmarking #{dir}"
|
61
|
+
make.benchmark(10)
|
62
|
+
rescue
|
63
|
+
end
|
64
|
+
benchmark(dir)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def site(folder)
|
69
|
+
build(folder)
|
70
|
+
test(folder)
|
71
|
+
|
72
|
+
Dir.mkdir("_jeka") unless Dir.exists?("_jeka")
|
73
|
+
Dir.mkdir("_jeka/algorithms") unless Dir.exists?("_jeka/algorithms")
|
74
|
+
Dir.mkdir("_jeka/algorithms/_posts") unless Dir.exists?("_jeka/algorithms/_posts")
|
75
|
+
Dir.mkdir("_jeka/implementations/") unless Dir.exists?("_jeka/implementations/")
|
76
|
+
Dir.mkdir("_jeka/implementations/_posts") unless Dir.exists?("_jeka/implementations/_posts")
|
77
|
+
|
78
|
+
_site(folder)
|
79
|
+
end
|
80
|
+
|
81
|
+
def _site(folder)
|
82
|
+
init(folder) do |dir|
|
83
|
+
begin
|
84
|
+
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
|
93
|
+
end
|
94
|
+
rescue
|
95
|
+
end
|
96
|
+
_site(dir)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
if ARGV.length == 2
|
101
|
+
case ARGV[0]
|
102
|
+
when "build"
|
103
|
+
build(ARGV[1])
|
104
|
+
when "test"
|
105
|
+
test(ARGV[1])
|
106
|
+
when "benchmark"
|
107
|
+
benchmark(ARGV[1])
|
108
|
+
when "site"
|
109
|
+
site(ARGV[1])
|
110
|
+
else
|
111
|
+
help
|
112
|
+
end
|
113
|
+
else
|
114
|
+
help
|
115
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Jeka
|
4
|
+
|
5
|
+
class Implementation
|
6
|
+
attr_reader :folder
|
7
|
+
attr_reader :info
|
8
|
+
|
9
|
+
def initialize(folder)
|
10
|
+
if folder[-1] == "/"
|
11
|
+
@folder = folder
|
12
|
+
else
|
13
|
+
@folder = "#{folder}/"
|
14
|
+
end
|
15
|
+
_load
|
16
|
+
end
|
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'))
|
22
|
+
end
|
23
|
+
|
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)
|
33
|
+
end
|
34
|
+
if output
|
35
|
+
system("#{command} #{arg if arg} #{"< #{input}" if input}")
|
36
|
+
else
|
37
|
+
IO.popen("#{command} #{arg if arg} #{"< #{input}" if input}") do |io|
|
38
|
+
out = io.readlines
|
39
|
+
end
|
40
|
+
end
|
41
|
+
return out.join("\n")
|
42
|
+
end
|
43
|
+
|
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)
|
51
|
+
end
|
52
|
+
system(new_command)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
data/lib/jeka/make.rb
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
require 'benchmark'
|
6
|
+
|
7
|
+
module Jeka
|
8
|
+
|
9
|
+
class Make
|
10
|
+
attr_reader :jeka
|
11
|
+
attr_reader :folder
|
12
|
+
|
13
|
+
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
|
43
|
+
end
|
44
|
+
|
45
|
+
def build
|
46
|
+
@implementations.each do |implementation|
|
47
|
+
implementation.build
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
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
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
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]
|
71
|
+
end
|
72
|
+
count += 1
|
73
|
+
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
|
+
end
|
80
|
+
|
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
|
94
|
+
end
|
95
|
+
algorithm, implementations = _generete_site(result_alg)
|
96
|
+
#puts algorithm
|
97
|
+
block.call([algorithm, @jeka], implementations) if block
|
98
|
+
end
|
99
|
+
|
100
|
+
def _generete_site(result)
|
101
|
+
implementations = []
|
102
|
+
page = "---\n"
|
103
|
+
page += "layout: algorithm\n"
|
104
|
+
page += "title: #{@jeka["name"]}\n"
|
105
|
+
page += "---\n\n"
|
106
|
+
page += "h1. #{@jeka["name"]}\n\n"
|
107
|
+
page += "h2. #{@jeka["type"]}\n\n"
|
108
|
+
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"
|
112
|
+
page += "h3. Complexidade\n\n"
|
113
|
+
page += "#{@jeka["complexity"]}\n\n"
|
114
|
+
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"
|
118
|
+
page += "h3. Implementações\n\n"
|
119
|
+
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]
|
139
|
+
end
|
140
|
+
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
|
153
|
+
end
|
154
|
+
return imp
|
155
|
+
end
|
156
|
+
|
157
|
+
def _generate_source_page(file, lang)
|
158
|
+
f = File.new(file, "r")
|
159
|
+
src = f.readlines.join()
|
160
|
+
page = "---\n"
|
161
|
+
page += "layout: implementation\n"
|
162
|
+
page += "title: Bubble Sort\n"
|
163
|
+
page += "---\n\n"
|
164
|
+
page += "{% highlight #{lang} %}\n"
|
165
|
+
page += src
|
166
|
+
page += "{% endhighlight %}\n"
|
167
|
+
return page
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
@@ -0,0 +1,27 @@
|
|
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
|
data/lib/jeka.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Bubble sort, also known as sinking sort, is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm gets its name from the way smaller elements "bubble" to the top of the list. Because it only uses comparisons to operate on elements, it is a comparison sort. The equally simple insertion sort has better performance than bubble sort, so some have suggested no longer teaching the bubble sort.
|
@@ -0,0 +1 @@
|
|
1
|
+
http://en.wikipedia.org/wiki/Bubble_sort
|
@@ -0,0 +1 @@
|
|
1
|
+
9 9 8 7 6 5 4 3 2 1
|
@@ -0,0 +1 @@
|
|
1
|
+
1 2 3 4 5 6 7 8 9
|
@@ -0,0 +1 @@
|
|
1
|
+
9 9 1 8 2 7 3 6 4 5
|
@@ -0,0 +1 @@
|
|
1
|
+
1 2 3 4 5 6 7 8 9
|
@@ -0,0 +1 @@
|
|
1
|
+
command: g++ -o $bubble $bubble.cpp
|
@@ -0,0 +1 @@
|
|
1
|
+
command: ./$bubble
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#include <iostream>
|
2
|
+
#include <vector>
|
3
|
+
#include <stdlib.h>
|
4
|
+
|
5
|
+
using namespace std;
|
6
|
+
|
7
|
+
vector<int> bubble_sort(vector<int> numbers) {
|
8
|
+
for(int i = 0; i < 9; i++) {
|
9
|
+
for(int j = i; j < 9; j++) {
|
10
|
+
if (numbers[i] > numbers[j]) {
|
11
|
+
int temp = numbers[i];
|
12
|
+
numbers[i] = numbers[j];
|
13
|
+
numbers[j] = temp;
|
14
|
+
}
|
15
|
+
}
|
16
|
+
}
|
17
|
+
return numbers;
|
18
|
+
}
|
19
|
+
|
20
|
+
int main() {
|
21
|
+
vector<int> numbers;
|
22
|
+
int max, v;
|
23
|
+
|
24
|
+
// Reading the input
|
25
|
+
cin >> max;
|
26
|
+
for (int i = 0; i < max; i++) {
|
27
|
+
cin >> v;
|
28
|
+
numbers.push_back(v);
|
29
|
+
}
|
30
|
+
|
31
|
+
numbers = bubble_sort(numbers);
|
32
|
+
|
33
|
+
// Printing the output
|
34
|
+
for (int i=0; i< 8; i++)
|
35
|
+
cout << numbers[i] << " ";
|
36
|
+
cout << numbers[8] << endl;
|
37
|
+
|
38
|
+
return 0;
|
39
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
command: ruby $bubble.rb
|
@@ -0,0 +1,21 @@
|
|
1
|
+
def bubble(numbers)
|
2
|
+
for i in (0..numbers.size-1)
|
3
|
+
for j in (i..numbers.size-1)
|
4
|
+
if numbers[i] > numbers[j]
|
5
|
+
temp = numbers[i]
|
6
|
+
numbers[i] = numbers[j]
|
7
|
+
numbers[j] = temp
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
numbers
|
12
|
+
end
|
13
|
+
|
14
|
+
# Reading the input
|
15
|
+
input = gets
|
16
|
+
input = input.split(' ')[1..-1].map {|c| c.to_i }
|
17
|
+
|
18
|
+
bubble(input)
|
19
|
+
|
20
|
+
# Printing the output
|
21
|
+
puts input.inject {|output, n| "#{output} #{n}"}
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'jeka'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
---
|
2
|
+
layout: algorithm
|
3
|
+
title: Bubble Sort
|
4
|
+
---
|
5
|
+
|
6
|
+
h1. Bubble Sort
|
7
|
+
|
8
|
+
h2. Sorting
|
9
|
+
|
10
|
+
h3. Descrição
|
11
|
+
|
12
|
+
Bubble sort, also known as sinking sort, is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm gets its name from the way smaller elements "bubble" to the top of the list. Because it only uses comparisons to operate on elements, it is a comparison sort. The equally simple insertion sort has better performance than bubble sort, so some have suggested no longer teaching the bubble sort.
|
13
|
+
|
14
|
+
h3. Complexidade
|
15
|
+
|
16
|
+
O(n^2)
|
17
|
+
|
18
|
+
h3. Referências
|
19
|
+
|
20
|
+
http://en.wikipedia.org/wiki/Bubble_sort
|
21
|
+
|
22
|
+
h3. Implementações
|
23
|
+
|
24
|
+
|_. Linguagem |_. Comentário |_. Código fonte |_. Tempo de execução médio |
|
25
|
+
| c++ | Implementação simples em C++ | "ver":../../../../implementations/2011/01/01/Implementa%C3%A7%C3%A3o_simples_em_C++.html | 0.003s |
|
26
|
+
| ruby | Implementação simples em Ruby | "ver":../../../../implementations/2011/01/01/Implementa%C3%A7%C3%A3o_simples_em_Ruby.html | 0.006500000000000001s |
|
27
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
---
|
2
|
+
layout: implementation
|
3
|
+
title: Bubble Sort
|
4
|
+
---
|
5
|
+
|
6
|
+
{% highlight ruby %}
|
7
|
+
#include <iostream>
|
8
|
+
#include <vector>
|
9
|
+
#include <stdlib.h>
|
10
|
+
|
11
|
+
using namespace std;
|
12
|
+
|
13
|
+
vector<int> bubble_sort(vector<int> numbers) {
|
14
|
+
for(int i = 0; i < 9; i++) {
|
15
|
+
for(int j = i; j < 9; j++) {
|
16
|
+
if (numbers[i] > numbers[j]) {
|
17
|
+
int temp = numbers[i];
|
18
|
+
numbers[i] = numbers[j];
|
19
|
+
numbers[j] = temp;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
return numbers;
|
24
|
+
}
|
25
|
+
|
26
|
+
int main() {
|
27
|
+
vector<int> numbers;
|
28
|
+
int max, v;
|
29
|
+
|
30
|
+
// Reading the input
|
31
|
+
cin >> max;
|
32
|
+
for (int i = 0; i < max; i++) {
|
33
|
+
cin >> v;
|
34
|
+
numbers.push_back(v);
|
35
|
+
}
|
36
|
+
|
37
|
+
numbers = bubble_sort(numbers);
|
38
|
+
|
39
|
+
// Printing the output
|
40
|
+
for (int i=0; i< 8; i++)
|
41
|
+
cout << numbers[i] << " ";
|
42
|
+
cout << numbers[8] << endl;
|
43
|
+
|
44
|
+
return 0;
|
45
|
+
}
|
46
|
+
{% endhighlight %}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
---
|
2
|
+
layout: implementation
|
3
|
+
title: Bubble Sort
|
4
|
+
---
|
5
|
+
|
6
|
+
{% highlight ruby %}
|
7
|
+
def bubble(numbers)
|
8
|
+
for i in (0..numbers.size-1)
|
9
|
+
for j in (i..numbers.size-1)
|
10
|
+
if numbers[i] > numbers[j]
|
11
|
+
temp = numbers[i]
|
12
|
+
numbers[i] = numbers[j]
|
13
|
+
numbers[j] = temp
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
numbers
|
18
|
+
end
|
19
|
+
|
20
|
+
# Reading the input
|
21
|
+
input = gets
|
22
|
+
input = input.split(' ')[1..-1].map {|c| c.to_i }
|
23
|
+
|
24
|
+
bubble(input)
|
25
|
+
|
26
|
+
# Printing the output
|
27
|
+
puts input.inject {|output, n| "#{output} #{n}"}
|
28
|
+
{% endhighlight %}
|
data/test/test_make.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestMake < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "The example" do
|
6
|
+
|
7
|
+
should "pass all the tests" do
|
8
|
+
make = Jeka::Make.new(File.join(File.dirname(__FILE__), "example", "01_bubble_sort"))
|
9
|
+
make.build
|
10
|
+
make.test do |implementation, input, output, result|
|
11
|
+
assert result
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
should "generate the web pages" do
|
16
|
+
falgorithm = File.new(File.join(File.dirname(__FILE__), "site", "algorithm.textile"), "r")
|
17
|
+
falgorithm = falgorithm.readlines.join()
|
18
|
+
falgorithm = falgorithm.gsub(/(\d)*\.(\d)*s/, "*")
|
19
|
+
fcpp = File.new(File.join(File.dirname(__FILE__), "site", "cpp.textile"), "r")
|
20
|
+
fcpp = fcpp.readlines.join()
|
21
|
+
fruby = File.new(File.join(File.dirname(__FILE__), "site", "ruby.textile"), "r")
|
22
|
+
fruby = fruby.readlines.join()
|
23
|
+
make = Jeka::Make.new(File.join(File.dirname(__FILE__), "example", "01_bubble_sort"))
|
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
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jeka
|
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
|
+
- Igor Bonadio
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-07-03 00:00:00 -03:00
|
18
|
+
default_executable: jeka
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: shoulda
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :development
|
31
|
+
prerelease: false
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 1
|
42
|
+
- 0
|
43
|
+
- 0
|
44
|
+
version: 1.0.0
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: jeweler
|
50
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 1
|
57
|
+
- 5
|
58
|
+
- 2
|
59
|
+
version: 1.5.2
|
60
|
+
type: :development
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: rcov
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
type: :development
|
74
|
+
prerelease: false
|
75
|
+
version_requirements: *id004
|
76
|
+
description: Jeka is an awesome build/test/benchmarking tool
|
77
|
+
email: igorbonadio@gmail.com
|
78
|
+
executables:
|
79
|
+
- jeka
|
80
|
+
extensions: []
|
81
|
+
|
82
|
+
extra_rdoc_files:
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.rdoc
|
85
|
+
files:
|
86
|
+
- .document
|
87
|
+
- Gemfile
|
88
|
+
- Gemfile.lock
|
89
|
+
- LICENSE.txt
|
90
|
+
- README.rdoc
|
91
|
+
- Rakefile
|
92
|
+
- VERSION
|
93
|
+
- bin/jeka
|
94
|
+
- lib/jeka.rb
|
95
|
+
- lib/jeka/implementation.rb
|
96
|
+
- lib/jeka/make.rb
|
97
|
+
- lib/jeka/test_set.rb
|
98
|
+
- test/example/01_bubble_sort/_description.textile
|
99
|
+
- test/example/01_bubble_sort/_jeka.yaml
|
100
|
+
- 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
|
108
|
+
- 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
|
111
|
+
- test/example/01_bubble_sort/ruby/bubble.rb
|
112
|
+
- test/helper.rb
|
113
|
+
- test/site/algorithm.textile
|
114
|
+
- test/site/cpp.textile
|
115
|
+
- test/site/ruby.textile
|
116
|
+
- test/test_make.rb
|
117
|
+
has_rdoc: true
|
118
|
+
homepage: http://github.com/igorbonadio/jeka
|
119
|
+
licenses:
|
120
|
+
- MIT
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
hash: 2111267639951866997
|
132
|
+
segments:
|
133
|
+
- 0
|
134
|
+
version: "0"
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
none: false
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
segments:
|
141
|
+
- 0
|
142
|
+
version: "0"
|
143
|
+
requirements: []
|
144
|
+
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 1.3.7
|
147
|
+
signing_key:
|
148
|
+
specification_version: 3
|
149
|
+
summary: Jeka is an awesome build/test/benchmarking tool
|
150
|
+
test_files:
|
151
|
+
- test/example/01_bubble_sort/ruby/bubble.rb
|
152
|
+
- test/helper.rb
|
153
|
+
- test/test_make.rb
|