diff --git a/uni_modules/uts-tests/utssdk/Set.uts b/uni_modules/uts-tests/utssdk/Set.uts index 1c325491087ba1c6b4baef0e85ecd30da1cf944c..4edc31d2fa2bd5f97ac00a16af5970f7474044e3 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