From 8a047ded51fd2ab09f36d165c163d1c2ed8817ae Mon Sep 17 00:00:00 2001 From: chengyuli Date: Thu, 11 Sep 2025 15:54:55 +0800 Subject: [PATCH] Container check empty Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/ICX827 Signed-off-by: chengyuli Change-Id: I5104f51839b800c44270d8ba66f63b416cb08158 --- .../plugins/ets/sdk/api/@ohos.util.Deque.ets | 34 +++++------- .../ets/sdk/api/@ohos.util.LinkedList.ets | 36 +++++-------- .../plugins/ets/sdk/api/@ohos.util.List.ets | 6 +-- .../plugins/ets/sdk/api/@ohos.util.Stack.ets | 26 +++++++-- .../ets/sdk/api/@ohos.util.TreeMap.ets | 54 ++++++++++++------- .../ets/sdk/api/@ohos.util.TreeSet.ets | 43 +++++++++------ .../plugins/ets/stdlib/escompat/Array.ets | 2 +- .../ets/stdlib/std/core/BuiltinArray.ets | 16 +++--- .../ets/templates/stdlib/Array_common.erb | 2 +- .../array_index16.ets | 2 +- .../ets/tests/ets_es_checked/array.yaml | 3 -- .../ets_func_tests/escompat/ArrayTest5.ets | 37 +++++++++++++ .../escompat/RegExpExecArrayTest.ets | 1 - .../std/containers/TrivialArrayTest.ets | 6 ++- .../DequeGetFirstGetLastIteratorTests.ets | 13 ++++- .../util/Deque/DequeHasPopForEachTests.ets | 13 ++++- .../api/@ohos/util/Deque/DequeHasPopTest.ets | 34 +++++++++--- .../LinkedList/LinkedListGetFirstLastTest.ets | 13 ++++- .../LinkedList/LinkedListInsertHasGetTest.ets | 8 ++- .../@ohos/util/LinkedList/LinkedListTest.ets | 6 ++- .../ListGetFirstLastEmptyIteratorTests.ets | 13 ++++- .../List/ListHasGetGetLastIndexOfTests.ets | 7 ++- .../ets_sdk/api/@ohos/util/List/ListTests.ets | 6 ++- .../@ohos/util/Queue/QueueAddPopGetTest.ets | 15 ++++-- .../Queue/QueueCreateLengthAddPopTests.ets | 7 ++- .../QueueForEachGetFirstIteratorTests.ets | 7 ++- .../StackCreateLengthPushPopPeekTests.ets | 13 ++++- .../@ohos/util/Stack/StackPushPopPeekTest.ets | 15 ++++-- ...TreeMapGetFirstKeyGetLastKeyRemoveTest.ets | 15 ++++-- .../TreeMapGetFirstKeyGetLastKeyTest.ets | 15 ++++-- .../TreeMapGetLowerKeyGetHigherKeyTest.ets | 29 +++++++--- ...eeMapSetAllGetLowerKeyGetHigherKeyTest.ets | 43 ++++++++++----- .../TreeSetGetFirstValueGetLastValueTest.ets | 15 ++++-- ...etFirstValuleGetLastValueAddRemoveTest.ets | 15 ++++-- ...etGetLowerValueGetHigherValueClearTest.ets | 43 ++++++++++----- ...TreeSetGetLowerValueGetHigherValueTest.ets | 29 +++++++--- .../TreeSetPopFirstPopLastIteratorTest.ets | 43 ++++++++++----- .../TreeSetPopFirstPopLastValuesTest.ets | 41 ++++++++++---- .../escompat/escompat_Array_misc.ets | 21 -------- 39 files changed, 510 insertions(+), 237 deletions(-) diff --git a/static_core/plugins/ets/sdk/api/@ohos.util.Deque.ets b/static_core/plugins/ets/sdk/api/@ohos.util.Deque.ets index a738a23922..fb0b2de84a 100644 --- a/static_core/plugins/ets/sdk/api/@ohos.util.Deque.ets +++ b/static_core/plugins/ets/sdk/api/@ohos.util.Deque.ets @@ -59,38 +59,30 @@ export default class Deque implements Iterable, JsonReplacer { /** * Returns the first element of the deque without removing it. * - * @returns {T | undefined} The first element of the deque if it exists, otherwise `undefined` if the deque is empty. + * @returns {T} The first element of the deque if it exists, otherwise `undefined` if the deque is empty. */ - public getFirst(): T | undefined { - if (this.isEmpty()) { - return undefined; - } - + public getFirst(): T { + this.checkEmptyContainer(); return this.buffer[this.front]; } /** * Returns the last element of the deque without removing it. * - * @returns {T | undefined} The last element of the deque if it exists, otherwise `undefined` if the deque is empty. + * @returns {T} The last element of the deque if it exists, otherwise `undefined` if the deque is empty. */ - public getLast(): T | undefined { - if (this.isEmpty()) { - return undefined; - } - + public getLast(): T { + this.checkEmptyContainer(); return this.buffer[(this.rear - 1 + this.capacity) % this.capacity]; } /** * Removes and returns the first element from the deque. * - * @returns {T | undefined} The first element of the deque if it exists, otherwise `undefined` if the deque is empty. + * @returns {T} The first element of the deque if it exists, otherwise `undefined` if the deque is empty. */ - public popFirst(): T | undefined { - if (this.isEmpty()) { - return undefined; - } + public popFirst(): T { + this.checkEmptyContainer(); let firstElement: T = this.buffer[this.front]; this.front = (this.front + 1) % this.capacity; @@ -101,12 +93,10 @@ export default class Deque implements Iterable, JsonReplacer { /** * Removes and returns the last element from the deque. * - * @returns {T | undefined} The last element of the deque if it exists, otherwise `undefined` if the deque is empty. + * @returns {T} The last element of the deque if it exists, otherwise `undefined` if the deque is empty. */ - public popLast(): T | undefined { - if (this.isEmpty()) { - return undefined; - } + public popLast(): T { + this.checkEmptyContainer(); this.rear = (this.rear - 1 + this.capacity) % this.capacity; let element: T = this.buffer[this.rear]; diff --git a/static_core/plugins/ets/sdk/api/@ohos.util.LinkedList.ets b/static_core/plugins/ets/sdk/api/@ohos.util.LinkedList.ets index b66db8e7a8..a8f5be5a7c 100644 --- a/static_core/plugins/ets/sdk/api/@ohos.util.LinkedList.ets +++ b/static_core/plugins/ets/sdk/api/@ohos.util.LinkedList.ets @@ -185,14 +185,11 @@ export class LinkedList implements Iterable, JsonReplacer { * @param index The index of the element to get. * @returns The element at the specified index, or undefined if the index is out of range. */ - public get(index: int): T | undefined { + public get(index: int): T { this.checkIndexType(index); - - if (index >= 0 && index < this.elementNum) { - let currentNode: ListNode | undefined = this.getNode(index); - return currentNode!.element; - } - return undefined; + this.checkIndex(index, this.elementNum - 1); + let currentNode: ListNode | undefined = this.getNode(index); + return currentNode!.element; } /** @@ -200,11 +197,9 @@ export class LinkedList implements Iterable, JsonReplacer { * * @returns The first element of type `T` if the list is not empty, otherwise `undefined`. */ - public getFirst(): T | undefined { - if (this.head !== undefined) { - return this.head!.element; - } - return undefined; + public getFirst(): T { + this.checkEmptyContainer(OutOfBoundsErrorCodeId); + return this.head!.element; } /** @@ -230,11 +225,9 @@ export class LinkedList implements Iterable, JsonReplacer { * * @returns The last element of type `T` if the list is not empty, otherwise `undefined`. */ - public getLast(): T | undefined { - if (this.tail !== undefined) { - return this.tail!.element; - } - return undefined; + public getLast(): T { + this.checkEmptyContainer(OutOfBoundsErrorCodeId); + return this.tail!.element; } /** @@ -432,17 +425,14 @@ export class LinkedList implements Iterable, JsonReplacer { * @param element The new element. * @returns The replaced element, or undefined if the index is out of range. */ - public set(index: int, element: T): T | undefined { + public set(index: int, element: T): T { this.checkIndexType(index); this.checkEmptyContainer(OutOfBoundsErrorCodeId); this.checkIndex(index, this.length - 1); let currentNode: ListNode | undefined = this.getNode(index); - if (currentNode !== undefined) { - currentNode!.element = element; - return currentNode!.element; - } - return undefined; + currentNode!.element = element; + return element; } /** diff --git a/static_core/plugins/ets/sdk/api/@ohos.util.List.ets b/static_core/plugins/ets/sdk/api/@ohos.util.List.ets index 34e2ea5480..11657c3712 100644 --- a/static_core/plugins/ets/sdk/api/@ohos.util.List.ets +++ b/static_core/plugins/ets/sdk/api/@ohos.util.List.ets @@ -288,11 +288,7 @@ export class List implements Iterable, JsonReplacer { * @returns The previous element at the specified index, or undefined if the index is out of range. * @throws BusinessError if the index is out of range. */ - public set(index: int, element: T): T | undefined { - this.checkIndexType(index); - this.checkEmptyContainer(); - this.checkIndex(index, this.length - 1); - + public set(index: int, element: T): T { return this.buffer.set(index, element); } diff --git a/static_core/plugins/ets/sdk/api/@ohos.util.Stack.ets b/static_core/plugins/ets/sdk/api/@ohos.util.Stack.ets index 16df6504d1..1187e7558d 100644 --- a/static_core/plugins/ets/sdk/api/@ohos.util.Stack.ets +++ b/static_core/plugins/ets/sdk/api/@ohos.util.Stack.ets @@ -13,7 +13,19 @@ * limitations under the License. */ - export type StackForEachCb = (value: T, index: int, stack: Stack) => void; +import { BusinessError } from "@ohos.base"; + +const OutOfBoundsErrorCodeId: int = 10200001; + +function createBusinessError(code: int, message: string) { + let err = new BusinessError(); + err.code = code; + err.name = 'BusinessError'; + err.message = message; + return err; +} + +export type StackForEachCb = (value: T, index: int, stack: Stack) => void; export class Stack implements Iterable { private buffer: Array; @@ -33,8 +45,9 @@ export class Stack implements Iterable { * Retrieves the top element in the Stack without removing it. * @returns The top element in the Stack, or undefined if the Stack is empty. */ - public peek(): T | undefined { - return this.buffer.length == 0 ? undefined : this.buffer[this.length - 1]; + public peek(): T { + this.checkEmptyContainer(); + return this.buffer[this.length - 1]; } /** @@ -51,6 +64,7 @@ export class Stack implements Iterable { * @returns The first element in the Stack, or undefined if the Stack is empty. */ public pop(): T | undefined { + this.checkEmptyContainer(); return this.buffer.pop(); } @@ -95,4 +109,10 @@ export class Stack implements Iterable { public override $_iterator(): IterableIterator { return this.buffer.$_iterator(); } + + private checkEmptyContainer(): void { + if (this.isEmpty()) { + throw createBusinessError(OutOfBoundsErrorCodeId, `Container is empty`); + } + } } diff --git a/static_core/plugins/ets/sdk/api/@ohos.util.TreeMap.ets b/static_core/plugins/ets/sdk/api/@ohos.util.TreeMap.ets index 0d02963f5e..29add740ae 100644 --- a/static_core/plugins/ets/sdk/api/@ohos.util.TreeMap.ets +++ b/static_core/plugins/ets/sdk/api/@ohos.util.TreeMap.ets @@ -13,8 +13,20 @@ * limitations under the License. */ - export type TreeMapForEachCb = (value: V, key: K, map: TreeMap) => void; - export type TreeMapComparator = (firstValue: K, secondValue: K) => double; +import { BusinessError } from "@ohos.base"; + +const OutOfBoundsErrorCodeId: int = 10200001; + +function createBusinessError(code: int, message: string) { + let err = new BusinessError(); + err.code = code; + err.name = 'BusinessError'; + err.message = message; + return err; +} + +export type TreeMapForEachCb = (value: V, key: K, map: TreeMap) => void; +export type TreeMapComparator = (firstValue: K, secondValue: K) => double; export interface ReadonlyTreeMap extends Iterable<[K, V]> { /** @@ -372,16 +384,13 @@ export default class TreeMap implements ReadonlyTreeMap { * * @returns the key of the first element if exists */ - getFirstKey(): K | undefined { - if (this.rootEntry !== undefined) { - let entry = this.rootEntry!; - while (entry.left !== undefined) { - entry = entry.left!; - } - return entry.key; - } else { - return undefined; + getFirstKey(): K { + this.checkEmptyContainer(); + let entry = this.rootEntry!; + while (entry.left !== undefined) { + entry = entry.left!; } + return entry.key; } /** @@ -392,6 +401,7 @@ export default class TreeMap implements ReadonlyTreeMap { * @returns the higher key of the given key's element if exists or undefined */ getHigherKey(key: K): K | undefined { + this.checkEmptyContainer(); let resultEntry: TreeMapEntry | undefined = undefined; let entry = this.rootEntry; @@ -416,16 +426,13 @@ export default class TreeMap implements ReadonlyTreeMap { * * @returns the key of the last element if exists */ - getLastKey(): K | undefined { - if (this.rootEntry !== undefined) { - let entry = this.rootEntry!; - while (entry.right !== undefined) { - entry = entry.right!; - } - return entry.key; - } else { - return undefined; + getLastKey(): K { + this.checkEmptyContainer(); + let entry = this.rootEntry!; + while (entry.right !== undefined) { + entry = entry.right!; } + return entry.key; } /** @@ -436,6 +443,7 @@ export default class TreeMap implements ReadonlyTreeMap { * @returns the lower key of the given key's element if exists or undefined */ getLowerKey(key: K): K | undefined { + this.checkEmptyContainer(); let resultEntry: TreeMapEntry | undefined = undefined; let entry = this.rootEntry; @@ -777,4 +785,10 @@ export default class TreeMap implements ReadonlyTreeMap { override $_iterator(): IterableIterator<[K, V]> { return this.entries(); } + + private checkEmptyContainer(): void { + if (this.isEmpty()) { + throw createBusinessError(OutOfBoundsErrorCodeId, `Container is empty`); + } + } } diff --git a/static_core/plugins/ets/sdk/api/@ohos.util.TreeSet.ets b/static_core/plugins/ets/sdk/api/@ohos.util.TreeSet.ets index 874ec1a1ce..1304d3a8b8 100644 --- a/static_core/plugins/ets/sdk/api/@ohos.util.TreeSet.ets +++ b/static_core/plugins/ets/sdk/api/@ohos.util.TreeSet.ets @@ -14,6 +14,17 @@ */ import TreeMap from '@ohos.util.TreeMap'; +import { BusinessError } from "@ohos.base"; + +const OutOfBoundsErrorCodeId: int = 10200001; + +function createBusinessError(code: int, message: string) { + let err = new BusinessError(); + err.code = code; + err.name = 'BusinessError'; + err.message = message; + return err; +} export type TreeSetForEachCb = (value: T, key: T, set: TreeSet) => void; export type TreeSetComparator = (firstValue: T, secondValue: T) => double; @@ -199,14 +210,11 @@ export class TreeSet implements ReadonlyTreeSet { * * @returns the value of the first element in the TreeSet if exists */ - popFirst(): T | undefined { - if (this.isEmpty()) { - return undefined; - } else { - const res = this.getFirstValue()!; - this.remove(res); - return res; - } + popFirst(): T { + this.checkEmptyContainer(); + const res = this.getFirstValue()!; + this.remove(res); + return res; } /** @@ -214,14 +222,11 @@ export class TreeSet implements ReadonlyTreeSet { * * @returns the value of the last element in the TreeSet if exists */ - popLast(): T | undefined { - if (this.isEmpty()) { - return undefined; - } else { - const res = this.getLastValue()!; - this.remove(res); - return res; - } + popLast(): T { + this.checkEmptyContainer(); + const res = this.getLastValue()!; + this.remove(res); + return res; } /** @@ -248,4 +253,10 @@ export class TreeSet implements ReadonlyTreeSet { override $_iterator(): IterableIterator { return this.treeMap.keys(); } + + private checkEmptyContainer(): void { + if (this.isEmpty()) { + throw createBusinessError(OutOfBoundsErrorCodeId, `Container is empty`); + } + } } diff --git a/static_core/plugins/ets/stdlib/escompat/Array.ets b/static_core/plugins/ets/stdlib/escompat/Array.ets index 9935fe6816..59360e7823 100644 --- a/static_core/plugins/ets/stdlib/escompat/Array.ets +++ b/static_core/plugins/ets/stdlib/escompat/Array.ets @@ -992,7 +992,7 @@ export class Array implements ReadonlyArray, Iterable { } if (k < 0 || k >= len) { - return undefined; + throw new RangeError("Invalid index"); } return this.$_get_unsafe(k); diff --git a/static_core/plugins/ets/stdlib/std/core/BuiltinArray.ets b/static_core/plugins/ets/stdlib/std/core/BuiltinArray.ets index 9934928668..ba8c167f7e 100644 --- a/static_core/plugins/ets/stdlib/std/core/BuiltinArray.ets +++ b/static_core/plugins/ets/stdlib/std/core/BuiltinArray.ets @@ -151,7 +151,7 @@ export function at(self: FixedArray, index: int): Boolean | undefined { } if (k < 0 || k >= len) { - return undefined; + throw new RangeError("Invalid index"); } return self[k]; @@ -1084,7 +1084,7 @@ export function at(self: FixedArray, index: int): Byte | undefined { } if (k < 0 || k >= len) { - return undefined; + throw new RangeError("Invalid index"); } return self[k]; @@ -2017,7 +2017,7 @@ export function at(self: FixedArray, index: int): Short | undefined { } if (k < 0 || k >= len) { - return undefined; + throw new RangeError("Invalid index"); } return self[k]; @@ -2950,7 +2950,7 @@ export function at(self: FixedArray, index: int): Int | undefined { } if (k < 0 || k >= len) { - return undefined; + throw new RangeError("Invalid index"); } return self[k]; @@ -3883,7 +3883,7 @@ export function at(self: FixedArray, index: int): Long | undefined { } if (k < 0 || k >= len) { - return undefined; + throw new RangeError("Invalid index"); } return self[k]; @@ -4816,7 +4816,7 @@ export function at(self: FixedArray, index: int): Float | undefined { } if (k < 0 || k >= len) { - return undefined; + throw new RangeError("Invalid index"); } return self[k]; @@ -5757,7 +5757,7 @@ export function at(self: FixedArray, index: int): Double | undefined { } if (k < 0 || k >= len) { - return undefined; + throw new RangeError("Invalid index"); } return self[k]; @@ -6698,7 +6698,7 @@ export function at(self: FixedArray, index: int): Char | undefined { } if (k < 0 || k >= len) { - return undefined; + throw new RangeError("Invalid index"); } return self[k]; diff --git a/static_core/plugins/ets/templates/stdlib/Array_common.erb b/static_core/plugins/ets/templates/stdlib/Array_common.erb index ef32888ad9..3b80625e6f 100644 --- a/static_core/plugins/ets/templates/stdlib/Array_common.erb +++ b/static_core/plugins/ets/templates/stdlib/Array_common.erb @@ -84,7 +84,7 @@ } if (k < 0 || k >= len) { - return undefined; + throw new RangeError("Invalid index"); } return <%= get_unsafe.(this, 'k') %>; diff --git a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/01.array_indexing_expression/array_index16.ets b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/01.array_indexing_expression/array_index16.ets index 36715b06be..fafe6b127f 100644 --- a/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/01.array_indexing_expression/array_index16.ets +++ b/static_core/plugins/ets/tests/ets-templates/07.expressions/12.indexing_expression/01.array_indexing_expression/array_index16.ets @@ -24,6 +24,6 @@ function main(): void { if (first !== undefined) { // Safe to use `first` as a number } else { - // Handle the case where the array is empty + // Handle the case where the Invalid index } } \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets_es_checked/array.yaml b/static_core/plugins/ets/tests/ets_es_checked/array.yaml index 0ec8309686..0e6277d712 100644 --- a/static_core/plugins/ets/tests/ets_es_checked/array.yaml +++ b/static_core/plugins/ets/tests/ets_es_checked/array.yaml @@ -60,9 +60,6 @@ sub: ((): void => { self.length = pars })() params: - paramOf '0', '-1' - - method: at - params: - - paramOf(*default_inds) - method: "with" params: - paramOf(*default_inds) diff --git a/static_core/plugins/ets/tests/ets_func_tests/escompat/ArrayTest5.ets b/static_core/plugins/ets/tests/ets_func_tests/escompat/ArrayTest5.ets index 4469887d8a..fdf1aff074 100644 --- a/static_core/plugins/ets/tests/ets_func_tests/escompat/ArrayTest5.ets +++ b/static_core/plugins/ets/tests/ets_func_tests/escompat/ArrayTest5.ets @@ -21,6 +21,7 @@ function main(): int { failures += check((): int => { return length() }, "length"); failures += check((): int => { return shiftUnshift() }, "shiftUnshift"); failures += check((): int => { return pushPop() }, "pushPop"); + failures += check((): int => { return at() }, "at"); return check(failures, "All tests run"); } @@ -126,6 +127,42 @@ function pushPop(): int { }) } +function at(): int { + return check(() => new Array, (a: Array) => { + try { + arr.at(50) + return fail; + } catch (e: Error) { + arktest.assertEQ(e.message, "Invalid index"); + } + a.pushECMA(1, 2, 3, 4, 5) + if (a.length != 5) { + return fail; + } + for (let i = 5; i >= 0; i--) { + if (a.at(i)! != i) { + return fail + } + } + try { + arr.at(arr.length); + return fail; + } catch (e: Error) { + arktest.assertEQ(e.message, "Invalid index"); + } + try { + arr.at(-arr.length - 1); + return fail; + } catch (e: Error) { + arktest.assertEQ(e.message, "Invalid index"); + } + if (arr.at(-arr.length)! != arr[0] || arr.at(-arr.length + 1)! != arr[1]) { + return fail; + } + return success; + }) +} + function check(result: int, message: String): int { if (result == success) { diff --git a/static_core/plugins/ets/tests/ets_func_tests/escompat/RegExpExecArrayTest.ets b/static_core/plugins/ets/tests/ets_func_tests/escompat/RegExpExecArrayTest.ets index 90fae40c59..c4e8ee4c84 100644 --- a/static_core/plugins/ets/tests/ets_func_tests/escompat/RegExpExecArrayTest.ets +++ b/static_core/plugins/ets/tests/ets_func_tests/escompat/RegExpExecArrayTest.ets @@ -504,7 +504,6 @@ function testAt(): void { arktest.assertEQ(match.at(0), "a", "at positive index"); arktest.assertEQ(match.at(-1), "c", "at negative index"); - arktest.assertEQ(match.at(10), undefined, "at out of bounds"); } /** diff --git a/static_core/plugins/ets/tests/ets_func_tests/std/containers/TrivialArrayTest.ets b/static_core/plugins/ets/tests/ets_func_tests/std/containers/TrivialArrayTest.ets index bd459d5b28..6c89d78d59 100644 --- a/static_core/plugins/ets/tests/ets_func_tests/std/containers/TrivialArrayTest.ets +++ b/static_core/plugins/ets/tests/ets_func_tests/std/containers/TrivialArrayTest.ets @@ -23,7 +23,11 @@ function main(): void { for (let i = 0; i < 30; i++) { arktest.assertTrue( arr.includes(i, undefined)) } - arktest.assertEQ( arr.at(50), undefined) + try { + arr.at(50) + } catch (e: Error) { + arktest.assertEQ(e.message, "Invalid index"); + } arktest.assertEQ( arr.length, 30) for (let i = 0; i < 30; i++) { arktest.assertEQ( arr.pop()!, 30 - 1 - i) diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Deque/DequeGetFirstGetLastIteratorTests.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Deque/DequeGetFirstGetLastIteratorTests.ets index c109ff8348..10e91a83fe 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Deque/DequeGetFirstGetLastIteratorTests.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Deque/DequeGetFirstGetLastIteratorTests.ets @@ -14,6 +14,7 @@ */ import Deque from "@ohos.util.Deque"; +import { BusinessError } from "@ohos.base"; function main(): int { const suite = new arktest.ArkTestsuite("Deque API tests"); @@ -40,7 +41,11 @@ class TestData { function testGetFirstFromEmptyDeque() { let deque = new Deque(); arktest.assertEQ(deque.length, 0, "Initial deque length should be 0"); - arktest.assertEQ(deque.getFirst(), undefined, "Get first from empty deque should return undefined"); + try { + let first = deque.getFirst(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } function testGetFirstFromNonEmptyDeque() { @@ -56,7 +61,11 @@ function testGetFirstFromNonEmptyDeque() { function testGetLastFromEmptyDeque() { let deque = new Deque(); arktest.assertEQ(deque.length, 0, "Initial deque length should be 0"); - arktest.assertEQ(deque.getLast(), undefined, "Get last from empty deque should return undefined"); + try { + let first = deque.getLast(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } function testGetLastFromNonEmptyDeque() { diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Deque/DequeHasPopForEachTests.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Deque/DequeHasPopForEachTests.ets index 5abc46c5e2..9b2af61565 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Deque/DequeHasPopForEachTests.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Deque/DequeHasPopForEachTests.ets @@ -14,6 +14,7 @@ */ import Deque from "@ohos.util.Deque"; +import { BusinessError } from "@ohos.base"; function main(): int { const suite = new arktest.ArkTestsuite("Deque API tests"); @@ -85,7 +86,11 @@ function testDequeHasObjectElement() { function testDequePopFirstFromEmpty() { let deque = new Deque(); arktest.assertEQ(deque.length, 0, "Initial deque length should be 0"); - arktest.assertEQ(deque.popFirst(), undefined, "Pop first from empty deque should return undefined"); + try { + let result = deque.popFirst(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } function testDequePopFirstElement() { @@ -108,7 +113,11 @@ function testDequePopFirstElement() { function testDequePopLastFromEmpty() { let deque = new Deque(); arktest.assertEQ(deque.length, 0, "Initial deque length should be 0"); - arktest.assertEQ(deque.popLast(), undefined, "Pop last from empty deque should return undefined"); + try { + let result = deque.popLast(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } function testDequePopLastElement() { diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Deque/DequeHasPopTest.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Deque/DequeHasPopTest.ets index 0637771b72..f627b34b1c 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Deque/DequeHasPopTest.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Deque/DequeHasPopTest.ets @@ -14,6 +14,7 @@ */ import Deque from "@ohos.util.Deque"; +import { BusinessError } from "@ohos.base"; class C1 { name: string = ""; @@ -82,17 +83,31 @@ function testPopFirstAndRetrieveNewFirst() { // Test cases ported from ArkTS 1.0: DEQUE_1300 function testPopFirstFromEmptyDeque() { let deque = new Deque(); - deque.popFirst(); - let result = deque.getFirst(); - arktest.assertEQ(result, undefined); + try { + let first = deque.popFirst(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } + try { + let first = deque.getFirst(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } // Test cases ported from ArkTS 1.0: DEQUE_1500 function testGetFirstFromEmptyDeque() { let deque = new Deque(); - deque.popLast(); - let result = deque.getFirst(); - arktest.assertEQ(result, undefined); + try { + let first = deque.popLast(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } + try { + let first = deque.getFirst(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } // Test cases ported from ArkTS 1.0: DEQUE_1600 @@ -109,8 +124,11 @@ function testGetLastAfterMultipleInserts() { // Test cases ported from ArkTS 1.0: DEQUE_1700 function testGetLastFromEmptyDeque() { let deque = new Deque(); - let result = deque.getLast(); - arktest.assertEQ(result, undefined); + try { + let first = deque.getLast(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } // Test cases ported from ArkTS 1.0: DEQUE_1800 diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/LinkedList/LinkedListGetFirstLastTest.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/LinkedList/LinkedListGetFirstLastTest.ets index cc8b8233ac..b7d8d79321 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/LinkedList/LinkedListGetFirstLastTest.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/LinkedList/LinkedListGetFirstLastTest.ets @@ -14,6 +14,7 @@ */ import {LinkedList} from "@ohos.util.LinkedList"; +import { BusinessError } from "@ohos.base"; function main() { const suite = new arktest.ArkTestsuite("LinkedList API tests"); @@ -49,7 +50,11 @@ function testGetFirstNonEmptyContainer() { function testGetFirstEmptyContainer() { let linkedList = new LinkedList(); - arktest.assertEQ(linkedList.getFirst(), undefined); + try { + let first = linkedList.getFirst(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } function testGetFirstUndefined() { @@ -67,7 +72,11 @@ function testGetLastNonEmptyContainer() { function testGetLastEmptyContainer() { let linkedList = new LinkedList(); - arktest.assertEQ(linkedList.getLast(), undefined); + try { + let first = linkedList.getLast(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } function testGetLastUndefined() { diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/LinkedList/LinkedListInsertHasGetTest.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/LinkedList/LinkedListInsertHasGetTest.ets index ad9e0de9c1..4ac948e70f 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/LinkedList/LinkedListInsertHasGetTest.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/LinkedList/LinkedListInsertHasGetTest.ets @@ -14,7 +14,7 @@ */ import {LinkedList} from "@ohos.util.LinkedList"; -import {BusinessError} from "@ohos.base"; +import { BusinessError } from "@ohos.base"; const OutOfBoundsErrorCodeId: int = 10200001; @@ -177,7 +177,11 @@ function testGetWithinRange() { function testGetOutsideRange() { let linkedList = new LinkedList(); initializeLinkedList(linkedList, TestData.arrayForNumber1); - arktest.assertEQ(linkedList.get(TestData.testNumber1w), undefined, "Element at index 10000 should be undefined"); + try { + let result = linkedList.get(TestData.testNumber1w); + } catch (e: BusinessError) { + arktest.assertEQ(e.code, 10200001); + } } function initializeLinkedList(linkedList: LinkedList, sourceArray: Array) { diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/LinkedList/LinkedListTest.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/LinkedList/LinkedListTest.ets index 1326921d3d..65941d58b0 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/LinkedList/LinkedListTest.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/LinkedList/LinkedListTest.ets @@ -111,7 +111,11 @@ function testLinkedListBasicCRUD() { list1.forEach((d, i) => { arktest.assertEQ(d, testArray1[i]); }); - arktest.assertEQ(list.get(1232), undefined); + try { + let result = list.get(1232); + } catch (e: BusinessError) { + arktest.assertEQ(e.code, 10200001); + } arktest.assertEQ(list.getLastIndexOf(3333), -1); let exceptionCheck = (e: Error | Exception): boolean | string => { diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/List/ListGetFirstLastEmptyIteratorTests.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/List/ListGetFirstLastEmptyIteratorTests.ets index efb0db7165..b88157cf34 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/List/ListGetFirstLastEmptyIteratorTests.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/List/ListGetFirstLastEmptyIteratorTests.ets @@ -14,6 +14,7 @@ */ import {List} from '@ohos.util.List'; +import { BusinessError } from "@ohos.base"; function main() { const suite = new arktest.ArkTestsuite("List API tests"); @@ -53,7 +54,11 @@ function testGetFirstNonEmptyContainer() { function testGetFirstEmptyContainer() { let list = new List(); - arktest.assertEQ(list.getFirst(), undefined, "First element should be undefined when container is empty"); + try { + let result = list.getFirst(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } function testGetFirstUndefined() { @@ -71,7 +76,11 @@ function testGetLastNonEmptyContainer() { function testGetLastEmptyContainer() { let list = new List(); - arktest.assertEQ(list.getLast(), undefined, "Last element should be undefined when container is empty"); + try { + let result = list.getLast(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } function testGetLastUndefined() { diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/List/ListHasGetGetLastIndexOfTests.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/List/ListHasGetGetLastIndexOfTests.ets index 7231773d2d..6e95be8610 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/List/ListHasGetGetLastIndexOfTests.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/List/ListHasGetGetLastIndexOfTests.ets @@ -14,6 +14,7 @@ */ import {List} from '@ohos.util.List'; +import { BusinessError } from "@ohos.base"; function main() { const suite = new arktest.ArkTestsuite("List API tests"); @@ -98,7 +99,11 @@ function testGetWithinRange() { function testGetOutsideRange() { let list = new List(); initializeList(list, TestData.arrayForNumber1); - arktest.assertEQ(list.get(TestData.testNumber1w), undefined, "Element at index 10000 should be undefined"); + try { + let result = list.get(TestData.testNumber1w); + } catch (e: BusinessError) { + arktest.assertEQ(e.code, 10200001); + } } function testGetLastIndexOfUniqueElement() { diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/List/ListTests.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/List/ListTests.ets index 4b1858c59e..a9bb609e27 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/List/ListTests.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/List/ListTests.ets @@ -160,7 +160,11 @@ function testBasicOperationsAndMethods() { arktest.assertEQ(d, testArray2[i.toInt()]); }) - arktest.assertEQ(list1.get(200), undefined); + try { + let result = list1.get(200); + } catch (e: BusinessError) { + arktest.assertEQ(e.code, 10200001); + } arktest.assertEQ(list1.getLastIndexOf(3333), -1); arktest.expectThrow(() => {list1.removeByIndex(99)}); diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Queue/QueueAddPopGetTest.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Queue/QueueAddPopGetTest.ets index da8e0a7afd..f728248c57 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Queue/QueueAddPopGetTest.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Queue/QueueAddPopGetTest.ets @@ -14,6 +14,7 @@ */ import {Queue} from "@ohos.util.Queue"; +import { BusinessError } from "@ohos.base"; class C1 { name: string = ""; @@ -93,8 +94,11 @@ function testQueuePopWithElements() { // Test cases ported from ArkTS 1.0: QUEUE_POP_0700 function testQueuePopWithoutElements() { let queue = new Queue(); - let result = queue.pop(); - arktest.assertEQ(result, undefined); + try { + let result = queue.pop(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } // Test cases ported from ArkTS 1.0: QUEUE_GETFIRST_0800 @@ -115,6 +119,9 @@ function testQueueGetFirstWithElements() { // Test cases ported from ArkTS 1.0: QUEUE_GETFIRST_0900 function testQueueGetFirstWithoutElements() { let queue = new Queue(); - let result = queue.getFirst(); - arktest.assertEQ(result, undefined); + try { + let result = queue.getFirst(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Queue/QueueCreateLengthAddPopTests.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Queue/QueueCreateLengthAddPopTests.ets index 6db36e70b3..b949537424 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Queue/QueueCreateLengthAddPopTests.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Queue/QueueCreateLengthAddPopTests.ets @@ -14,6 +14,7 @@ */ import {Queue} from "@ohos.util.Queue"; +import { BusinessError } from "@ohos.base"; function main() { const suite = new arktest.ArkTestsuite("Queue API tests"); @@ -104,7 +105,11 @@ function testQueueAddElements() { function testQueuePopEmpty() { let queue = new Queue(); arktest.assertEQ(queue.length, 0, "Initial queue length should be 0"); - arktest.assertEQ(queue.pop(), undefined, "Pop from empty queue should return undefined"); + try { + let result = queue.pop(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } function testQueuePopFirstElement() { diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Queue/QueueForEachGetFirstIteratorTests.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Queue/QueueForEachGetFirstIteratorTests.ets index c3f6dc1e45..dce70e11d8 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Queue/QueueForEachGetFirstIteratorTests.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Queue/QueueForEachGetFirstIteratorTests.ets @@ -14,6 +14,7 @@ */ import {Queue} from "@ohos.util.Queue"; +import { BusinessError } from "@ohos.base"; function main() { const suite = new arktest.ArkTestsuite("Queue API tests"); @@ -113,7 +114,11 @@ function testQueueForEachChangeElements() { function testQueueGetFirstEmpty() { let queue = new Queue(); arktest.assertEQ(queue.length, 0, "Initial queue length should be 0"); - arktest.assertEQ(queue.getFirst(), undefined, "Get first from empty queue should return undefined"); + try { + let first = queue.getFirst(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } function testQueueGetFirst() { diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Stack/StackCreateLengthPushPopPeekTests.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Stack/StackCreateLengthPushPopPeekTests.ets index 82561886d2..cd37838eb0 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Stack/StackCreateLengthPushPopPeekTests.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Stack/StackCreateLengthPushPopPeekTests.ets @@ -14,6 +14,7 @@ */ import {Stack} from "@ohos.util.Stack"; +import {BusinessError} from "@ohos.base"; function main() { const suite = new arktest.ArkTestsuite("Stack API tests"); @@ -108,7 +109,11 @@ function testStackPush() { function testPopFromEmptyStack() { let stack = new Stack(); arktest.assertEQ(stack.length, 0, "Initial stack length should be 0"); - arktest.assertEQ(stack.pop(), undefined, "Pop from empty stack should return undefined"); + try { + let first = stack.pop(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } function testPopFromNonEmptyStack() { @@ -131,7 +136,11 @@ function testPopFromNonEmptyStack() { function testPeekEmptyStack() { let stack = new Stack(); arktest.assertEQ(stack.length, 0, "Initial stack length should be 0"); - arktest.assertEQ(stack.peek(), undefined, "Peek from empty stack should return undefined"); + try { + let first = stack.peek(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } function testPeekNonEmptyStack() { diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Stack/StackPushPopPeekTest.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Stack/StackPushPopPeekTest.ets index a0a30c0ac1..7668cc06bb 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Stack/StackPushPopPeekTest.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/Stack/StackPushPopPeekTest.ets @@ -14,6 +14,7 @@ */ import { Stack } from "@ohos.util.Stack"; +import { BusinessError } from "@ohos.base"; class C1 { name: string = ""; @@ -95,8 +96,11 @@ function testStackPopWithMultipleElements() { // Test cases ported from ArkTS 1.0: STACK_POP_0700 function testStackPopWithoutElements() { let stack = new Stack(); - let result = stack.pop(); - arktest.assertEQ(result, undefined); + try { + let first = stack.pop(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } // Test cases ported from ArkTS 1.0: STACK_PEEK_0900 @@ -118,6 +122,9 @@ function testStackPeekWithElements() { // Test cases ported from ArkTS 1.0: STACK_PEEK_0100 function testStackPeekWithoutElements() { let stack = new Stack(); - let result = stack.peek(); - arktest.assertEQ(result, undefined); + try { + let first = stack.peek(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeMap/TreeMapGetFirstKeyGetLastKeyRemoveTest.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeMap/TreeMapGetFirstKeyGetLastKeyRemoveTest.ets index d049e441e2..abbc2f53e1 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeMap/TreeMapGetFirstKeyGetLastKeyRemoveTest.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeMap/TreeMapGetFirstKeyGetLastKeyRemoveTest.ets @@ -14,6 +14,7 @@ */ import TreeMap from "@ohos.util.TreeMap"; +import {BusinessError} from "@ohos.base"; function main(): int { const suite = new arktest.ArkTestsuite("TreeMap GetFirstKey GetLastKey Remove API tests") @@ -47,8 +48,11 @@ function main(): int { //Test cases ported from ArkTS 1.0:TREEMAP_2400 function testGetFirstKeyOnEmptyMap() { let treeMap = new TreeMap(); - let result = treeMap.getFirstKey(); - arktest.assertEQ(result, undefined); + try { + let result = treeMap.getFirstKey(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } //Test cases ported from ArkTS 1.0:TREEMAP_2500 @@ -103,8 +107,11 @@ function testGetFirstKeyWithCustomNaturalOrderComparator() { //Test cases ported from ArkTS 1.0:TREEMAP_2900 function testGetLastKeyOnEmptyMap() { let treeMap = new TreeMap(); - let result = treeMap.getLastKey(); - arktest.assertEQ(result, undefined); + try { + let result = treeMap.getLastKey(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } //Test cases ported from ArkTS 1.0:TREEMAP_3000 diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeMap/TreeMapGetFirstKeyGetLastKeyTest.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeMap/TreeMapGetFirstKeyGetLastKeyTest.ets index cdc14374f7..20ae2aaffd 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeMap/TreeMapGetFirstKeyGetLastKeyTest.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeMap/TreeMapGetFirstKeyGetLastKeyTest.ets @@ -14,6 +14,7 @@ */ import TreeMap from "@ohos.util.TreeMap"; +import { BusinessError } from "@ohos.base"; function main(): int { const suite = new arktest.ArkTestsuite("TreeMap GetFirstKey GetLastKey API tests") @@ -62,10 +63,16 @@ function testGetFirstKeyAndLastKeyEmptyTreeMap() { new TreeMap((firstValue: string, secondValue: string): double => { return secondValue.compareTo(firstValue); }); - let first = treeMap.getFirstKey(); - let last = treeMap.getLastKey(); - arktest.assertEQ(first, undefined, "The treeMap should return undefined for the first key in an empty map"); - arktest.assertEQ(last, undefined, "The treeMap should return undefined for the last key in an empty map"); + try { + let first = treeMap.getFirstKey(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } + try { + let last = treeMap.getLastKey(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } arktest.assertEQ(treeMap.length, 0, "The treeMap length should be 0"); } diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeMap/TreeMapGetLowerKeyGetHigherKeyTest.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeMap/TreeMapGetLowerKeyGetHigherKeyTest.ets index 6acbf03930..2ccd522d48 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeMap/TreeMapGetLowerKeyGetHigherKeyTest.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeMap/TreeMapGetLowerKeyGetHigherKeyTest.ets @@ -14,6 +14,7 @@ */ import TreeMap from "@ohos.util.TreeMap"; +import { BusinessError } from "@ohos.base"; function main(): int { const suite = new arktest.ArkTestsuite("TreeMap GetLowerKey GetHigherKey API tests") @@ -74,10 +75,16 @@ function testGetLowerKeyAndHigherKeyEmptyTreeMap() { new TreeMap((firstValue: string, secondValue: string): double => { return secondValue.compareTo(firstValue) }); - let lower = treeMap.getLowerKey("bb"); - let higher = treeMap.getHigherKey("aa"); - arktest.assertEQ(lower, undefined, "The treeMap should return undefined for the lower key in an empty map"); - arktest.assertEQ(higher, undefined, "The treeMap should return undefined for the higher key in an empty map"); + try { + let lower = treeMap.getLowerKey("bb"); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } + try { + let higher = treeMap.getHigherKey("aa"); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } arktest.assertEQ(treeMap.length, 0, "The treeMap length should be 0"); } @@ -125,10 +132,16 @@ function testGetLowerKeyAndHigherKeyEmptyStringKey() { new TreeMap((firstValue: string, secondValue: string): double => { return secondValue.compareTo(firstValue) }); - let lower = treeMap.getLowerKey(""); - let higher = treeMap.getHigherKey(""); - arktest.assertEQ(lower, undefined, "The treeMap should return undefined for the lower key at the boundary value"); - arktest.assertEQ(higher, undefined, "The treeMap should return undefined for the higher key at the boundary value"); + try { + let lower = treeMap.getLowerKey(""); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } + try { + let higher = treeMap.getHigherKey(""); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } arktest.assertEQ(treeMap.length, 0, "The treeMap length should be 0"); } diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeMap/TreeMapSetAllGetLowerKeyGetHigherKeyTest.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeMap/TreeMapSetAllGetLowerKeyGetHigherKeyTest.ets index 568212a36e..93e91cd37d 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeMap/TreeMapSetAllGetLowerKeyGetHigherKeyTest.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeMap/TreeMapSetAllGetLowerKeyGetHigherKeyTest.ets @@ -14,6 +14,7 @@ */ import TreeMap from "@ohos.util.TreeMap"; +import { BusinessError } from "@ohos.base"; function main(): int { const suite = new arktest.ArkTestsuite("TreeMap SetAll GetLowerKey GetHigherKey API tests") @@ -131,23 +132,32 @@ function testSetAllToNonEmptyMap() { //Test cases ported from ArkTS 1.0:TREEMAP_5400 function testGetLowerKeyEmptyStringOnEmptyMap() { let treeMap = new TreeMap(); - let result = treeMap.getLowerKey(""); - arktest.assertEQ(result, undefined); + try { + let result = treeMap.getLowerKey(""); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } //Test cases ported from ArkTS 1.0:TREEMAP_5700 function testGetLowerKeyNonExistingKeyOnEmptyMap() { let treeMap = new TreeMap(); - let result = treeMap.getLowerKey("key"); - arktest.assertEQ(result, undefined); + try { + let result = treeMap.getLowerKey("key"); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } //Test cases ported from ArkTS 1.0:TREEMAP_5800 function testGetLowerKeyWithOnlyKeyInMap() { let treeMap = new TreeMap(); treeMap.set("squirrel", 123); - let result = treeMap.getLowerKey("squirrel"); - arktest.assertEQ(result, undefined); + try { + let result = treeMap.getLowerKey("squirrel"); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } //Test cases ported from ArkTS 1.0:TREEMAP_5900 @@ -175,23 +185,32 @@ function testGetLowerKeyNonExistingKeyWithLower() { //Test cases ported from ArkTS 1.0:TREEMAP_6100 function testGetHigherKeyEmptyStringOnEmptyMap() { let treeMap = new TreeMap(); - let result = treeMap.getHigherKey(""); - arktest.assertEQ(result, undefined); + try { + let result = treeMap.getHigherKey(""); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } //Test cases ported from ArkTS 1.0:TREEMAP_6400 function testGetHigherKeyNonExistingKeyOnEmptyMap() { let treeMap = new TreeMap(); - let result = treeMap.getHigherKey('key'); - arktest.assertEQ(result, undefined); + try { + let result = treeMap.getHigherKey('key'); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } //Test cases ported from ArkTS 1.0:TREEMAP_6500 function testGetHigherKeyWithOnlyKeyInMap() { let treeMap = new TreeMap(); treeMap.set("AAA", 123); - let result = treeMap.getHigherKey('AAA'); - arktest.assertEQ(result, undefined); + try { + let result = treeMap.getHigherKey('AAA'); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } //Test cases ported from ArkTS 1.0:TREEMAP_6600 diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeSet/TreeSetGetFirstValueGetLastValueTest.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeSet/TreeSetGetFirstValueGetLastValueTest.ets index c4e642d539..e823d94797 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeSet/TreeSetGetFirstValueGetLastValueTest.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeSet/TreeSetGetFirstValueGetLastValueTest.ets @@ -14,6 +14,7 @@ */ import {TreeSet} from "@ohos.util.TreeSet"; +import { BusinessError } from "@ohos.base"; function main(): int { const suite = new arktest.ArkTestsuite("TreeSet GetFirstValue GetLastValue API tests") @@ -57,10 +58,16 @@ function testGetFirstValueGetLastValueSingleElement() { function testGetFirstValueGetLastValueEmptyTreeSet() { let treeSet: TreeSet = new TreeSet((firstValue: string, secondValue: string): double => { return secondValue.compareTo(firstValue) }); - let result1 = treeSet.getFirstValue(); - let result2 = treeSet.getLastValue(); - arktest.assertEQ(result1, undefined, "The treeSet should return undefined for the first value in an empty set"); - arktest.assertEQ(result2, undefined, "The treeSet should return undefined for the last value in an empty set"); + try { + let result1 = treeSet.getFirstValue(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } + try { + let result2 = treeSet.getLastValue(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } arktest.assertEQ(treeSet.length, 0, "The treeSet length should be 0") } diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeSet/TreeSetGetFirstValuleGetLastValueAddRemoveTest.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeSet/TreeSetGetFirstValuleGetLastValueAddRemoveTest.ets index 1e855a32d8..157a73f6d1 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeSet/TreeSetGetFirstValuleGetLastValueAddRemoveTest.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeSet/TreeSetGetFirstValuleGetLastValueAddRemoveTest.ets @@ -14,6 +14,7 @@ */ import {TreeSet} from "@ohos.util.TreeSet"; +import { BusinessError } from "@ohos.base"; function main(): int { const suite = new arktest.ArkTestsuite("TreeSet GetFirstValue GetLastValue Add Remove API tests") @@ -48,8 +49,11 @@ function main(): int { //Test cases ported from ArkTS 1.0:TREESET_1800 function testGetFirstValueOnEmptySet() { let treeSet = new TreeSet(); - let result = treeSet.getFirstValue(); - arktest.assertEQ(result, undefined); + try { + let result = treeSet.getFirstValue(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } //Test cases ported from ArkTS 1.0:TREESET_1900 @@ -85,8 +89,11 @@ function testGetFirstValueWithCustomReverseComparator() { //Test cases ported from ArkTS 1.0:TREESET_2200 function testGetLastValueOnEmptySet() { let treeSet = new TreeSet(); - let result = treeSet.getLastValue(); - arktest.assertEQ(result, undefined); + try { + let result = treeSet.getLastValue(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } //Test cases ported from ArkTS 1.0:TREESET_2300 diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeSet/TreeSetGetLowerValueGetHigherValueClearTest.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeSet/TreeSetGetLowerValueGetHigherValueClearTest.ets index 44852f44e7..da5cd25a04 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeSet/TreeSetGetLowerValueGetHigherValueClearTest.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeSet/TreeSetGetLowerValueGetHigherValueClearTest.ets @@ -14,6 +14,7 @@ */ import {TreeSet} from "@ohos.util.TreeSet"; +import { BusinessError } from "@ohos.base"; function main(): int { const suite = new arktest.ArkTestsuite("TreeSet GetLowerValue GetHigherValue Clear API tests") @@ -44,22 +45,31 @@ function main(): int { //Test cases ported from ArkTS 1.0:TREESET_4200 function testGetLowerValueEmptyStringOnEmptySet() { let treeSet = new TreeSet(); - let result = treeSet.getLowerValue(""); - arktest.assertEQ(result, undefined); + try { + let result = treeSet.getLowerValue(""); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } //Test cases ported from ArkTS 1.0:TREESET_4500 function testGetLowerValueNumberOnEmptySet1() { let treeSet = new TreeSet(); - let result = treeSet.getLowerValue(123); - arktest.assertEQ(result, undefined); + try { + let result = treeSet.getLowerValue(123); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } //Test cases ported from ArkTS 1.0:TREESET_4600 function testGetLowerValueNumberOnEmptySet2() { let treeSet = new TreeSet(); - let result = treeSet.getLowerValue(123); - arktest.assertEQ(result, undefined); + try { + let result = treeSet.getLowerValue(123); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } //Test cases ported from ArkTS 1.0:TREESET_4700 @@ -87,22 +97,31 @@ function testGetLowerValueWithCustomReverseComparator() { //Test cases ported from ArkTS 1.0:TREESET_4900 function testGetHigherValueEmptyStringOnEmptySet() { let treeSet = new TreeSet(); - let result = treeSet.getHigherValue(""); - arktest.assertEQ(result, undefined); + try { + let result = treeSet.getHigherValue(""); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } //Test cases ported from ArkTS 1.0:TREESET_5200 function testGetHigherValueNumberOnEmptySet1() { let treeSet = new TreeSet(); - let result = treeSet.getHigherValue(123); - arktest.assertEQ(result, undefined); + try { + let result = treeSet.getHigherValue(123); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } //Test cases ported from ArkTS 1.0:TREESET_5300 function testGetHigherValueNumberOnEmptySet2() { let treeSet = new TreeSet(); - let result = treeSet.getHigherValue(123); - arktest.assertEQ(result, undefined); + try { + let result = treeSet.getHigherValue(123); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } //Test cases ported from ArkTS 1.0:TREESET_5400 diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeSet/TreeSetGetLowerValueGetHigherValueTest.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeSet/TreeSetGetLowerValueGetHigherValueTest.ets index 81701318fd..835d935b27 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeSet/TreeSetGetLowerValueGetHigherValueTest.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeSet/TreeSetGetLowerValueGetHigherValueTest.ets @@ -14,6 +14,7 @@ */ import {TreeSet} from "@ohos.util.TreeSet"; +import { BusinessError } from "@ohos.base"; function main(): int { const suite = new arktest.ArkTestsuite("TreeSet GetLowerValue GetHigherValue API tests") @@ -73,10 +74,16 @@ function testGetLowerValueGetHigherValueValidValues() { function testGetLowerValueGetHigherValueEmptyTreeSet() { let treeSet: TreeSet = new TreeSet((firstValue: string, secondValue: string): double => { return secondValue.compareTo(firstValue) }); - let lower = treeSet.getLowerValue("bb"); - let higher = treeSet.getHigherValue("aa"); - arktest.assertEQ(lower, undefined, "The treeSet should return undefined for the lower value in an empty set"); - arktest.assertEQ(higher, undefined, "The treeSet should return undefined for the higher value in an empty set"); + try { + let lower = treeSet.getLowerValue("bb"); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } + try { + let higher = treeSet.getHigherValue("aa"); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } arktest.assertEQ(treeSet.length, 0, "The treeSet length should be 0") } @@ -118,10 +125,16 @@ function testGetLowerValueAndHigherValueNonExistingValue() { function testGetLowerValueGetHigherValueEmptyStringValue() { let treeSet: TreeSet = new TreeSet((firstValue: string, secondValue: string): double => { return secondValue.compareTo(firstValue) }); - let lower = treeSet.getLowerValue(""); - let higher = treeSet.getHigherValue(""); - arktest.assertEQ(lower, undefined, "The treeSet should return undefined for the lower value in an empty set"); - arktest.assertEQ(higher, undefined, "The treeSet should return undefined for the higher value in an empty set"); + try { + let lower = treeSet.getLowerValue(""); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } + try { + let higher = treeSet.getHigherValue(""); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } arktest.assertEQ(treeSet.length, 0, "The treeSet length should be 0") } diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeSet/TreeSetPopFirstPopLastIteratorTest.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeSet/TreeSetPopFirstPopLastIteratorTest.ets index 75aef467e3..dd4c47d9e7 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeSet/TreeSetPopFirstPopLastIteratorTest.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeSet/TreeSetPopFirstPopLastIteratorTest.ets @@ -14,6 +14,7 @@ */ import {TreeSet} from "@ohos.util.TreeSet"; +import { BusinessError } from "@ohos.base"; function main(): int { const suite = new arktest.ArkTestsuite("TreeSet PopFirst PopLast Iterator API tests") @@ -57,10 +58,16 @@ function testPopFirstPopLastValidValues() { function testPopFirstPopLastEmptyTreeSet() { let treeSet: TreeSet = new TreeSet((firstValue: string, secondValue: string): double => { return secondValue.compareTo(firstValue) }); - let result_popFirst = treeSet.popFirst(); - let result_popLast = treeSet.popLast(); - arktest.assertEQ(result_popFirst, undefined, "The treeSet should return undefined for popping first value in an empty set"); - arktest.assertEQ(result_popLast, undefined, "The treeSet should return undefined for popping last value in an empty set"); + try { + let result_popFirst = treeSet.popFirst(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } + try { + let result_popLast = treeSet.popLast(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } arktest.assertEQ(treeSet.length, 0, "The treeSet length should be 0") } @@ -68,10 +75,16 @@ function testPopFirstPopLastMultipleValues() { let treeSet: TreeSet = new TreeSet((firstValue: string, secondValue: string): double => { return secondValue.compareTo(firstValue) }); treeSet.add("aa"); - let result_popFirst = treeSet.popFirst(); - let result_popLast = treeSet.popLast(); - arktest.assertEQ(result_popFirst, "aa", "The treeSet should pop the first value"); - arktest.assertEQ(result_popLast, undefined, "The treeSet should pop the last value"); + try { + let result_popFirst = treeSet.popFirst(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } + try { + let result_popLast = treeSet.popLast(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } arktest.assertEQ(treeSet.length, 0, "The treeSet length should be 0"); } @@ -96,12 +109,18 @@ function testPopFirstPopLastAfterClear() { treeSet.add("sparrow"); treeSet.clear(); let result1 = treeSet.isEmpty(); - let result_popFirst = treeSet.popFirst(); - let result_popLast = treeSet.popLast(); + try { + let result_popFirst = treeSet.popFirst(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } + try { + let result_popLast = treeSet.popLast(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } let result2 = treeSet.has("squirrel"); let result3 = treeSet.has("sparrow"); - arktest.assertEQ(result_popFirst, undefined, "The treeSet should pop the first value"); - arktest.assertEQ(result_popLast, undefined, "The treeSet should pop the last value"); arktest.assertEQ(result1, true, "The treeSet should be empty"); arktest.assertEQ(result2, false, "The treeSet should not contain the value that is not set"); arktest.assertEQ(result3, false, "The treeSet should not contain the value that is not set"); diff --git a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeSet/TreeSetPopFirstPopLastValuesTest.ets b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeSet/TreeSetPopFirstPopLastValuesTest.ets index 69cb673e1a..8e7fe3d29b 100644 --- a/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeSet/TreeSetPopFirstPopLastValuesTest.ets +++ b/static_core/plugins/ets/tests/ets_sdk/api/@ohos/util/TreeSet/TreeSetPopFirstPopLastValuesTest.ets @@ -14,6 +14,7 @@ */ import {TreeSet} from "@ohos.util.TreeSet"; +import { BusinessError } from "@ohos.base"; function main(): int { const suite = new arktest.ArkTestsuite("TreeSet PopFirst PopLast Values API tests") @@ -46,8 +47,11 @@ function main(): int { //Test cases ported from ArkTS 1.0:TREESET_5600 function testPopFirstOnEmptySet() { let treeSet = new TreeSet(); - let result = treeSet.popFirst(); - arktest.assertEQ(result, undefined); + try { + let result = treeSet.popLast(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } //Test cases ported from ArkTS 1.0:TREESET_5700 @@ -88,7 +92,11 @@ function testPopFirstAfterRemoveMakesEmpty() { let treeSet = new TreeSet(); treeSet.add("squirrel"); treeSet.remove("squirrel"); - treeSet.popFirst(); + try { + let result = treeSet.popFirst(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } let result = treeSet.has("squirrel"); arktest.assertFalse(result, "Expected has('squirrel') to be false after remove() and then popFirst() on an empty set"); @@ -100,8 +108,11 @@ function testPopFirstAfterClear() { treeSet.add("squirrel"); treeSet.add("sparrow"); treeSet.clear(); - let result = treeSet.popFirst(); - arktest.assertEQ(result, undefined); + try { + let result = treeSet.popFirst(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } let resultOne = treeSet.has("squirrel"); arktest.assertFalse(resultOne, "Expected has('squirrel') to be false after clear() and popFirst()"); let resultTwo = treeSet.has("sparrow"); @@ -111,8 +122,11 @@ function testPopFirstAfterClear() { //Test cases ported from ArkTS 1.0:TREESET_6200 function testPopLastOnEmptySet() { let treeSet = new TreeSet(); - let result = treeSet.popLast(); - arktest.assertEQ(result, undefined); + try { + let result = treeSet.popLast(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } } //Test cases ported from ArkTS 1.0:TREESET_6300 @@ -153,7 +167,11 @@ function testPopLastAfterRemoveMakesEmpty() { let treeSet = new TreeSet(); treeSet.add("squirrel"); treeSet.remove("squirrel"); - treeSet.popLast(); + try { + let result = treeSet.popLast(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } let result = treeSet.has("squirrel"); arktest.assertFalse(result, "Expected has('squirrel') to be false after remove() and then popLast() on an empty set"); @@ -165,8 +183,11 @@ function testPopLastAfterClear() { treeSet.add("squirrel"); treeSet.add("sparrow"); treeSet.clear(); - let result = treeSet.popLast(); - arktest.assertEQ(result, undefined); + try { + let result = treeSet.popLast(); + } catch (e: BusinessError) { + arktest.assertEQ(e.message, "Container is empty"); + } let resultOne = treeSet.has("squirrel"); arktest.assertFalse(resultOne, "Expected has('squirrel') to be false after clear() and popLast()"); let resultTwo = treeSet.has("sparrow"); diff --git a/static_core/plugins/ets/tests/stdlib-templates/escompat/escompat_Array_misc.ets b/static_core/plugins/ets/tests/stdlib-templates/escompat/escompat_Array_misc.ets index d880e6b3d2..62a475b13b 100644 --- a/static_core/plugins/ets/tests/stdlib-templates/escompat/escompat_Array_misc.ets +++ b/static_core/plugins/ets/tests/stdlib-templates/escompat/escompat_Array_misc.ets @@ -25,9 +25,6 @@ function main(): int { failures += check((): int => { return testGoodNegIndex()}, "Test good negative index") failures += check((): int => { return testGoodPosIndex()}, "Test good positive index") - failures += check((): int => { return testBadNegIndex()}, "Test bad negative index") - failures += check((): int => { return testBadPosIndex()}, "Test bad positive index") - failures += check((): int => { return testJoinEmpty()}, "Test join(0) method with empty source array") failures += check((): int => { return testJoin0()}, "Test join(0) method") failures += check((): int => { return testJoin1()}, "Test join(1) method") @@ -239,24 +236,6 @@ function testGoodNegIndex(): int { return FAILURE } - -function testBadNegIndex(): int { - const array = Array.from(source) - let exp = array.at(-100) - if (exp == null) return SUCCESS - console.println("Unexpected result on bad negative index") - return FAILURE -} - -function testBadPosIndex(): int { - const array = Array.from(source) - let exp = array.at(100) - if (exp == null) return SUCCESS - console.println("Unexpected result on bad positive index") - return FAILURE -} - - // currently not used tests *Flat* function testFlatEmpty(): int { -- Gitee