Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Math:gen_rngのテストを改善 #660

Merged
merged 3 commits into from
May 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3301,18 +3301,32 @@ describe('std', () => {
});

test.concurrent('gen_rng', async () => {
const res = await exe(`
@test(seed) {
let random = Math:gen_rng(seed)
return random(0 100)
// 2つのシード値から1~maxの乱数をn回生成して一致率を見る
const res = await exe(`
@test(seed1, seed2) {
let n = 100
let max = 100000
let threshold = 0.05
let random1 = Math:gen_rng(seed1)
let random2 = Math:gen_rng(seed2)
var same = 0
for n {
if random1(1, max) == random2(1, max) {
same += 1
}
}
let rate = same / n
if seed1 == seed2 { rate == 1 }
else { rate < threshold }
}
let seed1 = \`{Util:uuid()}\`
let seed2 = \`{Date:year()}\`
let test1 = if (test(seed1) == test(seed1)) {true} else {false}
let test2 = if (test(seed1) == test(seed2)) {true} else {false}
<: [test1 test2]
<: [
test(seed1, seed1)
test(seed1, seed2)
]
`)
eq(res, ARR([BOOL(true), BOOL(false)]));
eq(res, ARR([BOOL(true), BOOL(true)]));
});
});

Expand Down
Loading