Sha256: fff5ea2613196ab6285c910d22b5c9a2071d563e900baa1ea9c41cd157517222

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

require 'spec_helper'

describe Point do
  describe ".parse" do
    context "with a correctly formatted point" do
      before do
        @result = Point.parse("  16.5 0.0 -0.75 ")
      end
      
      it "should return a point object" do
        @result.should be_a Point
      end
      
      it "should correctly set the X value" do
        @result.x.should == 16.5
      end
      
      it "should correctly set the Y value" do
        @result.y.should == 0
      end
      
      it "should correctly set the Z value" do
        @result.z.should == -0.75
      end
    end
    
    context "with a point that contains exponential notation" do
      before do
        @result = Point.parse("  -5.23431439438796e-32 0.0 5.23431439438796e32 ")
      end
      
      it "should correctly set the X value" do
        @result.x.should == -5.23431439438796e-32
      end
      
      it "should correctly set the Y value" do
        @result.y.should == 0.0
      end
      
      it "should correctly set the Z value" do
        @result.z.should == 5.23431439438796e32
      end
    end
  end
  
  describe "#to_s" do
    it "should return the XYZ components separated by spaces" do
      point = Point.new(1.0, 2.0, -3.1)
      point.to_s.should == "1.0 2.0 -3.1"
    end
    
    it "should convert integers into floats for output" do
      point = Point.new(1, 2, 3)
      point.to_s.should == "1.0 2.0 3.0"
    end
  end
  
  describe "#==" do
    it "should return true when the points have identical values" do
      (Point.new(1.0, 2.0, -3.1) == Point.new(1.0, 2.0, -3.1)).should be_true
    end
    
    it "should return false when the points do not have identical values" do
      (Point.new(1.0, 2.0, -3.1) == Point.new(1.0, 2.0, -3.2)).should be_false
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
triangular-0.0.1 spec/point_spec.rb