Skip to content

Commit 4368fa8

Browse files
.
0 parents  commit 4368fa8

File tree

6 files changed

+370
-0
lines changed

6 files changed

+370
-0
lines changed

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
max_line_length = 140
7+
indent_size = 2
8+
indent_style = space
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
12+
[*.md]
13+
max_line_length = off
14+
trim_trailing_whitespace = false

.gitattributes

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# https://html5boilerplate.com
2+
3+
## AUTO-DETECT
4+
* text=auto
5+
6+
## SOURCE CODE
7+
*.bat text eol=crlf
8+
*.coffee text
9+
*.css text
10+
*.htm text
11+
*.html text
12+
*.inc text
13+
*.ini text
14+
*.js text
15+
*.json text
16+
*.jsx text
17+
*.less text
18+
*.od text
19+
*.onlydata text
20+
*.php text
21+
*.pl text
22+
*.py text
23+
*.rb text
24+
*.sass text
25+
*.scm text
26+
*.scss text
27+
*.sh text eol=lf
28+
*.sql text
29+
*.styl text
30+
*.tag text
31+
*.ts text
32+
*.tsx text
33+
*.xml text
34+
*.xhtml text
35+
36+
## DOCKER
37+
*.dockerignore text
38+
Dockerfile text
39+
40+
## DOCUMENTATION
41+
*.markdown text
42+
*.md text
43+
*.mdwn text
44+
*.mdown text
45+
*.mkd text
46+
*.mkdn text
47+
*.mdtxt text
48+
*.mdtext text
49+
*.txt text
50+
AUTHORS text
51+
CHANGELOG text
52+
CHANGES text
53+
CONTRIBUTING text
54+
COPYING text
55+
copyright text
56+
*COPYRIGHT* text
57+
INSTALL text
58+
license text
59+
LICENSE text
60+
NEWS text
61+
readme text
62+
*README* text
63+
TODO text
64+
65+
## TEMPLATES
66+
*.dot text
67+
*.ejs text
68+
*.haml text
69+
*.handlebars text
70+
*.hbs text
71+
*.hbt text
72+
*.jade text
73+
*.latte text
74+
*.mustache text
75+
*.njk text
76+
*.phtml text
77+
*.tmpl text
78+
*.tpl text
79+
*.twig text
80+
81+
## LINTERS
82+
.babelrc text
83+
.csslintrc text
84+
.eslintrc text
85+
.htmlhintrc text
86+
.jscsrc text
87+
.jshintrc text
88+
.jshintignore text
89+
.prettierrc text
90+
.stylelintrc text
91+
92+
## CONFIGS
93+
*.bowerrc text
94+
*.cnf text
95+
*.conf text
96+
*.config text
97+
.browserslistrc text
98+
.editorconfig text
99+
.gitattributes text
100+
.gitconfig text
101+
.gitignore text
102+
.htaccess text
103+
*.npmignore text
104+
*.yaml text
105+
*.yml text
106+
browserslist text
107+
Makefile text
108+
makefile text
109+
110+
## HEROKU
111+
Procfile text
112+
.slugignore text
113+
114+
## GRAPHICS
115+
*.ai binary
116+
*.bmp binary
117+
*.eps binary
118+
*.gif binary
119+
*.ico binary
120+
*.jng binary
121+
*.jp2 binary
122+
*.jpg binary
123+
*.jpeg binary
124+
*.jpx binary
125+
*.jxr binary
126+
*.pdf binary
127+
*.png binary
128+
*.psb binary
129+
*.psd binary
130+
*.svg text
131+
*.svgz binary
132+
*.tif binary
133+
*.tiff binary
134+
*.wbmp binary
135+
*.webp binary
136+
137+
## AUDIO
138+
*.kar binary
139+
*.m4a binary
140+
*.mid binary
141+
*.midi binary
142+
*.mp3 binary
143+
*.ogg binary
144+
*.ra binary
145+
146+
## VIDEO
147+
*.3gpp binary
148+
*.3gp binary
149+
*.as binary
150+
*.asf binary
151+
*.asx binary
152+
*.fla binary
153+
*.flv binary
154+
*.m4v binary
155+
*.mng binary
156+
*.mov binary
157+
*.mp4 binary
158+
*.mpeg binary
159+
*.mpg binary
160+
*.ogv binary
161+
*.swc binary
162+
*.swf binary
163+
*.webm binary
164+
165+
## ARCHIVES
166+
*.7z binary
167+
*.gz binary
168+
*.jar binary
169+
*.rar binary
170+
*.tar binary
171+
*.zip binary
172+
173+
## FONTS
174+
*.ttf binary
175+
*.eot binary
176+
*.otf binary
177+
*.woff binary
178+
*.woff2 binary
179+
180+
## EXECUTABLES
181+
*.exe binary
182+
*.pyc binary

