From 0cc821c2f53479101c498333dce980797958a089 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Sun, 17 Jan 2016 20:39:56 -0800 Subject: [PATCH] [rust][7.0] Add some more tests around Circuit --- rust/src/day_07.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/rust/src/day_07.rs b/rust/src/day_07.rs index 686d6ec..98b0570 100644 --- a/rust/src/day_07.rs +++ b/rust/src/day_07.rs @@ -23,8 +23,11 @@ pub fn solve(input: &str, wire: &str) -> u16 { #[test] fn test_circuit() { - let circuit = Circuit::new("123 -> x"); + let circuit = Circuit::new("123 -> x\nx -> y\nNOT x -> h"); assert_eq!(Some(&Signal::Value(123)), circuit.connections.get(&Wire("x"))); + assert_eq!(Some(&Signal::Wire(Wire("x"))), circuit.connections.get(&Wire("y"))); + assert_eq!(Some(&Signal::Wire(Wire("x"))), circuit.connections.get(&Wire("y"))); + assert_eq!(Some(&Signal::Gate(Gate::Not(Wire("x")))), circuit.connections.get(&Wire("h"))); } struct Circuit<'a> { @@ -35,8 +38,7 @@ impl<'a> Circuit<'a> { fn new(input: &str) -> Circuit { let mut connections = HashMap::new(); for line in input.lines() - .map(|line| line.split(" -> ") - .collect::>()) { + .map(|line| line.split(" -> ").collect::>()) { let wire = Wire(line.last().unwrap()); let signal = Signal::new(line.first().unwrap().split(" ").collect()); connections.insert(wire, signal);