summaryrefslogtreecommitdiff
path: root/spec/ruby/library/matrix/vector/normalize_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/matrix/vector/normalize_spec.rb')
-rw-r--r--spec/ruby/library/matrix/vector/normalize_spec.rb18
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..bb1f046786
--- /dev/null
+++ b/spec/ruby/library/matrix/vector/normalize_spec.rb
@@ -0,0 +1,18 @@
+require_relative '../../../spec_helper'
+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
+ -> {
+ Vector[].normalize
+ }.should.raise(Vector::ZeroVectorError)
+ -> {
+ Vector[0, 0, 0].normalize
+ }.should.raise(Vector::ZeroVectorError)
+ end
+end