二七王:SeatMap 座位号显式校验,去掉恒真断言
- toDisplay 此前不校验入参:toDisplay(seat, undefined) 会算出 NaN,NaN 既不等于 0
也不等于 1,最后落到 return 'LEFT'——一个看起来很合理的错误答案。现与兄弟方法
toSeat 一样对非 0/1/2 显式抛错;toSeat 的 mySeat 同样校验(否则算出 NaN 座位号)。
补 8 条反面用例 + 1 条「合法组合不被误伤」的正面用例。
- test_cardcodec.js 删掉 t.eq('deck1/deck2 全部同帧', true, true) 这条恒真断言,
改为收集不匹配项后断言为空——恒真断言在上面的循环被删掉后仍会 PASS。
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -13,16 +13,27 @@ var EQW_SeatMap = EQW_SeatMap || {
|
||||
LEFT: 'LEFT',
|
||||
RIGHT: 'RIGHT',
|
||||
|
||||
//服务端座位 → 显示位键
|
||||
//服务端座位 → 显示位键。
|
||||
//入参必须是 0/1/2:非法值(undefined / 3 / 小数)会算出 NaN,NaN 既不等于 0 也不等于 1,
|
||||
//最后落到 return 'LEFT'——一个看起来很合理的错误答案。故与 toSeat 一样显式抛错
|
||||
toDisplay: function (seat, mySeat) {
|
||||
this._requireSeat(seat, 'seat');
|
||||
this._requireSeat(mySeat, 'mySeat');
|
||||
var d = ((seat - mySeat) % 3 + 3) % 3;
|
||||
if (d === 0) { return 'SELF'; }
|
||||
if (d === 1) { return 'RIGHT'; }
|
||||
return 'LEFT';
|
||||
},
|
||||
|
||||
//显示位键 → 服务端座位
|
||||
_requireSeat: function (v, name) {
|
||||
if (v !== 0 && v !== 1 && v !== 2) {
|
||||
throw new Error('[EQW_SeatMap] ' + name + ' 必须是 0/1/2,收到: ' + v);
|
||||
}
|
||||
},
|
||||
|
||||
//显示位键 → 服务端座位。mySeat 同样必须是 0/1/2(否则算出 NaN 座位号)
|
||||
toSeat: function (displayKey, mySeat) {
|
||||
this._requireSeat(mySeat, 'mySeat');
|
||||
if (displayKey === 'SELF') { return mySeat; }
|
||||
if (displayKey === 'RIGHT') { return (mySeat + 1) % 3; }
|
||||
if (displayKey === 'LEFT') { return (mySeat + 2) % 3; }
|
||||
|
||||
Reference in New Issue
Block a user