test/geometry/line.rb in geometry-6.4 vs test/geometry/line.rb in geometry-6.5

- old
+ new

@@ -132,10 +132,33 @@ line2 = Geometry::TwoPointLine.new([1,2], [2,5]) line3 = Geometry::TwoPointLine.new([1,2], [2,4]) line2.must_equal subject line3.wont_equal subject end + + it 'must know how to be horizontal' do + Geometry::PointSlopeLine.new([1,2],0).horizontal?.must_equal true + Geometry::PointSlopeLine.new([1,2],1).horizontal?.must_equal false + end + + it 'must know how to be vertical' do + Geometry::PointSlopeLine.new([1,2], Float::INFINITY).vertical?.must_equal true + Geometry::PointSlopeLine.new([1,2], -Float::INFINITY).vertical?.must_equal true + Geometry::PointSlopeLine.new([1,2],1).vertical?.must_equal false + end + + it 'must have an x-intercept' do + subject.intercept(:x).must_equal 1 + end + + it 'must not have an x-intercept for horizontal lines' do + Geometry::PointSlopeLine.new([1,2], 0).intercept(:x).must_equal nil + end + + it 'must have a y-intercept' do + subject.intercept.must_equal -1 + end end describe Geometry::SlopeInterceptLine do subject { Geometry::SlopeInterceptLine.new 3, 2 } @@ -161,10 +184,33 @@ line2 = Geometry::TwoPointLine.new([0,2], [1,5]) line3 = Geometry::TwoPointLine.new([0,2], [1,4]) line2.must_equal subject line3.wont_equal subject end + + it 'must know how to be horizontal' do + Geometry::SlopeInterceptLine.new(0, 2).horizontal?.must_equal true + Geometry::SlopeInterceptLine.new(1, 2).horizontal?.must_equal false + end + + it 'must know how to be vertical' do + Geometry::SlopeInterceptLine.new(Float::INFINITY, 2).vertical?.must_equal true + Geometry::SlopeInterceptLine.new(-Float::INFINITY, 2).vertical?.must_equal true + Geometry::SlopeInterceptLine.new(1, 2).vertical?.must_equal false + end + + it 'must have an x-intercept' do + subject.intercept(:x).must_equal -2/3 + end + + it 'must not have an x-intercept for horizontal lines' do + Geometry::SlopeInterceptLine.new(0, 2).intercept(:x).must_equal nil + end + + it 'must have a y-intercept' do + subject.intercept.must_equal 2 + end end describe Geometry::TwoPointLine do subject { Geometry::TwoPointLine.new [1,2], [3,4] } @@ -189,7 +235,34 @@ it 'must handle equality with a SlopeInterceptLine' do line2 = Geometry::SlopeInterceptLine.new(1, 1) line3 = Geometry::SlopeInterceptLine.new(1, -1) line2.must_equal subject line3.wont_equal subject + end + + it 'must know how to be horizontal' do + Geometry::TwoPointLine.new([1,2],[2,2]).horizontal?.must_equal true + Geometry::TwoPointLine.new([1,2],[3,4]).horizontal?.must_equal false + end + + it 'must know how to be vertical' do + Geometry::TwoPointLine.new([1,2], [1,3]).vertical?.must_equal true + Geometry::TwoPointLine.new([1,2], [1,-3]).vertical?.must_equal true + Geometry::TwoPointLine.new([1,2],[3,4]).vertical?.must_equal false + end + + it 'must have an x-intercept' do + subject.intercept(:x).must_equal -1 + end + + it 'must not have an x-intercept for horizontal lines' do + Geometry::TwoPointLine.new([1,2],[2,2]).intercept(:x).must_equal nil + end + + it 'must have an x-intercept for vertical lines' do + Geometry::TwoPointLine.new([1,2], [1,3]).intercept(:x).must_equal 1 + end + + it 'must have a y-intercept' do + subject.intercept.must_equal 1 end end