jeka 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,4 +1,4 @@
1
- = Jeka v0.2.1
1
+ = Jeka v0.2.2
2
2
 
3
3
  Jeka is an awesome build/test/benchmarking tool.
4
4
 
@@ -22,7 +22,7 @@ Building a Jeka repository:
22
22
 
23
23
  Running implementations:
24
24
 
25
- $ jeka run -n 5 "your_repository_folder/**/algorithm_*.rb" # it will generate a sqlite3 database named 'analysis.jeka'
25
+ $ jeka run -o analysis.jeka -n 5 "your_repository_folder/**/algorithm_*.rb" # it will generate a sqlite3 database named 'analysis.jeka'
26
26
 
27
27
  == Supported Compilers/Interpreters:
28
28
 
data/TODO CHANGED
@@ -1,7 +1,9 @@
1
- 0.2.2
2
- - helper para analisadores
3
- - mais opções na linha de comando (executar/compilar uma implementação dada)
4
- - mais compiladores
1
+ - improve command line
2
+ - run/build only one implementation/algorithm
5
3
 
6
- 0.2.3
7
- - melhorar desempenho (memoria - nesse momento os modelos do db estao em memoria)
4
+ - add more analysis
5
+ - lines of code
6
+ - density
7
+
8
+ - improve performance
9
+ - memory: currently all the models are loaded in memory
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
data/bin/jeka CHANGED
@@ -17,12 +17,27 @@ run_optparse = OptionParser.new do |opts|
17
17
  opts.on '-n', '--n-repetitions N', Integer, 'Number of repetions' do |n|
18
18
  options[:n] = n
19
19
  end
20
+
21
+ options[:b] = false
22
+ opts.on '-b', '--build', 'Number of repetions' do
23
+ options[:b] = true
24
+ end
25
+
26
+ options[:o] = 'analysis.jeka'
27
+ opts.on '-o', '--output O', 'Number of repetions' do |o|
28
+ options[:o] = o
29
+ end
30
+
20
31
  end
21
32
 
22
33
  build_optparse = OptionParser.new do |opts|
23
34
  opts.banner = "Usage: jeka build [options] file ..."
24
35
  end
25
36
 
37
+ test_optparse = OptionParser.new do |opts|
38
+ opts.banner = "Usage: jeka test [options] file ..."
39
+ end
40
+
26
41
  def cmd(files, options)
27
42
  if not files.length == 1
28
43
  puts "ERROR: invalid number of files..."
@@ -39,15 +54,22 @@ def cmd(files, options)
39
54
  build(options)
40
55
  when :run
41
56
  run(options)
57
+ when :test
58
+ test(options)
42
59
  end
43
60
  end
44
61
 
62
+ def test(options)
63
+ Jeka::Console::test
64
+ end
65
+
45
66
  def build(options)
46
67
  Jeka::Console::build
47
68
  end
48
69
 
49
70
  def run(options)
50
- Jeka::Console::run(options[:n])
71
+ build(options) if options[:b]
72
+ Jeka::Console::run(options[:n], options[:o])
51
73
  end
52
74
 
53
75
  def help()
@@ -64,6 +86,9 @@ begin
64
86
  when "run"
65
87
  options[:command] = :run
66
88
  files = run_optparse.parse!(ARGV[1..-1])
89
+ when "test"
90
+ options[:command] = :test
91
+ files = test_optparse.parse!(ARGV[1..-1])
67
92
  else
68
93
  help()
69
94
  end
data/jeka.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "jeka"
8
- s.version = "0.2.1"
8
+ s.version = "0.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Igor Bonadio"]
12
- s.date = "2011-09-29"
12
+ s.date = "2011-10-08"
13
13
  s.description = "Jeka is an awesome build/test/benchmarking tool"
14
14
  s.email = "igorbonadio@gmail.com"
15
15
  s.executables = ["jeka"]
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
25
25
  "LICENSE.txt",
26
26
  "README.rdoc",
27
27
  "Rakefile",
28
+ "TODO",
28
29
  "VERSION",
29
30
  "bin/jeka",
30
31
  "jeka.gemspec",
@@ -66,6 +67,7 @@ Gem::Specification.new do |s|
66
67
  "test/double/ruby/double.rb",
