Skip to content

Commit

Permalink
remove tests
Browse files Browse the repository at this point in the history
  • Loading branch information
manusant committed Apr 10, 2024
1 parent 421d0f4 commit 5861f6c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 172 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "katxupa",
"version": "1.9.2",
"version": "1.9.4",
"description": "Delicious Dish for Typescript and JavaScript projects",
"author": "Manuel Santos <ney.br.santos@gmail.com>",
"license": "MIT",
Expand All @@ -13,7 +13,7 @@
"bugs": {
"url": "https://github.com/manusant/Katxupa/issues"
},
"homepage": "https://manusant.github.io/Katxupa/",
"homepage": "https://katxupa.gitbook.io",
"keywords": [
"utility",
"typescript",
Expand Down
39 changes: 8 additions & 31 deletions src/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ declare global {
* @returns {Record<string, V>} - A record associating keys with their corresponding values.
* @example
* const elements = [{ id: 1, value: 'a' }, { id: 2, value: 'b' }];
* const keyValuePairs = collection.associateWith(
* const keyValuePairs = elements.associateWith(
* (element) => element.id,
* (element) => element.value
* );
Expand All @@ -52,18 +52,7 @@ declare global {
): Record<string, V>;

/**
* Maps each element to a new value using the provided transformation function.
* @template U - The type of the resulting elements.
* @param {function(T, number): U} transform - The function to transform each element.
* @returns {ReadonlyArray<U>} - A readonly array containing the transformed elements.
* @example
* const numbers = [1, 2, 3];
* const squaredNumbers = collection.mapIndexed((num, index) => num * num + index);
*/
mapIndexed<U>(transform: (element: T, index: number) => U): ReadonlyArray<U>;

/**
* Sorts the collection using the provided comparator function.
* Sorts the array using the provided comparator function.
*
* @param {function(T, T): number} comparator - The function to compare elements.
* @return this - reference of the sorted array
Expand All @@ -84,7 +73,7 @@ declare global {
* @param {T[]} other - The array to concatenate with the current collection.
* @returns {T[]} - A new array containing elements from both the current collection and the provided array.
* @example
* const collection = new Collection(1, 2, 3);
* const collection = mutableListOf(1, 2, 3);
* const otherArray = [4, 5, 6];
* const result = collection.plus(otherArray);
* // result is [1, 2, 3, 4, 5, 6]
Expand All @@ -96,7 +85,7 @@ declare global {
* @param {T[]} other - The array containing elements to be removed from the current collection.
* @returns {T[]} - A new array with elements not present in the provided array.
* @example
* const collection = new Collection(1, 2, 3, 4, 5);
* const collection = mutableListOf(1, 2, 3, 4, 5);
* const elementsToRemove = [3, 5];
* const result = collection.minus(elementsToRemove);
* // result is [1, 2, 4]
Expand All @@ -110,7 +99,7 @@ declare global {
* @return this - reference to affected array
*
* @example
* const collection = new Collection(1, 2, 3, 4, 5);
* const collection = mutableListOf(1, 2, 3, 4, 5);
* const elementsToRemove = [3, 5];
* collection.minusAssign(elementsToRemove);
* // collection is now [1, 2, 4]
Expand All @@ -124,7 +113,7 @@ declare global {
* @return this - reference to affected array
*
* @example
* const collection = new Collection(1, 2, 3);
* const collection = mutableListOf(1, 2, 3);
* const additionalElements = [4, 5, 6];
* collection.plusAssign(additionalElements);
* // collection is now [1, 2, 3, 4, 5, 6]
Expand All @@ -135,7 +124,7 @@ declare global {
* Returns the number of elements in the collection.
* @returns {number} - The number of elements in the collection.
* @example
* const collection = new Collection(1, 2, 3, 4, 5);
* const collection = mutableListOf(1, 2, 3, 4, 5);
* const count = collection.count();
* // count is 5
*/
Expand All @@ -146,7 +135,7 @@ declare global {
* @param {((item: T) => boolean) | T[]} predicate - The predicate function or collection of elements to remove.
* @returns {T[]} - A new array with elements removed based on the provided predicate or collection.
* @example
* const collection = new Collection(1, 2, 3, 4, 5);
* const collection = mutableListOf(1, 2, 3, 4, 5);
* const elementsToRemove = [3, 5];
* const result = collection.removeAll(elementsToRemove);
* // result is [1, 2, 4]
Expand Down Expand Up @@ -256,18 +245,6 @@ Object.defineProperty(Array.prototype, 'associateWith', {
configurable: false
});

Object.defineProperty(Array.prototype, 'mapIndexed', {
value: function <T, U>(
this: Array<T>,
transform: (element: T, index: number) => U
): ReadonlyArray<U> {
return this.map((element, index) => transform(element, index));
},
enumerable: false,
writable: false,
configurable: false
});

Object.defineProperty(Array.prototype, 'sortBy', {
value: function <T>(
this: Array<T>,
Expand Down
105 changes: 0 additions & 105 deletions src/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,66 +34,6 @@ declare global {
function emptySet<T>(): ReadonlySet<T>;

interface Set<T> {
/**
* Returns a new Set containing elements that are common between the current Set and another Set.
* @param {Set<T>} other - The Set to intersect with.
* @returns {Set<T>} - A new Set with common elements.
* @example
* const set1 = setOf([1, 2, 3]);
* const set2 = setOf([2, 3, 4]);
* const intersectionSet = set1.intersection(set2);
* // Result: Set([2, 3])
*/
intersection(other: Set<T>): Set<T>;

/**
* Returns a new Set containing all unique elements from both the current Set and another Set.
* @param {Set<T>} other - The Set to union with.
* @returns {Set<T>} - A new Set with elements from both Sets.
* @example
* const set1 = setOf([1, 2, 3]);
* const set2 = setOf([3, 4, 5]);
* const unionSet = set1.union(set2);
* // Result: Set([1, 2, 3, 4, 5])
*/
union(other: Set<T>): Set<T>;

/**
* Returns a new Set containing elements that are in the current Set but not in another Set.
* @param {Set<T>} other - The Set to subtract from the current Set.
* @returns {Set<T>} - A new Set with elements not present in the other Set.
* @example
* const set1 = setOf([1, 2, 3]);
* const set2 = setOf([2, 3, 4]);
* const differenceSet = set1.difference(set2);
* // Result: Set([1])
*/
difference(other: Set<T>): Set<T>;

/**
* Checks if the current Set is a subset of another Set.
* @param {Set<T>} other - The Set to check against.
* @returns {boolean} - true if the current Set is a subset, otherwise false.
* @example
* const set1 = setOf([1, 2]);
* const set2 = setOf([1, 2, 3, 4]);
* const isSubset = set1.isSubsetOf(set2);
* // Result: true
*/
isSubsetOf(other: Set<T>): boolean;

/**
* Checks if the current Set is a superset of another Set.
* @param {Set<T>} other - The Set to check against.
* @returns {boolean} - true if the current Set is a superset, otherwise false.
* @example
* const set1 = setOf([1, 2, 3, 4]);
* const set2 = setOf([1, 2]);
* const isSuperset = set1.isSupersetOf(set2);
* // Result: true
*/
isSupersetOf(other: Set<T>): boolean;

/**
* Maps each element to a new value using the provided transformation function.
* @template U - The type of the resulting elements.
Expand Down Expand Up @@ -135,51 +75,6 @@ _global.emptySet = function <T>(): ReadonlySet<T> {
}

// Set Extension
Object.defineProperty(Set.prototype, 'intersection', {
value: function <T>(this: Set<T>, other: Set<T>): Set<T> {
return new Set([...this].filter((element) => other.has(element)));
},
enumerable: false,
writable: false,
configurable: false
});

Object.defineProperty(Set.prototype, 'union', {
value: function <T>(this: Set<T>, other: Set<T>): Set<T> {
return new Set([...this, ...other]);
},
enumerable: false,
writable: false,
configurable: false
});

Object.defineProperty(Set.prototype, 'difference', {
value: function <T>(this: Set<T>, other: Set<T>): Set<T> {
return new Set([...this].filter((element) => !other.has(element)));
},
enumerable: false,
writable: false,
configurable: false
});

Object.defineProperty(Set.prototype, 'isSubsetOf', {
value: function <T>(this: Set<T>, other: Set<T>): boolean {
return [...this].every((element) => other.has(element));
},
enumerable: false,
writable: false,
configurable: false
});

Object.defineProperty(Set.prototype, 'isSupersetOf', {
value: function <T>(this: Set<T>, other: Set<T>): boolean {
return [...other].every((element) => this.has(element));
},
enumerable: false,
writable: false,
configurable: false
});

Object.defineProperty(Set.prototype, 'map', {
value: function <T, U>(this: Set<T>, transform: (element: T) => U): Set<U> {
return new Set([...this].map(transform));
Expand Down
6 changes: 0 additions & 6 deletions test/array.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ describe('Array Functions', () => {
});
});

test('mapIndexed', () => {
const mappedArray = array.mapIndexed((element, index) => element + index);
expect(Array.isArray(mappedArray)).toBe(true);
expect(mappedArray).toEqual([1, 3, 5, 7, 9]);
});

test('sortBy', () => {
const users = [
{ name: 'John', age: 30 },
Expand Down
28 changes: 0 additions & 28 deletions test/set.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,6 @@ describe('Set Functions', () => {
set2 = setOf(2, 3, 4);
});

test('intersection', () => {
const intersectionSet = set1.intersection(set2);
expect(intersectionSet instanceof Set).toBe(true);
expect([...intersectionSet]).toEqual([2, 3]);
});

test('union', () => {
const unionSet = set1.union(set2);
expect(unionSet instanceof Set).toBe(true);
expect([...unionSet]).toEqual([1, 2, 3, 4]);
});

test('difference', () => {
const differenceSet = set1.difference(set2);
expect(differenceSet instanceof Set).toBe(true);
expect([...differenceSet]).toEqual([1]);
});

test('isSubsetOf', () => {
const isSubset = set1.isSubsetOf(set2);
expect(isSubset).toBe(false);
});

test('isSupersetOf', () => {
const isSuperset = set1.isSupersetOf(set2);
expect(isSuperset).toBe(false);
});

test('map', () => {
const squaredSet = set1.map((num) => num * num);
expect(squaredSet instanceof Set).toBe(true);
Expand Down

0 comments on commit 5861f6c

Please sign in to comment.