提交 4faada1a 编写于 作者: M mahaifeng

[set]去除文档中手动生成的代码,添加注释

上级 1cc52c77
import { describe, test, expect, Result } from './tests.uts' import { describe, test, expect, Result } from './tests.uts'
export function testSet(): Result { export function testSet() : Result {
return describe("Set", () => { return describe("Set", () => {
test('size', () => { test('size', () => {
const set1 = new Set<any>(); // #TEST Set.size
const object1 = {}; const set1 = new Set<any>();
set1.add(42); const object1 = {};
set1.add('forty two'); set1.add(42);
set1.add('forty two'); set1.add('forty two');
set1.add(object1); set1.add('forty two');
expect(set1.size).toEqual(3); set1.add(object1);
}) console.log(set1.size);
test('add', () => { // expected output: 3
const set1 = new Set<number>(); // #END
set1.add(42); expect(set1.size).toEqual(3);
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<any>();
set1.add(1);
set1.add('foo');
expect(set1.size).toEqual(2);
set1.clear();
expect(set1.size).toEqual(0);
})
test('delete', () => {
const set1 = new Set<any>();
set1.add(10);
set1.add(20);
set1.delete(10);
expect(set1.size).toEqual(1);
})
test('has', () => {
const set1 = new Set<number>([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<any>(['foo', 'bar'])
const logSetElements = (value:any) => {
expect(set1.has(value)).toEqual(true);
}
set1.forEach(logSetElements);
})
test("entries", () => {
// const mySet = new Set<string>();
// 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<string>();
// 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<string>();
// 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);
})
}) })
} test('add', () => {
// #TEST Set.add
const set1 = new Set<number>();
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<any>();
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<any>();
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<number>([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<any>(['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<string>();
// 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<string>();
// 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<string>();
// 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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册