jeka 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. data/Gemfile +4 -0
  2. data/Gemfile.lock +55 -2
  3. data/README.rdoc +6 -14
  4. data/VERSION +1 -1
  5. data/bin/jeka +64 -94
  6. data/jeka.gemspec +56 -28
  7. data/lib/jeka.rb +6 -4
  8. data/lib/jeka/algorithm.rb +106 -24
  9. data/lib/jeka/analysis.rb +15 -0
  10. data/lib/jeka/analysis/algorithm.rb +13 -0
  11. data/lib/jeka/analysis/compiler.rb +14 -0
  12. data/lib/jeka/analysis/compiler_option.rb +24 -0
  13. data/lib/jeka/analysis/database.rb +11 -0
  14. data/lib/jeka/analysis/implementation.rb +15 -0
  15. data/lib/jeka/analysis/implementation_information.rb +24 -0
  16. data/lib/jeka/analysis/result.rb +20 -0
  17. data/lib/jeka/analysis/source_file.rb +24 -0
  18. data/lib/jeka/analysis/test.rb +15 -0
  19. data/lib/jeka/analysis/test_case.rb +13 -0
  20. data/lib/jeka/compilers.rb +3 -0
  21. data/lib/jeka/compilers/compiler.rb +48 -0
  22. data/lib/jeka/compilers/gpp.rb +29 -0
  23. data/lib/jeka/compilers/ruby.rb +21 -0
  24. data/lib/jeka/console.rb +55 -0
  25. data/lib/jeka/implementation.rb +22 -97
  26. data/lib/jeka/test.rb +15 -31
  27. data/lib/jeka/test_case.rb +41 -0
  28. data/test/bubble_sort/_tests/_test_01.rb +13 -0
  29. data/test/bubble_sort/algorithm_bubble_sort.rb +15 -0
  30. data/test/bubble_sort/cpp/_implementation.yaml +3 -0
  31. data/test/{example/01_bubble_sort/cpp/bubble.cpp → bubble_sort/cpp/bubble_sort.cpp} +9 -10
  32. data/test/bubble_sort/ruby/_implementation.yaml +3 -0
  33. data/test/{example/01_bubble_sort/ruby/bubble.rb → bubble_sort/ruby/bubble_sort.rb} +2 -5
  34. data/test/double/_tests/_test_01.rb +13 -0
  35. data/test/double/algorithm_double.rb +15 -0
  36. data/test/double/cpp/double.cpp +10 -0
  37. data/test/double/ruby/double.rb +2 -0
  38. data/test/test_algorithm.rb +25 -11
  39. data/test/test_gpp.rb +29 -0
  40. data/test/test_implementation.rb +25 -10
  41. data/test/test_test_case.rb +21 -0
  42. metadata +94 -52
  43. data/lib/jeka/jeka_helper.rb +0 -16
  44. data/lib/jeka/make.rb +0 -103
  45. data/test/example/01_bubble_sort/_algorithm.yaml +0 -12
  46. data/test/example/01_bubble_sort/_description.textile +0 -1
  47. data/test/example/01_bubble_sort/_references.textile +0 -1
  48. data/test/example/01_bubble_sort/_tests/test_01.yaml +0 -3
  49. data/test/example/01_bubble_sort/_tests/test_02.yaml +0 -3
  50. data/test/example/01_bubble_sort/cpp/_implementation.yaml +0 -9
  51. data/test/example/01_bubble_sort/ruby/_implementation.yaml +0 -6
  52. data/test/site/algorithm.textile +0 -27
  53. data/test/site/cpp.textile +0 -46
  54. data/test/site/ruby.textile +0 -28
  55. data/test/test_make.rb +0 -34
  56. 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
@@ -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
@@ -1,111 +1,36 @@
1
1
  require 'yaml'
2
- require 'benchmark'
3
2
 
4
3
  module Jeka
5
-
6
- class Implementation < JekaHelper
7
-
8
- jeka_reader :language
9
- jeka_reader :source
10
- jeka_reader :comment
11
-
12
- attr_accessor :algorithm
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 build
24
- if @jeka["build"]
25
- command = @jeka["build"]["command"].gsub("$", @folder)
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
- out = ""
36
- IO.popen(command) do |io|
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 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
23
+ def information
24
+ @information
71
25
  end
72
26
 
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
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
- class Test < JekaHelper
2
+ class Test
3
+ attr_reader :database
4
+ attr_accessor :input
5
+ attr_accessor :output
6
+ attr_accessor :name
6
7
 
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
8
+ def initialize(name)
9
+ @name = name
15
10
  end
16
11
 
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
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
@@ -0,0 +1,3 @@
1
+ language: c++
2
+ source: bubble_sort.cpp
3
+ comment: Simple implementation in C++
@@ -5,8 +5,9 @@
5
5
  using namespace std;
6
6
 
7
7
  vector<int> bubble_sort(vector<int> numbers) {
8
- for(int i = 0; i < 9; i++) {
9
- for(int j = i; j < 9; j++) {
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 max, v;
23
+ int v;
23
24
 
24
25
  // Reading the input
25
- cin >> max;
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
- for (int i=0; i< 8; i++)
35
- cout << numbers[i] << " ";
36
- cout << numbers[8] << endl;
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
  }
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ source: bubble_sort.rb
3
+ comment: Simple implementation in Ruby
@@ -11,11 +11,8 @@ def bubble(numbers)
11
11
  numbers
12
12
  end
13
13
 
14
- # Reading the input
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
- # Printing the output
21
- puts input.inject {|output, n| "#{output} #{n}"}
18
+ print input.inject {|output, n| "#{output} #{n}"}
@@ -0,0 +1,13 @@
1
+ class TestAlgorithmDouble < Jeka::TestCase
2
+
3
+ test 'One' do |t|
4
+ t.input = '1'
5
+ t.output = '2'
6
+ end
7
+
8
+ test 'Two' do |t|
9
+ t.input = '2'
10
+ t.output = '4'
11
+ end
12
+
13
+ end
@@ -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
@@ -0,0 +1,10 @@
1
+ #include <iostream>
2
+
3
+ using namespace std;
4
+
5
+ int main() {
6
+ int n;
7
+ cin >> n;
8
+ cout << 2*n;
9
+ return 0;
10
+ }