mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-04-18 03:00:27 -04:00
Improve swap copy testing and add new failing copy test
This commit is contained in:
@@ -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;
|
||||
}
|
||||
29
inputs/failing/copyCounting/externalMethod.ts
Normal file
29
inputs/failing/copyCounting/externalMethod.ts
Normal 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;
|
||||
}
|
||||
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