Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save codeangler/a56dbddbc52f6a60563c3f1c3bb0b111 to your computer and use it in GitHub Desktop.
Save codeangler/a56dbddbc52f6a60563c3f1c3bb0b111 to your computer and use it in GitHub Desktop.
Exponential math with Unit Tests (Jasmine)
"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);
});
});
<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>
<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