-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from queenochaos/dev
Minor patches
- Loading branch information
Showing
2 changed files
with
30 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { GachaMachine } from "./mod.ts"; | ||
import { assertAlmostEquals } from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
|
||
import { Duration } from "https://deno.land/x/durationjs@v3.1.1/mod.ts"; | ||
import { Duration } from "https://deno.land/x/durationjs@v4.0.0/mod.ts"; | ||
|
||
import pokemon from "./testdata/pokemon.json" assert { type: "json" }; | ||
|
||
function countDupes(arr: string[]): Record<string, number> { | ||
let items: Record<string, number> = {}; | ||
arr.forEach((v, i) => { | ||
const items: Record<string, number> = {}; | ||
arr.forEach((v) => { | ||
if (items[v]) items[v]++; | ||
else items[v] = 1; | ||
}); | ||
|
@@ -54,39 +54,40 @@ Deno.test("Range Check", () => { | |
const pk = pokemon.find((y) => y.id === Number(x[0])); | ||
return { name: pk?.name, count: x[1], tier: pk?.tier }; | ||
}).sort((a, b) => a.count - b.count).reverse().forEach((x) => { | ||
if (x.tier === "normal") assertAlmostEquals(x.count / 10000, 0.67, 4e-2); | ||
if (x.tier === "normal") assertAlmostEquals(x.count / 10000, 0.67, 1e-1); | ||
else if (x.tier === "legendary") { | ||
assertAlmostEquals(x.count / 10000, 0.26, 4e-2); | ||
} else if (x.tier === "mythic") { | ||
assertAlmostEquals(x.count / 10000, 0.03, 4e-2); | ||
} | ||
}); | ||
}); | ||
|
||
Deno.test("Time Check", () => { | ||
assertAlmostEquals((timeRoll - timeInit) / 1000, 1.56, 1e-1) | ||
}) | ||
// TESTS END | ||
|
||
console.log("-----REPORT-----"); | ||
console.log( | ||
"Time taken to configure:", | ||
Duration.between(timeConfig, timeStart).stringify( | ||
Duration.between(timeConfig, timeStart).toShortString( | ||
["s", "ms", "us", "ns"], | ||
true, | ||
), | ||
); | ||
console.log( | ||
"Time taken to setup machine:", | ||
Duration.between(timeConfig, timeInit).stringify( | ||
Duration.between(timeConfig, timeInit).toShortString( | ||
["s", "ms", "us", "ns"], | ||
true, | ||
), | ||
); | ||
console.log( | ||
"Time taken to roll 1000000 items:", | ||
Duration.between(timeInit, timeRoll).stringify(["s", "ms", "us", "ns"], true), | ||
Duration.between(timeInit, timeRoll).toShortString(["s", "ms", "us", "ns"]), | ||
); | ||
console.log( | ||
"Time taken to reduce data into result:", | ||
Duration.between(timeReduce, timeRoll).stringify( | ||
Duration.between(timeReduce, timeRoll).toShortString( | ||
["s", "ms", "us", "ns"], | ||
true, | ||
), | ||
); |