ãã®ãã¹ãã¯ä½ãåé¡ã§ãããï¼
ä¸ã® pow ã®ãã¹ãã¯ä½ãåé¡ã§ãããï¼
it("Raises x to the power n", function() {
let x = 5;
let result = x;
assert.equal(pow(x, 1), result);
result *= x;
assert.equal(pow(x, 2), result);
result *= x;
assert.equal(pow(x, 3), result);
});
P.S. æ§æä¸ããã¹ãã¯æ£ãããã®ã§ãããåæ ¼ã¨ãªãã¾ãã
ãã®ãã¹ãã¯ããã¹ããæ¸ãæã«éçºè ãåºä¼ããã³ãã¬ã¼ãã®1ã¤ã§ãã
ããã§å®éã«æã£ã¦ãããã¹ã㯠3ã¤ã§ããã3ã¤ã®ã¢ãµã¼ããæã¤1ã¤ã®é¢æ°ã¨ãã¦ä¸¦ã¹ããã¦ãã¾ãã
ãã®æ¹æ³ã§æ¸ãã»ããç°¡åãªå ´åãããã¾ãããã¨ã©ã¼ãèµ·ããæãä½ãééã£ã¦ããã®ããæããã§ã¯ããã¾ããã
ããè¤éãªå®è¡ããã¼ã®ä¸ã§ã¨ã©ã¼ãèµ·ããå ´åããã®æã®ãã¼ã¿ãææ¡ããå¿ è¦ãããã¾ããå®éã« ãã¹ãããããã° ããªããã°ãªããªããªãã¾ãã
ãã¹ãããå
¥åºåãæç½ã«æ¸ãããè¤æ°ã® it ãããã¯ã«å´©ãæ¹ãã¯ããã«è¯ãã§ãã
ãã®ããã«:
describe("Raises x to power n", function() {
it("5 in the power of 1 equals 5", function() {
assert.equal(pow(5, 1), 5);
});
it("5 in the power of 2 equals 25", function() {
assert.equal(pow(5, 2), 25);
});
it("5 in the power of 3 equals 125", function() {
assert.equal(pow(5, 3), 125);
});
});
åä¸ã® it ã describe 㨠it ãããã¯ã®ã°ã«ã¼ãã«ç½®ãæãã¾ããã ä»ä½ãã失æããå ´åããã¼ã¿ãä½ã§ããããæç¢ºã«åããã¾ãã
ã¾ããit ã®ä»£ããã« it.only ãæ¸ããã¨ã§ãåä¸ã®ãã¹ãã«åé¢ããã¹ã¿ã³ãã¢ãã¼ã³ã¢ã¼ãã§å®è¡ãããã¨ãã§ãã¾ãã
describe("Raises x to power n", function() {
it("5 in the power of 1 equals 5", function() {
assert.equal(pow(5, 1), 5);
});
// Mocha will run only this block
it.only("5 in the power of 2 equals 25", function() {
assert.equal(pow(5, 2), 25);
});
it("5 in the power of 3 equals 125", function() {
assert.equal(pow(5, 3), 125);
});
});