Skip to content

Commit d2d6def

Browse files
committed
Update jsconfig.json to include all HTML files and add new Chinese README, coding standards, project structure, and testing guidelines documents
1 parent 3ddc965 commit d2d6def

File tree

5 files changed

+360
-1
lines changed

5 files changed

+360
-1
lines changed

.cursor/rules/coding-standards.mdc

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
globs: "*.js,*.ts,*.jsx,*.tsx"
3+
description: JavaScript和TypeScript代码标准和最佳实践
4+
---
5+
6+
# 代码标准和最佳实践
7+
8+
本规则适用于JavaScript和TypeScript文件,定义了项目的编码规范和最佳实践。
9+
10+
## JavaScript/TypeScript 编码规范
11+
12+
### 命名约定
13+
- 使用camelCase命名变量和函数
14+
- 使用PascalCase命名类和构造函数
15+
- 使用UPPER_CASE命名常量
16+
- 使用描述性的变量名,避免缩写
17+
- 文件名使用kebab-case(如:binary-search.js)
18+
19+
### 代码结构
20+
- 每个文件只导出一个主要的类或函数
21+
- 使用ES6模块语法(import/export)
22+
- 保持函数简洁,遵循单一职责原则
23+
- 添加适当的注释说明复杂逻辑
24+
- 使用JSDoc格式的注释
25+
26+
### 数据结构实现规范
27+
- 所有数据结构都应该有基本的增删查改操作
28+
- 实现toString()方法用于调试和可视化
29+
- 提供clear()方法清空数据结构
30+
- 实现size()或length属性获取元素数量
31+
- 处理空数据结构的边界情况
32+
- 提供迭代器支持(Symbol.iterator)
33+
34+
### 算法实现规范
35+
- 包含时间复杂度和空间复杂度注释
36+
- 提供多种实现方式(递归、迭代等)
37+
- 添加输入验证和边界情况处理
38+
- 提供使用示例和测试用例
39+
- 实现通用的比较函数支持
40+
41+
### 测试要求
42+
- 每个实现都必须有对应的测试文件
43+
- 测试覆盖正常情况、边界情况和异常情况
44+
- 使用描述性的测试名称
45+
- 验证返回值和副作用
46+
- 确保100%的代码覆盖率
47+
48+
### TypeScript特殊要求
49+
- 使用严格的类型检查
50+
- 为所有公共API提供类型定义
51+
- 避免使用any类型
52+
- 使用泛型增强代码复用性
53+
- 利用接口定义复杂的数据结构
54+
55+
### 错误处理
56+
- 使用Error类或其子类抛出异常
57+
- 提供清晰的错误消息
58+
- 对无效输入进行验证
59+
- 文档化可能抛出的异常
60+
61+
## 性能优化建议
62+
- 避免不必要的循环和递归
63+
- 使用适当的数据结构来优化查找和插入操作
64+
- 考虑内存使用效率
65+
- 实现懒加载策略(当适用时)
66+

