Skip to content

Commit b87e503

Browse files
authored
Merge pull request #363 from sir-gon/develop
[DOC] Better README.
2 parents 7e00440 + d26584f commit b87e503

File tree

1 file changed

+183
-82
lines changed

1 file changed

+183
-82
lines changed

README.md

Lines changed: 183 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -3,172 +3,273 @@
33
[![Node.js CI](https://github.com/sir-gon/algorithm-exercises-ts/actions/workflows/node.js.yml/badge.svg)](https://github.com/sir-gon/algorithm-exercises-ts/actions/workflows/node.js.yml)
44
[![codecov](https://codecov.io/gh/sir-gon/algorithm-exercises-ts/branch/main/graph/badge.svg?token=7NBP9SQAY0)](https://codecov.io/gh/sir-gon/algorithm-exercises-ts)
55
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bi.8713187.xyz%2Fsir-gon%2Fprojecteuler-ts.svg?type=shield)](https://app.fossa.com/projects/git%2Bi.8713187.xyz%2Fsir-gon%2Fprojecteuler-ts?ref=badge_shield)
6-
[![Markdown Lint](https://github.com/sir-gon/algorithm-exercises-ts/actions/workflows/markdown-lint.yml/badge.svg)](https://github.com/sir-gon/algorithm-exercises-ts/actions/workflows/markdown-lint.yml)
76

87
![GitHub](https://img.shields.io/github/license/sir-gon/algorithm-exercises-ts)
98
![GitHub language count](https://img.shields.io/github/languages/count/sir-gon/algorithm-exercises-ts)
109
![GitHub top language](https://img.shields.io/github/languages/top/sir-gon/algorithm-exercises-ts)
1110

11+
[![ESLint](https://github.com/sir-gon/algorithm-exercises-ts/actions/workflows/eslint.yml/badge.svg)](https://github.com/sir-gon/algorithm-exercises-ts/actions/workflows/eslint.yml)
12+
[![Markdown Lint](https://github.com/sir-gon/algorithm-exercises-ts/actions/workflows/markdown-lint.yml/badge.svg)](https://github.com/sir-gon/algorithm-exercises-ts/actions/workflows/markdown-lint.yml)
13+
[![YAML lint](https://github.com/sir-gon/algorithm-exercises-ts/actions/workflows/yamllint.yml/badge.svg)](https://github.com/sir-gon/algorithm-exercises-ts/actions/workflows/yamllint.yml)
14+
1215
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-ts&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-ts)
1316
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-ts&metric=coverage)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-ts)
1417
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-ts&metric=bugs)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-ts)
1518
[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-ts&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-ts)
1619
[![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-ts&metric=duplicated_lines_density)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-ts)
1720

21+
## TL;DR
22+
23+
[Install and run](#install-and-run)
24+
1825
## What is this?
1926

20-
[Project Euler](https://projecteuler.net/) provide some algorithms and
21-
mathematical problems to solve to be used as experience tests.
27+
This repository is part of a series that share and solve the same [objectives](#objetives),
28+
with the difference that each one is based on a different software ecosystem,
29+
depending on the chosen programming language:
2230

23-
Use this answers to learn some tip and tricks for algorithms tests.
31+
- [Modern Javascript: algorithm-exercises-js](https://github.com/sir-gon/algorithm-exercises-js)
32+
- [Python 3.x: algorithm-exercises-py](https://github.com/sir-gon/algorithm-exercises-py)
33+
- [Typescript: algorithm-exercises-ts](https://github.com/sir-gon/algorithm-exercises-ts)
34+
- [Go / Golang: algorithm-exercises-go](https://github.com/sir-gon/algorithm-exercises-go)
35+
- [Java: algorithm-exercises-java](https://github.com/sir-gon/algorithm-exercises-java)
36+
- [.NET / C#: algorithm-exercises-csharp](https://github.com/sir-gon/algorithm-exercises-csharp)
2437

25-
## Why I publish solutions?
38+
## Objetives
2639

27-
As Project Euler says:
40+
### Functional
2841

29-
<https://projecteuler.net/about#publish>
42+
- For academic purposes, it is an backup of some algorithm exercises
43+
(with their solutions), proposed by various sources:
44+
[leetcode, hackerrank, projecteuler](#algorithm-excersices-sources), ...
3045

31-
```text
32-
I learned so much solving problem XXX, so is it okay
33-
to publish my solution elsewhere?
34-
35-
It appears that you have answered your own question. There is nothing quite
36-
like that "Aha!" moment when you finally beat a problem which you have been
37-
working on for some time. It is often through the best of intentions in wishing
38-
to share our insights so that others can enjoy that moment too. Sadly, that
39-
will rarely be the case for your readers. Real learning is an active process
40-
and seeing how it is done is a long way from experiencing that epiphany of
41-
discovery. Please do not deny others what you have so richly valued yourself.
42-
43-
However, the rule about sharing solutions outside of Project Euler does not
44-
apply to the first one-hundred problems, as long as any discussion clearly aims
45-
to instruct methods, not just provide answers, and does not directly threaten
46-
to undermine the enjoyment of solving later problems. Problems 1 to 100 provide
47-
a wealth of helpful introductory teaching material and if you are able to
48-
respect our requirements, then we give permission for those problems and their
49-
solutions to be discussed elsewhere.
50-
```
46+
- The solutions must be written on "vanilla code", that is,
47+
avoiding as much as possible the use of external libraries (in runtime).
5148

52-
If you have better answers or optimal solutions, fork and PR-me
49+
- Adoption of methodology and good practices.
50+
Each exercise is implemented as a unit test set,
51+
using TDD (Test-driven Development) and Clean Code ideas.
5352

54-
Enjoy 😁 !
53+
### Technical
5554

56-
## Using NodeJS runtime
55+
Foundation of a project that supports:
5756

58-
### Requirements
57+
- Explicit **typing** when the language supports it, even when it is not mandatory.
58+
- Static Code Analysis (**Lint**) of code, scripts and documentation.
59+
- Uniform **Code Styling**.
60+
- **Unit Test** framework.
61+
- **Coverge** collection. High coverage percentage. Equal or close to 100%.
62+
- **Pipeline** (Github Actions). Each command must take care of its
63+
return status code.
64+
- **Docker**-based workflow to replicate behavior in any environment.
65+
- Other tools to support the reinforcement of software development **good practices**.
5966

60-
You must install dependencies:
67+
## Install and Run
6168

62-
```text
63-
npm install
64-
```
69+
You can run tests in the following ways:
6570

66-
Or using make
71+
- [Install and run directly](#install-and-run-directly) require runtime tools
72+
installed in your SO.
73+
- [Install and run with make](#install-and-run-using-make) require runtime tools
74+
and "make" installed in your SO.
75+
- [Install and in Docker](#install-and-running-with-docker-) require Docker and
76+
docker-compose installed.
77+
- (⭐️)
78+
[Install and in Docker with make](#install-and-running-with-docker--using-make)
79+
require docker-compose and make installed.
6780

68-
```text
69-
make dependencies
70-
```
81+
⭐️: Prefered way.
7182

72-
### Testing silently
83+
### Install and Run directly
84+
85+
Using a NodeJS runtime in your SO. You must install dependencies:
86+
87+
```bash
88+
npm install
89+
```
7390

7491
Every problem is a function with unit test.
92+
7593
Unit test has test cases and input data to solve the problem.
7694

7795
Run all tests:
7896

79-
```text
97+
```bash
8098
npm run test
8199
```
82100

83-
### Testing with full logs
101+
#### Test run with alternative behaviors
84102

85-
Run all tests with debug outputs:
103+
You can change test running behaviour using some environment variables as follows:
86104

87-
```text
105+
| Variable | Values | Default |
106+
| ------ | ------ | ------ |
107+
| LOG_LEVEL | `debug`, `warning`, `error`, `info` | `info` |
108+
| BRUTEFORCE | `true`, `false`| `false` |
109+
110+
- `LOG_LEVEL`: change verbosity level in outputs.
111+
- `BRUTEFORCE`: enable or disable running large tests.
112+
(long time, large amount of data, high memory consumition).
113+
114+
#### Examples running tests with alternative behaviors
115+
116+
Run tests with debug outputs:
117+
118+
```bash
88119
LOG_LEVEL=debug npm run test
89120
```
90121

91-
Use one of following values: debug, warning, error, info.
122+
Run brute-force tests with debug outputs:
92123

93-
### Testing using make
94-
95-
```text
96-
make test
124+
```bash
125+
BRUTEFORCE=true LOG_LEVEL=debug npm run test
97126
```
98127

99-
#### Enable all large BRUTEFORCE tests
128+
### Install and Run using make
100129

101-
Direct in host using a make:
130+
`make` tool is used to standardizes the commands for the same tasks
131+
across each sibling repository.
102132

103-
```text
104-
make test -e BRUTEFORCE=true
133+
Run tests (libraries are installed as dependency task in make):
134+
135+
```bash
136+
make test
105137
```
106138

107-
#### Enable all DEBUG outputs
139+
Run tests with debug outputs:
108140

109-
```text
141+
```bash
110142
make test -e LOG_LEVEL=debug
111143
```
112144

113-
#### Enable all large BRUTEFORCE tests and all DEBUG outputs
145+
Run brute-force tests with debug outputs:
114146

115-
```text
116-
make test -e LOG_LEVEL=debug -e BRUTEFORCE=true
147+
```bash
148+
make test -e BRUTEFORCE=true -e LOG_LEVEL=debug
117149
```
118150

119-
## Running with Docker 🐳
151+
Alternative way, use environment variables as prefix:
120152

121-
### Build a complete image with and run all tests
153+
```bash
154+
BRUTEFORCE=true LOG_LEVEL=debug make test
155+
```
122156

123-
Running container with testing (final) target.
157+
### Install and Running with Docker 🐳
124158

125-
Designed to store all application files and dependencies as a complete runnable image.
126-
Coverage results will be stored in host **/coverage** directory (mounted as volume).
159+
Build an image of the test stage.
160+
Then creates and ephemeral container an run tests.
127161

128-
```text
129-
# Build a complete image
130-
docker-compose build algorithm-exercises-ts
131-
docker-compose run --rm algorithm-exercises-ts npm run test
162+
BRUTEFORCE and LOG_LEVEL environment variables are passing from current
163+
environment using docker-compose.
164+
165+
```bash
166+
docker-compose --profile testing run --rm algorithm-exercises-ts-test
132167
```
133168

134-
### Enable BRUTEFORCE tests with full DEBUG output
169+
To change behavior using environment variables, you can pass to containers
170+
in the following ways:
135171

136-
With docker-compose:
172+
From host using docker-compose (compose.yaml) mechanism:
137173

138-
```text
139-
docker-compose --profile testing run --rm algorithm-exercises-ts make test -e LOG_LEVEL=DEBUG -e BRUTEFORCE=true
174+
```bash
175+
BRUTEFORCE=true LOG_LEVEL=debug docker-compose --profile testing run --rm algorithm-exercises-ts-test
140176
```
141177

142-
Using make:
178+
Overriding docker CMD, as parameter of make "-e":
143179

144-
```text
145-
make docker/compose-run -e LOG_LEVEL=DEBUG -e BRUTEFORCE=true
180+
```bash
181+
docker-compose --profile testing run --rm algorithm-exercises-ts-test make test -e LOG_LEVEL=DEBUG -e BRUTEFORCE=true
182+
```
183+
184+
### Install and Running with Docker 🐳 using make
185+
186+
```bash
187+
make compose/build
188+
make compose/test
189+
```
190+
191+
To pass environment variables you can use docker-compose
192+
or overriding CMD and passing to make as "-e" argument.
193+
194+
Passing environment variables using docker-compose (compose.yaml mechanism):
195+
196+
```bash
197+
BRUTEFORCE=true LOG_LEVEL=debug make compose/test
146198
```
147199

148-
### Build and run a development image
200+
## Development workflow using Docker / docker-compose
149201

150202
Running container with development target.
151-
Designed to develop on top of this image. All source application is mounted as
152-
a volume in **/app** directory.
153-
Dependencies should be installed to run (not present in this target) so, you
154-
must install dependencies before run (or after a dependency add/change).
203+
Designed for development workflow on top of this image.
204+
All source application is mounted as a volume in **/app** directory.
205+
Dependencies should be installed to run so, you must
206+
install dependencies before run (or after a dependency add/change).
155207

156-
```text
157-
# install node_modules dependencies using docker runtime and store them in host directory
208+
```bash
209+
# Build development target image
158210
docker-compose build --compress algorithm-exercises-ts-dev
211+
# run ephemeral container to install dependencies using docker runtime
212+
# and store them in host directory (by bind-mount volume)
159213
docker-compose run --rm algorithm-exercises-ts-dev npm install --verbose
214+
# Run ephemeral container and override command to run test
160215
docker-compose run --rm algorithm-exercises-ts-dev npm run test
161216
```
162217

218+
## Run complete workflow (Docker + make)
219+
220+
Following command simulates a standarized pipeline across environments,
221+
using docker-compose and make.
222+
223+
```bash
224+
make compose/build && make compose/lint && make compose/test && make compose/run
225+
```
226+
227+
- Build all Docker stages and tag relevant images.
228+
- Run static analysis (lint) checks
229+
- Run unit tests
230+
- Run a "final" production ready image as a final container.
231+
Final "production" image just shows a minimal "production ready"
232+
build (with no tests).
233+
163234
## About development
164235

165236
Developed with runtime:
166237

167238
```text
168239
node --version
169-
v22.1.0
240+
v22.2.0
170241
```
171242

243+
## Algorithm excersices sources
244+
245+
- [Leetcode](https://leetcode.com/) online platform for
246+
coding interview preparation.
247+
- [HackerRank](https://www.hackerrank.com/) competitive programming challenges
248+
for both consumers and businesses.
249+
- [Project Euler](https://projecteuler.net/) a series of computational problems
250+
intended to be solved with computer programs.
251+
252+
Use these answers to learn some tip and tricks for algorithms tests.
253+
254+
### Disclaimer. Why I publish solutions?
255+
256+
As Project Euler says:
257+
258+
<https://projecteuler.net/about#publish>
259+
260+
```text
261+
I learned so much solving problem XXX, so is it okay to publish my solution elsewhere?
262+
It appears that you have answered your own question. There is nothing quite like that "Aha!" moment when you finally beat a problem which you have been working on for some time. It is often through the best of intentions in wishing to share our insights so that others can enjoy that moment too. Sadly, that will rarely be the case for your readers. Real learning is an active process and seeing how it is done is a long way from experiencing that epiphany of discovery. Please do not deny others what you have so richly valued yourself.
263+
264+
However, the rule about sharing solutions outside of Project Euler does not apply to the first one-hundred problems, as long as any discussion clearly aims to instruct methods, not just provide answers, and does not directly threaten to undermine the enjoyment of solving later problems. Problems 1 to 100 provide a wealth of helpful introductory teaching material and if you are able to respect our requirements, then we give permission for those problems and their solutions to be discussed elsewhere.
265+
```
266+
267+
If you have better answers or optimal solutions, fork and PR-me
268+
269+
Enjoy 😁 !
270+
271+
## Status
272+
172273
### License
173274

174275
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bi.8713187.xyz%2Fsir-gon%2Fprojecteuler-ts.svg?type=large)](https://app.fossa.com/projects/git%2Bi.8713187.xyz%2Fsir-gon%2Fprojecteuler-ts?ref=badge_large)

0 commit comments

Comments
 (0)