From 4faada1a47230de6e03fad0307b5a20a9fb742db Mon Sep 17 00:00:00 2001 From: mahaifeng Date: Thu, 5 Sep 2024 16:37:37 +0800 Subject: [PATCH] =?UTF-8?q?[set]=E5=8E=BB=E9=99=A4=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E4=B8=AD=E6=89=8B=E5=8A=A8=E7=94=9F=E6=88=90=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uni_modules/uts-tests/utssdk/Set.uts | 212 ++++++++++++++++----------- 1 file changed, 125 insertions(+), 87 deletions(-) diff --git a/uni_modules/uts-tests/utssdk/Set.uts b/uni_modules/uts-tests/utssdk/Set.uts index 1c32549..4edc31d 100644 --- a/uni_modules/uts-tests/utssdk/Set.uts +++ b/uni_modules/uts-tests/utssdk/Set.uts @@ -1,90 +1,128 @@ import { describe, test, expect, Result } from './tests.uts' -export function testSet(): Result { - return describe("Set", () => { - test('size', () => { - const set1 = new Set(); - const object1 = {}; - set1.add(42); - set1.add('forty two'); - set1.add('forty two'); - set1.add(object1); - expect(set1.size).toEqual(3); - }) - test('add', () => { - const set1 = new Set(); - set1.add(42); - set1.add(42); - set1.add(13); - set1.forEach((item)=>{ - expect(set1.has(item)).toEqual(true); - }) - console.log(set1) - let set2 = set1.add(66); - console.log(set2) - }) - test('clear', () => { - const set1 = new Set(); - set1.add(1); - set1.add('foo'); - expect(set1.size).toEqual(2); - set1.clear(); - expect(set1.size).toEqual(0); - }) - test('delete', () => { - const set1 = new Set(); - set1.add(10); - set1.add(20); - set1.delete(10); - expect(set1.size).toEqual(1); - }) - test('has', () => { - const set1 = new Set([1, 2, 3, 4, 5]); - expect(set1.has(1)).toEqual(true); - expect(set1.has(5)).toEqual(true); - expect(set1.has(6)).toEqual(false); - }) - test('forEach', () => { - const set1 = new Set(['foo', 'bar']) - const logSetElements = (value:any) => { - expect(set1.has(value)).toEqual(true); - } - set1.forEach(logSetElements); - }) - - test("entries", () => { - // const mySet = new Set(); - // mySet.add("foo"); - // mySet.add("bar"); - // mySet.add("baz"); - // const setIter = mySet.entries(); - // expect(setIter.next().value).toEqual(["foo", "foo"]); - // expect(setIter.next().value).toEqual(["bar", "bar"]); - // expect(setIter.next().value).toEqual(["baz", "baz"]); - // expect(setIter.next().done).toEqual(true); - }) - test("keys", () => { - // const mySet = new Set(); - // mySet.add("foo"); - // mySet.add("bar"); - // mySet.add("baz"); - // const setIter = mySet.keys(); - // expect(setIter.next().value).toEqual("foo"); - // expect(setIter.next().value).toEqual("bar"); - // expect(setIter.next().value).toEqual("baz"); - // expect(setIter.next().done).toEqual(true); - }) - - test("values", () => { - // const mySet = new Set(); - // mySet.add("foo"); - // mySet.add("bar"); - // mySet.add("baz"); - // const setIter = mySet.values(); - // expect(setIter.next().value).toEqual("foo"); - // expect(setIter.next().value).toEqual("bar"); - // expect(setIter.next().value).toEqual("baz"); - // expect(setIter.next().done).toEqual(true); - }) +export function testSet() : Result { + return describe("Set", () => { + test('size', () => { + // #TEST Set.size + const set1 = new Set(); + const object1 = {}; + set1.add(42); + set1.add('forty two'); + set1.add('forty two'); + set1.add(object1); + console.log(set1.size); + // expected output: 3 + // #END + expect(set1.size).toEqual(3); }) -} + test('add', () => { + // #TEST Set.add + const set1 = new Set(); + set1.add(42); + set1.add(42); + set1.add(13); + set1.forEach((item) => { + console.log(item); + // expected output: 42 + // expected output: 13 + }) + // #END + + set1.forEach((item) => { + expect(set1.has(item)).toEqual(true); + }) + console.log(set1) + let set2 = set1.add(66); + console.log(set2) + }) + test('clear', () => { + // #TEST Set.clear + const set1 = new Set(); + set1.add(1); + set1.add('foo'); + set1.clear(); + console.log(set1.size); + // expected output: 0 + // #END + expect(set1.size).toEqual(0); + }) + test('delete', () => { + // #TEST Set.delete + const set1 = new Set(); + set1.add(10); + set1.add(20); + + set1.delete(10); + console.log(set1.size) //1 + // #END + + expect(set1.size).toEqual(1); + }) + test('has', () => { + // #TEST Set.has + const set1 = new Set([1, 2, 3, 4, 5]); + console.log(set1.has(1)); + // expected output: true + + console.log(set1.has(5)); + // expected output: true + + console.log(set1.has(6)); + // expected output: false + // #END + + expect(set1.has(1)).toEqual(true); + expect(set1.has(5)).toEqual(true); + expect(set1.has(6)).toEqual(false); + }) + test('forEach', () => { + // #TEST Set.forEach,Set.forEach_1,Set.forEach_2 + const set1 = new Set(['foo', 'bar']) + let logSetElements = (value : any) => { + console.log(value); + // expected output: foo + // expected output: bar + } + // #END + logSetElements = (value : any) => { + expect(set1.has(value)).toEqual(true); + } + set1.forEach(logSetElements); + }) + + test("entries", () => { + // const mySet = new Set(); + // mySet.add("foo"); + // mySet.add("bar"); + // mySet.add("baz"); + // const setIter = mySet.entries(); + // expect(setIter.next().value).toEqual(["foo", "foo"]); + // expect(setIter.next().value).toEqual(["bar", "bar"]); + // expect(setIter.next().value).toEqual(["baz", "baz"]); + // expect(setIter.next().done).toEqual(true); + }) + test("keys", () => { + // const mySet = new Set(); + // mySet.add("foo"); + // mySet.add("bar"); + // mySet.add("baz"); + // const setIter = mySet.keys(); + // expect(setIter.next().value).toEqual("foo"); + // expect(setIter.next().value).toEqual("bar"); + // expect(setIter.next().value).toEqual("baz"); + // expect(setIter.next().done).toEqual(true); + }) + + test("values", () => { + // const mySet = new Set(); + // mySet.add("foo"); + // mySet.add("bar"); + // mySet.add("baz"); + // const setIter = mySet.values(); + // expect(setIter.next().value).toEqual("foo"); + // expect(setIter.next().value).toEqual("bar"); + // expect(setIter.next().value).toEqual("baz"); + // expect(setIter.next().done).toEqual(true); + }) + }) +} \ No newline at end of file -- GitLab