From fdbf5661f9a2cbb721425bf7c35ad6a2a3f210d3 Mon Sep 17 00:00:00 2001 From: Chris Date: Sat, 23 Nov 2024 15:56:00 +0100 Subject: [PATCH] chore: wip --- src/collect.ts | 19 -- src/types.ts | 5 - test/index.test.ts | 619 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 616 insertions(+), 27 deletions(-) diff --git a/src/collect.ts b/src/collect.ts index 533cd27..0964592 100644 --- a/src/collect.ts +++ b/src/collect.ts @@ -2149,25 +2149,6 @@ ${collection.items.map(item => return this }, - lint(): Array<{ type: 'warning' | 'error', message: string, suggestion?: string }> { - const issues: Array<{ type: 'warning' | 'error', message: string, suggestion?: string }> = [] - - // Check for null values - for (const item of this.items) { - for (const [key, value] of Object.entries(item as object)) { - if (value === null) { - issues.push({ - type: 'warning', - message: `Null value found in field "${key}"`, - suggestion: 'Consider using undefined or providing a default value', - }) - } - } - } - - return issues - }, - sentiment(this: CollectionOperations): CollectionOperations<{ score: number, comparative: number }> { // Basic sentiment analysis using a simple positive/negative word approach const positiveWords = new Set(['good', 'great', 'awesome', 'excellent', 'happy', 'love']) diff --git a/src/types.ts b/src/types.ts index af00091..38f0cc8 100644 --- a/src/types.ts +++ b/src/types.ts @@ -474,11 +474,6 @@ export interface CollectionOperations extends Collection { memory: Record complexity: Record }> - lint: () => Array<{ - type: 'warning' | 'error' - message: string - suggestion?: string - }> // Advanced Mathematical Operations /** diff --git a/test/index.test.ts b/test/index.test.ts index 58bcb1b..ea4fde1 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -1,7 +1,620 @@ import { describe, expect, it } from 'bun:test' -describe('my awesome package', () => { - it('should work', () => { - expect(1).toBe(1) +import { collect } from './collect' + +describe('Collection Core Operations', () => { + // Basic Collection Creation + describe('collect()', () => { + it('should create collection from array', () => expect(true).toBe(true)) + it('should create collection from iterable', () => expect(true).toBe(true)) + it('should handle empty input', () => expect(true).toBe(true)) + }) + + // Transformation Operations + describe('map()', () => { + it('should transform items with index', () => expect(true).toBe(true)) + it('should handle empty collection', () => expect(true).toBe(true)) + it('should maintain types correctly', () => expect(true).toBe(true)) + }) + + describe('filter()', () => { + it('should filter items with predicate', () => expect(true).toBe(true)) + it('should pass index to predicate', () => expect(true).toBe(true)) + it('should handle empty collection', () => expect(true).toBe(true)) + }) + + describe('reduce()', () => { + it('should reduce collection with initial value', () => expect(true).toBe(true)) + it('should pass index to callback', () => expect(true).toBe(true)) + it('should handle empty collection', () => expect(true).toBe(true)) + }) + + describe('flatMap()', () => { + it('should flatten and map results', () => expect(true).toBe(true)) + it('should handle nested arrays', () => expect(true).toBe(true)) + it('should pass index to callback', () => expect(true).toBe(true)) + }) +}) + +describe('Collection Element Access', () => { + describe('first()', () => { + it('should return first element', () => expect(true).toBe(true)) + it('should return undefined for empty collection', () => expect(true).toBe(true)) + it('should return property when key provided', () => expect(true).toBe(true)) + }) + + describe('last()', () => { + it('should return last element', () => expect(true).toBe(true)) + it('should return undefined for empty collection', () => expect(true).toBe(true)) + it('should return property when key provided', () => expect(true).toBe(true)) + }) + + describe('nth()', () => { + it('should return element at index', () => expect(true).toBe(true)) + it('should return undefined for out of bounds', () => expect(true).toBe(true)) + }) +}) + +describe('Collection Aggregation Methods', () => { + describe('sum()', () => { + it('should sum numeric values', () => expect(true).toBe(true)) + it('should sum by key', () => expect(true).toBe(true)) + it('should handle empty collection', () => expect(true).toBe(true)) + }) + + describe('avg()', () => { + it('should calculate average of numbers', () => expect(true).toBe(true)) + it('should calculate average by key', () => expect(true).toBe(true)) + it('should handle empty collection', () => expect(true).toBe(true)) + }) + + describe('median()', () => { + it('should find median of odd length collection', () => expect(true).toBe(true)) + it('should find median of even length collection', () => expect(true).toBe(true)) + it('should find median by key', () => expect(true).toBe(true)) + }) +}) + +describe('Collection Grouping Operations', () => { + describe('chunk()', () => { + it('should create chunks of specified size', () => expect(true).toBe(true)) + it('should handle remainder chunk', () => expect(true).toBe(true)) + it('should throw for invalid chunk size', () => expect(true).toBe(true)) + }) + + describe('groupBy()', () => { + it('should group by key', () => expect(true).toBe(true)) + it('should group by callback', () => expect(true).toBe(true)) + it('should handle empty collection', () => expect(true).toBe(true)) + }) + + describe('partition()', () => { + it('should split collection by predicate', () => expect(true).toBe(true)) + it('should handle empty collection', () => expect(true).toBe(true)) + }) +}) + +describe('Collection Filtering Methods', () => { + describe('where()', () => { + it('should filter by key-value pair', () => expect(true).toBe(true)) + it('should handle non-existent key', () => expect(true).toBe(true)) + }) + + describe('whereIn()', () => { + it('should filter by value list', () => expect(true).toBe(true)) + it('should handle empty value list', () => expect(true).toBe(true)) + }) + + describe('whereBetween()', () => { + it('should filter values within range', () => expect(true).toBe(true)) + it('should include boundary values', () => expect(true).toBe(true)) + }) +}) + +describe('Collection Sorting Methods', () => { + describe('sort()', () => { + it('should sort with compare function', () => expect(true).toBe(true)) + it('should sort numbers by default', () => expect(true).toBe(true)) + it('should handle empty collection', () => expect(true).toBe(true)) + }) + + describe('sortBy()', () => { + it('should sort by key ascending', () => expect(true).toBe(true)) + it('should sort by key descending', () => expect(true).toBe(true)) + it('should handle non-existent key', () => expect(true).toBe(true)) + }) +}) + +describe('Collection Set Operations', () => { + describe('unique()', () => { + it('should remove duplicates', () => expect(true).toBe(true)) + it('should remove duplicates by key', () => expect(true).toBe(true)) + it('should handle empty collection', () => expect(true).toBe(true)) + }) + + describe('intersect()', () => { + it('should find common elements', () => expect(true).toBe(true)) + it('should work with array input', () => expect(true).toBe(true)) + it('should handle empty input', () => expect(true).toBe(true)) + }) + + describe('union()', () => { + it('should combine unique elements', () => expect(true).toBe(true)) + it('should work with array input', () => expect(true).toBe(true)) + it('should handle empty input', () => expect(true).toBe(true)) + }) +}) + +describe('Collection Utility Methods', () => { + describe('tap()', () => { + it('should execute callback and return collection', () => expect(true).toBe(true)) + it('should not modify collection', () => expect(true).toBe(true)) + }) + + describe('pipe()', () => { + it('should transform collection with callback', () => expect(true).toBe(true)) + it('should handle complex transformations', () => expect(true).toBe(true)) + }) +}) + +describe('Collection Async Operations', () => { + describe('mapAsync()', () => { + it('should transform items asynchronously', () => expect(true).toBe(true)) + it('should maintain order', () => expect(true).toBe(true)) + it('should handle rejections', () => expect(true).toBe(true)) + }) + + describe('filterAsync()', () => { + it('should filter items asynchronously', () => expect(true).toBe(true)) + it('should handle async predicates', () => expect(true).toBe(true)) + it('should handle rejections', () => expect(true).toBe(true)) + }) +}) + +describe('Collection Advanced Features', () => { + describe('timeSeries()', () => { + it('should create time series data', () => expect(true).toBe(true)) + it('should fill gaps correctly', () => expect(true).toBe(true)) + it('should handle different intervals', () => expect(true).toBe(true)) + }) + + describe('movingAverage()', () => { + it('should calculate moving average', () => expect(true).toBe(true)) + it('should handle different window sizes', () => expect(true).toBe(true)) + it('should support centered option', () => expect(true).toBe(true)) + }) +}) + +describe('Collection ML Operations', () => { + describe('kmeans()', () => { + it('should cluster data points', () => expect(true).toBe(true)) + it('should handle different distance metrics', () => expect(true).toBe(true)) + it('should respect max iterations', () => expect(true).toBe(true)) + }) + + describe('linearRegression()', () => { + it('should calculate regression coefficients', () => expect(true).toBe(true)) + it('should calculate R-squared', () => expect(true).toBe(true)) + it('should handle multiple independents', () => expect(true).toBe(true)) + }) +}) + +describe('Collection Serialization', () => { + describe('toJSON()', () => { + it('should serialize to JSON string', () => expect(true).toBe(true)) + it('should handle circular references', () => expect(true).toBe(true)) + it('should respect serialization options', () => expect(true).toBe(true)) + }) + + describe('toCsv()', () => { + it('should convert to CSV format', () => expect(true).toBe(true)) + it('should handle nested objects', () => expect(true).toBe(true)) + it('should escape special characters', () => expect(true).toBe(true)) + }) +}) + +describe('Collection Performance Features', () => { + describe('cache()', () => { + it('should cache results', () => expect(true).toBe(true)) + it('should respect TTL', () => expect(true).toBe(true)) + it('should handle cache invalidation', () => expect(true).toBe(true)) + }) + + describe('lazy()', () => { + it('should create lazy collection', () => expect(true).toBe(true)) + it('should defer execution', () => expect(true).toBe(true)) + it('should support chaining', () => expect(true).toBe(true)) + }) +}) + +// Previous test cases remain, adding all missing ones... + +describe('Advanced Transformations', () => { + describe('mapToGroups()', () => { + it('should map items to groups', () => expect(true).toBe(true)) + it('should handle complex group mappings', () => expect(true).toBe(true)) + }) + + describe('mapSpread()', () => { + it('should spread arguments to callback', () => expect(true).toBe(true)) + it('should handle arrays and objects', () => expect(true).toBe(true)) + }) + + describe('mapUntil()', () => { + it('should map until predicate is true', () => expect(true).toBe(true)) + it('should handle early termination', () => expect(true).toBe(true)) + }) + + describe('mapOption()', () => { + it('should filter out null/undefined values', () => expect(true).toBe(true)) + it('should transform remaining values', () => expect(true).toBe(true)) + }) +}) + +describe('String Operations', () => { + describe('join()', () => { + it('should join string collections', () => expect(true).toBe(true)) + it('should use custom separator', () => expect(true).toBe(true)) + }) + + describe('implode()', () => { + it('should join by key', () => expect(true).toBe(true)) + it('should use custom separator', () => expect(true).toBe(true)) + }) + + describe('lower()', () => { + it('should convert to lowercase', () => expect(true).toBe(true)) + }) + + describe('upper()', () => { + it('should convert to uppercase', () => expect(true).toBe(true)) + }) + + describe('slug()', () => { + it('should create URL-friendly slug', () => expect(true).toBe(true)) + it('should handle special characters', () => expect(true).toBe(true)) + }) +}) + +describe('Set Operations', () => { + describe('symmetricDiff()', () => { + it('should find symmetric difference', () => expect(true).toBe(true)) + it('should work with collections and arrays', () => expect(true).toBe(true)) + }) + + describe('cartesianProduct()', () => { + it('should compute cartesian product', () => expect(true).toBe(true)) + it('should handle empty collections', () => expect(true).toBe(true)) + }) + + describe('power()', () => { + it('should compute power set', () => expect(true).toBe(true)) + it('should include empty set', () => expect(true).toBe(true)) + }) +}) + +describe('Advanced Math Operations', () => { + describe('zscore()', () => { + it('should calculate z-scores', () => expect(true).toBe(true)) + it('should handle key parameter', () => expect(true).toBe(true)) + }) + + describe('kurtosis()', () => { + it('should calculate kurtosis', () => expect(true).toBe(true)) + it('should handle key parameter', () => expect(true).toBe(true)) + }) + + describe('skewness()', () => { + it('should calculate skewness', () => expect(true).toBe(true)) + it('should handle key parameter', () => expect(true).toBe(true)) + }) + + describe('covariance()', () => { + it('should calculate covariance', () => expect(true).toBe(true)) + it('should handle different keys', () => expect(true).toBe(true)) + }) + + describe('entropy()', () => { + it('should calculate entropy', () => expect(true).toBe(true)) + it('should handle key parameter', () => expect(true).toBe(true)) + }) + + describe('fft()', () => { + it('should compute FFT for number collections', () => expect(true).toBe(true)) + it('should throw for non-number collections', () => expect(true).toBe(true)) + }) + + describe('interpolate()', () => { + it('should interpolate values', () => expect(true).toBe(true)) + it('should handle different point counts', () => expect(true).toBe(true)) + }) + + describe('convolve()', () => { + it('should convolve with kernel', () => expect(true).toBe(true)) + it('should handle different kernel sizes', () => expect(true).toBe(true)) + }) + + describe('differentiate()', () => { + it('should compute derivative', () => expect(true).toBe(true)) + it('should handle numeric collections', () => expect(true).toBe(true)) + }) + + describe('integrate()', () => { + it('should compute integral', () => expect(true).toBe(true)) + it('should handle numeric collections', () => expect(true).toBe(true)) + }) +}) + +describe('Text Analysis', () => { + describe('sentiment()', () => { + it('should analyze sentiment', () => expect(true).toBe(true)) + it('should calculate comparative score', () => expect(true).toBe(true)) + }) + + describe('wordFrequency()', () => { + it('should count word occurrences', () => expect(true).toBe(true)) + it('should handle case sensitivity', () => expect(true).toBe(true)) + }) + + describe('ngrams()', () => { + it('should generate n-grams', () => expect(true).toBe(true)) + it('should handle different n values', () => expect(true).toBe(true)) + }) +}) + +describe('Data Quality Operations', () => { + describe('detectAnomalies()', () => { + it('should detect using z-score method', () => expect(true).toBe(true)) + it('should detect using IQR method', () => expect(true).toBe(true)) + it('should detect using isolation forest', () => expect(true).toBe(true)) + }) + + describe('impute()', () => { + it('should impute using mean', () => expect(true).toBe(true)) + it('should impute using median', () => expect(true).toBe(true)) + it('should impute using mode', () => expect(true).toBe(true)) + }) + + describe('normalize()', () => { + it('should normalize using min-max', () => expect(true).toBe(true)) + it('should normalize using z-score', () => expect(true).toBe(true)) + }) + + describe('removeOutliers()', () => { + it('should remove statistical outliers', () => expect(true).toBe(true)) + it('should handle custom threshold', () => expect(true).toBe(true)) + }) +}) + +describe('Type Operations', () => { + describe('as()', () => { + it('should cast to new type', () => expect(true).toBe(true)) + it('should handle type constraints', () => expect(true).toBe(true)) + }) + + describe('pick()', () => { + it('should pick specified keys', () => expect(true).toBe(true)) + it('should handle missing keys', () => expect(true).toBe(true)) + }) + + describe('omit()', () => { + it('should omit specified keys', () => expect(true).toBe(true)) + it('should handle missing keys', () => expect(true).toBe(true)) + }) + + describe('transform()', () => { + it('should transform using schema', () => expect(true).toBe(true)) + it('should handle complex transformations', () => expect(true).toBe(true)) + }) +}) + +describe('Specialized Data Types', () => { + describe('geoDistance()', () => { + it('should calculate distances in km', () => expect(true).toBe(true)) + it('should calculate distances in miles', () => expect(true).toBe(true)) + }) + + describe('money()', () => { + it('should format as currency', () => expect(true).toBe(true)) + it('should handle different currencies', () => expect(true).toBe(true)) + }) + + describe('dateTime()', () => { + it('should format dates', () => expect(true).toBe(true)) + it('should handle different locales', () => expect(true).toBe(true)) + }) +}) + +describe('Database-like Operations', () => { + describe('query()', () => { + it('should handle SQL-like queries', () => expect(true).toBe(true)) + it('should support parameterized queries', () => expect(true).toBe(true)) + }) + + describe('having()', () => { + it('should filter grouped results', () => expect(true).toBe(true)) + it('should support different operators', () => expect(true).toBe(true)) + }) + + describe('crossJoin()', () => { + it('should perform cross join', () => expect(true).toBe(true)) + it('should handle empty collections', () => expect(true).toBe(true)) + }) + + describe('leftJoin()', () => { + it('should perform left join', () => expect(true).toBe(true)) + it('should handle missing matches', () => expect(true).toBe(true)) + }) +}) + +describe('Export Operations', () => { + describe('toSQL()', () => { + it('should generate SQL insert statement', () => expect(true).toBe(true)) + it('should handle complex data types', () => expect(true).toBe(true)) + }) + + describe('toGraphQL()', () => { + it('should generate GraphQL query', () => expect(true).toBe(true)) + it('should handle nested structures', () => expect(true).toBe(true)) + }) + + describe('toElastic()', () => { + it('should format for Elasticsearch', () => expect(true).toBe(true)) + it('should handle bulk operations', () => expect(true).toBe(true)) + }) + + describe('toPandas()', () => { + it('should generate pandas DataFrame code', () => expect(true).toBe(true)) + it('should handle complex data structures', () => expect(true).toBe(true)) + }) +}) + +describe('Streaming Operations', () => { + describe('stream()', () => { + it('should create readable stream', () => expect(true).toBe(true)) + it('should handle backpressure', () => expect(true).toBe(true)) + }) + + describe('fromStream()', () => { + it('should collect from stream', () => expect(true).toBe(true)) + it('should handle stream errors', () => expect(true).toBe(true)) + }) + + describe('batch()', () => { + it('should process in batches', () => expect(true).toBe(true)) + it('should handle custom batch sizes', () => expect(true).toBe(true)) + }) +}) + +describe('Performance Monitoring', () => { + describe('metrics()', () => { + it('should collect performance metrics', () => expect(true).toBe(true)) + it('should track memory usage', () => expect(true).toBe(true)) + }) + + describe('profile()', () => { + it('should measure execution time', () => expect(true).toBe(true)) + it('should measure memory usage', () => expect(true).toBe(true)) + }) + + describe('instrument()', () => { + it('should track operation counts', () => expect(true).toBe(true)) + it('should provide performance stats', () => expect(true).toBe(true)) + }) +}) + +describe('Development Tools', () => { + describe('playground()', () => { + it('should initialize playground', () => expect(true).toBe(true)) + }) + + describe('explain()', () => { + it('should explain operation pipeline', () => expect(true).toBe(true)) + }) + + describe('benchmark()', () => { + it('should benchmark operations', () => expect(true).toBe(true)) + it('should calculate complexity', () => expect(true).toBe(true)) + }) +}) + +describe('Version Control', () => { + describe('diff()', () => { + it('should compare versions', () => expect(true).toBe(true)) + it('should detect changes', () => expect(true).toBe(true)) + }) + + describe('diffSummary()', () => { + it('should summarize changes', () => expect(true).toBe(true)) + it('should count modifications', () => expect(true).toBe(true)) + }) +}) + +describe('Parallel Processing', () => { + describe('parallel()', () => { + it('should process in parallel', () => expect(true).toBe(true)) + it('should respect concurrency limits', () => expect(true).toBe(true)) + }) + + describe('prefetch()', () => { + it('should prefetch results', () => expect(true).toBe(true)) + it('should cache prefetched data', () => expect(true).toBe(true)) + }) +}) + +describe('Cache and Memoization', () => { + describe('cacheStore', () => { + it('should store cache entries', () => expect(true).toBe(true)) + it('should respect cache entry expiry', () => expect(true).toBe(true)) + }) +}) + +describe('Conditional Operations', () => { + describe('when()', () => { + it('should execute when condition is true', () => expect(true).toBe(true)) + it('should skip when condition is false', () => expect(true).toBe(true)) + }) + + describe('unless()', () => { + it('should execute when condition is false', () => expect(true).toBe(true)) + it('should skip when condition is true', () => expect(true).toBe(true)) + }) +}) + +describe('Navigation and Paging', () => { + describe('forPage()', () => { + it('should return specific page', () => expect(true).toBe(true)) + it('should handle out of bounds pages', () => expect(true).toBe(true)) + }) + + describe('cursor()', () => { + it('should create async iterator', () => expect(true).toBe(true)) + it('should respect chunk size', () => expect(true).toBe(true)) + }) +}) + +describe('Fuzzy Matching', () => { + describe('calculateFuzzyScore()', () => { + it('should calculate similarity score', () => expect(true).toBe(true)) + it('should handle empty strings', () => expect(true).toBe(true)) + }) + + describe('levenshteinDistance()', () => { + it('should calculate edit distance', () => expect(true).toBe(true)) + it('should handle empty strings', () => expect(true).toBe(true)) + }) +}) + +describe('Machine Learning Utilities', () => { + describe('randomSplit()', () => { + it('should split data for isolation forest', () => expect(true).toBe(true)) + it('should respect max depth', () => expect(true).toBe(true)) + }) + + describe('distance()', () => { + it('should calculate distance for KNN', () => expect(true).toBe(true)) + it('should handle different feature sets', () => expect(true).toBe(true)) + }) +}) + +describe('Type Handling', () => { + describe('KeyType', () => { + it('should enforce matching key types', () => expect(true).toBe(true)) + it('should handle type constraints', () => expect(true).toBe(true)) + }) +}) + +describe('Geographic Calculations', () => { + describe('haversine()', () => { + it('should calculate great circle distance', () => expect(true).toBe(true)) + it('should handle different units', () => expect(true).toBe(true)) + }) +}) + +describe('Collection Core', () => { + describe('createCollectionOperations()', () => { + it('should create new collection operations', () => expect(true).toBe(true)) + it('should initialize with correct state', () => expect(true).toBe(true)) + it('should maintain type safety', () => expect(true).toBe(true)) }) })