From 2d3d923673275ae2899c455100a260c4f7b86141 Mon Sep 17 00:00:00 2001 From: penn Date: Mon, 5 Aug 2024 10:27:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=96=87=E4=BB=B6=E9=87=8D?= =?UTF-8?q?=E5=A4=8D;=20=E5=B7=B2=E5=AD=98=E5=9C=A8=20data/randomSelect.te?= =?UTF-8?q?st.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libPend/randomSelect.test.js | 58 ------------------------------------ 1 file changed, 58 deletions(-) delete mode 100644 libPend/randomSelect.test.js diff --git a/libPend/randomSelect.test.js b/libPend/randomSelect.test.js deleted file mode 100644 index 9b5c3b8..0000000 --- a/libPend/randomSelect.test.js +++ /dev/null @@ -1,58 +0,0 @@ -import { describe, it, expect } from 'vitest'; -import yd_object_randomSelect from '../../lib/object/randomSelect.js'; - -describe('yd_object_randomSelect function', () => { - it('should return a random element from an array', () => { - const array = [1, 2, 3, 4, 5]; - const result = yd_object_randomSelect(array); - expect(array).toContain(result); - }); - - it('should return a random character from a string', () => { - const string = 'hello'; - const result = yd_object_randomSelect(string); - expect(string).toContain(result); - }); - - it('should return a random element from a set', () => { - const set = new Set(['apple', 'banana', 'cherry']); - const result = yd_object_randomSelect(set); - expect(set.has(result)).toBe(true); - }); - - it('should return a random value from a map', () => { - const map = new Map([ - ['a', 1], - ['b', 2], - ['c', 3] - ]); - const result = yd_object_randomSelect(map); - expect(Array.from(map.values())).toContain(result); - }); - - it('should return a random value from an object', () => { - const obj = { x: 10, y: 20, z: 30 }; - const result = yd_object_randomSelect(obj); - expect(Object.values(obj)).toContain(result); - }); - - it('should throw TypeError if input is null', () => { - const testFunc = () => yd_object_randomSelect(null); - expect(testFunc).toThrowError(TypeError); - }); - - it('should throw TypeError if input is undefined', () => { - const testFunc = () => yd_object_randomSelect(undefined); - expect(testFunc).toThrowError(TypeError); - }); - - it('should throw Error if the collection is empty', () => { - const testFunc = () => yd_object_randomSelect([]); - expect(testFunc).toThrowError(Error); - }); - - it('should throw TypeError for unsupported types (like numbers)', () => { - const testFunc = () => yd_object_randomSelect(123); - expect(testFunc).toThrowError(TypeError); - }); -});