Created
August 3, 2024 11:39
-
-
Save freddiefujiwara/375ba26d488f821ff363feab6be61a4b to your computer and use it in GitHub Desktop.
https://www.coze.com/store/bot/7398851448076877832 で要求仕様: https://www.sessame.jp/workinggroup/WorkingGroup2/POT_Specification_v6.PDF を読み込んで自動生成させたコードとテストコード
This file contains hidden or 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
class Kettle { | |
constructor() { | |
this.temperature = 25; // 初期温度 | |
this.keepWarmMode = 'High'; // 初期保温モード | |
this.timer = 0; // 初期タイマー | |
this.isLocked = true; // 初期状態はロック | |
this.isBoiling = false; // 初期状態は沸騰していない | |
} | |
setTemperature(temp) { | |
this.temperature = temp; | |
} | |
toggleLock() { | |
if (!this.isBoiling) { | |
this.isLocked = !this.isLocked; | |
} | |
} | |
startBoiling() { | |
this.isBoiling = true; | |
this.setTemperature(100); // 沸騰温度 | |
} | |
stopBoiling() { | |
this.isBoiling = false; | |
} | |
setKeepWarmMode() { | |
const modes = ['High', 'Economy', 'Milk']; | |
const currentIndex = modes.indexOf(this.keepWarmMode); | |
this.keepWarmMode = modes[(currentIndex + 1) % modes.length]; | |
this.updateTemperature(); | |
} | |
updateTemperature() { | |
const temperatures = { | |
'High': 98, | |
'Economy': 90, | |
'Milk': 60 | |
}; | |
this.temperature = temperatures[this.keepWarmMode]; | |
} | |
startTimer() { | |
this.timer += 1; // 1分追加 | |
} | |
dispenseWater() { | |
if (!this.isLocked && !this.isBoiling) { | |
console.log('Water dispensed'); | |
} else { | |
console.log('Cannot dispense water: Locked or Boiling'); | |
} | |
} | |
} | |
module.exports = Kettle; |
This file contains hidden or 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
const Kettle = require('./Kettle'); | |
describe('Kettle', () => { | |
let kettle; | |
beforeEach(() => { | |
kettle = new Kettle(); | |
console.log = jest.fn(); // console.logのモック | |
}); | |
test('初期状態の確認', () => { | |
expect(kettle.temperature).toBe(25); | |
expect(kettle.keepWarmMode).toBe('High'); | |
expect(kettle.timer).toBe(0); | |
expect(kettle.isLocked).toBe(true); | |
expect(kettle.isBoiling).toBe(false); | |
}); | |
test('ロックの切り替え', () => { | |
kettle.toggleLock(); | |
expect(kettle.isLocked).toBe(false); | |
kettle.toggleLock(); | |
expect(kettle.isLocked).toBe(true); | |
}); | |
test('沸騰の開始と停止', () => { | |
kettle.startBoiling(); | |
expect(kettle.isBoiling).toBe(true); | |
expect(kettle.temperature).toBe(100); | |
kettle.stopBoiling(); | |
expect(kettle.isBoiling).toBe(false); | |
}); | |
test('保温モードの切り替え', () => { | |
kettle.setKeepWarmMode(); | |
expect(kettle.keepWarmMode).toBe('Economy'); | |
expect(kettle.temperature).toBe(90); | |
kettle.setKeepWarmMode(); | |
expect(kettle.keepWarmMode).toBe('Milk'); | |
expect(kettle.temperature).toBe(60); | |
kettle.setKeepWarmMode(); | |
expect(kettle.keepWarmMode).toBe('High'); | |
expect(kettle.temperature).toBe(98); | |
}); | |
test('タイマーの追加', () => { | |
kettle.startTimer(); | |
expect(kettle.timer).toBe(1); | |
kettle.startTimer(); | |
expect(kettle.timer).toBe(2); | |
}); | |
test('水の排出', () => { | |
kettle.toggleLock(); | |
kettle.dispenseWater(); // ロック解除 | |
expect(console.log).toHaveBeenCalledWith('Water dispensed'); | |
kettle.isBoiling = true; | |
kettle.dispenseWater(); // 沸騰中 | |
expect(console.log).toHaveBeenCalledWith('Cannot dispense water: Locked or Boiling'); | |
kettle.toggleLock(); // 再度ロック | |
kettle.dispenseWater(); // ロック中 | |
expect(console.log).toHaveBeenCalledWith('Cannot dispense water: Locked or Boiling'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment