diff options
Diffstat (limited to 'spec/ruby/library/matrix/vector/normalize_spec.rb')
-rw-r--r-- | spec/ruby/library/matrix/vector/normalize_spec.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/spec/ruby/library/matrix/vector/normalize_spec.rb b/spec/ruby/library/matrix/vector/normalize_spec.rb new file mode 100644 index 0000000000..14aac1f5e3 --- /dev/null +++ b/spec/ruby/library/matrix/vector/normalize_spec.rb @@ -0,0 +1,18 @@ +require File.expand_path('../../../../spec_helper', __FILE__) +require 'matrix' + +describe "Vector#normalize" do + it "returns a normalized copy of the vector" do + x = 0.2672612419124244 + Vector[1, 2, 3].normalize.should == Vector[x, x * 2, x * 3] + end + + it "raises an error for zero vectors" do + lambda { + Vector[].normalize + }.should raise_error(Vector::ZeroVectorError) + lambda { + Vector[0, 0, 0].normalize + }.should raise_error(Vector::ZeroVectorError) + end +end |