.cursor/rules/project-structure.mdc

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
alwaysApply: true
3+
description: JavaScript数据结构和算法项目的结构指南
4+
---
5+
6+
# 项目结构指南
7+
8+
这是一个JavaScript数据结构和算法学习项目,包含JavaScript和TypeScript两个版本的实现。
9+
10+
## 主要目录结构
11+
12+
### 源代码目录
13+
- **src/js/**: JavaScript版本的源代码
14+
- `data-structures/`: 各种数据结构实现(栈、队列、链表、树、图等)
15+
- `algorithms/`: 各种算法实现(排序、搜索、动态规划、图算法等)
16+
- `others/`: 其他实用工具和辅助函数
17+
- [util.js](mdc:src/js/util.js): 通用工具函数和常量定义
18+
- [index.js](mdc:src/js/index.js): 主要入口文件,导出所有模块
19+
20+
- **src/ts/**: TypeScript版本的源代码(结构与js版本相同)
21+
- 包含类型定义和更严格的类型检查
22+
- `models/`: 数据结构的模型定义和类型声明
23+
- [util.ts](mdc:src/ts/util.ts): TypeScript版本的工具函数
24+
- [index.ts](mdc:src/ts/index.ts): TypeScript主入口文件
25+
26+
### 测试目录
27+
- **test/**: 测试文件
28+
- `js/`: JavaScript版本的测试文件
29+
- `ts/`: TypeScript版本的测试文件
30+
- 每个实现都有对应的 `.spec.js` 或 `.spec.ts` 测试文件
31+
- 测试结构与源代码目录结构保持一致
32+
33+
### 示例和演示
34+
- **examples/**: 章节示例和演示代码
35+
- 按章节组织的学习示例(chapter01_02/, chapter03/, etc.)
36+
- 包含HTML页面用于演示算法和数据结构的可视化效果
37+
- 每个章节包含相应的JavaScript和HTML文件
38+
39+
## 开发约定
40+
41+
- 每个数据结构和算法都有JavaScript和TypeScript两个版本
42+
- 所有实现都有相应的单元测试
43+
- 使用ES6+语法特性
44+
- TypeScript版本包含完整的类型定义
45+
- 测试使用Mocha和Chai框架
46+
- 支持Webpack打包和构建
47+
48+
## 配置文件
49+
50+
### 项目配置
51+
- [package.json](mdc:package.json): 项目依赖和脚本配置
52+
- [tsconfig.json](mdc:tsconfig.json): TypeScript编译配置
53+
- [webpack.config.js](mdc:webpack.config.js): Webpack打包配置
54+
- [.eslintrc.json](mdc:.eslintrc.json): ESLint代码规范配置
55+
56+
### 开发工具
57+
- [.gitignore](mdc:.gitignore): Git忽略文件配置
58+
- [.editorconfig](mdc:.editorconfig): 编辑器配置
59+
- [tslint.json](mdc:tslint.json): TypeScript代码检查配置

.cursor/rules/testing-guidelines.mdc

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
globs: "*.spec.js,*.spec.ts,*.test.js,*.test.ts"
3+
description: 测试文件编写指导和最佳实践
4+
---
5+
6+
# 测试指导和最佳实践
7+
8+
本规则适用于所有测试文件,定义了测试编写的规范和最佳实践。
9+
10+
## 测试文件结构
11+
12+
### 文件命名
13+
- 测试文件使用 `.spec.js` 或 `.spec.ts` 后缀
14+
- 与被测试文件保持相同的基础名称
15+
- 例如:`binary-search.js` 对应 `binary-search.spec.js`
16+
17+
### 测试框架
18+
- 使用 **Mocha** 作为测试运行器
19+
- 使用 **Chai** 作为断言库
20+
- 支持JavaScript和TypeScript测试
21+
22+
## 测试组织结构
23+
24+
### 基本模板
25+
```javascript
26+
import 'mocha';
27+
import { expect } from 'chai';
28+
import { FunctionName } from '../../src/js/path/to/module';
29+
30+
describe('功能名称', () => {
31+
// 测试用例
32+
});
33+
```
34+
35+
### 测试分组
36+
- 使用 `describe` 对相关测试进行分组
37+
- 每个类或函数都应该有自己的 `describe` 块
38+
- 使用中文描述测试组和测试用例
39+
40+
### 测试用例命名
41+
- 使用清晰、描述性的测试名称
42+
- 描述测试的预期行为
43+
- 例如:`it('应该在空数组中返回-1', () => {...})`
44+
45+
## 数据结构测试标准
46+
47+
### 基本操作测试
48+
- 创建和初始化
49+
- 插入操作(push, enqueue, insert等)
50+
- 删除操作(pop, dequeue, remove等)
51+
- 查找操作(find, search, contains等)
52+
- 大小获取(size, length, isEmpty等)
53+
- 清空操作(clear)
54+
55+
### 边界情况测试
56+
- 空数据结构操作
57+
- 单个元素操作
58+
- 最大容量操作(如果适用)
59+
- 无效输入处理
60+
61+
### 状态验证
62+
- 验证数据结构的内部状态
63+
- 验证操作前后的状态变化
64+
- 使用 `toString()` 方法验证结构
65+
66+
## 算法测试标准
67+
68+
### 功能测试
69+
- 正常输入的正确性
70+
- 边界值测试
71+
- 异常输入处理
72+
- 性能基准测试(对于大数据集)
73+
74+
### 排序算法测试
75+
- 空数组测试
76+
- 已排序数组测试
77+
- 逆序数组测试
78+
- 重复元素测试
79+
- 自定义比较函数测试
80+
81+
### 搜索算法测试
82+
- 找到目标元素
83+
- 未找到目标元素
84+
- 第一个和最后一个位置
85+
- 自定义相等比较函数
86+
87+
## 测试工具函数
88+
89+
### 通用测试函数
90+
- 为排序算法提供通用测试套件
91+
- 为搜索算法提供通用测试套件
92+
- 数据生成器函数
93+
94+
### 示例:排序算法测试
95+
```javascript
96+
export function testSortAlgorithm(sortAlgorithm, algorithmName) {
97+
describe(algorithmName, () => {
98+
it('应该正确排序空数组', () => {
99+
expect(sortAlgorithm([])).to.deep.equal([]);
100+
});
101+
102+
it('应该正确排序非空数组', () => {
103+
const array = [3, 1, 4, 1, 5, 9, 2, 6, 5];
104+
const sorted = [1, 1, 2, 3, 4, 5, 5, 6, 9];
105+
expect(sortAlgorithm(array)).to.deep.equal(sorted);
106+
});
107+
});
108+
}
109+
```
110+
111+
## 测试质量要求
112+
113+
### 覆盖率要求
114+
- 代码覆盖率应达到100%
115+
- 分支覆盖率应达到100%
116+
- 功能覆盖率应达到100%
117+
118+
### 测试维护
119+
- 保持测试代码的清洁和可读性
120+
- 及时更新测试用例以反映代码变更
121+
- 删除无用的测试用例
122+
123+
### 性能测试
124+
- 对于算法实现,包含基本的性能测试
125+
- 验证时间复杂度符合预期
126+
- 测试大数据集的处理能力
127+

README_CN.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
学习JavaScript数据结构与算法
2+
====================================
3+
4+
[![构建状态](https://travis-ci.org/loiane/javascript-datastructures-algorithms.svg?branch=master)](https://travis-ci.org/loiane/javascript-datastructures-algorithms)
5+
[![代码覆盖率](https://codecov.io/gh/loiane/javascript-datastructures-algorithms/branch/master/graph/badge.svg)](https://codecov.io/gh/loiane/javascript-datastructures-algorithms)
6+
[![开发依赖状态](https://david-dm.org/loiane/javascript-datastructures-algorithms/dev-status.svg)](https://david-dm.org/loiane/javascript-datastructures-algorithms?type=dev)
7+
[![依赖状态](https://david-dm.org/loiane/javascript-datastructures-algorithms/status.svg)](https://david-dm.org/loiane/javascript-datastructures-algorithms)
8+
[![Greenkeeper badge](https://badges.greenkeeper.io/loiane/javascript-datastructures-algorithms.svg)](https://greenkeeper.io/)
9+
10+
**学习JavaScript数据结构与算法**》第三版书籍源代码。
11+
12+
## 可用章节列表:
13+
14+
* 01: [JavaScript 快速概览](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter01_02)
15+
* 02: [ECMAScript 和 TypeScript 介绍](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter01_02)
16+
* 03: [数组](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter03)
17+
* 04: [](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter04)
18+
* 05: [队列和双端队列](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter05)
19+
* 06: [链表](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter06)
20+
* 07: [集合](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter07)
21+
* 08: [字典和散列表](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter08)
22+
* 09: [递归](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter09)
23+
* 10: [](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter10)
24+
* 11: [](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter11)
25+
* 12: [](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter12)
26+
* 13: [排序和搜索算法](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter13)
27+
* 14: [算法设计与技巧](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter14)
28+
* 15: [算法复杂度](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter15)
29+
30+
### 第三版更新内容
31+
32+
* 使用 ES2015+ (ES6+) 的算法实现
33+
* 新的数据结构和算法
34+
* 所有章节都经过重写和审查
35+
* 新增三 (3) 个章节
36+
* 创建了一个可在浏览器或 Node.js 中使用的数据结构和算法库
37+
* 使用 Mocha + Chai 测试算法(测试代码在 `test` 目录中)
38+
* 包含源代码的 **TypeScript** 版本(包括库和测试)
39+
40+
## 项目结构
41+
42+
`src/js/index.js` 文件包含按章节列出的所有数据结构和算法。
43+
44+
```
45+
|_examples (如何使用每个数据结构和算法,按章节组织)
46+
|_src
47+
|___js (源代码:JavaScript 版本)
48+
|_____data-structures (数据结构)
49+
|_______models (数据结构使用的类:Node、ValuePair 等)
50+
|_____others (其他算法,如回文检查器、汉诺塔)
51+
|___ts (源代码:TypeScript 版本)
52+
|_____data-structures (数据结构)
53+
|_______models (模型)
54+
|_____others (其他算法)
55+
|_test (使用 Mocha 和 Chai 对 src 进行单元测试)
56+
|___js (JavaScript 代码测试)
57+
|___ts (TypeScript 代码测试)
58+
```
59+
60+
## 使用 Node.js 安装和运行书籍示例
61+
62+
* 安装 [Node](https://nodejs.org)
63+
* 打开终端/命令提示符,切换到项目文件夹目录:`cd /Users/.../javascript-datastructures-algorithms` (Linux/Mac) 或 `cd C:/.../javascript-datastructures-algorithms` (Windows)
64+
* 运行 `npm install` 安装所有依赖
65+
* 要查看示例,运行 `http-server html``npm run serve`。在浏览器中打开 `http:\\localhost:8080` 查看书籍示例
66+
* 或者 `cd html/chapter01` 并使用 node 运行每个 JavaScript 文件:`node 02-Variables`
67+
68+
## 在浏览器中运行示例
69+
70+
* 右键点击您想要查看示例的 HTML 文件,右键选择 "使用 Chrome(或任何其他浏览器)打开"
71+
72+
* 或者打开 `examples/index.html` 文件以轻松浏览所有示例:
73+
74+
* 在线演示:[https://javascript-ds-algorithms-book.firebaseapp.com](https://javascript-ds-algorithms-book.firebaseapp.com)
75+
76+
<img src="examples/examples-screenshot.png">
77+
78+
编程愉快!
79+
80+
## 其他版本
81+
82+
| 第一版 | 第二版 | 第三版 |
83+
| ------------- |:-------------:|:-------------:|
84+
| ![第一版](https://images-na.ssl-images-amazon.com/images/I/51xXGv7QlBL._SX403_BO1,204,203,200_.jpg) | ![第二版](https://images-na.ssl-images-amazon.com/images/I/51PWJ%2BoKc2L._SX403_BO1,204,203,200_.jpg) | ![第三版](https://images-na.ssl-images-amazon.com/images/I/41oSXp3VztL._SX404_BO1,204,203,200_.jpg) |
85+
| [书籍链接](http://amzn.to/1Y1OWPx)| [书籍链接](http://amzn.to/1TSkcA1)| [书籍链接](http://a.co/cbMlYmJ)|
86+
87+
第一版书籍链接:
88+
- [Packt](https://www.packtpub.com/application-development/learning-javascript-data-structures-and-algorithms)
89+
- [Amazon](http://amzn.to/1Y1OWPx)
90+
- [中文版](http://www.ituring.com.cn/book/1613)
91+
- [韩文版](http://www.acornpub.co.kr/book/javascript-data-structure)
92+
93+
第二版书籍链接:
94+
- [Packt](https://www.packtpub.com/web-development/learning-javascript-data-structures-and-algorithms-second-edition)
95+
- [Amazon](http://amzn.to/1TSkcA1)
96+
- [中文版](http://www.ituring.com.cn/book/2029)
97+
- [巴西葡萄牙语版](https://novatec.com.br/livros/estruturas-de-dados-algoritmos-em-javascript/)
98+
99+
第三版书籍链接:
100+
- [Packt](https://www.packtpub.com/en-us/product/learning-javascript-data-structures-and-algorithms-9781788624947)
101+
- [Amazon](http://a.co/cbMlYmJ)
102+
- [中文版](http://www.ituring.com.cn/book/2653)
103+
- [巴西葡萄牙语版](https://novatec.com.br/livros/estruturas-de-dados-algoritmos-em-javascript-2ed/)
104+
105+
### 发现问题或有疑问?
106+
107+
请创建一个 [Issue](https://github.com/loiane/javascript-datastructures-algorithms/issues)[Pull Request](https://github.com/loiane/javascript-datastructures-algorithms/pulls)

jsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
"strict": true
88
},
99
"exclude": ["node_modules", "dist"],
10-
"include": ["src/js/**/*","html/**"]
10+
"include": ["src/js/**/*","html/**/*"]
1111
}

0 commit comments

Comments
 (0)