Convert javascript_arrays.i example into testcase

This commit is contained in:
William S Fulton 2021-03-06 10:55:47 +00:00
commit 227614056b
9 changed files with 53 additions and 52 deletions

View file

@ -16,6 +16,9 @@ top_builddir = @top_builddir@
C_TEST_CASES += \
ccomplextest \
CPP_TEST_CASES += \
javascript_lib_arrays \
SWIGEXE = $(top_builddir)/swig
SWIG_LIB_DIR = $(top_srcdir)/Lib

View file

@ -0,0 +1,20 @@
var javascript_lib_arrays = require("javascript_lib_arrays");
var arr = [1, 2, 3, 4, 5];
function check(a, b) {
if (a !== b) {
throw new Error("Not equal: " + a + " " + b)
}
}
function check_array(a, b) {
if (a.length != b.length)
throw new Error("Array length mismatch " + a.length + " " + b.length)
if (!a.every(function(element, index) { return element === b[index]; }))
throw new Error("Arrays don't match a:" + a + " b:" + b)
}
check(15, javascript_lib_arrays.sum1(arr, arr.length));
check(6, javascript_lib_arrays.sum2(arr));
check_array([1, 2, 3, 4], javascript_lib_arrays.data3)