Skip to content

Instantly share code, notes, and snippets.

@SpencerCooley
Created April 18, 2012 21:42
Show Gist options
  • Save SpencerCooley/2416792 to your computer and use it in GitHub Desktop.
Save SpencerCooley/2416792 to your computer and use it in GitHub Desktop.
describe("calculate Bill With Energy Cost Increase", function(){
it("with an average monthly bill $300 and energy cost increase rate of 5% your monthly bill for year 2 should be $315/mo", function(){
expect(calculateBillWithEnergyCostIncrease(300,0.05)).toEqual(315);
});
});
describe("bill iterator. This is the function that calculates for 5 and ten years.", function(){
it("with an average monthly bill $300 and energy cost increase rate of 5%/yr your monthly bill for year 3 should be $330.75/mo", function(){
expect(billIncludeRate(0.05,300,3)).toEqual(330.75);
});
});
//calculate at 5 and 10 functions.
function calculateBillWithEnergyCostIncrease(bill,rate){
return (bill*rate)+bill
}
function billIncludeRate(rate,billNow,noOfYears){
var stopCase = noOfYears -2;
var i=0;
var averageMonthlyBill = billNow;
for (i=0;i<=stopCase;i++)
{
var iterateBill = calculateBillWithEnergyCostIncrease(averageMonthlyBill,rate);
averageMonthlyBill = iterateBill;
}
//ends the for loop
return averageMonthlyBill;
}
describe("bill iterator. This is the function that calculates for 5 and ten years.", function(){
it("with an average monthly bill $300 and energy cost increase rate of 5%/yr your monthly bill for year 4 should be $337.2875/mo", function(){
expect(billIncludeRate(0.05,300,4)).toEqual(347.2875);
});
});
describe("bill iterator. This is the function that calculates for 5 and ten years.", function(){
it("with an average monthly bill $300 and energy cost increase rate of 5%/yr your monthly bill for year 5 should be $364.651875/mo", function(){
expect(billIncludeRate(0.05,300,5)).toEqual(364.651875);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment