You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.5 KiB
42 lines
1.5 KiB
//测试随机选择功能
|
|
const weightedRandomSelection = require('./script'); // 假设你的函数在script.js中导出
|
|
|
|
describe('weightedRandomSelection', () => {
|
|
test('should return a student from the list', () => {
|
|
const students = [
|
|
{ name: 'Alice', points: 1 },
|
|
{ name: 'Bob', points: 2 },
|
|
{ name: 'Charlie', points: 3 }
|
|
];
|
|
const selectedStudent = weightedRandomSelection(students);
|
|
expect(students).toContainEqual(selectedStudent);
|
|
});
|
|
|
|
test('should return a student with higher points more frequently', () => {
|
|
const students = [
|
|
{ name: 'Alice', points: 1 },
|
|
{ name: 'Bob', points: 10 }
|
|
];
|
|
const results = { 'Alice': 0, 'Bob': 0 };
|
|
for (let i = 0; i < 1000; i++) {
|
|
const selectedStudent = weightedRandomSelection(students);
|
|
results[selectedStudent.name]++;
|
|
}
|
|
expect(results['Bob']).toBeGreaterThan(results['Alice']);
|
|
});
|
|
});
|
|
//测试文件上传处理
|
|
const readExcel = require('./script'); // 假设你的函数在script.js中导出
|
|
|
|
describe('readExcel', () => {
|
|
test('should parse Excel file and return student list', () => {
|
|
const file = new Blob([/* Excel file data */], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
|
|
return readExcel(file).then(students => {
|
|
expect(students).toEqual([
|
|
{ name: 'Alice', points: 1 },
|
|
{ name: 'Bob', points: 2 }
|
|
]);
|
|
});
|
|
});
|
|
});
|