#advent #input #solution #test-framework #boilerplate #advent-of-code #aoc

aoc-lib

一个让你在解 Advent of Code 时专注于解决问题而不是模板代码的库

10 个版本 (4 个稳定版)

1.0.3 2022年12月3日
1.0.1 2022年12月1日
0.4.3 2021年12月4日
0.3.0 2021年12月3日
0.1.0 2021年12月2日

#10#advent-of-code

每月32 次下载

Apache-2.0

9KB
176

Advent of Code 辅助库

一个让你在解 Advent of Code 时专注于解决问题而不是模板代码的库。

此库利用 Rust 的测试框架运行每天的每个部分,使用来自 adventofcode.com 的真实输入或你自己的测试输入。

它还包含一些实用函数,可以加快常见的输入转换。

安装

将以下内容放置在你的 Cargo.toml 依赖部分

[dependencies]
aoc-lib = "1.0.0"

或者你可以使用 cargo add aoc-lib 命令。

用法

自动下载功能需要一个 Cookie 来与 AOC 进行身份验证。

从你的浏览器中获取 adventofcode.com Cookie 的 ,并将其放置在 ~/.aoc.cookie 文件中(名称:.aoc.cookie,在你的主目录中)。

有很多浏览器扩展可以帮助你查看 Cookie。

你的仓库

尽可能遵循以下示例

src
├── lib.rs
└── year2022
    ├── day01.rs
    └── mod.rs

年文件夹必须遵循正则表达式 ^year\d\d\d\d$,而天数必须遵循正则表达式 ^day\d\d.rs$

提示:为了避免 unused 警告,你的 mod.rs 文件应该使用 pub: pub mod dayXX,同样对于你的 lib.rs: pub mod year2022

以下是一个模板 dayXX.rs 文件

pub fn part1(_input: String) -> usize {
    0
}

pub fn part2(_input: String) -> usize {
    0
}

#[cfg(test)]
mod tests {
    use super::*;
    use aoc_lib::*;

    #[test]
    fn test_part1() {
        run_test!(part1);
    }

    #[test]
    fn run_part1() {
        run_real!(part1);
    }

    #[test]
    fn test_part2() {
        run_test!(part2);
    }

    #[test]
    fn run_part2() {
        run_real!(part2);
    }
}

完成所有以上设置后,只需运行测试即可!

在提交任何内容之前,别忘了将 .gitignore 文件添加到 /input 文件夹。

依赖

~4–19MB
~241K SLoC