File: vector_spec.rb

package info (click to toggle)
ruby-rubyvis 0.7.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 1,808 kB
  • sloc: ruby: 11,120; javascript: 25; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 1,033 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
describe Rubyvis::Vector do
  before do
    @x1,@x2,@y1,@y2=rand(10)+1,rand(10)+1,rand(10)+1,rand(10)+1
    @v1=Rubyvis::Vector.new(@x1,@y1)
    @v2=Rubyvis::Vector.new(@x2,@y2)
  end
  it "should return the same as Rubyvis.vector" do
    expect(Rubyvis.vector(@x1,@y1)).to eq(@v1)
  end
  it "method perp" do
    expect(@v1.perp).to eq(Rubyvis::Vector.new(-@y1,@x1))
  end
  it "method times" do
    times=rand(10)+1
    expect(@v1.times(times)).to eq(Rubyvis::Vector.new(@x1*times,@y1*times))
  end
  it "method length" do
    l=Math.sqrt(@x1*@x1+@y1*@y1)
    expect(@v1.length).to eq l
  end
  it "method norm" do
    l=@v1.length
    expect(@v1.norm).to eq(@v1.times(1/l.to_f))
  end
  it "method plus" do
    expect(@v1.plus(@v2)).to eq(Rubyvis::Vector.new(@x1+@x2,@y1+@y2))
  end
  it "method minus" do
    expect(@v1.minus(@v2)).to eq(Rubyvis::Vector.new(@x1-@x2,@y1-@y2))
  end
  it "method dot" do
    expect(@v1.dot(@v2)).to eq(@x1*@x2+@y1*@y2)
  end
end