Move files around, add drone-ci
This commit is contained in:
parent
19d34d9263
commit
11c9bfc33e
10
.drone-ci.yml
Normal file
10
.drone-ci.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
kind: pipeline
|
||||
type: kubernetes
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: test
|
||||
image: rust:1.56
|
||||
commands:
|
||||
- cargo build --verbose --all
|
||||
- cargo test --verbose --all
|
|
@ -1,9 +1,7 @@
|
|||
use std::fs::read_to_string;
|
||||
|
||||
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone)]
|
||||
pub struct Day1(Vec<i32>);
|
||||
pub struct Day01(Vec<i32>);
|
||||
|
||||
impl crate::day::Day for Day1 {
|
||||
impl crate::day::Day for Day01 {
|
||||
fn init(f: String) -> Self {
|
||||
let v = f.split('\n').map(|x| x.parse::<i32>().unwrap()).collect::<Vec<i32>>();
|
||||
Self(v)
|
||||
|
@ -36,20 +34,20 @@ fn increments((a, b): (i32, i32), c: &i32) -> (i32, i32) {
|
|||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use std::fs::read_to_string;
|
||||
use super::Day1;
|
||||
use super::Day01;
|
||||
use crate::day::Day;
|
||||
|
||||
#[test]
|
||||
pub fn part1_real() {
|
||||
let f = read_to_string("./input/day1").expect("Could not load input");
|
||||
let d = Day1::init(f);
|
||||
let f = read_to_string("./input/day01").expect("Could not load input");
|
||||
let d = Day01::init(f);
|
||||
assert_eq!("1466", d.part1())
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn part2_real() {
|
||||
let f = read_to_string("./input/day1").expect("Could not load input");
|
||||
let d = Day1::init(f);
|
||||
let f = read_to_string("./input/day01").expect("Could not load input");
|
||||
let d = Day01::init(f);
|
||||
assert_eq!("1491", d.part2())
|
||||
}
|
||||
|
||||
|
@ -57,7 +55,7 @@ pub mod tests {
|
|||
pub fn part1_test() {
|
||||
let v = vec![199, 200, 208, 210, 200, 207, 240, 269, 260, 263];
|
||||
let strs = v.iter().map(i32::to_string).collect::<Vec<String>>().join("\n");
|
||||
let d = Day1::init(strs);
|
||||
let d = Day01::init(strs);
|
||||
assert_eq!("7", d.part1())
|
||||
}
|
||||
|
||||
|
@ -65,7 +63,7 @@ pub mod tests {
|
|||
pub fn part2_test() {
|
||||
let v = vec![199, 200, 208, 210, 200, 207, 240, 269, 260, 263];
|
||||
let strs = v.iter().map(i32::to_string).collect::<Vec<String>>().join("\n");
|
||||
let d = Day1::init(strs);
|
||||
let d = Day01::init(strs);
|
||||
assert_eq!("5", d.part2())
|
||||
}
|
||||
}
|
11
src/main.rs
11
src/main.rs
|
@ -1,12 +1,11 @@
|
|||
use std::fs::read_to_string;
|
||||
use std::time::SystemTime;
|
||||
use chrono::Datelike;
|
||||
use clap::{App, Arg, SubCommand};
|
||||
use crate::day1::Day1;
|
||||
use clap::{App, Arg};
|
||||
use crate::day01::Day01;
|
||||
use crate::day::Day;
|
||||
|
||||
mod day;
|
||||
mod day1;
|
||||
mod day01;
|
||||
|
||||
fn load_input(day: &str) -> String {
|
||||
read_to_string(format!("./input/day{}", day)).expect("Could not load input")
|
||||
|
@ -41,9 +40,9 @@ fn main() {
|
|||
.multiple(true))
|
||||
.get_matches();
|
||||
|
||||
let days: Vec<Box<dyn Day>> = vec![Box::new(Day1::init(load_input("1")))];
|
||||
let days: Vec<Box<dyn Day>> = vec![Box::new(Day01::init(load_input("01")))];
|
||||
|
||||
let verbosity = matches.occurrences_of("v");
|
||||
let _verbosity = matches.occurrences_of("v");
|
||||
if matches.is_present("all") {
|
||||
let l = days.len();
|
||||
println!("running {} days!", l);
|
||||
|
|
Loading…
Reference in a new issue