feat: complete placement analysis workflow
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { maximumWeightMatching } from './maximum-weight-matching.ts';
|
||||
|
||||
test('전체 합이 가장 큰 일대일 배치를 선택한다', () => {
|
||||
const matches = maximumWeightMatching([
|
||||
[9, 8, 1],
|
||||
[8, 1, 1]
|
||||
]);
|
||||
|
||||
assert.deepEqual(matches.map(({ rowIndex, columnIndex }) => [rowIndex, columnIndex]).sort(), [[0, 1], [1, 0]]);
|
||||
assert.equal(matches.reduce((sum, match) => sum + match.weight, 0), 16);
|
||||
});
|
||||
|
||||
test('카드 수가 슬롯보다 많아도 각 슬롯과 카드를 한 번만 사용한다', () => {
|
||||
const matches = maximumWeightMatching([
|
||||
[7, 0],
|
||||
[6, 5],
|
||||
[0, 9]
|
||||
]);
|
||||
|
||||
assert.equal(matches.length, 2);
|
||||
assert.equal(new Set(matches.map((match) => match.rowIndex)).size, 2);
|
||||
assert.equal(new Set(matches.map((match) => match.columnIndex)).size, 2);
|
||||
assert.equal(matches.reduce((sum, match) => sum + match.weight, 0), 16);
|
||||
});
|
||||
|
||||
test('효과가 없는 배치는 결과에서 제외한다', () => {
|
||||
assert.deepEqual(maximumWeightMatching([[0, 0]]), []);
|
||||
});
|
||||
Reference in New Issue
Block a user