mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-05-10 03:00:06 -04:00
Improve swap copy testing and add new failing copy test
This commit is contained in:
28
inputs/passing/copyCounting/arraySwap.ts
Normal file
28
inputs/passing/copyCounting/arraySwap.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
//! test_output(0)
|
||||
|
||||
/// <reference path="../../../concept-code/vs.d.ts" />
|
||||
|
||||
export default function main() {
|
||||
return measure(true) - measure(false);
|
||||
}
|
||||
|
||||
function measure(doSwap: boolean) {
|
||||
const x = Debug.makeCopyCounter("x");
|
||||
|
||||
let arr: unknown[] = [x, "y", "z"];
|
||||
arr = swapFn(arr, 1, 2, doSwap);
|
||||
|
||||
return len(arr) + x.count;
|
||||
}
|
||||
|
||||
function swapFn(arr: unknown[], i: number, j: number, doSwap: boolean) {
|
||||
if (doSwap) {
|
||||
[arr[i], arr[j]] = [arr[j], arr[i]];
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
function len(arr: unknown[]) {
|
||||
return arr.length;
|
||||
}
|
||||
Reference in New Issue
Block a user