@gabrielrufino/cube 1.0.1 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/package.json +6 -6
  2. package/.github/workflows/cd.yml +0 -26
  3. package/.github/workflows/ci.yml +0 -23
  4. package/coverage/clover.xml +0 -706
  5. package/coverage/coverage-final.json +0 -19
  6. package/coverage/lcov-report/base.css +0 -224
  7. package/coverage/lcov-report/block-navigation.js +0 -87
  8. package/coverage/lcov-report/favicon.png +0 -0
  9. package/coverage/lcov-report/index.html +0 -327
  10. package/coverage/lcov-report/prettify.css +0 -1
  11. package/coverage/lcov-report/prettify.js +0 -2
  12. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  13. package/coverage/lcov-report/sorter.js +0 -196
  14. package/coverage/lcov-report/src/Algorithms/index.html +0 -117
  15. package/coverage/lcov-report/src/Algorithms/index.ts.html +0 -149
  16. package/coverage/lcov-report/src/Array/index.html +0 -117
  17. package/coverage/lcov-report/src/Array/index.ts.html +0 -290
  18. package/coverage/lcov-report/src/DataStructure/index.html +0 -117
  19. package/coverage/lcov-report/src/DataStructure/index.ts.html +0 -131
  20. package/coverage/lcov-report/src/Deck/index.html +0 -117
  21. package/coverage/lcov-report/src/Deck/index.ts.html +0 -239
  22. package/coverage/lcov-report/src/Dictionary/index.html +0 -117
  23. package/coverage/lcov-report/src/Dictionary/index.ts.html +0 -350
  24. package/coverage/lcov-report/src/DoublyLinkedList/Node.ts.html +0 -113
  25. package/coverage/lcov-report/src/DoublyLinkedList/index.html +0 -132
  26. package/coverage/lcov-report/src/DoublyLinkedList/index.ts.html +0 -836
  27. package/coverage/lcov-report/src/HashTable/index.html +0 -117
  28. package/coverage/lcov-report/src/HashTable/index.ts.html +0 -320
  29. package/coverage/lcov-report/src/HashTableLinearProbing/index.html +0 -117
  30. package/coverage/lcov-report/src/HashTableLinearProbing/index.ts.html +0 -95
  31. package/coverage/lcov-report/src/HashTableSeparateChaining/HashTableSeparateChainingElement.ts.html +0 -149
  32. package/coverage/lcov-report/src/HashTableSeparateChaining/index.html +0 -132
  33. package/coverage/lcov-report/src/HashTableSeparateChaining/index.ts.html +0 -398
  34. package/coverage/lcov-report/src/LinkedList/Node.ts.html +0 -110
  35. package/coverage/lcov-report/src/LinkedList/index.html +0 -132
  36. package/coverage/lcov-report/src/LinkedList/index.ts.html +0 -641
  37. package/coverage/lcov-report/src/List/index.html +0 -117
  38. package/coverage/lcov-report/src/List/index.ts.html +0 -89
  39. package/coverage/lcov-report/src/Queue/index.html +0 -117
  40. package/coverage/lcov-report/src/Queue/index.ts.html +0 -218
  41. package/coverage/lcov-report/src/Set/index.html +0 -117
  42. package/coverage/lcov-report/src/Set/index.ts.html +0 -488
  43. package/coverage/lcov-report/src/Stack/index.html +0 -117
  44. package/coverage/lcov-report/src/Stack/index.ts.html +0 -215
  45. package/coverage/lcov-report/src/index.html +0 -117
  46. package/coverage/lcov-report/src/index.ts.html +0 -125
  47. package/coverage/lcov.info +0 -1346
  48. package/src/Algorithms/index.spec.ts +0 -15
  49. package/src/Algorithms/index.ts +0 -21
  50. package/src/Array/IArray.ts +0 -10
  51. package/src/Array/index.spec.ts +0 -151
  52. package/src/Array/index.ts +0 -68
  53. package/src/BinarySearchTree/BinarySearchTreeNode.spec.ts +0 -29
  54. package/src/BinarySearchTree/BinarySearchTreeNode.ts +0 -23
  55. package/src/BinarySearchTree/IBinarySearchNodeOptions.ts +0 -6
  56. package/src/BinarySearchTree/IBinarySearchTree.ts +0 -16
  57. package/src/BinarySearchTree/IBinarySearchTreeData.ts +0 -9
  58. package/src/BinarySearchTree/index.spec.ts +0 -486
  59. package/src/BinarySearchTree/index.ts +0 -198
  60. package/src/DataStructure/index.spec.ts +0 -25
  61. package/src/DataStructure/index.ts +0 -15
  62. package/src/Deck/IDeck.ts +0 -10
  63. package/src/Deck/index.spec.ts +0 -131
  64. package/src/Deck/index.ts +0 -51
  65. package/src/Dictionary/IDictionary.ts +0 -18
  66. package/src/Dictionary/IDictionaryData.ts +0 -5
  67. package/src/Dictionary/index.spec.ts +0 -310
  68. package/src/Dictionary/index.ts +0 -88
  69. package/src/DoublyLinkedList/IDoublyLinkedList.ts +0 -18
  70. package/src/DoublyLinkedList/Node.ts +0 -9
  71. package/src/DoublyLinkedList/index.spec.ts +0 -478
  72. package/src/DoublyLinkedList/index.ts +0 -250
  73. package/src/Graph/GraphNodeNotFoundError.ts +0 -7
  74. package/src/Graph/GraphSearchNodeStates.ts +0 -8
  75. package/src/Graph/IGraph.ts +0 -15
  76. package/src/Graph/IGraphOptions.ts +0 -6
  77. package/src/Graph/index.spec.ts +0 -318
  78. package/src/Graph/index.ts +0 -170
  79. package/src/HashTable/IHashTable.ts +0 -11
  80. package/src/HashTable/IHashTableData.ts +0 -5
  81. package/src/HashTable/IHashTableInputs.ts +0 -5
  82. package/src/HashTable/IHashTableOptions.ts +0 -5
  83. package/src/HashTable/index.spec.ts +0 -136
  84. package/src/HashTable/index.ts +0 -78
  85. package/src/HashTableLinearProbing/HashTableLinearProbingElement.spec.ts +0 -28
  86. package/src/HashTableLinearProbing/HashTableLinearProbingElement.ts +0 -18
  87. package/src/HashTableLinearProbing/IHashTableLinearProbing.ts +0 -11
  88. package/src/HashTableLinearProbing/IHashTableLinearProbingData.ts +0 -7
  89. package/src/HashTableLinearProbing/IHashTableLinearProbingInputs.ts +0 -5
  90. package/src/HashTableLinearProbing/IHashTableLinearProbingOptions.ts +0 -5
  91. package/src/HashTableLinearProbing/index.spec.ts +0 -266
  92. package/src/HashTableLinearProbing/index.ts +0 -128
  93. package/src/HashTableSeparateChaining/HashTableSeparateChainingElement.ts +0 -21
  94. package/src/HashTableSeparateChaining/IHashTableSeparateChaining.ts +0 -12
  95. package/src/HashTableSeparateChaining/IHashTableSeparateChainingData.ts +0 -7
  96. package/src/HashTableSeparateChaining/IHashTableSeparateChainingInputs.ts +0 -5
  97. package/src/HashTableSeparateChaining/IHashTableSeparateChainingOptions.ts +0 -5
  98. package/src/HashTableSeparateChaining/index.spec.ts +0 -173
  99. package/src/HashTableSeparateChaining/index.ts +0 -104
  100. package/src/LinkedList/ILinkedList.ts +0 -15
  101. package/src/LinkedList/ILinkedListItem.ts +0 -6
  102. package/src/LinkedList/Node.ts +0 -8
  103. package/src/LinkedList/index.spec.ts +0 -355
  104. package/src/LinkedList/index.ts +0 -185
  105. package/src/List/index.ts +0 -1
  106. package/src/MaxHeap/IMaxHeap.ts +0 -10
  107. package/src/MaxHeap/IMaxHeapOptions.ts +0 -6
  108. package/src/MaxHeap/index.spec.ts +0 -161
  109. package/src/MaxHeap/index.ts +0 -91
  110. package/src/MinHeap/IMinHeap.ts +0 -10
  111. package/src/MinHeap/IMinHeapOptions.ts +0 -6
  112. package/src/MinHeap/index.spec.ts +0 -161
  113. package/src/MinHeap/index.ts +0 -91
  114. package/src/Queue/IQueue.ts +0 -9
  115. package/src/Queue/index.spec.ts +0 -92
  116. package/src/Queue/index.ts +0 -44
  117. package/src/Set/ISet.ts +0 -17
  118. package/src/Set/index.spec.ts +0 -246
  119. package/src/Set/index.ts +0 -134
  120. package/src/Stack/IStack.ts +0 -9
  121. package/src/Stack/index.spec.ts +0 -108
  122. package/src/Stack/index.ts +0 -43
  123. package/src/index.ts +0 -17
