viiite 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/Gemfile +25 -0
- data/Gemfile.lock +55 -0
- data/LICENCE.md +22 -0
- data/Manifest.txt +15 -0
- data/README.md +204 -0
- data/Rakefile +23 -0
- data/bin/viiite +4 -0
- data/examples/bench_iteration.rb +9 -0
- data/examples/bench_sort.eps +816 -0
- data/examples/bench_sort.rash +100 -0
- data/examples/bench_sort.rb +38 -0
- data/examples/raw.rash +6 -0
- data/lib/viiite/command/graph_style.rash +1 -0
- data/lib/viiite/command/help.rb +24 -0
- data/lib/viiite/command/plot.rb +88 -0
- data/lib/viiite/command/report.rb +47 -0
- data/lib/viiite/command/run.rb +23 -0
- data/lib/viiite/command/serie_style.rash +1 -0
- data/lib/viiite/command.rb +45 -0
- data/lib/viiite/formatter/plot.rb +38 -0
- data/lib/viiite/formatter.rb +5 -0
- data/lib/viiite/loader.rb +3 -0
- data/lib/viiite/runner.rb +59 -0
- data/lib/viiite/tms.rb +89 -0
- data/lib/viiite/version.rb +14 -0
- data/lib/viiite/viiite_file.rb +20 -0
- data/lib/viiite.rb +56 -0
- data/spec/fixtures/bench_iteration.rb +9 -0
- data/spec/integration/raw_data.rash +6 -0
- data/spec/integration/report/viiite_report_1.cmd +1 -0
- data/spec/integration/report/viiite_report_1.stdout +7 -0
- data/spec/integration/report/viiite_report_2.cmd +1 -0
- data/spec/integration/report/viiite_report_2.stdout +10 -0
- data/spec/integration/report/viiite_report_3.cmd +1 -0
- data/spec/integration/report/viiite_report_3.stdout +18 -0
- data/spec/integration/report/viiite_report_4.cmd +1 -0
- data/spec/integration/report/viiite_report_4.stdout +22 -0
- data/spec/integration/test_command.rb +33 -0
- data/spec/integration/viiite/viiite_help.cmd +1 -0
- data/spec/integration/viiite/viiite_help.stdout +25 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/unit/command/test_run.rb +25 -0
- data/spec/unit/formatter/plot/test_to_data.rb +16 -0
- data/spec/unit/formatter/plot/test_to_dataset.rb +22 -0
- data/spec/unit/formatter/plot/test_to_plot.rb +21 -0
- data/spec/unit/test_runner.rb +57 -0
- data/spec/unit/test_viiite.rb +12 -0
- data/spec/unit/tms/test_coerce.rb +46 -0
- data/spec/unit/tms/test_divide.rb +26 -0
- data/spec/unit/tms/test_minus.rb +26 -0
- data/spec/unit/tms/test_plus.rb +34 -0
- data/spec/unit/tms/test_times.rb +26 -0
- data/spec/unit/tms/test_to_a.rb +11 -0
- data/spec/unit/tms/test_to_ruby_literal.rb +11 -0
- data/spec/unit/tms/test_to_s.rb +11 -0
- data/tasks/clean.rake +3 -0
- data/tasks/debug_mail.rake +78 -0
- data/tasks/debug_mail.txt +13 -0
- data/tasks/gem.rake +68 -0
- data/tasks/integration_test.rake +51 -0
- data/tasks/spec_test.rake +79 -0
- data/tasks/unit_test.rake +77 -0
- data/tasks/yard.rake +51 -0
- data/viiite.gemspec +192 -0
- data/viiite.noespec +40 -0
- metadata +297 -0
data/lib/viiite.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require "viiite/version"
|
2
|
+
require "viiite/loader"
|
3
|
+
require "viiite/tms"
|
4
|
+
require "viiite/formatter"
|
5
|
+
require "viiite/runner"
|
6
|
+
require "viiite/command"
|
7
|
+
require "viiite/viiite_file"
|
8
|
+
require "benchmark"
|
9
|
+
|
10
|
+
#
|
11
|
+
# Benchmarking and complexity analyzer utility
|
12
|
+
#
|
13
|
+
module Viiite
|
14
|
+
|
15
|
+
# Builds a Tms object
|
16
|
+
def self.Tms(*args)
|
17
|
+
Viiite::Tms.coerce(args)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.measure(&block)
|
21
|
+
Viiite::Tms.coerce Benchmark.measure(&block)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Builds a runner instance via the DSL definition given by the block.
|
25
|
+
#
|
26
|
+
# Example
|
27
|
+
#
|
28
|
+
# Viiite.runner do |b|
|
29
|
+
# b.variation_point :ruby_version, Viiite.which_ruby
|
30
|
+
# b.range_over([100, 1000, 10000, 100000], :runs) do |runs|
|
31
|
+
# b.variation_point :test, :via_reader do
|
32
|
+
# b.report{ runs.times{ foo.via_reader } }
|
33
|
+
# end
|
34
|
+
# b.variation_point :test, :via_method do
|
35
|
+
# b.report{ runs.times{ foo.via_method } }
|
36
|
+
# end
|
37
|
+
# end
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
def self.bm(&block)
|
41
|
+
Runner.new(block)
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# Returns a short string with a ruby interpreter description
|
46
|
+
#
|
47
|
+
def self.which_ruby
|
48
|
+
if Object.const_defined?(:RUBY_DESCRIPTION)
|
49
|
+
RUBY_DESCRIPTION =~ /^([^\s]+\s*[^\s]+)/
|
50
|
+
$1
|
51
|
+
else
|
52
|
+
"ruby #{RUBY_VERSION} (#{RUBY_PLATFORM})"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end # module Viiite
|
@@ -0,0 +1,6 @@
|
|
1
|
+
{:bench => :for, :ruby => "ruby 1.8.7", :tms => Viiite::Tms(0.01,0.0,0.0,0.0,0.0111169815063477)}
|
2
|
+
{:bench => :times, :ruby => "ruby 1.8.7", :tms => Viiite::Tms(0.01,0.0,0.0,0.0,0.00408315658569336)}
|
3
|
+
{:bench => :upto, :ruby => "ruby 1.8.7", :tms => Viiite::Tms(0.0,0.0,0.0,0.0,0.00950002670288086)}
|
4
|
+
{:ruby => "ruby 1.9.2p136", :bench => :for, :tms => Viiite::Tms(0.010000000000000009,0.0,0.0,0.0,0.0076122283935546875)}
|
5
|
+
{:ruby => "ruby 1.9.2p136", :bench => :times, :tms => Viiite::Tms(0.010000000000000009,0.0,0.0,0.0,0.006944417953491211)}
|
6
|
+
{:ruby => "ruby 1.9.2p136", :bench => :upto, :tms => Viiite::Tms(0.0,0.0,0.0,0.0,0.003862142562866211)}
|
@@ -0,0 +1 @@
|
|
1
|
+
viiite report raw_data
|
@@ -0,0 +1,7 @@
|
|
1
|
+
+--------+-----------------------------------------------+
|
2
|
+
| :bench | :measure |
|
3
|
+
+--------+-----------------------------------------------+
|
4
|
+
| :for | 0.010000 0.000000 0.010000 ( 0.009365) |
|
5
|
+
| :times | 0.010000 0.000000 0.010000 ( 0.005514) |
|
6
|
+
| :upto | 0.000000 0.000000 0.000000 ( 0.006681) |
|
7
|
+
+--------+-----------------------------------------------+
|
@@ -0,0 +1 @@
|
|
1
|
+
viiite report raw_data --regroup=ruby,bench
|
@@ -0,0 +1,10 @@
|
|
1
|
+
+----------------+--------+-----------------------------------------------+
|
2
|
+
| :ruby | :bench | :measure |
|
3
|
+
+----------------+--------+-----------------------------------------------+
|
4
|
+
| ruby 1.8.7 | :for | 0.010000 0.000000 0.010000 ( 0.011117) |
|
5
|
+
| ruby 1.8.7 | :times | 0.010000 0.000000 0.010000 ( 0.004083) |
|
6
|
+
| ruby 1.8.7 | :upto | 0.000000 0.000000 0.000000 ( 0.009500) |
|
7
|
+
| ruby 1.9.2p136 | :for | 0.010000 0.000000 0.010000 ( 0.007612) |
|
8
|
+
| ruby 1.9.2p136 | :times | 0.010000 0.000000 0.010000 ( 0.006944) |
|
9
|
+
| ruby 1.9.2p136 | :upto | 0.000000 0.000000 0.000000 ( 0.003862) |
|
10
|
+
+----------------+--------+-----------------------------------------------+
|
@@ -0,0 +1 @@
|
|
1
|
+
viiite report raw_data --hierarchy --regroup=ruby,bench
|
@@ -0,0 +1,18 @@
|
|
1
|
+
+----------------+------------------------------------------------------------+
|
2
|
+
| :ruby | :measure |
|
3
|
+
+----------------+------------------------------------------------------------+
|
4
|
+
| ruby 1.8.7 | +--------+-----------------------------------------------+ |
|
5
|
+
| | | :bench | :measure | |
|
6
|
+
| | +--------+-----------------------------------------------+ |
|
7
|
+
| | | :for | 0.010000 0.000000 0.010000 ( 0.011117) | |
|
8
|
+
| | | :times | 0.010000 0.000000 0.010000 ( 0.004083) | |
|
9
|
+
| | | :upto | 0.000000 0.000000 0.000000 ( 0.009500) | |
|
10
|
+
| | +--------+-----------------------------------------------+ |
|
11
|
+
| ruby 1.9.2p136 | +--------+-----------------------------------------------+ |
|
12
|
+
| | | :bench | :measure | |
|
13
|
+
| | +--------+-----------------------------------------------+ |
|
14
|
+
| | | :for | 0.010000 0.000000 0.010000 ( 0.007612) | |
|
15
|
+
| | | :times | 0.010000 0.000000 0.010000 ( 0.006944) | |
|
16
|
+
| | | :upto | 0.000000 0.000000 0.000000 ( 0.003862) | |
|
17
|
+
| | +--------+-----------------------------------------------+ |
|
18
|
+
+----------------+------------------------------------------------------------+
|
@@ -0,0 +1 @@
|
|
1
|
+
viiite report raw_data --hierarchy --regroup=bench,ruby
|
@@ -0,0 +1,22 @@
|
|
1
|
+
+--------+--------------------------------------------------------------------+
|
2
|
+
| :bench | :measure |
|
3
|
+
+--------+--------------------------------------------------------------------+
|
4
|
+
| :for | +----------------+-----------------------------------------------+ |
|
5
|
+
| | | :ruby | :measure | |
|
6
|
+
| | +----------------+-----------------------------------------------+ |
|
7
|
+
| | | ruby 1.8.7 | 0.010000 0.000000 0.010000 ( 0.011117) | |
|
8
|
+
| | | ruby 1.9.2p136 | 0.010000 0.000000 0.010000 ( 0.007612) | |
|
9
|
+
| | +----------------+-----------------------------------------------+ |
|
10
|
+
| :times | +----------------+-----------------------------------------------+ |
|
11
|
+
| | | :ruby | :measure | |
|
12
|
+
| | +----------------+-----------------------------------------------+ |
|
13
|
+
| | | ruby 1.8.7 | 0.010000 0.000000 0.010000 ( 0.004083) | |
|
14
|
+
| | | ruby 1.9.2p136 | 0.010000 0.000000 0.010000 ( 0.006944) | |
|
15
|
+
| | +----------------+-----------------------------------------------+ |
|
16
|
+
| :upto | +----------------+-----------------------------------------------+ |
|
17
|
+
| | | :ruby | :measure | |
|
18
|
+
| | +----------------+-----------------------------------------------+ |
|
19
|
+
| | | ruby 1.8.7 | 0.000000 0.000000 0.000000 ( 0.009500) | |
|
20
|
+
| | | ruby 1.9.2p136 | 0.000000 0.000000 0.000000 ( 0.003862) | |
|
21
|
+
| | +----------------+-----------------------------------------------+ |
|
22
|
+
+--------+--------------------------------------------------------------------+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe "viiite command / " do
|
3
|
+
|
4
|
+
Dir[File.expand_path('../**/*.cmd', __FILE__)].each do |input|
|
5
|
+
cmd = File.readlines(input).first
|
6
|
+
specify{ cmd.should =~ /^viiite / }
|
7
|
+
|
8
|
+
describe "#{File.basename(input)}: #{cmd}" do
|
9
|
+
let(:argv) { Quickl.parse_commandline_args(cmd)[1..-1] }
|
10
|
+
let(:stdout) { File.join(File.dirname(input), "#{File.basename(input, ".cmd")}.stdout") }
|
11
|
+
let(:stderr) { File.join(File.dirname(input), "#{File.basename(input, ".cmd")}.stderr") }
|
12
|
+
let(:stdout_expected) { File.exists?(stdout) ? File.read(stdout) : "" }
|
13
|
+
let(:stderr_expected) { File.exists?(stderr) ? File.read(stderr) : "" }
|
14
|
+
|
15
|
+
before{ redirect_io }
|
16
|
+
after { restore_io }
|
17
|
+
|
18
|
+
specify{
|
19
|
+
begin
|
20
|
+
if i = argv.index("raw_data")
|
21
|
+
argv[i] = File.expand_path('../raw_data.rash', __FILE__)
|
22
|
+
end
|
23
|
+
Viiite::Command.run(argv)
|
24
|
+
rescue SystemExit
|
25
|
+
$stdout << "SystemExit" << "\n"
|
26
|
+
end
|
27
|
+
$stdout.string.should(eq(stdout_expected)) unless RUBY_VERSION < "1.9"
|
28
|
+
$stderr.string.should(eq(stderr_expected)) unless RUBY_VERSION < "1.9"
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
viiite --help
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
viiite - Benchmark ruby scripts the easy way
|
3
|
+
|
4
|
+
SYNOPSIS
|
5
|
+
viiite [--version] [--help] COMMAND [cmd opts] ARGS...
|
6
|
+
|
7
|
+
OPTIONS
|
8
|
+
-Idirectory specify $LOAD_PATH directory (may be used more than once)
|
9
|
+
-rlibrary require the library, before executing viiite
|
10
|
+
--help Show help
|
11
|
+
--version Show version
|
12
|
+
|
13
|
+
COMMANDS
|
14
|
+
help Show help about a specific command
|
15
|
+
run Run a benchmark and output raw data
|
16
|
+
report Report benchmarking results as a table
|
17
|
+
plot Report benchmarking results as a plot
|
18
|
+
|
19
|
+
DESCRIPTION
|
20
|
+
This command helps you benchmarking ruby applications and manipulating
|
21
|
+
benchmark results very simply.
|
22
|
+
|
23
|
+
See 'viiite help COMMAND' for more information on a specific command.
|
24
|
+
|
25
|
+
SystemExit
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
require 'viiite'
|
3
|
+
|
4
|
+
def redirect_io
|
5
|
+
$oldstdout = $stdout
|
6
|
+
$oldstderr = $stderr
|
7
|
+
$stdout = StringIO.new
|
8
|
+
$stderr = StringIO.new
|
9
|
+
[$stdout, $stderr]
|
10
|
+
end
|
11
|
+
|
12
|
+
def restore_io
|
13
|
+
$stdout = $oldstdout
|
14
|
+
$stderr = $oldstderr
|
15
|
+
$oldstdout = nil
|
16
|
+
$oldstderr = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def bench_iteration
|
20
|
+
File.expand_path('../fixtures/bench_iteration.rb', __FILE__)
|
21
|
+
end
|
22
|
+
|
23
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Viiite
|
3
|
+
class Command
|
4
|
+
describe Run do
|
5
|
+
|
6
|
+
subject{ Run.run(argv) }
|
7
|
+
|
8
|
+
before{ redirect_io }
|
9
|
+
after { restore_io }
|
10
|
+
|
11
|
+
describe "when passed a benchmark file" do
|
12
|
+
let(:argv){ [bench_iteration] }
|
13
|
+
specify{
|
14
|
+
subject
|
15
|
+
$stdout.string.each_line do |line|
|
16
|
+
h = eval(line)
|
17
|
+
h.should be_a(Hash)
|
18
|
+
h[:tms].should be_a(Viiite::Tms)
|
19
|
+
end
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Viiite
|
3
|
+
class Formatter::Plot
|
4
|
+
describe "to_data" do
|
5
|
+
|
6
|
+
let(:data) { [ {:x => 1, :y => 10}, {:x => 2, :y => 20} ] }
|
7
|
+
|
8
|
+
subject{ Formatter::Plot.to_data(data) }
|
9
|
+
|
10
|
+
it "should return the expected array" do
|
11
|
+
subject.should == [ [1,2], [10,20] ]
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Viiite
|
3
|
+
class Formatter::Plot
|
4
|
+
describe "to_dataset" do
|
5
|
+
|
6
|
+
let(:tuple) {
|
7
|
+
{:title => "serie",
|
8
|
+
:linewidth => 4,
|
9
|
+
:data => [ {:x => 1, :y => 10}, {:x => 2, :y => 20} ] }
|
10
|
+
}
|
11
|
+
subject{ Formatter::Plot.to_dataset(tuple) }
|
12
|
+
|
13
|
+
it "should return a correct dataset instance" do
|
14
|
+
subject.should be_a(Gnuplot::DataSet)
|
15
|
+
subject.title.should == "serie"
|
16
|
+
subject.linewidth.should == 4
|
17
|
+
subject.data.should == [ [1,2], [10,20] ]
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Viiite
|
3
|
+
class Formatter::Plot
|
4
|
+
describe "to_plot" do
|
5
|
+
|
6
|
+
let(:data) { [ {:x => 1, :y => 10}, {:x => 2, :y => 20} ] }
|
7
|
+
|
8
|
+
let(:dataset) { {:title => "serie", :linewidth => 4, :data => data } }
|
9
|
+
|
10
|
+
let(:plot) { {:title => "plot", :series => [ dataset ] } }
|
11
|
+
|
12
|
+
subject{ Formatter::Plot.to_plot(plot) }
|
13
|
+
|
14
|
+
it "should return a correct plot instance" do
|
15
|
+
subject.is_a?(Gnuplot::Plot).should be_true
|
16
|
+
subject["title"].should == '"plot"'
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Viiite
|
3
|
+
describe Runner do
|
4
|
+
|
5
|
+
it "should be definable with Viiite.bm" do
|
6
|
+
b = Viiite.bm do |viiite|
|
7
|
+
viiite.report{ 1 + 1 }
|
8
|
+
end
|
9
|
+
b.should be_kind_of(Viiite::Runner)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be executable" do
|
13
|
+
b = Viiite.bm do |viiite|
|
14
|
+
viiite.report{ 1 + 1 }
|
15
|
+
end
|
16
|
+
res = []
|
17
|
+
b.each do |tuple|
|
18
|
+
tuple.should have_key(:tms)
|
19
|
+
res << tuple
|
20
|
+
end
|
21
|
+
res.should be_kind_of(Array)
|
22
|
+
res.size.should == 1
|
23
|
+
res.first[:tms].should be_kind_of(Viiite::Tms)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should be enumerable" do
|
27
|
+
b = Viiite.bm do |viiite|
|
28
|
+
viiite.report{ 1 + 1 }
|
29
|
+
end
|
30
|
+
res = b.to_a
|
31
|
+
res.should be_kind_of(Array)
|
32
|
+
res.size.should == 1
|
33
|
+
res.first[:tms].should be_kind_of(Viiite::Tms)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should support variation points" do
|
37
|
+
b = Viiite.bm do |viiite|
|
38
|
+
2.times do |i|
|
39
|
+
viiite.variation_point(:"#run", i)
|
40
|
+
viiite.report do end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
res = b.to_a
|
44
|
+
res.collect{|t| t[:"#run"]}.should == [0, 1]
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should support ranging over values" do
|
48
|
+
b = Viiite.bm do |viiite|
|
49
|
+
viiite.range_over [10, 100, 1000], :times do |t|
|
50
|
+
viiite.report do end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
b.to_a.collect{|t| t[:times]}.should == [10, 100, 1000]
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Viiite
|
3
|
+
describe Tms, ".coerce" do
|
4
|
+
|
5
|
+
subject{ Tms.coerce(arg) }
|
6
|
+
|
7
|
+
describe "from zero" do
|
8
|
+
let(:arg){ 0.0 }
|
9
|
+
specify{
|
10
|
+
subject.should be_a(Tms)
|
11
|
+
subject.to_a.should eq([0.0, 0.0, 0.0, 0.0, 0.0])
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "from one" do
|
16
|
+
let(:arg){ 1.0 }
|
17
|
+
specify{
|
18
|
+
subject.should be_a(Tms)
|
19
|
+
subject.to_a.should eq([1.0, 0.0, 0.0, 0.0, 0.0])
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "from a complete hash" do
|
24
|
+
let(:arg){ {
|
25
|
+
:utime => 1.0,
|
26
|
+
:stime => 2.0,
|
27
|
+
:cutime => 3.0,
|
28
|
+
:cstime => 4.0,
|
29
|
+
:real => 5.0,
|
30
|
+
} }
|
31
|
+
specify{
|
32
|
+
subject.should be_a(Tms)
|
33
|
+
subject.to_a.should eq([1.0, 2.0, 3.0, 4.0, 5.0])
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "from an array" do
|
38
|
+
let(:arg){ [1.0, 2.0, 3.0, 4.0, 5.0] }
|
39
|
+
specify{
|
40
|
+
subject.should be_a(Tms)
|
41
|
+
subject.to_a.should eq([1.0, 2.0, 3.0, 4.0, 5.0])
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Viiite
|
3
|
+
describe Tms, "#divide" do
|
4
|
+
|
5
|
+
subject{ tms / operand }
|
6
|
+
let(:tms){ Viiite::Tms.new([1.0, 2.0, 3.0, 4.0, 5.0]) }
|
7
|
+
|
8
|
+
describe "with an integer" do
|
9
|
+
let(:operand){ 2 }
|
10
|
+
specify{
|
11
|
+
subject.should be_a(Tms)
|
12
|
+
subject.to_a.should eq([0.5, 1.0, 1.5, 2.0, 2.5])
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "with another tms" do
|
17
|
+
let(:operand){ tms }
|
18
|
+
specify{
|
19
|
+
subject.should be_a(Tms)
|
20
|
+
subject.to_a.should eq([1.0, 1.0, 1.0, 1.0, 1.0])
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Viiite
|
3
|
+
describe Tms, "#minus" do
|
4
|
+
|
5
|
+
subject{ tms - operand }
|
6
|
+
let(:tms){ Viiite::Tms.new([1.0, 2.0, 3.0, 4.0, 5.0]) }
|
7
|
+
|
8
|
+
describe "with an integer" do
|
9
|
+
let(:operand){ 1 }
|
10
|
+
specify{
|
11
|
+
subject.should be_a(Tms)
|
12
|
+
subject.to_a.should eq([0.0, 1.0, 2.0, 3.0, 4.0])
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "with another tms" do
|
17
|
+
let(:operand){ tms }
|
18
|
+
specify{
|
19
|
+
subject.should be_a(Tms)
|
20
|
+
subject.to_a.should eq([0.0, 0.0, 0.0, 0.0, 0.0])
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Viiite
|
3
|
+
describe Tms, "#plus" do
|
4
|
+
|
5
|
+
subject{ tms + operand }
|
6
|
+
let(:tms){ Viiite::Tms.new([1.0, 2.0, 3.0, 4.0, 5.0]) }
|
7
|
+
|
8
|
+
describe "with an integer" do
|
9
|
+
let(:operand){ 2 }
|
10
|
+
specify{
|
11
|
+
subject.should be_a(Tms)
|
12
|
+
subject.to_a.should eq([3.0, 4.0, 5.0, 6.0, 7.0])
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "with another tms" do
|
17
|
+
let(:operand){ tms }
|
18
|
+
specify{
|
19
|
+
subject.should be_a(Tms)
|
20
|
+
subject.to_a.should eq([2.0, 4.0, 6.0, 8.0, 10.0])
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "the other way around" do
|
25
|
+
subject{ 2 + tms }
|
26
|
+
specify{
|
27
|
+
subject.should be_a(Tms)
|
28
|
+
subject.to_a.should eq([3.0, 4.0, 5.0, 6.0, 7.0])
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module Viiite
|
3
|
+
describe Tms, "#times" do
|
4
|
+
|
5
|
+
subject{ tms * operand }
|
6
|
+
let(:tms){ Viiite::Tms.new([1.0, 2.0, 3.0, 4.0, 5.0]) }
|
7
|
+
|
8
|
+
describe "with an integer" do
|
9
|
+
let(:operand){ 2 }
|
10
|
+
specify{
|
11
|
+
subject.should be_a(Tms)
|
12
|
+
subject.to_a.should eq([2.0, 4.0, 6.0, 8.0, 10.0])
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "with another tms" do
|
17
|
+
let(:operand){ tms }
|
18
|
+
specify{
|
19
|
+
subject.should be_a(Tms)
|
20
|
+
subject.to_a.should eq([1.0, 4.0, 9.0, 16.0, 25.0])
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
data/tasks/clean.rake
ADDED