jeka 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/Gemfile.lock +55 -2
- data/README.rdoc +6 -14
- data/VERSION +1 -1
- data/bin/jeka +64 -94
- data/jeka.gemspec +56 -28
- data/lib/jeka.rb +6 -4
- data/lib/jeka/algorithm.rb +106 -24
- data/lib/jeka/analysis.rb +15 -0
- data/lib/jeka/analysis/algorithm.rb +13 -0
- data/lib/jeka/analysis/compiler.rb +14 -0
- data/lib/jeka/analysis/compiler_option.rb +24 -0
- data/lib/jeka/analysis/database.rb +11 -0
- data/lib/jeka/analysis/implementation.rb +15 -0
- data/lib/jeka/analysis/implementation_information.rb +24 -0
- data/lib/jeka/analysis/result.rb +20 -0
- data/lib/jeka/analysis/source_file.rb +24 -0
- data/lib/jeka/analysis/test.rb +15 -0
- data/lib/jeka/analysis/test_case.rb +13 -0
- data/lib/jeka/compilers.rb +3 -0
- data/lib/jeka/compilers/compiler.rb +48 -0
- data/lib/jeka/compilers/gpp.rb +29 -0
- data/lib/jeka/compilers/ruby.rb +21 -0
- data/lib/jeka/console.rb +55 -0
- data/lib/jeka/implementation.rb +22 -97
- data/lib/jeka/test.rb +15 -31
- data/lib/jeka/test_case.rb +41 -0
- data/test/bubble_sort/_tests/_test_01.rb +13 -0
- data/test/bubble_sort/algorithm_bubble_sort.rb +15 -0
- data/test/bubble_sort/cpp/_implementation.yaml +3 -0
- data/test/{example/01_bubble_sort/cpp/bubble.cpp → bubble_sort/cpp/bubble_sort.cpp} +9 -10
- data/test/bubble_sort/ruby/_implementation.yaml +3 -0
- data/test/{example/01_bubble_sort/ruby/bubble.rb → bubble_sort/ruby/bubble_sort.rb} +2 -5
- data/test/double/_tests/_test_01.rb +13 -0
- data/test/double/algorithm_double.rb +15 -0
- data/test/double/cpp/double.cpp +10 -0
- data/test/double/ruby/double.rb +2 -0
- data/test/test_algorithm.rb +25 -11
- data/test/test_gpp.rb +29 -0
- data/test/test_implementation.rb +25 -10
- data/test/test_test_case.rb +21 -0
- metadata +94 -52
- data/lib/jeka/jeka_helper.rb +0 -16
- data/lib/jeka/make.rb +0 -103
- data/test/example/01_bubble_sort/_algorithm.yaml +0 -12
- data/test/example/01_bubble_sort/_description.textile +0 -1
- data/test/example/01_bubble_sort/_references.textile +0 -1
- data/test/example/01_bubble_sort/_tests/test_01.yaml +0 -3
- data/test/example/01_bubble_sort/_tests/test_02.yaml +0 -3
- data/test/example/01_bubble_sort/cpp/_implementation.yaml +0 -9
- data/test/example/01_bubble_sort/ruby/_implementation.yaml +0 -6
- data/test/site/algorithm.textile +0 -27
- data/test/site/cpp.textile +0 -46
- data/test/site/ruby.textile +0 -28
- data/test/test_make.rb +0 -34
- data/test/test_test.rb +0 -16
@@ -0,0 +1,21 @@
|
|
1
|
+
module Jeka
|
2
|
+
module Compiler
|
3
|
+
|
4
|
+
class Ruby < Compiler
|
5
|
+
def initialize(file, options = {})
|
6
|
+
@files = [file]
|
7
|
+
@options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def _run_command
|
13
|
+
"ruby " << @files[0]
|
14
|
+
end
|
15
|
+
|
16
|
+
def _build_command
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/jeka/console.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
module Jeka
|
2
|
+
module Console
|
3
|
+
|
4
|
+
def self.add_algorithms(dir)
|
5
|
+
Jeka::Algorithm.reset
|
6
|
+
Dir.glob(dir).each do |d|
|
7
|
+
load d
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.run(n)
|
12
|
+
error = false
|
13
|
+
Jeka::Algorithm.run_all(n) do |p, t, o|
|
14
|
+
self._show(p, t, o, false)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.build
|
19
|
+
error = false
|
20
|
+
Jeka::Algorithm.build_all do |p, t, o|
|
21
|
+
self._show(p, t, o, true)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self._show(p, t, o, s)
|
26
|
+
case t
|
27
|
+
when :step
|
28
|
+
p = p.to_s
|
29
|
+
while p.length < 3
|
30
|
+
p = " " + p
|
31
|
+
end
|
32
|
+
puts "[#{p}%] #{o}"
|
33
|
+
when :output
|
34
|
+
if s
|
35
|
+
o = o.join
|
36
|
+
if o.length > 0
|
37
|
+
puts o
|
38
|
+
end
|
39
|
+
end
|
40
|
+
when :error
|
41
|
+
o = o.join
|
42
|
+
if o.length > 0
|
43
|
+
puts o
|
44
|
+
end
|
45
|
+
error = true
|
46
|
+
when :done
|
47
|
+
if error
|
48
|
+
puts "[100%] Some error occurs..."
|
49
|
+
else
|
50
|
+
puts "[100%] Done!"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/jeka/implementation.rb
CHANGED
@@ -1,111 +1,36 @@
|
|
1
1
|
require 'yaml'
|
2
|
-
require 'benchmark'
|
3
2
|
|
4
3
|
module Jeka
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
def initialize(folder)
|
15
|
-
super(File.join(folder, "_implementation.yaml"))
|
16
|
-
end
|
17
|
-
|
18
|
-
def source_code
|
19
|
-
f = File.open(File.join(@folder, source), "r")
|
20
|
-
return f.readlines.join()
|
4
|
+
class Implementation
|
5
|
+
attr_reader :database
|
6
|
+
attr_accessor :name
|
7
|
+
attr_accessor :compiler
|
8
|
+
|
9
|
+
def initialize(name)
|
10
|
+
@name = name
|
11
|
+
@information = {}
|
21
12
|
end
|
22
13
|
|
23
|
-
def
|
24
|
-
if
|
25
|
-
|
26
|
-
system(command)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def run(input, verbose)
|
31
|
-
command = "#{@jeka["run"]["command"].gsub("$", @folder)} #{"< #{input}" if input}"
|
32
|
-
if verbose
|
33
|
-
system(command)
|
14
|
+
def information=(info)
|
15
|
+
if info.kind_of? Hash
|
16
|
+
@information = info
|
34
17
|
else
|
35
|
-
|
36
|
-
|
37
|
-
out = io.readlines
|
38
|
-
end
|
39
|
-
return out.join("")
|
18
|
+
@yaml = YAML::load(File.open(info))
|
19
|
+
@yaml.each_key {|key| @information[key.to_sym] = @yaml[key]}
|
40
20
|
end
|
41
21
|
end
|
42
22
|
|
43
|
-
def
|
44
|
-
|
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
|
23
|
+
def information
|
24
|
+
@information
|
71
25
|
end
|
72
26
|
|
73
|
-
def
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
f = File.open(File.join(@folder, d), "r")
|
80
|
-
benchmarks << eval(f.readlines.join(""))
|
81
|
-
n += 1
|
82
|
-
end
|
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
|
27
|
+
def jekafy
|
28
|
+
@database = Jeka::Analysis::Implementation.create(
|
29
|
+
name: @name,
|
30
|
+
compiler: @compiler.jekafy,
|
31
|
+
implementation_information: Jeka::Analysis::ImplementationInformation.convert(@information)
|
32
|
+
)
|
107
33
|
end
|
108
34
|
|
109
35
|
end
|
110
|
-
|
111
|
-
end
|
36
|
+
end
|
data/lib/jeka/test.rb
CHANGED
@@ -1,38 +1,22 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
1
|
module Jeka
|
4
|
-
|
5
|
-
|
2
|
+
class Test
|
3
|
+
attr_reader :database
|
4
|
+
attr_accessor :input
|
5
|
+
attr_accessor :output
|
6
|
+
attr_accessor :name
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
jeka_reader :output
|
10
|
-
|
11
|
-
def initialize(file)
|
12
|
-
super(file)
|
13
|
-
@file = file
|
14
|
-
@generated = false
|
8
|
+
def initialize(name)
|
9
|
+
@name = name
|
15
10
|
end
|
16
11
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
return filename
|
12
|
+
def jekafy
|
13
|
+
@database = Jeka::Analysis::Test.create(
|
14
|
+
name: @name,
|
15
|
+
output: @output,
|
16
|
+
input: @input
|
17
|
+
)
|
18
|
+
@database
|
25
19
|
end
|
26
20
|
|
27
21
|
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
|
22
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Jeka
|
2
|
+
|
3
|
+
class TestCase
|
4
|
+
attr_reader :database
|
5
|
+
|
6
|
+
def tests
|
7
|
+
methods.select {|m| m =~ /^test_/}.map {|m| send(m)}
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.test(name)
|
11
|
+
t = Test.new(name)
|
12
|
+
yield t
|
13
|
+
define_method("test_#{name}".to_sym) do
|
14
|
+
return t
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.reset
|
19
|
+
@@test_suites = {}
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.inherited(klass)
|
23
|
+
@@test_suites ||= {}
|
24
|
+
@@test_suites[klass] = true
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.test_suites
|
28
|
+
@@test_suites ||= {}
|
29
|
+
@@test_suites.keys.sort_by { |ts| ts.name }.collect{|ts| ts.new}
|
30
|
+
end
|
31
|
+
|
32
|
+
def jekafy
|
33
|
+
@database = Jeka::Analysis::TestCase.create(
|
34
|
+
name: self.class.to_s,
|
35
|
+
tests: tests.collect {|t| t.jekafy}
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class TestAlgorithmBubbleSort < Jeka::TestCase
|
2
|
+
|
3
|
+
test 'Decreasing Sequence' do |t|
|
4
|
+
t.input = '9 8 7 6 5 4 3 2 1'
|
5
|
+
t.output = '1 2 3 4 5 6 7 8 9'
|
6
|
+
end
|
7
|
+
|
8
|
+
test 'Random Sequence' do |t|
|
9
|
+
t.input = '3 1 5 7 6 8 9 4 2'
|
10
|
+
t.output = '1 2 3 4 5 6 7 8 9'
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class AlgorithmBubbleSort < Jeka::Algorithm
|
2
|
+
|
3
|
+
add_tests File.join(File.dirname(__FILE__), '_tests', '**', '_test_*.rb')
|
4
|
+
|
5
|
+
implementation 'c++' do |imp|
|
6
|
+
imp.information = {language: 'c++', comment: 'Simple implementation in C++'}
|
7
|
+
imp.compiler = Jeka::Compiler::Gpp.new([File.join(File.dirname(__FILE__), 'cpp', 'bubble_sort.cpp')], {:o => 'bubble_sort_cpp'})
|
8
|
+
end
|
9
|
+
|
10
|
+
implementation 'ruby' do |imp|
|
11
|
+
imp.information = {language: 'ruby', comment: 'Simple implementation in Ruby'}
|
12
|
+
imp.compiler = Jeka::Compiler::Ruby.new(File.join(File.dirname(__FILE__), 'ruby', 'bubble_sort.rb'))
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -5,8 +5,9 @@
|
|
5
5
|
using namespace std;
|
6
6
|
|
7
7
|
vector<int> bubble_sort(vector<int> numbers) {
|
8
|
-
|
9
|
-
|
8
|
+
int n = numbers.size();
|
9
|
+
for(int i = 0; i < n; i++) {
|
10
|
+
for(int j = i; j < n; j++) {
|
10
11
|
if (numbers[i] > numbers[j]) {
|
11
12
|
int temp = numbers[i];
|
12
13
|
numbers[i] = numbers[j];
|
@@ -19,21 +20,19 @@ vector<int> bubble_sort(vector<int> numbers) {
|
|
19
20
|
|
20
21
|
int main() {
|
21
22
|
vector<int> numbers;
|
22
|
-
int
|
23
|
+
int v;
|
23
24
|
|
24
25
|
// Reading the input
|
25
|
-
cin >>
|
26
|
-
for (int i = 0; i < max; i++) {
|
27
|
-
cin >> v;
|
26
|
+
while (cin >> v)
|
28
27
|
numbers.push_back(v);
|
29
|
-
}
|
30
28
|
|
31
29
|
numbers = bubble_sort(numbers);
|
32
30
|
|
33
31
|
// Printing the output
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
vector<int>::iterator it;
|
33
|
+
for (it = numbers.begin(); it < numbers.end()-1; it++)
|
34
|
+
cout << (*it) << " ";
|
35
|
+
cout << (*it);
|
37
36
|
|
38
37
|
return 0;
|
39
38
|
}
|
@@ -11,11 +11,8 @@ def bubble(numbers)
|
|
11
11
|
numbers
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
input = gets
|
16
|
-
input = input.split(' ')[1..-1].map {|c| c.to_i }
|
14
|
+
input = STDIN.gets.split(" ").collect {|i| i.to_i}
|
17
15
|
|
18
16
|
bubble(input)
|
19
17
|
|
20
|
-
|
21
|
-
puts input.inject {|output, n| "#{output} #{n}"}
|
18
|
+
print input.inject {|output, n| "#{output} #{n}"}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class AlgorithmDouble < Jeka::Algorithm
|
2
|
+
|
3
|
+
add_tests File.join(File.dirname(__FILE__), '_tests', '**', '_test_*.rb')
|
4
|
+
|
5
|
+
implementation 'c++' do |imp|
|
6
|
+
imp.information = {language: 'c++', comment: 'Simple implementation in C++'}
|
7
|
+
imp.compiler = Jeka::Compiler::Gpp.new([File.join(File.dirname(__FILE__), 'cpp', 'double.cpp')], {:o => 'double_cpp'})
|
8
|
+
end
|
9
|
+
|
10
|
+
implementation 'ruby' do |imp|
|
11
|
+
imp.information = {language: 'ruby', comment: 'Simple implementation in Ruby'}
|
12
|
+
imp.compiler = Jeka::Compiler::Ruby.new(File.join(File.dirname(__FILE__), 'ruby', 'double.rb'))
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|