@@ -1,15 +0,0 @@
1
- import {describe, it, expect} from '@jest/globals';
2
-
3
- import Algorithms from './';
4
-
5
- describe('Algorithms', () => {
6
- describe('.decimalToBinary()', () => {
7
- it('Should return the correct result', () => {
8
- const n = 10;
9
- const expected = '1010';
10
-
11
- const result = Algorithms.decimalToBinary(n);
12
- expect(result).toBe(expected);
13
- });
14
- });
15
- });
@@ -1,21 +0,0 @@
1
- import {Stack} from '..';
2
-
3
- export default class Algorithms {
4
- public static decimalToBinary(n: number) {
5
- const stack = new Stack();
6
-
7
- while (n > 0) {
8
- const rem = Math.floor(n % 2);
9
- stack.push(rem);
10
- n = Math.floor(n / 2);
11
- }
12
-
13
- let binary = '';
14
- while (!stack.isEmpty) {
15
- // eslint-disable-next-line no-unsafe-optional-chaining
16
- binary += stack.pop()?.toString();
17
- }
18
-
19
- return binary;
20
- }
21
- }
@@ -1,10 +0,0 @@
1
- interface IArray<T> {
2
- insertInLastPosition(_element: T): T;
3
- insertInFirstPosition(_element: T): T;
4
- insertInPosition(_position: number, _element: T): T;
5
- removeFromLastPosition(): T | undefined;
6
- removeFromFirstPosition(): T | undefined;
7
- removeFromPosition(_position: number): T | undefined;
8
- }
9
-
10
- export default IArray;
@@ -1,151 +0,0 @@
1
- import {describe, expect, it} from '@jest/globals';
2
- import faker from 'faker';
3
-
4
- import Array from './';
5
-
6
- describe('Array', () => {
7
- it('Should create an empty array with no problems', () => {
8
- const array = new Array();
9
-
10
- expect(array.data).toEqual([]);
11
- expect(array.size).toBe(0);
12
- });
13
-
14
- it('Should create a filled array with no problems', () => {
15
- const array = new Array(1, 2, 3, 4, 5);
16
-
17
- expect(array.data).toEqual([1, 2, 3, 4, 5]);
18
- expect(array.size).toBe(5);
19
- });
20
-
21
- it('Should return the correct size of the array', () => {
22
- const size = faker.datatype.number(200);
23
- const params = [];
24
-
25
- for (let i = 0; i < size; i++) {
26
- params.push(faker.datatype.number());
27
- }
28
-
29
- const array = new Array(...params);
30
-
31
- expect(array.size).toBe(size);
32
- });
33
-
34
- describe('.insertInLastPosition()', () => {
35
- it('Should insert a new element in the last position', () => {
36
- const array = new Array(1, 2, 3);
37
- array.insertInLastPosition(4);
38
-
39
- expect(array.data).toEqual([1, 2, 3, 4]);
40
- });
41
- });
42
-
43
- describe('.insertInFirstPosition()', () => {
44
- it('Should insert a new element in the first position', () => {
45
- const array = new Array(2, 3, 4);
46
- array.insertInFirstPosition(1);
47
-
48
- expect(array.data).toEqual([1, 2, 3, 4]);
49
- });
50
-
51
- it('Should insert a new element in a arbitrary position of an array', () => {
52
- const array = new Array(1, 2, 4);
53
- array.insertInPosition(2, 3);
54
-
55
- expect(array.data).toEqual([1, 2, 3, 4]);
56
- });
57
- });
58
-
59
- describe('.removeFromLastPosition()', () => {
60
- it('Should remove and return the last element of the array', () => {
61
- const array = new Array(1, 2, 3, 4);
62
- const element = array.removeFromLastPosition();
63
-
64
- expect(array.data).toEqual([1, 2, 3]);
65
- expect(element).toBe(4);
66
- });
67
-
68
- it('Should ruturn undefined when trying to remove the last element of an empty array', () => {
69
- const array = new Array();
70
- const element = array.removeFromLastPosition();
71
-
72
- expect(array.data).toEqual([]);
73
- expect(element).toBe(undefined);
74
- });
75
- });
76
-
77
- describe('.removeFromFirstPosition()', () => {
78
- it('Should remove and return the first element of the array', () => {
79
- const array = new Array(1, 2, 3, 4);
80
- const element = array.removeFromFirstPosition();
81
-
82
- expect(array.data).toEqual([2, 3, 4]);
83
- expect(element).toBe(1);
84
- });
85
-
86
- it('Should ruturn undefined when trying to remove the first element of an empty array', () => {
87
- const array = new Array();
88
- const element = array.removeFromFirstPosition();
89
-
90
- expect(array.data).toEqual([]);
91
- expect(element).toBe(undefined);
92
- });
93
- });
94
-
95
- describe('.removeFromPosition()', () => {
96
- it('Should remove and return the element of an arbitrary position from array', () => {
97
- const array = new Array(1, 2, 3, 4);
98
- const element = array.removeFromPosition(2);
99
-
100
- expect(array.data).toEqual([1, 2, 4]);
101
- expect(element).toBe(3);
102
- });
103
-
104
- it('Should return return when trying to remove the element of an arbitrary position from an empty array', () => {
105
- const array = new Array();
106
- const element = array.removeFromPosition(faker.datatype.number());
107
-
108
- expect(array.data).toEqual([]);
109
- expect(element).toBe(undefined);
110
- });
111
- });
112
-
113
- describe('Bidimensional array', () => {
114
- it('Should create an bidimensional array with no problems', () => {
115
- const array = new Array<Array>(
116
- new Array(1, 2, 3),
117
- new Array(4, 5, 6),
118
- new Array(7, 8, 9),
119
- );
120
-
121
- expect(array.data).toEqual([
122
- new Array(1, 2, 3),
123
- new Array(4, 5, 6),
124
- new Array(7, 8, 9),
125
- ]);
126
- expect(array.data[0].data).toEqual([1, 2, 3]);
127
- expect(array.data[1].data).toEqual([4, 5, 6]);
128
- expect(array.data[2].data).toEqual([7, 8, 9]);
129
- expect(array.size).toBe(3);
130
- expect(array.data[0].size).toEqual(3);
131
- expect(array.data[1].size).toEqual(3);
132
- expect(array.data[2].size).toEqual(3);
133
- });
134
- });
135
-
136
- describe('Conversion to primitive', () => {
137
- it('Should return the elements separated by comma in string conversion', () => {
138
- const array = new Array(1, 2, 3, 4);
139
- const string = String(array);
140
-
141
- expect(string).toBe('1, 2, 3, 4');
142
- });
143
-
144
- it('Should return the array size in number conversion', () => {
145
- const array = new Array(1, 2, 3, 4);
146
- const number = Number(array);
147
-
148
- expect(number).toBe(4);
149
- });
150
- });
151
- });
@@ -1,68 +0,0 @@
1
- import DataStructure from '../DataStructure';
2
- import IArray from './IArray';
3
-
4
- export default class Array<T = number> extends DataStructure<T> implements IArray<T> {
5
- constructor(...inputs: T[]) {
6
- super(inputs);
7
- }
8
-
9
- public insertInLastPosition(element: T): T {
10
- this._data[this.size] = element;
11
- return element;
12
- }
13
-
14
- public insertInFirstPosition(element: T): T {
15
- for (let i = this.size; i > 0; i--) {
16
- this._data[i] = this._data[i - 1];
17
- }
18
-
19
- this._data[0] = element;
20
- return element;
21
- }
22
-
23
- public insertInPosition(position: number, element: T): T {
24
- this._data.splice(position, 0, element);
25
- return element;
26
- }
27
-
28
- public removeFromLastPosition(): T | undefined {
29
- const element = this._data[this.size - 1];
30
- const array = new Array<T>();
31
-
32
- for (let i = 0; i < this.size - 1; i++) {
33
- array.insertInLastPosition(this._data[i]);
34
- }
35
-
36
- this._data = array.data;
37
- return element;
38
- }
39
-
40
- public removeFromFirstPosition(): T | undefined {
41
- const element = this._data[0];
42
- const array = new Array<T>();
43
-
44
- for (let i = 0; i < this.size - 1; i++) {
45
- array.insertInLastPosition(this._data[i + 1]);
46
- }
47
-
48
- this._data = array.data;
49
- return element;
50
- }
51
-
52
- public removeFromPosition(position: number): T | undefined {
53
- const [element] = this._data.splice(position, 1);
54
- return element;
55
- }
56
-
57
- private [Symbol.toPrimitive](type: string): string | number | null {
58
- if (type === 'string') {
59
- return this.data.join(', ');
60
- }
61
-
62
- if (type === 'number') {
63
- return this.size;
64
- }
65
-
66
- return null;
67
- }
68
- }
@@ -1,29 +0,0 @@
1
- import {describe, it, expect} from '@jest/globals';
2
- import faker from 'faker';
3
-
4
- import BinarySearchTreeNode from './BinarySearchTreeNode';
5
-
6
- describe('BinarySearchTreeNode', () => {
7
- it('Should create a node without problems', () => {
8
- const number = faker.datatype.number();
9
- const binarySearchTreeNode = new BinarySearchTreeNode<number>(number);
10
-
11
- expect(binarySearchTreeNode.value).toBe(number);
12
- expect(binarySearchTreeNode.left).toBeNull();
13
- expect(binarySearchTreeNode.right).toBeNull();
14
- });
15
-
16
- describe('Conversion to primitive', () => {
17
- it('Should return the value poiting to left and right nodes in string conversion', () => {
18
- const rootNumber = faker.datatype.number();
19
- const leftNumber = faker.datatype.number();
20
- const rightNumber = faker.datatype.number();
21
- const node = new BinarySearchTreeNode(rootNumber);
22
- node.left = new BinarySearchTreeNode(leftNumber);
23
- node.right = new BinarySearchTreeNode(rightNumber);
24
- const string = String(node);
25
-
26
- expect(string).toBe(`[[null] <= (${leftNumber}) => [null]] <= (${rootNumber}) => [[null] <= (${rightNumber}) => [null]]`);
27
- });
28
- });
29
- });
@@ -1,23 +0,0 @@
1
- export default class BinarySearchTreeNode<T> {
2
- public value: T;
3
- public left: BinarySearchTreeNode<T> | null = null;
4
- public right: BinarySearchTreeNode<T> | null = null;
5
-
6
- constructor(value: T) {
7
- this.value = value;
8
- this.left = null;
9
- this.right = null;
10
- }
11
-
12
- [Symbol.toPrimitive](type: string): string | number | null {
13
- if (type === 'string') {
14
- return `[${this.left}] <= (${this.value}) => [${this.right}]`;
15
- }
16
-
17
- if (type === 'number') {
18
- return 1 + (this.left ? 1 : 0) + (this.right ? 1 : 0);
19
- }
20
-
21
- return null;
22
- }
23
- }
@@ -1,6 +0,0 @@
1
- interface IBinarySearchNodeOptions<T> {
2
- inputs?: T[];
3
- lessThanOrEqualTo?: (_value1: T, _value2: T) => boolean;
4
- }
5
-
6
- export default IBinarySearchNodeOptions;
@@ -1,16 +0,0 @@
1
- import IBinarySearchTreeData from './IBinarySearchTreeData';
2
-
3
- interface IBinarySearchTree<T> {
4
- get data(): IBinarySearchTreeData<T>;
5
- get size(): number;
6
- get min(): T | null;
7
- get max(): T | null;
8
- insert(_value: T): T;
9
- walkInOrder(_callback: (_value: T) => any): void;
10
- walkPreOrder(_callback: (_value: T) => any): void;
11
- walkPostOrder(_callback: (_value: T) => any): void;
12
- search(_value: T): boolean;
13
- remove(_value: T): T | null;
14
- }
15
-
16
- export default IBinarySearchTree;
@@ -1,9 +0,0 @@
1
- import BinarySearchTreeNode from './BinarySearchTreeNode';
2
-
3
- interface IBinarySearchTreeData<T> {
4
- left: BinarySearchTreeNode<T> | null;
5
- value: T | null;
6
- right: BinarySearchTreeNode<T> | null;
7
- }
8
-
9
- export default IBinarySearchTreeData;