1 Star 0 Fork 0

邓适存/entropy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
entropy.test.js 692 Bytes
一键复制 编辑 原始数据 按行查看 历史
邓适存 提交于 2024-10-06 16:08 . feat:作业提交
const { calculateEntropy, validateProbabilities } = require('./entropy');
// 测试熵计算
test('calculateEntropy works correctly', () => {
const probabilities = [0.5, 0.5];
const result = calculateEntropy(probabilities);
expect(result).toBeCloseTo(1, 3);
});
// 测试概率验证
test('validateProbabilities works correctly', () => {
const probabilities = [0.5, 0.5];
expect(() => validateProbabilities(probabilities)).not.toThrow();
});
test('validateProbabilities throws error for invalid probabilities', () => {
const invalidProbabilities = [0.5, 0.6];
expect(() => validateProbabilities(invalidProbabilities)).toThrow('概率总和必须为 1!');
});
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
NodeJS
1
https://gitee.com/dengdoris/entropy.git
git@gitee.com:dengdoris/entropy.git
dengdoris
entropy
entropy
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385