roguri-palindrome
Version:
Palindrome detector
39 lines (37 loc) • 1.75 kB
JavaScript
// 2つのnpmモジュールをインポート
let assert = require("assert"); // Node.jsの組み込みアサーションモジュール
let Phrase = require("../index.js"); // テストしたいPhraseオブジェクトをインポート
describe("Phrase", function () {
describe("#palindrome", function () {
it("should return true for a palindrome", function () {
let plainPalindrome = new Phrase("racecar");
assert(plainPalindrome.palindrome());
});
it("should return false for a non-palindrome", function () {
let nonPalindrome = new Phrase("apple");
assert(!nonPalindrome.palindrome());
});
it("should return true for a mixed-case palindrome", function () {
let mixedCase = new Phrase("RaceCar");
assert(mixedCase.palindrome());
});
it("should return true for a palindrome with punctuation", function () {
let punctuatedPalindrome = new Phrase("Madam, I'm Adam.");
assert(punctuatedPalindrome.palindrome());
});
it("should return false for an empty string", function () {
let emptyPhrase = new Phrase("");
assert(!emptyPhrase.palindrome());
});
describe("#letters", function () {
it("should return only letters", function () {
let punctuatedPalindrome = new Phrase("Madam, I'm Adam.");
assert.strictEqual(punctuatedPalindrome.letters(), "MadamImAdam");
});
it("should return nothing for a null", function () {
let noLetters = new Phrase("1234.56")
assert.strictEqual(noLetters.letters(), "")
})
});
});
});