.gitignore

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Compiled output
2+
/build
3+
/dist
4+
/documentation
5+
/out-tsc
6+
/tmp
7+
8+
# Composer
9+
./vendor
10+
composer.lock
11+
12+
# Dependencies
13+
/node_modules
14+
package-lock.json
15+
16+
# Environment
17+
.env
18+
19+
# IDEs + Editors
20+
*.launch
21+
*.sublime-workspace
22+
/.idea
23+
.c9
24+
.classpath
25+
.history
26+
.project
27+
.settings
28+
29+
# IDE - VSCode
30+
.vscode/*
31+
!.vscode/extensions.json
32+
!.vscode/launch.json
33+
!.vscode/settings.json
34+
!.vscode/tasks.json
35+
36+
# Misc
37+
/.sass-cache
38+
/connect.lock
39+
/coverage
40+
/libpeerconnection.log
41+
/typings
42+
npm-debug.log
43+
php_errorlog
44+
testem.log
45+
yarn-error.log
46+
47+
# System files
48+
*/*.lnk
49+
*desktop.ini
50+
.DS_Store
51+
Thumbs.db

package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "unit-testing",
3+
"license": "UNLICENSED",
4+
"private": true,
5+
"scripts": {
6+
"test": "npm run test:watch -- --colors",
7+
"test:watch": "npx jest --watch",
8+
"test:once": "npx jest"
9+
},
10+
"dependencies": {
11+
"jest": "^26.6.3"
12+
},
13+
"type":"module",
14+
"jest": {
15+
"verbose": true
16+
}
17+
}

tests/word-search.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class WordSearch {
2+
constructor(words) {
3+
this.words = words;
4+
}
5+
6+
search(text) {
7+
if (!text) {
8+
return [];
9+
}
10+
11+
return this.getWords(text);
12+
}
13+
14+
getWords(text) {
15+
let results = this.words
16+
.filter(word => text.length >= 2)
17+
.filter(word => word.startsWith(text));
18+
19+
return results;
20+
}
21+
}
22+
23+
24+
module.exports = WordSearch;
25+

tests/word-search.test.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
1. Decide tiny aspects + Limitations (data requirements, responsibilities)
3+
2. Define input/output of feature (data types, structures, results)
4+
Define function signature (parameters, variants)
5+
3. Define test case for each tiny feature (including misuse + expected fails)
6+
4. Write code
7+
8+
---
9+
10+
1.
11+
- Have: Word list [A, B, ...]
12+
- Expect: All words to be strings, No empty values,
13+
No foreign/multibyte chars, Sorted A-Z, Upper/Lowercase
14+
- Have at least 2 letters to start searching
15+
- Get 1-N word(s) that start with letters
16+
- Return empty list for no results []
17+
18+
2. + 3.
19+
- constructor(array words)
20+
- getWordsForText(string text): array[string]
21+
22+
4.
23+
- No results : ''
24+
- No results : 'A'
25+
- 2 results : 'Ap'
26+
- 1 result : 'App'
27+
28+
*/
29+
30+
const WordSearch = require('./word-search');
31+
32+
33+
describe('Word search', () => {
34+
const words = [
35+
'Apple',
36+
'Apricot',
37+
'Avocado',
38+
'Banana',
39+
'Broccoli',
40+
'Cucumber',
41+
'',
42+
];
43+
44+
const wordSearch = new WordSearch(words);
45+
46+
test('no results for empty value', () => {
47+
const result = wordSearch.search('');
48+
expect(result).toStrictEqual([]);
49+
});
50+
51+
test('no results for single letter', () => {
52+
const result = wordSearch.search('A');
53+
expect(result).toStrictEqual([]);
54+
});
55+
56+
test('2 results for letter combination available > 1 times', () => {
57+
const result = wordSearch.search('Ap');
58+
expect(result).toStrictEqual(['Apple', 'Apricot']);
59+
});
60+
61+
test('1 result for letter combination available = 1 time', () => {
62+
const result = wordSearch.search('App');
63+
expect(result).toStrictEqual(['Apple']);
64+
});
65+
66+
});
67+
68+
69+
70+
71+
/*
72+
73+
toStrictEqual // Type + Structure
74+
toBe // Primitives, References
75+
toEqual // Deep/Recursive object equality
76+
toBeTruthy //
77+
toBeFalsy //
78+
toBeCloseTo // Float
79+
80+
*/
81+

0 commit comments

Comments
 (0)