@gabrielrufino/cerebrum 2.0.1 → 2.0.3
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.
- package/package.json +1 -1
- package/src/Search/{BinarySearch.test.ts → BinarySearch.spec.ts} +1 -1
- package/src/Search/{LinearSearch.test.ts → LinearSearch.spec.ts} +1 -1
- package/src/Search/{Search.test.ts → Search.spec.ts} +1 -1
- package/tsconfig.json +2 -1
- package/dist/NLP/Tokenizer.test.js +0 -49
- package/dist/Search/BinarySearch.test.js +0 -8
- package/dist/Search/LinearSearch.test.js +0 -15
- package/dist/Search/Search.test.js +0 -60
- /package/src/NLP/{Tokenizer.test.ts → Tokenizer.spec.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
import { LinearSearch } from './LinearSearch'
|
|
3
|
-
import { SearchTestsSuite } from './Search.
|
|
3
|
+
import { SearchTestsSuite } from './Search.spec'
|
|
4
4
|
|
|
5
5
|
describe('LinearSearch', () => {
|
|
6
6
|
SearchTestsSuite.execute(LinearSearch)
|
|
@@ -9,7 +9,7 @@ describe('Search', () => {
|
|
|
9
9
|
})
|
|
10
10
|
|
|
11
11
|
export class SearchTestsSuite {
|
|
12
|
-
static execute(Class:
|
|
12
|
+
static execute(Class: new (elements?: Array<number>, target?: number) => Search) {
|
|
13
13
|
it('should return the index of the target when it exists in the array', () => {
|
|
14
14
|
const result = new Class()
|
|
15
15
|
.setElements([1, 2, 3, 4, 5])
|
package/tsconfig.json
CHANGED
|
@@ -106,5 +106,6 @@
|
|
|
106
106
|
/* Completeness */
|
|
107
107
|
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
108
108
|
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
109
|
-
},
|
|
109
|
+
},
|
|
110
|
+
"exclude": ["**/*.spec.ts"]
|
|
110
111
|
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const vitest_1 = require("vitest");
|
|
4
|
-
const Tokenizer_1 = require("./Tokenizer");
|
|
5
|
-
(0, vitest_1.describe)('Tokenizer', () => {
|
|
6
|
-
(0, vitest_1.it)('should tokenize a simple text', () => {
|
|
7
|
-
const tokens = new Tokenizer_1.Tokenizer()
|
|
8
|
-
.setText("Hello world")
|
|
9
|
-
.execute();
|
|
10
|
-
(0, vitest_1.expect)(tokens).toEqual(['Hello', 'world']);
|
|
11
|
-
});
|
|
12
|
-
(0, vitest_1.it)('should remove punctuation', () => {
|
|
13
|
-
const tokens = new Tokenizer_1.Tokenizer()
|
|
14
|
-
.setText("Hello, world!")
|
|
15
|
-
.execute();
|
|
16
|
-
(0, vitest_1.expect)(tokens).toEqual(['Hello', 'world']);
|
|
17
|
-
});
|
|
18
|
-
(0, vitest_1.it)('should handle multiple spaces between words', () => {
|
|
19
|
-
const tokens = new Tokenizer_1.Tokenizer()
|
|
20
|
-
.setText("Hello world")
|
|
21
|
-
.execute();
|
|
22
|
-
(0, vitest_1.expect)(tokens).toEqual(['Hello', 'world']);
|
|
23
|
-
});
|
|
24
|
-
(0, vitest_1.it)('should ignore specified words', () => {
|
|
25
|
-
const tokens = new Tokenizer_1.Tokenizer()
|
|
26
|
-
.setText("Hello, world! Let's tokenize this text with attention to hyphenated-words.")
|
|
27
|
-
.setIgnore(['this', 'with', 'to'])
|
|
28
|
-
.execute();
|
|
29
|
-
(0, vitest_1.expect)(tokens).toEqual(['Hello', 'world', "Let's", 'tokenize', 'text', 'attention', 'hyphenated-words']);
|
|
30
|
-
});
|
|
31
|
-
(0, vitest_1.it)('should return an empty array for empty text', () => {
|
|
32
|
-
const tokens = new Tokenizer_1.Tokenizer()
|
|
33
|
-
.execute();
|
|
34
|
-
(0, vitest_1.expect)(tokens).toEqual([]);
|
|
35
|
-
});
|
|
36
|
-
(0, vitest_1.it)('should allow setting text and ignore list after instantiation', () => {
|
|
37
|
-
const tokenizer = new Tokenizer_1.Tokenizer();
|
|
38
|
-
tokenizer.setText("Testing tokenization").setIgnore(['Testing']);
|
|
39
|
-
const tokens = tokenizer.execute();
|
|
40
|
-
(0, vitest_1.expect)(tokens).toEqual(['tokenization']);
|
|
41
|
-
});
|
|
42
|
-
(0, vitest_1.it)('should be case insensitive when filtering ignored words', () => {
|
|
43
|
-
const tokens = new Tokenizer_1.Tokenizer()
|
|
44
|
-
.setText("Tokenize and ignore some Words")
|
|
45
|
-
.setIgnore(['and', 'some', 'words'])
|
|
46
|
-
.execute();
|
|
47
|
-
(0, vitest_1.expect)(tokens).toEqual(['Tokenize', 'ignore']);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const vitest_1 = require("vitest");
|
|
4
|
-
const BinarySearch_1 = require("./BinarySearch");
|
|
5
|
-
const Search_test_1 = require("./Search.test");
|
|
6
|
-
(0, vitest_1.describe)('BinarySearch', () => {
|
|
7
|
-
Search_test_1.SearchTestsSuite.execute(BinarySearch_1.BinarySearch);
|
|
8
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const vitest_1 = require("vitest");
|
|
4
|
-
const LinearSearch_1 = require("./LinearSearch");
|
|
5
|
-
const Search_test_1 = require("./Search.test");
|
|
6
|
-
(0, vitest_1.describe)('LinearSearch', () => {
|
|
7
|
-
Search_test_1.SearchTestsSuite.execute(LinearSearch_1.LinearSearch);
|
|
8
|
-
(0, vitest_1.it)('should return the index when target is 0', () => {
|
|
9
|
-
const result = new LinearSearch_1.LinearSearch()
|
|
10
|
-
.setElements([1, 0, 3, 4, 5])
|
|
11
|
-
.setTarget(0)
|
|
12
|
-
.execute();
|
|
13
|
-
(0, vitest_1.expect)(result).toBe(1);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SearchTestsSuite = void 0;
|
|
4
|
-
const vitest_1 = require("vitest");
|
|
5
|
-
const Search_1 = require("./Search");
|
|
6
|
-
(0, vitest_1.describe)('Search', () => {
|
|
7
|
-
(0, vitest_1.it)('should be defined', () => {
|
|
8
|
-
(0, vitest_1.expect)(Search_1.Search).toBeDefined();
|
|
9
|
-
});
|
|
10
|
-
});
|
|
11
|
-
class SearchTestsSuite {
|
|
12
|
-
static execute(Class) {
|
|
13
|
-
(0, vitest_1.it)('should return the index of the target when it exists in the array', () => {
|
|
14
|
-
const result = new Class()
|
|
15
|
-
.setElements([1, 2, 3, 4, 5])
|
|
16
|
-
.setTarget(3)
|
|
17
|
-
.execute();
|
|
18
|
-
(0, vitest_1.expect)(result).toBe(2);
|
|
19
|
-
});
|
|
20
|
-
(0, vitest_1.it)('should return null when the target does not exist in the array', () => {
|
|
21
|
-
const result = new Class()
|
|
22
|
-
.setElements([1, 2, 3, 4, 5])
|
|
23
|
-
.setTarget(6)
|
|
24
|
-
.execute();
|
|
25
|
-
(0, vitest_1.expect)(result).toBeNull();
|
|
26
|
-
});
|
|
27
|
-
(0, vitest_1.it)('should throw an error if elements are not defined', () => {
|
|
28
|
-
const search = new Class()
|
|
29
|
-
.setTarget(3);
|
|
30
|
-
(0, vitest_1.expect)(() => search.execute()).toThrow('Elements should be defined');
|
|
31
|
-
});
|
|
32
|
-
(0, vitest_1.it)('should throw an error if target is not defined', () => {
|
|
33
|
-
const search = new Class()
|
|
34
|
-
.setElements([1, 2, 3, 4, 5]);
|
|
35
|
-
(0, vitest_1.expect)(() => search.execute()).toThrow('Target should be defined');
|
|
36
|
-
});
|
|
37
|
-
(0, vitest_1.it)('should return the index when searching for 0 in a list that contains 0', () => {
|
|
38
|
-
const result = new Class()
|
|
39
|
-
.setElements([0, 1, 2, 3, 4, 5])
|
|
40
|
-
.setTarget(0)
|
|
41
|
-
.execute();
|
|
42
|
-
(0, vitest_1.expect)(result).toBe(0);
|
|
43
|
-
});
|
|
44
|
-
(0, vitest_1.it)('should return null if target is smaller than all elements', () => {
|
|
45
|
-
const result = new Class()
|
|
46
|
-
.setElements([10, 20, 30, 40, 50])
|
|
47
|
-
.setTarget(5)
|
|
48
|
-
.execute();
|
|
49
|
-
(0, vitest_1.expect)(result).toBeNull();
|
|
50
|
-
});
|
|
51
|
-
(0, vitest_1.it)('should return null if target is larger than all elements', () => {
|
|
52
|
-
const result = new Class()
|
|
53
|
-
.setElements([10, 20, 30, 40, 50])
|
|
54
|
-
.setTarget(60)
|
|
55
|
-
.execute();
|
|
56
|
-
(0, vitest_1.expect)(result).toBeNull();
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.SearchTestsSuite = SearchTestsSuite;
|
|
File without changes
|