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

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

上级 1cc52c77
import { describe, test, expect, Result } from './tests.uts'
export function testSet(): Result {
export function testSet() : Result {
return describe("Set", () => {
test('size', () => {
// #TEST Set.size
const set1 = new Set<any>();
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<number>();
set1.add(42);
set1.add(42);
set1.add(13);
set1.forEach((item)=>{
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)
......@@ -24,29 +36,55 @@ export function testSet(): Result {
console.log(set2)
})
test('clear', () => {
// #TEST Set.clear
const set1 = new Set<any>();
set1.add(1);
set1.add('foo');
expect(set1.size).toEqual(2);
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'])
const logSetElements = (value:any) => {
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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册