viiite 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +70 -0
- data/Gemfile +2 -9
- data/Gemfile.lock +11 -32
- data/README.md +42 -123
- data/examples/bench_attr_vs_method-1.8.7.jpeg +0 -0
- data/examples/bench_attr_vs_method-1.9.3.jpeg +0 -0
- data/examples/bench_attr_vs_method.rb +18 -0
- data/examples/bench_iteration.rb +2 -4
- data/examples/bench_sort.rb +2 -7
- data/lib/viiite.rb +40 -18
- data/lib/viiite/bdb.rb +28 -0
- data/lib/viiite/bdb/cached.rb +63 -0
- data/lib/viiite/bdb/immediate.rb +46 -0
- data/lib/viiite/bdb/utils.rb +16 -0
- data/lib/viiite/benchmark.rb +35 -0
- data/lib/viiite/benchmark/runner.rb +50 -0
- data/lib/viiite/command.rb +33 -2
- data/lib/viiite/command/commons.rb +22 -0
- data/lib/viiite/command/help.rb +4 -5
- data/lib/viiite/command/plot.rb +44 -44
- data/lib/viiite/command/plot/to_gnuplot.rb +65 -0
- data/lib/viiite/command/{graph_style.rash → plot/to_gnuplot_graph.rash} +0 -0
- data/lib/viiite/command/{serie_style.rash → plot/to_gnuplot_serie.rash} +0 -0
- data/lib/viiite/command/plot/to_highcharts.rb +38 -0
- data/lib/viiite/command/plot/to_highcharts_graph.rb +29 -0
- data/lib/viiite/command/plot/to_text.rb +30 -0
- data/lib/viiite/command/report.rb +32 -10
- data/lib/viiite/command/run.rb +30 -7
- data/lib/viiite/errors.rb +5 -0
- data/lib/viiite/loader.rb +2 -2
- data/lib/viiite/tms.rb +21 -31
- data/lib/viiite/version.rb +5 -5
- data/spec/fixtures/bdb/Array/bench_sort.rb +7 -0
- data/spec/fixtures/{bench_iteration.rb → bdb/bench_iteration.rb} +2 -4
- data/spec/fixtures/command/bench_iteration.rb +3 -0
- data/spec/fixtures/saved/Array/bench_sort.rash +12 -0
- data/spec/fixtures/saved/bench_iteration.rash +18 -0
- data/spec/integration/plot/plot_1.cmd +1 -0
- data/spec/integration/plot/plot_1.stdout +64 -0
- data/spec/integration/plot/plot_2.cmd +1 -0
- data/spec/integration/plot/plot_2.stdout +37 -0
- data/spec/integration/plot/plot_3.cmd +1 -0
- data/spec/integration/plot/plot_3.stdout +64 -0
- data/spec/integration/plot/plot_4.cmd +1 -0
- data/spec/integration/plot/plot_4.stdout +1 -0
- data/spec/integration/report/viiite_report_1.cmd +1 -1
- data/spec/integration/report/viiite_report_1.stdout +7 -7
- data/spec/integration/report/viiite_report_2.cmd +1 -1
- data/spec/integration/report/viiite_report_2.stdout +22 -10
- data/spec/integration/report/viiite_report_3.cmd +1 -1
- data/spec/integration/report/viiite_report_3.stdout +46 -18
- data/spec/integration/report/viiite_report_4.cmd +1 -1
- data/spec/integration/report/viiite_report_4.stdout +34 -22
- data/spec/integration/report/viiite_report_5.cmd +1 -0
- data/spec/integration/report/viiite_report_5.stdout +7 -0
- data/spec/integration/report/viiite_report_6.cmd +1 -0
- data/spec/integration/report/viiite_report_6.stdout +7 -0
- data/spec/integration/report/viiite_report_7.cmd +1 -0
- data/spec/integration/report/viiite_report_7.stdout +7 -0
- data/spec/integration/report/viiite_report_8.cmd +1 -0
- data/spec/integration/report/viiite_report_8.stdout +16 -0
- data/spec/integration/report/viiite_report_9.cmd +1 -0
- data/spec/integration/report/viiite_report_9.stdout +88 -0
- data/spec/integration/test_command.rb +19 -23
- data/spec/integration/viiite/viiite_help.stdout +6 -0
- data/spec/spec_helper.rb +11 -17
- data/spec/unit/bdb/cached/test_dataset.rb +68 -0
- data/spec/unit/bdb/immediate/test_benchmark.rb +31 -0
- data/spec/unit/bdb/immediate/test_dataset.rb +31 -0
- data/spec/unit/bdb/immediate/test_enumerable.rb +20 -0
- data/spec/unit/bdb/immediate/test_pattern.rb +25 -0
- data/spec/unit/bdb/test_new.rb +44 -0
- data/spec/unit/bdb/utils/test_bench_file.rb +24 -0
- data/spec/unit/bdb/utils/test_replace_extension.rb +21 -0
- data/spec/unit/benchmark/bench_add.rb +3 -0
- data/spec/unit/benchmark/test_new.rb +28 -0
- data/spec/unit/command/commons/existing.rash +1 -0
- data/spec/unit/command/commons/test_single_source.rb +64 -0
- data/spec/unit/{formatter/plot → command/plot/gnuplot_utils}/test_to_data.rb +4 -4
- data/spec/unit/{formatter/plot → command/plot/gnuplot_utils}/test_to_dataset.rb +5 -5
- data/spec/unit/{formatter/plot → command/plot/gnuplot_utils}/test_to_plot.rb +4 -4
- data/spec/unit/command/test_run.rb +25 -12
- data/spec/unit/{test_runner.rb → test_benchmark.rb} +30 -11
- data/spec/unit/test_viiite.rb +17 -4
- data/spec/unit/tms/test_attributes.rb +11 -0
- data/spec/unit/tms/test_coerce.rb +11 -23
- data/spec/unit/tms/test_conversions.rb +23 -0
- data/spec/unit/tms/test_operations.rb +22 -0
- data/tasks/clean.rake +1 -1
- data/tasks/debug_mail.rake +13 -13
- data/tasks/gem.rake +13 -13
- data/tasks/integration_test.rake +3 -3
- data/tasks/spec_test.rake +9 -9
- data/tasks/unit_test.rake +9 -10
- data/tasks/yard.rake +13 -13
- data/viiite.gemspec +26 -29
- data/viiite.noespec +4 -7
- metadata +335 -235
- data/examples/bench_sort.eps +0 -816
- data/examples/bench_sort.rash +0 -100
- data/examples/raw.rash +0 -6
- data/lib/viiite/formatter.rb +0 -5
- data/lib/viiite/formatter/plot.rb +0 -38
- data/lib/viiite/runner.rb +0 -59
- data/lib/viiite/viiite_file.rb +0 -20
- data/spec/integration/raw_data.rash +0 -6
- data/spec/unit/tms/test_divide.rb +0 -26
- data/spec/unit/tms/test_minus.rb +0 -26
- data/spec/unit/tms/test_plus.rb +0 -34
- data/spec/unit/tms/test_times.rb +0 -26
- data/spec/unit/tms/test_to_a.rb +0 -11
- data/spec/unit/tms/test_to_ruby_literal.rb +0 -11
- data/spec/unit/tms/test_to_s.rb +0 -11
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Viiite
|
3
|
+
class BDB
|
4
|
+
describe Utils, ".replace_extension" do
|
5
|
+
|
6
|
+
let(:utils){ Object.new.extend(Utils) }
|
7
|
+
subject{ utils.replace_extension(file, ".ext") }
|
8
|
+
|
9
|
+
describe "on a file without extension" do
|
10
|
+
let(:file){ "hello/world" }
|
11
|
+
it{ should eq("hello/world.ext") }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "on a file with extension" do
|
15
|
+
let(:file){ "hello/world.rb" }
|
16
|
+
it{ should eq("hello/world.ext") }
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Viiite
|
3
|
+
describe Benchmark, '.new' do
|
4
|
+
|
5
|
+
subject{ Benchmark.new(arg) }
|
6
|
+
|
7
|
+
after{
|
8
|
+
subject.to_a.size.should eq(1)
|
9
|
+
subject.to_a.first.keys.sort_by(&:to_s).should eq([:bench, :tms])
|
10
|
+
}
|
11
|
+
|
12
|
+
describe 'with a Proc' do
|
13
|
+
let(:arg){ lambda{|b| b.report(:add){ 1+1 } } }
|
14
|
+
it{ should be_a(Benchmark) }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'with an existing file' do
|
18
|
+
let(:arg){ File.expand_path('../bench_add.rb', __FILE__) }
|
19
|
+
it{ should be_a(Benchmark) }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'with an IO' do
|
23
|
+
let(:arg){ File.open(File.expand_path('../bench_add.rb', __FILE__), 'r') }
|
24
|
+
it{ should be_a(Benchmark) }
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{:name => "existing"}
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Viiite
|
3
|
+
class Command
|
4
|
+
describe Commons, "#single_source" do
|
5
|
+
|
6
|
+
let(:commons){
|
7
|
+
Object.new.extend(Commons).
|
8
|
+
extend(Module.new{
|
9
|
+
attr_accessor :requester
|
10
|
+
})
|
11
|
+
}
|
12
|
+
subject{ commons.single_source(argv) }
|
13
|
+
|
14
|
+
describe "with an empty argv" do
|
15
|
+
let(:argv){ [] }
|
16
|
+
it{ should be_a(Alf::Reader) }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "with an argv with more than one arg" do
|
20
|
+
let(:argv){ [1, 2, 3] }
|
21
|
+
specify{
|
22
|
+
lambda{subject}.should raise_error(Quickl::InvalidArgument)
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "with a argv with one existing file" do
|
27
|
+
let(:argv){ [ File.expand_path("../existing.rash", __FILE__) ] }
|
28
|
+
it{ should be_a(Alf::Reader) }
|
29
|
+
specify{
|
30
|
+
subject.to_a.should eq([{:name => 'existing'}])
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "with a argv with a benchmark name but no requester" do
|
35
|
+
let(:argv){ [ :hello ] }
|
36
|
+
specify{
|
37
|
+
lambda{subject}.should raise_error(Quickl::InvalidArgument)
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'with a argv and a requester' do
|
42
|
+
let(:argv){ [ :hello ] }
|
43
|
+
let(:requester){
|
44
|
+
Object.new.extend Module.new{
|
45
|
+
def bdb; self; end
|
46
|
+
def dataset(name); name.to_s.upcase; end
|
47
|
+
}
|
48
|
+
}
|
49
|
+
before{ commons.requester = requester }
|
50
|
+
describe "with a block" do
|
51
|
+
subject{
|
52
|
+
commons.single_source(argv){|*args| args}
|
53
|
+
}
|
54
|
+
it{ should eq([requester, :hello]) }
|
55
|
+
end
|
56
|
+
describe "without block" do
|
57
|
+
it{ should eq("HELLO") }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
module Viiite
|
3
|
-
class
|
4
|
-
describe "to_data" do
|
3
|
+
class Command::Plot
|
4
|
+
describe GnuplotUtils, "#to_data" do
|
5
5
|
|
6
6
|
let(:data) { [ {:x => 1, :y => 10}, {:x => 2, :y => 20} ] }
|
7
7
|
|
8
|
-
subject{
|
8
|
+
subject{ GnuplotUtils.to_data(data) }
|
9
9
|
|
10
10
|
it "should return the expected array" do
|
11
11
|
subject.should == [ [1,2], [10,20] ]
|
12
12
|
end
|
13
13
|
|
14
14
|
end
|
15
|
-
end
|
15
|
+
end
|
16
16
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
module Viiite
|
3
|
-
class
|
4
|
-
describe "to_dataset" do
|
3
|
+
class Command::Plot
|
4
|
+
describe GnuplotUtils, "#to_dataset" do
|
5
5
|
|
6
6
|
let(:tuple) {
|
7
|
-
{:title => "serie",
|
7
|
+
{:title => "serie",
|
8
8
|
:linewidth => 4,
|
9
9
|
:data => [ {:x => 1, :y => 10}, {:x => 2, :y => 20} ] }
|
10
10
|
}
|
11
|
-
subject{
|
11
|
+
subject{ GnuplotUtils.to_dataset(tuple) }
|
12
12
|
|
13
13
|
it "should return a correct dataset instance" do
|
14
14
|
subject.should be_a(Gnuplot::DataSet)
|
@@ -18,5 +18,5 @@ module Viiite
|
|
18
18
|
end
|
19
19
|
|
20
20
|
end
|
21
|
-
end
|
21
|
+
end
|
22
22
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
module Viiite
|
3
|
-
class
|
4
|
-
describe "to_plot" do
|
3
|
+
class Command::Plot
|
4
|
+
describe GnuplotUtils, "#to_plot" do
|
5
5
|
|
6
6
|
let(:data) { [ {:x => 1, :y => 10}, {:x => 2, :y => 20} ] }
|
7
7
|
|
@@ -9,7 +9,7 @@ module Viiite
|
|
9
9
|
|
10
10
|
let(:plot) { {:title => "plot", :series => [ dataset ] } }
|
11
11
|
|
12
|
-
subject{
|
12
|
+
subject{ GnuplotUtils.to_plot(plot) }
|
13
13
|
|
14
14
|
it "should return a correct plot instance" do
|
15
15
|
subject.is_a?(Gnuplot::Plot).should be_true
|
@@ -17,5 +17,5 @@ module Viiite
|
|
17
17
|
end
|
18
18
|
|
19
19
|
end
|
20
|
-
end
|
20
|
+
end
|
21
21
|
end
|
@@ -3,21 +3,34 @@ module Viiite
|
|
3
3
|
class Command
|
4
4
|
describe Run do
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
let(:bench_iteration){ fixtures_folder+'/command/bench_iteration.rb' }
|
7
|
+
subject{
|
8
|
+
out, err = capture_io { Run.run(argv) }
|
9
|
+
rel = Alf::Reader.reader(StringIO.new(out)).to_rel
|
10
|
+
rel = rel.project([:tms], {:allbut => true})
|
11
|
+
}
|
10
12
|
|
11
13
|
describe "when passed a benchmark file" do
|
12
|
-
let(:argv){ [bench_iteration] }
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
let(:argv){ [ bench_iteration ] }
|
15
|
+
it{ should eq(Alf::Relation[{:bench => :times}]) }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "with --runs" do
|
19
|
+
let(:argv){ [ bench_iteration, "--runs=2" ] }
|
20
|
+
let(:expected){
|
21
|
+
Alf::Relation[{:bench => :times, :run => 0},
|
22
|
+
{:bench => :times, :run => 1}]
|
23
|
+
}
|
24
|
+
it{ should eq(expected) }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "with --runs and --run-key" do
|
28
|
+
let(:argv){ [ bench_iteration, "--runs=2", "--run-key=hello" ] }
|
29
|
+
let(:expected){
|
30
|
+
Alf::Relation[{:bench => :times, :hello => 0},
|
31
|
+
{:bench => :times, :hello => 1}]
|
20
32
|
}
|
33
|
+
it{ should eq(expected) }
|
21
34
|
end
|
22
35
|
|
23
36
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
module Viiite
|
3
|
-
describe
|
4
|
-
|
5
|
-
it "should be definable with Viiite.
|
6
|
-
b = Viiite.
|
3
|
+
describe Benchmark do
|
4
|
+
|
5
|
+
it "should be definable with Viiite.bench" do
|
6
|
+
b = Viiite.bench do |viiite|
|
7
7
|
viiite.report{ 1 + 1 }
|
8
8
|
end
|
9
|
-
b.should be_kind_of(Viiite::
|
9
|
+
b.should be_kind_of(Viiite::Benchmark)
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should be executable" do
|
13
|
-
b = Viiite.
|
13
|
+
b = Viiite.bench do |viiite|
|
14
14
|
viiite.report{ 1 + 1 }
|
15
15
|
end
|
16
16
|
res = []
|
@@ -24,7 +24,7 @@ module Viiite
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should be enumerable" do
|
27
|
-
b = Viiite.
|
27
|
+
b = Viiite.bench do |viiite|
|
28
28
|
viiite.report{ 1 + 1 }
|
29
29
|
end
|
30
30
|
res = b.to_a
|
@@ -32,10 +32,10 @@ module Viiite
|
|
32
32
|
res.size.should == 1
|
33
33
|
res.first[:tms].should be_kind_of(Viiite::Tms)
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
it "should support variation points" do
|
37
|
-
b = Viiite.
|
38
|
-
2.times do |i|
|
37
|
+
b = Viiite.bench do |viiite|
|
38
|
+
2.times do |i|
|
39
39
|
viiite.variation_point(:"#run", i)
|
40
40
|
viiite.report do end
|
41
41
|
end
|
@@ -45,7 +45,7 @@ module Viiite
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should support ranging over values" do
|
48
|
-
b = Viiite.
|
48
|
+
b = Viiite.bench do |viiite|
|
49
49
|
viiite.range_over [10, 100, 1000], :times do |t|
|
50
50
|
viiite.report do end
|
51
51
|
end
|
@@ -53,5 +53,24 @@ module Viiite
|
|
53
53
|
b.to_a.collect{|t| t[:times]}.should == [10, 100, 1000]
|
54
54
|
end
|
55
55
|
|
56
|
+
it "should support nested #with, #variation_point and #range_over" do
|
57
|
+
Viiite.bench do |r|
|
58
|
+
r.variation_point :all, true
|
59
|
+
r.variation_point(:ruby, :ruby) do
|
60
|
+
r.variation_point :for_bench1, true
|
61
|
+
r.range_over(1..2, :i) do
|
62
|
+
r.report(:bench1) {}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
r.with(:a => :b) do
|
66
|
+
r.report(:bench2) {}
|
67
|
+
end
|
68
|
+
end.to_rel.project([:tms], {:allbut => true}).should == Alf::Relation[
|
69
|
+
{:all => true, :ruby => :ruby, :for_bench1 => true, :i => 1, :bench => :bench1},
|
70
|
+
{:all => true, :ruby => :ruby, :for_bench1 => true, :i => 2, :bench => :bench1},
|
71
|
+
{:all => true, :a => :b, :bench => :bench2}
|
72
|
+
]
|
73
|
+
end
|
74
|
+
|
56
75
|
end
|
57
76
|
end
|
data/spec/unit/test_viiite.rb
CHANGED
@@ -1,12 +1,25 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
describe Viiite do
|
3
|
-
|
3
|
+
|
4
4
|
it "should have a version number" do
|
5
5
|
Viiite.const_defined?(:VERSION).should be_true
|
6
6
|
end
|
7
7
|
|
8
|
-
it "should provide a way to have short ruby
|
9
|
-
|
8
|
+
it "should provide a way to have a short ruby description" do
|
9
|
+
{
|
10
|
+
'ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux]' => 'ruby 1.8.7p334',
|
11
|
+
'ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]' => 'ruby 1.8.7p352',
|
12
|
+
'ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2011.03' => 'ree 2011.03',
|
13
|
+
'ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]' => 'ruby 1.9.2p290',
|
14
|
+
'ruby 1.9.3dev (2011-07-31 revision 32789) [x86_64-linux]' => 'ruby 1.9.3dev',
|
15
|
+
'ruby 1.9.4dev (2011-08-24 trunk 33047) [x86_64-linux]' => 'ruby 1.9.4dev',
|
16
|
+
'rubinius 1.2.5dev (1.8.7 489d5384 yyyy-mm-dd JI) [x86_64-unknown-linux-gnu]' => 'rubinius 1.2.5dev',
|
17
|
+
'rubinius 2.0.0dev (1.8.7 d705d318 yyyy-mm-dd JI) [x86_64-unknown-linux-gnu]' => 'rubinius 2.0.0dev',
|
18
|
+
'jruby 1.6.3 (ruby-1.8.7-p330) (2011-07-07 965162f) (OpenJDK 64-Bit Server VM 1.6.0_22) [linux-amd64-java]' => 'jruby 1.6.3',
|
19
|
+
'jruby 1.7.0.dev (ruby-1.8.7-p330) (2011-08-24 7b9f999) (OpenJDK 64-Bit Server VM 1.6.0_22) [linux-amd64-java]' => 'jruby 1.7.0.dev',
|
20
|
+
}.each_pair { |description, short|
|
21
|
+
Viiite.short_ruby_description(description).should == short
|
22
|
+
}
|
10
23
|
end
|
11
|
-
|
24
|
+
|
12
25
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Viiite
|
3
|
+
describe Tms, "#attributes" do
|
4
|
+
subject { Tms.new(1.0, 2.0, 3.0, 4.0, 5.0) }
|
5
|
+
its(:utime) { should eq 1.0 }
|
6
|
+
its(:stime) { should eq 2.0 }
|
7
|
+
its(:cutime) { should eq 3.0 }
|
8
|
+
its(:cstime) { should eq 4.0 }
|
9
|
+
its(:real) { should eq 5.0 }
|
10
|
+
end
|
11
|
+
end
|
@@ -6,40 +6,28 @@ module Viiite
|
|
6
6
|
|
7
7
|
describe "from zero" do
|
8
8
|
let(:arg){ 0.0 }
|
9
|
-
|
10
|
-
subject.should be_a(Tms)
|
11
|
-
subject.to_a.should eq([0.0, 0.0, 0.0, 0.0, 0.0])
|
12
|
-
}
|
9
|
+
it { should eq Tms[0.0, 0.0, 0.0, 0.0, 0.0] }
|
13
10
|
end
|
14
11
|
|
15
12
|
describe "from one" do
|
16
13
|
let(:arg){ 1.0 }
|
17
|
-
|
18
|
-
subject.should be_a(Tms)
|
19
|
-
subject.to_a.should eq([1.0, 0.0, 0.0, 0.0, 0.0])
|
20
|
-
}
|
14
|
+
it { should eq Tms[1.0, 0.0, 0.0, 0.0, 0.0] }
|
21
15
|
end
|
22
16
|
|
23
17
|
describe "from a complete hash" do
|
24
18
|
let(:arg){ {
|
25
|
-
:utime => 1.0,
|
26
|
-
:stime => 2.0,
|
27
|
-
:cutime => 3.0,
|
28
|
-
:cstime => 4.0,
|
29
|
-
:real => 5.0,
|
30
|
-
} }
|
31
|
-
|
32
|
-
subject.should be_a(Tms)
|
33
|
-
subject.to_a.should eq([1.0, 2.0, 3.0, 4.0, 5.0])
|
34
|
-
}
|
19
|
+
:utime => 1.0,
|
20
|
+
:stime => 2.0,
|
21
|
+
:cutime => 3.0,
|
22
|
+
:cstime => 4.0,
|
23
|
+
:real => 5.0,
|
24
|
+
} }
|
25
|
+
it { should eq Tms[1.0, 2.0, 3.0, 4.0, 5.0] }
|
35
26
|
end
|
36
27
|
|
37
28
|
describe "from an array" do
|
38
|
-
let(:arg){ [1.0, 2.0, 3.0, 4.0, 5.0] }
|
39
|
-
|
40
|
-
subject.should be_a(Tms)
|
41
|
-
subject.to_a.should eq([1.0, 2.0, 3.0, 4.0, 5.0])
|
42
|
-
}
|
29
|
+
let(:arg){ [1.0, 2.0, 3.0, 4.0, 5.0] }
|
30
|
+
it { should eq Tms[1.0, 2.0, 3.0, 4.0, 5.0] }
|
43
31
|
end
|
44
32
|
|
45
33
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Viiite
|
3
|
+
describe Tms, "conversions" do
|
4
|
+
|
5
|
+
let(:tms) { Tms.new(1.0, 2.0, 3.0, 4.0, 5.0) }
|
6
|
+
|
7
|
+
specify '#to_s' do
|
8
|
+
tms.to_s.should eq " 1.000000 2.000000 10.000000 ( 5.000000)"
|
9
|
+
end
|
10
|
+
|
11
|
+
specify '#to_a' do
|
12
|
+
tms.to_a.should eq [1.0, 2.0, 3.0, 4.0, 5.0]
|
13
|
+
end
|
14
|
+
|
15
|
+
specify '#to_h' do
|
16
|
+
tms.to_h.should eq :utime=>1.0, :stime=>2.0, :cutime=>3.0, :cstime=>4.0, :real=>5.0
|
17
|
+
end
|
18
|
+
|
19
|
+
specify '#to_ruby_literal' do
|
20
|
+
eval(tms.to_ruby_literal).should eq tms
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Viiite
|
3
|
+
describe Tms, "operations: +,-,*,/" do
|
4
|
+
|
5
|
+
let(:tms){ Tms.new(1.0, 2.0, 3.0, 4.0, 5.0) }
|
6
|
+
|
7
|
+
specify "with an integer" do
|
8
|
+
(tms + 2).should eq Tms[3.0, 4.0, 5.0, 6.0, 7.0]
|
9
|
+
(tms / 2).should eq Tms[0.5, 1.0, 1.5, 2.0, 2.5]
|
10
|
+
end
|
11
|
+
|
12
|
+
specify "with another tms" do
|
13
|
+
(tms - tms).should eq Tms[0.0, 0.0, 0.0, 0.0, 0.0]
|
14
|
+
(tms / tms).should eq Tms[1.0, 1.0, 1.0, 1.0, 1.0]
|
15
|
+
end
|
16
|
+
|
17
|
+
specify "the other way round" do
|
18
|
+
(2 + tms).should eq Tms[3.0, 4.0, 5.0, 6.0, 7.0]
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|