summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2016-12-03 23:20:01 -0500
committerJune McEnroe <june@causal.agency>2020-11-22 00:13:50 -0500
commit5d3bf32e78c007e4fe33b0bd2363538f8202357a (patch)
treef5b0f402ff08228bf603966c6fadfb7e06b451cf
parentAdd tests to day 1 (diff)
downloadaoc-5d3bf32e78c007e4fe33b0bd2363538f8202357a.tar.gz
aoc-5d3bf32e78c007e4fe33b0bd2363538f8202357a.zip
Add test to day 2
Diffstat (limited to '')
-rw-r--r--src/bin/day02.rs22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/bin/day02.rs b/src/bin/day02.rs
index c5a7f11..21d101b 100644
--- a/src/bin/day02.rs
+++ b/src/bin/day02.rs
@@ -1,6 +1,6 @@
 use std::io::{self, Read};
 
-#[derive(Debug, Clone, Copy)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
 enum Keypad {
     K1, K2, K3,
     K4, K5, K6,
@@ -47,10 +47,7 @@ impl Keypad {
     }
 }
 
-fn main() {
-    let mut input = String::new();
-    io::stdin().read_to_string(&mut input).unwrap();
-
+fn solve(input: &str) -> Vec<Keypad> {
     let mut code = Vec::new();
     let mut key = Keypad::K5;
 
@@ -67,5 +64,18 @@ fn main() {
         code.push(key);
     }
 
-    println!("Part 1: {:?}", code);
+    code
+}
+
+fn main() {
+    let mut input = String::new();
+    io::stdin().read_to_string(&mut input).unwrap();
+
+    println!("Part 1: {:?}", solve(&input));
+}
+
+#[test]
+fn part1() {
+    use Keypad::*;
+    assert_eq!(vec![K1, K9, K8, K5], solve("ULL\nRRDDD\nLURDL\nUUUUD"));
 }
td> 2018-09-13Move color selection to format.cJune McEnroe 2018-09-13Fix len for format->split at end of stringJune McEnroe 2018-09-13Avoid uninitialized x in uiReadJune McEnroe 2018-09-13Add IRCDefault to colors enumJune McEnroe 2018-09-13Return a format->split even at the end of the stringJune McEnroe 2018-09-13Fix weird tab-complete after commaJune McEnroe 2018-09-13Rewrite UI againJune McEnroe 2018-09-12Add note about C-oJune McEnroe 2018-09-12Use formatParse split to position input cursorJune McEnroe 2018-09-12Factor out IRC formatting parsingJune McEnroe 2018-09-11Add /help equivalent to /manJune McEnroe 2018-09-11Don't render every PM as a pingJune McEnroe 2018-09-11Add urlOpenMatchJune McEnroe 2018-09-10Depend on man.sh for chroot.tar targetJune McEnroe 2018-09-10Set LESSSECURE=1 in man.shJune McEnroe 2018-09-10Add /man commandJune McEnroe 2018-09-10Install man page in chrootJune McEnroe 2018-09-10Install man pageJune McEnroe 2018-09-10Split keys into subsections and document colorsJune McEnroe 2018-09-10Add "blank" lines to chatte.1June McEnroe 2018-09-10Document key bindings in chatte.1June McEnroe 2018-09-08Document slash commands in chatte.1June McEnroe