Created
March 22, 2013 00:19
-
-
Save lmazardo/5218004 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'hw7' | |
# tests | |
describe "Homework 7" do | |
describe Let do | |
before(:each) do | |
@let = Let.new("A", Point.new(10.0, 10.0), Shift.new(-10.0, -10.0, Var.new("A"))) | |
end | |
it "should have a preprocess method" do | |
@let.should respond_to ("preprocess_prog") | |
end | |
it "should have a eval_prog method" do | |
@let.should respond_to ("eval_prog") | |
expect { @let.eval_prog}.to raise_error(ArgumentError) | |
#expect { @let.eval_prog([])}.to raise_error(ArgumentError) | |
end | |
end | |
describe Intersect do | |
before(:each) do | |
@intersect = Intersect.new(nil, nil) | |
end | |
it "should have a preprocess method" do | |
@intersect.should respond_to ("preprocess_prog") | |
end | |
it "should have a eval_prog method" do | |
@intersect.should respond_to ("eval_prog") | |
end | |
end | |
describe Var do | |
before(:each) do | |
@var = Var.new("") | |
end | |
it "should have a preprocess method" do | |
@var.should respond_to ("preprocess_prog") | |
end | |
it "should have a eval_prog method" do | |
@var.should respond_to ("eval_prog") | |
end | |
end | |
describe Shift do | |
before(:each) do | |
@shift = Shift.new(0, 0, nil) | |
end | |
it "should have a preprocess method" do | |
@shift.should respond_to ("preprocess_prog") | |
end | |
it "should have a eval_prog method" do | |
@shift.should respond_to ("eval_prog") | |
end | |
end | |
describe NoPoints do | |
before(:each) do | |
@nopoints = NoPoints.new | |
end | |
it "should have a preprocess method" do | |
@nopoints.should respond_to ("preprocess_prog") | |
end | |
end | |
describe Point do | |
before(:each) do | |
@point = Point.new(10.0, 10.0) | |
@bad_point = Point.new(10.0, 11.0) | |
@good_line = Line.new(1.0, 0) | |
@bad_line = Line.new(1.0, 1) | |
@good_vline = VerticalLine.new(10.0) | |
@bad_vline = VerticalLine.new(0.0) | |
end | |
it "should have a preprocess and eval_prog methods" do | |
@point.should respond_to ("preprocess_prog") | |
@point.should respond_to ("eval_prog") | |
end | |
it "should have a shift method and it is working" do | |
@point.should respond_to ("shift") | |
@point.shift(3.0, 3.0).x.should be_within(GeometryExpression::Epsilon).of(13.0) | |
@point.shift(3.0, 4.0).y.should be_within(GeometryExpression::Epsilon).of(14.0) | |
end | |
it "should have a intersect method" do | |
@point.should respond_to ("intersect") | |
end | |
it "should have a intersectPoint method and it is working" do | |
@point.should respond_to ("intersectPoint") | |
@point.intersectPoint(@point).x.should be_within(GeometryExpression::Epsilon).of(@point.x) | |
@point.intersectPoint(@point).x.should be_within(GeometryExpression::Epsilon).of(@point.x) | |
@point.intersectPoint(@bad_point).should be_a_kind_of NoPoints | |
end | |
it "should have a intersectLine method and it is working" do | |
@point.should respond_to ("intersectLine") | |
@point.intersectLine(@good_line).x.should be_within(GeometryExpression::Epsilon).of(@point.x) | |
@point.intersectLine(@good_line).x.should be_within(GeometryExpression::Epsilon).of(@point.x) | |
@point.intersectLine(@bad_line).should be_a_kind_of NoPoints | |
end | |
it "should have a intersectVerticalLine method and it is working" do | |
@point.should respond_to ("intersectVerticalLine") | |
@point.intersectVerticalLine(@bad_vline).should be_a_kind_of NoPoints | |
@point.intersectVerticalLine(@good_vline).x.should be_within(GeometryExpression::Epsilon).of(@point.x) | |
@point.intersectVerticalLine(@good_vline).y.should be_within(GeometryExpression::Epsilon).of(@point.y) | |
end | |
it "should have an intersectWithSegmentAsLineResult method" do | |
@point.should respond_to("intersectWithSegmentAsLineResult") | |
end | |
end | |
describe VerticalLine do | |
before(:each) do | |
@vline = VerticalLine.new(1.0) | |
end | |
it "should have a preprocess and eval_prog methods" do | |
@vline.should respond_to ("preprocess_prog") | |
@vline.should respond_to ("eval_prog") | |
end | |
it "should have a shift method and it is working" do | |
@vline.should respond_to ("shift") | |
@vline.shift(2.0, 3.0).x.should be_within(GeometryExpression::Epsilon).of(3.0) | |
end | |
it "should have an intersect method" do | |
@vline.should respond_to ("intersect") | |
end | |
it "should have an intersectPoint method" do | |
@vline.should respond_to ("intersectPoint") | |
@vline.intersect(Point.new(-5.0, 0.0)).should be_a_kind_of NoPoints | |
@vline.intersect(Point.new(@vline.x, 10.0)).should be_a_kind_of Point | |
@vline.intersect(Point.new(@vline.x, 10.0)).x.should be_within(GeometryExpression::Epsilon).of(@vline.x) | |
end | |
it "should have an intersectVerticalLine method" do | |
@vline.should respond_to ("intersectVerticalLine") | |
@vline.intersect(@vline).x.should be_within(GeometryExpression::Epsilon).of(@vline.x) | |
@vline.intersect(VerticalLine.new(-5.0)).should be_a_kind_of NoPoints | |
end | |
it "should have an intersectLine method" do | |
@vline.should respond_to ("intersectLine") | |
end | |
end | |
describe Line do | |
before(:each) do | |
@line = Line.new(4.0, 4.0) | |
@good_point = Point.new(0.0, 4.0) | |
@bad_point = Point.new(1.0, 4.0) | |
end | |
it "should have a preprocess and eval_prog methods" do | |
@line.should respond_to ("preprocess_prog") | |
@line.should respond_to ("eval_prog") | |
end | |
it "should have a shift method and it is working" do | |
@line.should respond_to ("shift") | |
@line.shift(3.0, 4.0).m.should be_within(GeometryExpression::Epsilon).of(4.0) | |
@line.shift(3.0, 4.0).b.should be_within(GeometryExpression::Epsilon).of(-4.0) | |
end | |
it "should have a intersect method" do | |
@line.should respond_to("intersect") | |
@line.intersect(@good_point).should be_a_kind_of Point | |
end | |
it "should have an intersectPoint method" do | |
@line.should respond_to("intersectPoint") | |
@line.intersectPoint(@good_point).x.should be_within(GeometryExpression::Epsilon).of(@good_point.x) | |
@line.intersectPoint(@good_point).y.should be_within(GeometryExpression::Epsilon).of(@good_point.y) | |
@line.intersectPoint(@bad_point).should be_a_kind_of NoPoints | |
end | |
it "should have an intersectLine method" do | |
@line.should respond_to("intersectLine") | |
@line.intersectLine(@line).should be_a_kind_of Line | |
@line.intersectLine(@line).m.should be_within(GeometryExpression::Epsilon).of(@line.m) | |
@line.intersectLine(@line).b.should be_within(GeometryExpression::Epsilon).of(@line.b) | |
end | |
it "should have an intersectVerticalLine method" do | |
@line.should respond_to("intersectVerticalLine") | |
@line.intersect(VerticalLine.new(0.0)).should be_a_kind_of Point | |
@line.intersectVerticalLine(VerticalLine.new(0.0)).x.should be_within(GeometryExpression::Epsilon).of(0.0) | |
@line.intersectVerticalLine(VerticalLine.new(0.0)).y.should be_within(GeometryExpression::Epsilon).of(4.0) | |
end | |
it "should have an intersectWithSegmentAsLineResult method" do | |
@line.should respond_to("intersectWithSegmentAsLineResult") | |
end | |
end | |
describe LineSegment do | |
before(:each) do | |
@line_segment = LineSegment.new(10.0, 10.0, -10.0, 20.0) | |
@ls_as_point = LineSegment.new(10.0, 10.0, 10.0, 10.0) | |
end | |
it "should have a preprocess and it is working" do | |
@line_segment.should respond_to ("preprocess_prog") | |
@ls_as_point.preprocess_prog.should be_a_kind_of Point | |
@line_segment.preprocess_prog.x1.should be_within(GeometryExpression::Epsilon).of(@line_segment.x2) | |
@line_segment.preprocess_prog.y1.should be_within(GeometryExpression::Epsilon).of(@line_segment.y2) | |
end | |
it "should have eval_prog methods" do | |
@line_segment.should respond_to ("eval_prog") | |
end | |
it "should have a shift method and it is working" do | |
@line_segment.should respond_to ("shift") | |
@line_segment.shift(3.0, 4.0).x1.should be_within(GeometryExpression::Epsilon).of(13.0) | |
@line_segment.shift(3.0, 4.0).x2.should be_within(GeometryExpression::Epsilon).of(-7.0) | |
@line_segment.shift(3.0, 4.0).y1.should be_within(GeometryExpression::Epsilon).of(14.0) | |
@line_segment.shift(3.0, 4.0).y2.should be_within(GeometryExpression::Epsilon).of(24.0) | |
end | |
it "should have an intersect methods" do | |
@line_segment.should respond_to ("intersect") | |
@line_segment.should respond_to ("intersectPoint") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment