File: vector_spec.rb

package info (click to toggle)
ruby-rubyvis 0.6.1%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 1,808 kB
  • ctags: 679
  • sloc: ruby: 11,114; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 981 bytes parent folder | download | duplicates (3)
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
    Rubyvis.vector(@x1,@y1).should== @v1
  end
  it "method perp" do
    @v1.perp.should==Rubyvis::Vector.new(-@y1,@x1)
  end
  it "method times" do
    times=rand(10)+1
    @v1.times(times).should==Rubyvis::Vector.new(@x1*times,@y1*times)
  end
  it "method length" do
    l=Math.sqrt(@x1*@x1+@y1*@y1)
    @v1.length.should eq l
  end
  it "method norm" do
    l=@v1.length
    @v1.norm.should==@v1.times(1/l.to_f)
  end
  it "method plus" do
    @v1.plus(@v2).should==Rubyvis::Vector.new(@x1+@x2,@y1+@y2)
  end
  it "method minus" do
    @v1.minus(@v2).should==Rubyvis::Vector.new(@x1-@x2,@y1-@y2)
  end
  it "method dot" do
    @v1.dot(@v2).should==@x1*@x2+@y1*@y2
  end
end