Skip to content

Instantly share code, notes, and snippets.

@bChiquet
Created January 9, 2021 14:48
Show Gist options
  • Save bChiquet/c97188acc02676f8879569e23ea7705e to your computer and use it in GitHub Desktop.
Save bChiquet/c97188acc02676f8879569e23ea7705e to your computer and use it in GitHub Desktop.
fn main() {
println!("Hello, world!");
}
fn process(input: &str) -> Vec<Vec<String>> {
input.split("\n")
.map(|line| line.split(','))
.map(|fields| fields.map(|field| field.to_string()))
.map(|fields| fields.collect::<Vec<_>>())
.collect::<Vec<_>>()
}
fn total_by_category(transactions: [Transaction]) -> [()] {
}
#[cfg(test)]
mod business_rules {
use crate::total_by_category;
#[test]
fn sum_by_category() {
assert_eq!([()], total_by_category([]));
}
}
#[cfg(test)]
mod parse_csv {
use crate::process;
#[test]
fn read_in_one_line() {
let input= "1,2,3";
let strings= process(input);
assert_eq!("1", strings[0][0]);
assert_eq!("2", strings[0][1]);
assert_eq!("3", strings[0][2]);
}
#[test]
fn read_in_all_lines() {
let input= "1,2,3\n4,5,6";
let strings = process(input);
assert_eq!("1", strings[0][0]);
assert_eq!("2", strings[0][1]);
assert_eq!("3", strings[0][2]);
assert_eq!("4", strings[1][0]);
assert_eq!("5", strings[1][1]);
assert_eq!("6", strings[1][2]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment