test/geometry/point.rb in geometry-6.2 vs test/geometry/point.rb in geometry-6.3
- old
+ new
@@ -1,12 +1,21 @@
require 'minitest/autorun'
require 'geometry/point'
describe Geometry::Point do
+ PointOne = Geometry::PointOne
PointZero = Geometry::PointZero
describe "class methods" do
+ it 'must generate a PointOne' do
+ Point.one.must_be_instance_of PointOne
+ end
+
+ it 'must generate a Point full of ones' do
+ Point.one(3).must_equal Point[1,1,1]
+ end
+
it "must generate a PointZero" do
Point.zero.must_be_instance_of(PointZero)
end
it "must generate a Point full of zeros" do
@@ -54,16 +63,26 @@
point = Geometry::Point[Geometry::Point[13,14]]
assert_equal(2, point.size)
assert_equal(13, point.x)
assert_equal(14, point.y)
end
- it "allow indexed element access" do
- point = Geometry::Point[5,6]
- assert_equal(2, point.size)
- assert_equal(5, point[0])
- assert_equal(6, point[1])
+
+ describe 'when array access' do
+ it 'must allow indexed access' do
+ point = Geometry::Point[5,6]
+ point.size.must_equal 2
+ point[0].must_equal 5
+ point[1].must_equal 6
+ end
+
+ it 'must slize with a start index and a length' do
+ point = Geometry::Point[5, 6, 7]
+ slice = point[1,2]
+ slice.length.must_equal 2
+ end
end
+
it "allow named element access" do
point = Geometry::Point[5,6,7]
assert_equal(3, point.size)
assert_equal(5, point.x)
assert_equal(6, point.y)
@@ -130,10 +149,14 @@
it "must return a Point when adding a Vector" do
(left + Vector[5,6]).must_equal Point[6,8]
(Vector[5,6] + right).must_equal Vector[8,10]
end
+ it 'must add a PointOne' do
+ (left + Point.one).must_equal Point[2,3]
+ end
+
it "must return self when adding a PointZero" do
(left + Point.zero).must_equal left
end
it "must return self when adding a NilClass" do
@@ -157,10 +180,14 @@
it "must raise an exception when subtracting mismatched sizes" do
lambda { left - [1,2,3,4] }.must_raise Geometry::DimensionMismatch
end
+ it 'must subtract a PointOne' do
+ (left - Point.one).must_equal Point[0,1]
+ end
+
it "must return self when subtracting a PointZero" do
(left - Point.zero).must_equal left
end
it "must return self when subtracting a NilClass" do
@@ -216,9 +243,17 @@
end
it "must not compare equal to an unequal Point" do
point.wont_equal Point[3,2]
Point[3,2].wont_equal point
+ end
+
+ it 'must compare to a PointOne' do
+ point.wont_equal Point.one
+ Point.one.wont_equal point
+
+ Point[1,1].must_equal Point.one
+ Point.one.must_equal Point[1,1]
end
it "must compare equal to an equal Vector" do
point.must_equal Vector[1,2]
Vector[1,2].must_equal point