51 lines
968 B
Text
51 lines
968 B
Text
@arr_equal(arr1, arr2) {
|
|
if arr1.len != arr2.len {
|
|
return false
|
|
}
|
|
for let i,arr1.len {
|
|
if arr1[i] != arr2[i] {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
// TESTS
|
|
|
|
let unit_tests = []
|
|
|
|
@deftest(test_name, test_func) {
|
|
unit_tests.push({name: test_name, func: test_func})
|
|
}
|
|
|
|
deftest("arr_equal pos", @() {
|
|
return arr_equal([1, 2, 3], [1, 2, 3])
|
|
})
|
|
|
|
deftest("arr_equal neg element", @() {
|
|
return !arr_equal([1, 2, 3], [1, 2, 4])
|
|
})
|
|
|
|
deftest("arr_equal neg size", @() {
|
|
return !arr_equal([1, 2, 3], [1, 2])
|
|
})
|
|
|
|
@run_all_tests() {
|
|
print("Running unit tests...")
|
|
var fails = 0
|
|
each let test, unit_tests {
|
|
if !test.func() {
|
|
fails += 1
|
|
print(`Test {test.name} failed.`)
|
|
}
|
|
}
|
|
if fails == 0 {
|
|
print(`All {unit_tests.len} tests successful!`)
|
|
return true
|
|
}
|
|
print(`{fails}/{unit_tests.len} tests failed.`)
|
|
Mk:dialog("Load error", "An error occurred while loading the plugin. Please contact the script author.", "error")
|
|
return false
|
|
}
|
|
|
|
run_all_tests()
|