From 58b2e2a57107e4b251cf8cafbd4d68fd9d6756c6 Mon Sep 17 00:00:00 2001 From: Akshay Rawat Date: Thu, 4 Oct 2007 21:48:15 +0530 Subject: [PATCH] Specs for the module Precision --- spec/core/precision/included_spec.rb | 11 +++++++++++ spec/core/precision/prec_f_spec.rb | 11 +++++++++++ spec/core/precision/prec_i_spec.rb | 10 ++++++++++ spec/core/precision/prec_spec.rb | 21 +++++++++++++++++++++ 4 files changed, 53 insertions(+), 0 deletions(-) diff --git a/spec/core/precision/included_spec.rb b/spec/core/precision/included_spec.rb index 76f7125..6c08d07 100644 --- a/spec/core/precision/included_spec.rb +++ b/spec/core/precision/included_spec.rb @@ -1 +1,12 @@ require File.dirname(__FILE__) + '/../../spec_helper' + +describe "Prec.included" do + it "raises a TypeError when a class mixed with Precision does not specify induced_from" do + + class Foo ;include Precision ;end + should_raise(TypeError, "undefined conversion from Fixnum into Foo") do + Foo.induced_from(1) + end + + end +end diff --git a/spec/core/precision/prec_f_spec.rb b/spec/core/precision/prec_f_spec.rb index 76f7125..84d1f47 100644 --- a/spec/core/precision/prec_f_spec.rb +++ b/spec/core/precision/prec_f_spec.rb @@ -1 +1,12 @@ require File.dirname(__FILE__) + '/../../spec_helper' + +describe "Precision#prec_f" do + it "converts a Integer to Float when called on an Integer" do + 1.prec_f.should==1.0 + end + + it "returns the same Float when called on a Float" do + 1.9.prec_f.should==1.9 + end +end + diff --git a/spec/core/precision/prec_i_spec.rb b/spec/core/precision/prec_i_spec.rb index 76f7125..7018d7b 100644 --- a/spec/core/precision/prec_i_spec.rb +++ b/spec/core/precision/prec_i_spec.rb @@ -1 +1,11 @@ require File.dirname(__FILE__) + '/../../spec_helper' + +describe "Precision#prec_i" do + it "returns the same Integer when called on an Integer" do + 1.prec_i.should == 1 + end + + it "converts Float to an Integer when called on an Integer" do + 1.9.prec_i.should == 1 + end +end \ No newline at end of file diff --git a/spec/core/precision/prec_spec.rb b/spec/core/precision/prec_spec.rb index 76f7125..1164f19 100644 --- a/spec/core/precision/prec_spec.rb +++ b/spec/core/precision/prec_spec.rb @@ -1 +1,22 @@ require File.dirname(__FILE__) + '/../../spec_helper' + +describe "Float#prec" do + it "returns the same Float when given the class Float" do + 1.4.prec(Float).should == 1.4 + end + + it "converts the Float to an Integer when given the class Integer" do + 1.4.prec(Integer).should == 1 + end +end + +describe "Integer#prec" do + it "returns the same Integer when given the class Integer" do + 1.prec(Integer).should == 1 + end + + it "converts the Integer to Float when given the class Float" do + 1.prec(Float).should == 1.0 + end +end + -- 1.5.3.2