You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lavos/README.md

32 lines
1.5 KiB

4 months ago
# Lavos
算法设计与分析例题/作业代码合集,使用go编写实现
## 目录结构
包代码目录格式为,`cap{x}`,对应的是第x章的例题和作业代码,其中每个例题/作业代码文件均命名为`ex{x}.go`以及`work{x}.go`。
如第三章例6,位于`cap3/ex6.go`中,第四章作业5,位于`cap4/ex5.go`中。
## 运行/测试
要运行测试,需要go开发环境。[Go installation instructions: https://go.dev/doc/install](https://go.dev/doc/install)
完成后,运行
```shell
go test lavos/cap3
```
即可运行该章节下所有的例题和作业的test用例,例题和作业的test代码位于`example_test.go`和`work_test.go`中。
如果需要单独测试某一个题目,运行
```shell
go test lavos/cap3 -v '-test.run' 'Ex6$'
go test lavos/cap3 -v '-test.run' 'Work1$'
```
即可运行对应的题目,如示例中将会运行第三章例题6的test和作业1
## 其他细节
由于习惯原因,我并不是很喜欢在算法代码中进行具体的输出操作,或者直接将输出输入放置于算法代码中,而是使用了类似于leetcode中的核心代码模式,因此`ex{x}.go`和`work{x}.go`中的代码模式均为核心代码,不负责输出输入,
如有需要输出的算法,通过callback实现,传入能够实现输出的callback函数,在核心中调用callback来实现输出,核心代码不关心也不区负责输出输入,输出输入由test负责实现。