forked from tamc/excel_to_code
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented EXP, INT, and MONTH functions
- Loading branch information
Christopher Rankin
committed
Apr 10, 2013
1 parent
3fa911a
commit d46088e
Showing
9 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require_relative '../../spec_helper.rb' | ||
|
||
describe "ExcelFunctions: EXP" do | ||
|
||
it "should return the constant e when given a power of 1" do | ||
FunctionTest.exp(1).should == Math::E | ||
end | ||
|
||
it "should return the the square of constant e when given a power of 2 (7.3890560989306495)" do | ||
FunctionTest.exp(2).should == Math::E ** 2 | ||
end | ||
|
||
it "should return an error when given inappropriate arguments" do | ||
FunctionTest.exp("Asdasddf").should == :error | ||
end | ||
|
||
it "should treat nil as zero" do | ||
FunctionTest.exp(nil).should == 0 | ||
end | ||
|
||
it "should return an error if an argument is an error" do | ||
FunctionTest.exp(:error).should == :error | ||
end | ||
|
||
it "should be in the list of functions that can be mapped to ruby" do | ||
MapFormulaeToRuby::FUNCTIONS['EXP'].should == 'exp' | ||
end | ||
|
||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require_relative '../../spec_helper.rb' | ||
|
||
describe "ExcelFunctions: INT" do | ||
|
||
it "should return 1 rounded to lowest integer (1.49)" do | ||
FunctionTest.int(1.49).should == 1 | ||
end | ||
|
||
it "should return 3 rounded to lowest integer (3.0723)" do | ||
FunctionTest.int(3).should == 3 | ||
end | ||
|
||
it "should return 7 rounded to lowest integer (7.9999999999)" do | ||
FunctionTest.int(7).should == 7 | ||
end | ||
|
||
it "should return an error when given inappropriate arguments" do | ||
FunctionTest.int("Asdasddf").should == :error | ||
end | ||
|
||
it "should treat nil as zero" do | ||
FunctionTest.int(nil).should == 0 | ||
end | ||
|
||
it "should return an error if an argument is an error" do | ||
FunctionTest.int(:error).should == :error | ||
end | ||
|
||
it "should be in the list of functions that can be mapped to ruby" do | ||
MapFormulaeToRuby::FUNCTIONS['INT'].should == 'int' | ||
end | ||
|
||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require_relative '../../spec_helper.rb' | ||
|
||
describe "ExcelFunctions: MONTH" do | ||
|
||
it "should return 3 when date is 03/26/2013 (serial: 41359)" do | ||
FunctionTest.month(41359).should == 3 | ||
end | ||
|
||
it "should return an error when given inappropriate arguments" do | ||
FunctionTest.month("Asdasddf").should == :error | ||
end | ||
|
||
it "should treat nil as zero" do | ||
FunctionTest.month(nil).should == 0 | ||
end | ||
|
||
it "should return an error if an argument is an error" do | ||
FunctionTest.month(:error).should == :error | ||
end | ||
|
||
it "should be in the list of functions that can be mapped to ruby" do | ||
MapFormulaeToRuby::FUNCTIONS['MONTH'].should == 'month' | ||
end | ||
|
||
end |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module ExcelFunctions | ||
|
||
def exp(a) | ||
return 0 if a.nil? | ||
return :error unless a.is_a? Numeric | ||
a ||= 0 | ||
result = Math::E ** a | ||
return result | ||
end | ||
|
||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module ExcelFunctions | ||
|
||
def int(a) | ||
return 0 if a.nil? | ||
return :error unless a.is_a? Numeric | ||
a ||= 0 | ||
result = a.to_s.split('.')[0].to_i | ||
return result | ||
end | ||
|
||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require 'date' | ||
require 'active_support' | ||
require 'active_support/core_ext' | ||
|
||
module ExcelFunctions | ||
|
||
def month(a) | ||
return 0 if a.nil? | ||
return :error unless a.is_a? Numeric | ||
a ||= 0 | ||
|
||
result = (Date.civil(1899, 12, 31) + (a - 1).days).month | ||
return result | ||
end | ||
|
||
end |