Improve swap copy testing and add new failing copy test

This commit is contained in:
Andrew Morris
2023-06-30 17:51:47 +10:00
parent 264b8dee40
commit 996ffc2df2
3 changed files with 57 additions and 20 deletions

View File

@@ -1,20 +0,0 @@
//! test_output(2)
// Should be: 0
/// <reference path="../../../concept-code/vs.d.ts" />
export default function main() {
return measure(true) - measure(false);
}
function measure(swap: boolean) {
const x = Debug.makeCopyCounter("x");
let arr = [x, "y", "z"];
if (swap) {
[arr[1], arr[2]] = [arr[2], arr[1]];
}
return x.count;
}

View File

@@ -0,0 +1,29 @@
//! test_output(1)
// Should be: 0
/// <reference path="../../../concept-code/vs.d.ts" />
export default function main() {
return measure(true) - measure(false);
}
function measure(doPush: boolean) {
const x = Debug.makeCopyCounter("x");
let arr: unknown[] = echo([x]);
if (doPush) {
arr = push(arr, "y");
}
return x.count;
}
function push<T>(x: T[], value: T) {
x.push(value);
return x;
}
function echo<T>(x: T) {
return x;
}