Update Lab 4
This commit is contained in:
parent
fb355f26e8
commit
48746c0fbf
|
@ -12,7 +12,7 @@
|
||||||
[Lab4/](Lab4/)文件夹中是一个功能极简的用Python实现图数据结构的包`pygraph`,该项目目前采用[Poetry](https://python-poetry.org/)进行依赖管理,[pytest](https://docs.pytest.org/en/7.1.x/)作为测试框架,文件结构如下:
|
[Lab4/](Lab4/)文件夹中是一个功能极简的用Python实现图数据结构的包`pygraph`,该项目目前采用[Poetry](https://python-poetry.org/)进行依赖管理,[pytest](https://docs.pytest.org/en/7.1.x/)作为测试框架,文件结构如下:
|
||||||
|
|
||||||
* `pygraph.py`实现图数据结构,包含一个类和一些简单函数,均未实现,且结构混乱。
|
* `pygraph.py`实现图数据结构,包含一个类和一些简单函数,均未实现,且结构混乱。
|
||||||
* `pyproject.toml`是Poetry使用的依赖配置文件。
|
* `pyproject.toml`是Poetry使用的依赖配置文件,文件中声明了本项目支持的Python版本(**仅支持Python 3.10**),以及本Lab中需要的各种开发依赖。
|
||||||
* `tests/`文件夹包含若干测试。
|
* `tests/`文件夹包含若干测试。
|
||||||
* `pyproject.toml`是`pytest`的配置文件。
|
* `pyproject.toml`是`pytest`的配置文件。
|
||||||
|
|
||||||
|
@ -70,6 +70,8 @@ Lab 4需要为这个项目配置开发环境,补全未实现的代码,并配
|
||||||
>
|
>
|
||||||
> 不过非常遗憾的是,私有仓库的GitHub Page是收费功能。如果同学们以后创建自己的项目,可以尝试用同样的方法自动部署各种网页,确认实际效果。
|
> 不过非常遗憾的是,私有仓库的GitHub Page是收费功能。如果同学们以后创建自己的项目,可以尝试用同样的方法自动部署各种网页,确认实际效果。
|
||||||
|
|
||||||
|
> 需要注意CI环境里是不能使用`poetry shell`的([相关讨论](https://github.com/python-poetry/poetry/discussions/3526))。
|
||||||
|
|
||||||
8. 将所有更改体现在GitHub仓库中。
|
8. 将所有更改体现在GitHub仓库中。
|
||||||
|
|
||||||
## 提交前检查
|
## 提交前检查
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from pprint import pprint
|
import pytest
|
||||||
from pygraph import Graph
|
from pygraph import Graph
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,11 +8,17 @@ def test_indegree(small_directed: Graph, small_undirected: Graph):
|
||||||
assert small_undirected.indegree("c") == 2
|
assert small_undirected.indegree("c") == 2
|
||||||
assert small_undirected.indegree("d") == 2
|
assert small_undirected.indegree("d") == 2
|
||||||
|
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
small_undirected.indegree("e")
|
||||||
|
|
||||||
assert small_directed.indegree("a") == 0
|
assert small_directed.indegree("a") == 0
|
||||||
assert small_directed.indegree("b") == 1
|
assert small_directed.indegree("b") == 1
|
||||||
assert small_directed.indegree("c") == 1
|
assert small_directed.indegree("c") == 1
|
||||||
assert small_directed.indegree("d") == 2
|
assert small_directed.indegree("d") == 2
|
||||||
|
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
small_directed.indegree("e")
|
||||||
|
|
||||||
|
|
||||||
def test_outdegree(small_directed: Graph, small_undirected: Graph):
|
def test_outdegree(small_directed: Graph, small_undirected: Graph):
|
||||||
assert small_undirected.outdegree("a") == 1
|
assert small_undirected.outdegree("a") == 1
|
||||||
|
@ -20,7 +26,13 @@ def test_outdegree(small_directed: Graph, small_undirected: Graph):
|
||||||
assert small_undirected.outdegree("c") == 2
|
assert small_undirected.outdegree("c") == 2
|
||||||
assert small_undirected.outdegree("d") == 2
|
assert small_undirected.outdegree("d") == 2
|
||||||
|
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
small_undirected.indegree("e")
|
||||||
|
|
||||||
assert small_directed.outdegree("a") == 1
|
assert small_directed.outdegree("a") == 1
|
||||||
assert small_directed.outdegree("b") == 2
|
assert small_directed.outdegree("b") == 2
|
||||||
assert small_directed.outdegree("c") == 1
|
assert small_directed.outdegree("c") == 1
|
||||||
assert small_directed.outdegree("d") == 0
|
assert small_directed.outdegree("d") == 0
|
||||||
|
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
small_directed.indegree("e")
|
||||||
|
|
Loading…
Reference in New Issue