diff options
author | davidot <david.tuin@gmail.com> | 2021-08-06 16:02:14 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-08-06 16:17:25 +0100 |
commit | 5cd2e0f3a26fb4e548c11056e6ec962392e50f15 (patch) | |
tree | 9bc0d692145be8d32d9a70551a369d73c71884cf /Userland/Libraries/LibJS | |
parent | 871a29884d704117fb1f1d2f47cbb1e8bdeefa17 (diff) | |
download | serenity-5cd2e0f3a26fb4e548c11056e6ec962392e50f15.zip |
LibJS: Improve the TypedArray.prototype.find{,Index} tests
Before this we did not check that it actually gave the first result.
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r-- | Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.find.js | 12 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.findIndex.js | 12 |
2 files changed, 24 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.find.js b/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.find.js index 701730d155..149e41e27c 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.find.js +++ b/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.find.js @@ -55,6 +55,12 @@ describe("normal behaviour", () => { expect(typedArray.find((value, index) => index === 1)).toBe(2); expect(typedArray.find(value => value == "1")).toBe(1); expect(typedArray.find(value => value === 10)).toBeUndefined(); + + const typedArrayDuplicates = new T([2, 1, 2, 3, 1]); + + expect(typedArrayDuplicates.find(value => value < 3)).toBe(2); + expect(typedArrayDuplicates.find(value => value < 2)).toBe(1); + expect(typedArrayDuplicates.find(value => value > 1)).toBe(2); }); BIGINT_TYPED_ARRAYS.forEach(T => { @@ -67,6 +73,12 @@ describe("normal behaviour", () => { expect(typedArray.find(value => value == 1)).toBe(1n); expect(typedArray.find(value => value == "1")).toBe(1n); expect(typedArray.find(value => value === 1)).toBeUndefined(); + + const typedArrayDuplicates = new T([2n, 1n, 2n, 3n, 1n]); + + expect(typedArrayDuplicates.find(value => value < 3)).toBe(2n); + expect(typedArrayDuplicates.find(value => value < 2)).toBe(1n); + expect(typedArrayDuplicates.find(value => value > 1)).toBe(2n); }); }); diff --git a/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.findIndex.js b/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.findIndex.js index 0e55c4c577..98c61e0dfd 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.findIndex.js +++ b/Userland/Libraries/LibJS/Tests/builtins/TypedArray/TypedArray.prototype.findIndex.js @@ -55,6 +55,12 @@ describe("normal behaviour", () => { expect(typedArray.findIndex((value, index) => index === 1)).toBe(1); expect(typedArray.findIndex(value => value == "1")).toBe(0); expect(typedArray.findIndex(value => value === 10)).toBe(-1); + + const typedArrayDuplicates = new T([1, 2, 3, 1]); + + expect(typedArrayDuplicates.findIndex(value => value === 1)).toBe(0); + expect(typedArrayDuplicates.findIndex(value => value === 2)).toBe(1); + expect(typedArrayDuplicates.findIndex(value => value === 3)).toBe(2); }); BIGINT_TYPED_ARRAYS.forEach(T => { @@ -67,6 +73,12 @@ describe("normal behaviour", () => { expect(typedArray.findIndex(value => value == 1)).toBe(0); expect(typedArray.findIndex(value => value == "1")).toBe(0); expect(typedArray.findIndex(value => value === 1)).toBe(-1); + + const typedArrayDuplicates = new T([1n, 2n, 3n, 1n]); + + expect(typedArrayDuplicates.findIndex(value => value === 1n)).toBe(0); + expect(typedArrayDuplicates.findIndex(value => value === 2n)).toBe(1); + expect(typedArrayDuplicates.findIndex(value => value === 3n)).toBe(2); }); }); |