Sha256: dfe90107169a39285352b6b48dcbf52a6f636f3bc4972c4c88313ab111a97635

Contents?: true

Size: 998 Bytes

Versions: 1

Compression:

Stored size: 998 Bytes

Contents

require 'minitest/autorun'
require 'geometry/vector'

describe Vector do
    describe "when monkeypatching Vector" do
	let(:left) { Vector[1,2] }
	let(:right) { Vector[3,4] }
	
	it "must have +@" do
	    (+left).must_equal Vector[1,2]
	end
	
	it "must have unary negation" do
	    (-left).must_equal Vector[-1,-2]
	end
	
	it "must cross product" do
	    left.cross(right).must_equal(-2)
	    Vector[1,2,3].cross(Vector[3,4,5]).must_equal Vector[-2, 4, -2]
	    (Vector[1,2,3] ** Vector[3,4,5]).must_equal Vector[-2, 4, -2]
	end

	it "must have a constant representing the X axis" do
	    Vector::X.must_equal Vector[1,0,0]
	end

	it "must have a constant representing the Y axis" do
	    Vector::Y.must_equal Vector[0,1,0]
	end

	it "must have a constant representing the Z axis" do
	    Vector::Z.must_equal Vector[0,0,1]
	end

	it "must not create global axis constants" do
	    -> { X }.must_raise NameError
	    -> { Y }.must_raise NameError
	    -> { Z }.must_raise NameError
	end
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
geometry-6.6 test/geometry/vector.rb