67
68
  "test/helper.rb",
68
69
  "test/test_algorithm.rb",
70
+ "test/test_console.rb",
69
71
  "test/test_gpp.rb",
70
72
  "test/test_implementation.rb",
71
73
  "test/test_test_case.rb"
@@ -84,6 +86,7 @@ Gem::Specification.new do |s|
84
86
  "test/double/ruby/double.rb",
85
87
  "test/helper.rb",
86
88
  "test/test_algorithm.rb",
89
+ "test/test_console.rb",
87
90
  "test/test_gpp.rb",
88
91
  "test/test_implementation.rb",
89
92
  "test/test_test_case.rb"
@@ -46,7 +46,7 @@ module Jeka
46
46
  end
47
47
  end
48
48
 
49
- def run(n=1, &block)
49
+ def run(n=1, check=false, &block)
50
50
  implementations.each do |imp|
51
51
  test_suites.each do |ts|
52
52
  ts.tests.each do |test|
@@ -54,6 +54,12 @@ module Jeka
54
54
  test_result = imp.compiler.run("#{test.input}\n")
55
55
  block.call(nil, :output, test_result[0]) if block_given?
56
56
  block.call(nil, :error, test_result[1]) if block_given? and (not test_result[2] == 0)
57
+ if block_given? and check
58
+ txt = "#{imp.name} -> #{ts.class}::#{test.name}"
59
+ unless test_result[0].join == test.output
60
+ block.call(0, :test, "#{txt}...failures")
61
+ end
62
+ end
57
63
  Jeka::Analysis::Result.create(
58
64
  stdout: test_result[0].join,
59
65
  stderr: test_result[1].join,
@@ -86,6 +92,22 @@ module Jeka
86
92
  @@algorithms.keys.sort_by { |ts| ts.name }.collect{|ts| ts.new}
87
93
  end
88
94
 
95
+ def self.test_all(&block)
96
+ block.call(0, :step, "Testing algorithms...") if block_given?
97
+ s = self.algorithms.length + 1
98
+ i = 0
99
+ self.algorithms.each do |alg|
100
+ i += 1
101
+ block.call(100*i/s, :step, "Testing #{alg.class.to_s}...") if block_given?
102
+ if block_given?
103
+ alg.run(1, true, &block)
104
+ else
105
+ alg.run(1, true)
106
+ end
107
+ end
108
+ block.call(100, :done, "Done") if block_given?
109
+ end
110
+
89
111
  def self.build_all(&block)
90
112
  block.call(0, :step, "Building algorithms...") if block_given?
91
113
  n = self.algorithms.length + 1
@@ -98,8 +120,8 @@ module Jeka
98
120
  block.call(100, :done, "Done") if block_given?
99
121
  end
100
122
 
101
- def self.run_all(n=1, &block)
102
- Jeka::Analysis::Database.create(File.join(Dir.getwd, "analysis.jeka"))
123
+ def self.run_all(n=1, output="analysis.jeka", &block)
124
+ Jeka::Analysis::Database.create(File.absolute_path(output))
103
125
  block.call(0, :step, "Running algorithms...") if block_given?
104
126
  s = self.algorithms.length + 1
105
127
  i = 0
@@ -3,9 +3,13 @@ module Jeka
3
3
  class Database
4
4
  def self.create(path)
5
5
  DataMapper.finalize
6
- DataMapper.setup(:default, "sqlite://#{path}")
6
+ self.open(path)
7
7
  DataMapper.auto_migrate!
8
8
  end
9
+
10
+ def self.open(path)
11
+ DataMapper.setup(:default, "sqlite://#{path}")
12
+ end
9
13
  end
10
14
  end
11
15
  end
@@ -10,6 +10,20 @@ module Jeka
10
10
  has 1, :compiler
11
11
  has n, :implementation_information
12
12
  has n, :results
13
+
14
+ def method_missing(method, *args)
15
+ if method =~ /^average_/
16
+ r = (/^average_(.*)/.match(method))[1].to_sym
17
+ avg = 0
18
+ i = 0
19
+ self.results.each do |result|
20
+ avg += result.send(r)
21
+ i += 1
22
+ end
23
+ return avg/i
24
+ end
25
+ raise NoMethodError
26
+ end
13
27
  end
14
28
  end
15
29
  end
data/lib/jeka/console.rb CHANGED
@@ -11,9 +11,9 @@ module Jeka
11
11
  ok
12
12
  end
13
13
 
14
- def self.run(n=1)
14
+ def self.run(n=1, output="analysis.jeka")
15
15
  error = false
16
- Jeka::Algorithm.run_all(n) do |p, t, o|
16
+ Jeka::Algorithm.run_all(n, output) do |p, t, o|
17
17
  self._show(p, t, o, false)
18
18
  end
19
19
  end
@@ -25,6 +25,13 @@ module Jeka
25
25
  end
26
26
  end
27
27
 
28
+ def self.test
29
+ error = false
30
+ Jeka::Algorithm.test_all do |p, t, o|
31
+ self._show(p, t, o, false)
32
+ end
33
+ end
34
+
28
35
  def self._show(p, t, o, s)
29
36
  case t
30
37
  when :step
@@ -40,6 +47,8 @@ module Jeka
40
47
  puts o
41
48
  end
42
49
  end
50
+ when :test
51
+ puts " > #{o}"
43
52
  when :error
44
53
  o = o.join
45
54
  if o.length > 0
@@ -0,0 +1,68 @@
1
+ require 'helper'
2
+
3
+ class TestConsole < Test::Unit::TestCase
4
+
5
+ def TestConsole.command(cmd)
6
+ stdout_ = nil
7
+ stderr_ = nil
8
+ exit_status_ = nil
9
+
10
+ Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
11
+ stdout_ = stdout.readlines
12
+ stderr_ = stderr.readlines
13
+ exit_status_ = wait_thr.value
14
+ end
15
+
16
+ return stdout_, stderr_, exit_status_.exitstatus
17
+ end
18
+
19
+ context "jeka run command" do
20
+
21
+ should "shows help" do
22
+ stdout, stderr, exit_status = TestConsole.command("ruby bin/jeka run --help")
23
+ assert_equal "jeka v0.2.1\nUsage: jeka run [options] file ...\n -n, --n-repetitions N Number of repetions\n -b, --build Number of repetions\n -o, --output O Number of repetions\n",
24
+ stdout.join
25
+ assert_equal 0, exit_status
26
+ end
27
+
28
+ should "show help" do
29
+ stdout, stderr, exit_status = TestConsole.command("ruby bin/jeka run -h")
30
+ assert_equal "jeka v0.2.1\nUsage: jeka run [options] file ...\n -n, --n-repetitions N Number of repetions\n -b, --build Number of repetions\n -o, --output O Number of repetions\n",
31
+ stdout.join
32
+ assert_equal 0, exit_status
33
+ end
34
+
35
+ should "run algorithms" do
36
+ stdout, stderr, exit_status = TestConsole.command("ruby bin/jeka build 'test/**/algorithm_*.rb'")
37
+ stdout, stderr, exit_status = TestConsole.command("ruby bin/jeka run 'test/**/algorithm_*.rb'")
38
+ assert_equal "jeka v0.2.1\n[ 0%] Running algorithms...\n[ 33%] Running AlgorithmBubbleSort...\n[ 66%] Running AlgorithmDouble...\n[100%] Done!\n",
39
+ stdout.join
40
+ assert_equal 0, exit_status
41
+ end
42
+
43
+ should "run algorithms 3 times" do
44
+ stdout, stderr, exit_status = TestConsole.command("ruby bin/jeka build 'test/**/algorithm_*.rb'")
45
+ stdout, stderr, exit_status = TestConsole.command("ruby bin/jeka run -n 3 'test/**/algorithm_*.rb'")
46
+ assert_equal "jeka v0.2.1\n[ 0%] Running algorithms...\n[ 33%] Running AlgorithmBubbleSort...\n[ 66%] Running AlgorithmDouble...\n[100%] Done!\n",
47
+ stdout.join
48
+ assert_equal 0, exit_status
49
+ end
50
+
51
+ should "run and build algorithms" do
52
+ stdout, stderr, exit_status = TestConsole.command("ruby bin/jeka run -b 'test/**/algorithm_*.rb'")
53
+ assert_equal "jeka v0.2.1\n[ 0%] Building algorithms...\n[ 33%] Building AlgorithmBubbleSort\n[ 66%] Building AlgorithmDouble\n[100%] Done!\n[ 0%] Running algorithms...\n[ 33%] Running AlgorithmBubbleSort...\n[ 66%] Running AlgorithmDouble...\n[100%] Done!\n",
54
+ stdout.join
55
+ assert_equal 0, exit_status
56
+ end
57
+
58
+ should "run algorithms and create an output file" do
59
+ File.delete("output_teste.jeka") if File.exists?("output_teste.jeka")
60
+ stdout, stderr, exit_status = TestConsole.command("ruby bin/jeka run -b -o output_teste.jeka 'test/**/algorithm_*.rb'")
61
+ assert File.exists?("output_teste.jeka")
62
+ assert_equal 0, exit_status
63
+ File.delete("output_teste.jeka") if File.exists?("output_teste.jeka")
64
+ end
65
+
66
+ end
67
+
68
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jeka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-29 00:00:00.000000000Z
12
+ date: 2011-10-08 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dm-sqlite-adapter
16
- requirement: &70188295884960 !ruby/object:Gem::Requirement
16
+ requirement: &70192081814220 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70188295884960
24
+ version_requirements: *70192081814220
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: data_mapper
27
- requirement: &70188295884480 !ruby/object:Gem::Requirement
27
+ requirement: &70192081813120 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70188295884480
35
+ version_requirements: *70192081813120
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: shoulda
38
- requirement: &70188295884000 !ruby/object:Gem::Requirement
38
+ requirement: &70192081811400 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70188295884000
46
+ version_requirements: *70192081811400
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &70188295883520 !ruby/object:Gem::Requirement
49
+ requirement: &70192081810220 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.0.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70188295883520
57
+ version_requirements: *70192081810220
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: jeweler
60
- requirement: &70188295883040 !ruby/object:Gem::Requirement
60
+ requirement: &70192081809380 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.5.2
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70188295883040
68
+ version_requirements: *70192081809380
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rcov
71
- requirement: &70188295882560 !ruby/object:Gem::Requirement
71
+ requirement: &70192081807700 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70188295882560
79
+ version_requirements: *70192081807700
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: dm-sqlite-adapter
82
- requirement: &70188295882080 !ruby/object:Gem::Requirement
82
+ requirement: &70192081806460 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70188295882080
90
+ version_requirements: *70192081806460
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: data_mapper
93
- requirement: &70188295881600 !ruby/object:Gem::Requirement
93
+ requirement: &70192081805780 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70188295881600
101
+ version_requirements: *70192081805780
102
102
  description: Jeka is an awesome build/test/benchmarking tool
103
103
  email: igorbonadio@gmail.com
104
104
  executables:
@@ -115,6 +115,7 @@ files:
115
115
  - LICENSE.txt
116
116
  - README.rdoc
117
117
  - Rakefile
118
+ - TODO
118
119
  - VERSION
119
120
  - bin/jeka
120
121
  - jeka.gemspec
@@ -156,10 +157,10 @@ files:
156
157
  - test/double/ruby/double.rb
157
158
  - test/helper.rb
158
159
  - test/test_algorithm.rb
160
+ - test/test_console.rb
159
161
  - test/test_gpp.rb
160
162
  - test/test_implementation.rb
161
163
  - test/test_test_case.rb
162
- - TODO
163
164
  homepage: http://github.com/igorbonadio/jeka
164
165
  licenses:
165
166
  - MIT
@@ -175,7 +176,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
175
176
  version: '0'
176
177
  segments:
177
178
  - 0
178
- hash: -3355155901599309883
179
+ hash: -4567337074381682559
179
180
  required_rubygems_version: !ruby/object:Gem::Requirement
180
181
  none: false
181
182
  requirements:
@@ -197,6 +198,7 @@ test_files:
197
198
  - test/double/ruby/double.rb
198
199
  - test/helper.rb
199
200
  - test/test_algorithm.rb
201
+ - test/test_console.rb
200
202
  - test/test_gpp.rb
201
203
  - test/test_implementation.rb
202
204
  - test/test_test_case.rb