A Pen by Casey Burnett on CodePen.
Created
October 13, 2016 02:31
-
-
Save anonymous/261ebfcecb66712a10cfaa09da511ba1 to your computer and use it in GitHub Desktop.
Exponential math with Unit Tests (Jasmine)
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
"use strict"; | |
const mathPower = (base, n) => { | |
return Array.from({length: n}) | |
.fill(base) | |
.reduce((prev, curr) => prev * curr, 1); | |
} | |
console.log(mathPower(3, 3)) | |
// Tests | |
describe("A function that takes a base to the power of n", function() { | |
it("should return 0 for all base 0^n", () =>{ | |
expect() | |
}); | |
it("should return 9 for base 3^2", function() { | |
expect(mathPower(3, 2)).toEqual(9); | |
expect(mathPower(3, 2)).not.toBe(undefined); | |
}); | |
it("should return 1 for base^0", function() { | |
expect(mathPower(3, 0)).toEqual(1); | |
expect(mathPower(3, 2)).not.toBe(undefined); | |
expect(mathPower(3, 0)).not.toBe(undefined); | |
}); | |
}); |
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
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.4/jasmine.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.4/jasmine-html.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.4/boot.js"></script> |
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
<link href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.4/jasmine.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment