|
| 1 | +import { describe, expect, test } from "bun:test"; |
| 2 | +import { Cat } from "./cat"; |
| 3 | + |
| 4 | +describe("Cat", () => { |
| 5 | + const cat = new Cat(); |
| 6 | + |
| 7 | + test("should respond with greeting sounds for greeting messages", async () => { |
| 8 | + const greetingMessages = ["こんにちは", "おはよう", "はじめまして"]; |
| 9 | + const greetingSounds = ["ニャッ", "ミャッ", "ニャ"]; |
| 10 | + |
| 11 | + for (const message of greetingMessages) { |
| 12 | + const response = await cat.response(message); |
| 13 | + expect(greetingSounds).toContain(response); |
| 14 | + } |
| 15 | + }); |
| 16 | + |
| 17 | + test("should respond with affection sounds for affection messages", async () => { |
| 18 | + const affectionMessages = ["可愛いね", "好きだよ", "撫でて"]; |
| 19 | + const affectionSounds = ["ニャオ~ン", "ミャオ~", "ニャンニャン"]; |
| 20 | + |
| 21 | + for (const message of affectionMessages) { |
| 22 | + const response = await cat.response(message); |
| 23 | + expect(affectionSounds).toContain(response); |
| 24 | + } |
| 25 | + }); |
| 26 | + |
| 27 | + test("should respond with satisfaction sounds for satisfaction messages", async () => { |
| 28 | + const satisfactionMessages = ["ありがとう", "嬉しい", "素晴らしい"]; |
| 29 | + const satisfactionSounds = ["ゴロゴロ", "ニャ~"]; |
| 30 | + |
| 31 | + for (const message of satisfactionMessages) { |
| 32 | + const response = await cat.response(message); |
| 33 | + expect(satisfactionSounds).toContain(response); |
| 34 | + } |
| 35 | + }); |
| 36 | + |
| 37 | + test("should respond with excitement sounds for excitement messages", async () => { |
| 38 | + const excitementMessages = ["遊ぼう", "楽しい", "やったー"]; |
| 39 | + const excitementSounds = ["ニャニャニャ!", "ミャー!", "ニャッニャッ"]; |
| 40 | + |
| 41 | + for (const message of excitementMessages) { |
| 42 | + const response = await cat.response(message); |
| 43 | + expect(excitementSounds).toContain(response); |
| 44 | + } |
| 45 | + }); |
| 46 | + |
| 47 | + test("should respond with playful sounds for playful messages", async () => { |
| 48 | + const playfulMessages = ["ゲーム", "おもちゃ", "じゃれる"]; |
| 49 | + const playfulSounds = ["ニャーン", "ミャミャ", "ニャオッ"]; |
| 50 | + |
| 51 | + for (const message of playfulMessages) { |
| 52 | + const response = await cat.response(message); |
| 53 | + expect(playfulSounds).toContain(response); |
| 54 | + } |
| 55 | + }); |
| 56 | + |
| 57 | + test("should respond with sleepy sounds for sleepy messages", async () => { |
| 58 | + const sleepyMessages = ["眠い", "疲れた", "おやすみ"]; |
| 59 | + const sleepySounds = ["ニャ…", "フニャ~", "ニャ~ン"]; |
| 60 | + |
| 61 | + for (const message of sleepyMessages) { |
| 62 | + const response = await cat.response(message); |
| 63 | + expect(sleepySounds).toContain(response); |
| 64 | + } |
| 65 | + }); |
| 66 | + |
| 67 | + test("should respond with hungry sounds for hungry messages", async () => { |
| 68 | + const hungryMessages = ["お腹すいた", "ごはん", "美味しい"]; |
| 69 | + const hungrySounds = ["ニャオォン", "ミャーオ", "ニャンニャン!"]; |
| 70 | + |
| 71 | + for (const message of hungryMessages) { |
| 72 | + const response = await cat.response(message); |
| 73 | + expect(hungrySounds).toContain(response); |
| 74 | + } |
| 75 | + }); |
| 76 | + |
| 77 | + test("should respond with default sounds for unrecognized messages", async () => { |
| 78 | + const unknownMessages = ["テスト", "何これ", "xyz123"]; |
| 79 | + const defaultSounds = ["ニャー", "ニャン", "ミャー"]; |
| 80 | + |
| 81 | + for (const message of unknownMessages) { |
| 82 | + const response = await cat.response(message); |
| 83 | + expect(defaultSounds).toContain(response); |
| 84 | + } |
| 85 | + }); |
| 86 | + |
| 87 | + test("should handle empty string", async () => { |
| 88 | + const response = await cat.response(""); |
| 89 | + const defaultSounds = ["ニャー", "ニャン", "ミャー"]; |
| 90 | + expect(defaultSounds).toContain(response); |
| 91 | + }); |
| 92 | + |
| 93 | + test("should detect emotion from case-insensitive messages", async () => { |
| 94 | + const response1 = await cat.response("こんにちは"); |
| 95 | + const response2 = await cat.response("コンニチハ"); |
| 96 | + const greetingSounds = ["ニャッ", "ミャッ", "ニャ"]; |
| 97 | + |
| 98 | + expect(greetingSounds).toContain(response1); |
| 99 | + // response2 should be default since hiragana detection only works for lowercase |
| 100 | + const defaultSounds = ["ニャー", "ニャン", "ミャー"]; |
| 101 | + expect(defaultSounds).toContain(response2); |
| 102 | + }); |
| 103 | +}); |
0 commit comments