Set.uts 3.0 KB
Newer Older
Y
yurj26 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
import { describe, test, expect, Result } from './tests.uts'

export function testSet(): Result {
    return describe("Set", () => {
        test('size', () => {
            const set1 = new Set<Any>();
            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<number>();
            set1.add(42);
            set1.add(42);
            set1.add(13);
            set1.forEach((item)=>{
              expect(set1.has(item)).toEqual(true);
            })
        })
        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);
        })
    })
}