use statrs::distribution::{
Exp, LogNormal, ContinuousCDF}; // Continuous needed for pdf
-// CLI Parser, replaces need for use `std::env`
-use clap::Parser;
+use clap::Parser; // CLI Parser, replaces need for use `std::env`
+use regex::Regex;
const DEBUG: bool = false;
-fn winnow(list: &mut Vec<String>) {
+
+fn winnow(mut list: Vec<String>) -> (Conf, Vec<String> ) {
+ list.retain(|x| x != ""); // only keep nonempty
+
+ let conf = Conf {
+ };
+
+ // Remove patterns and trim
for l in &mut *list {
*l = l.trim().to_owned();
}
- list.retain(|x| x != ""); // only keep nonempty
- // Search bullets
+ list.retain(|x| x != ""); // again
+ return (conf, list)
}
-fn input() -> Vec<String> {
+fn input() -> (Conf, Vec<String>) {
let stdin = io::stdin();
- let mut list: Vec<String> =
+ let list: Vec<String> =
stdin.lock().lines()
.map(|x| x.unwrap())
.collect();
- winnow(&mut list);
- list
+ return winnow(list)
}
-fn output(prio: &Vec<f64>, ranked: &Vec<String>) {
+fn output(conf: &Conf, prio: &Vec<f64>, ranked: &Vec<String>) {
for (p, l) in prio.iter().zip(ranked.iter()) {
println!("{:2.0} %\t{}", p * 100.0, l);
}
normalize(prio)
}
+struct Conf {
+}
+
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
if DEBUG { eprintln!("Finally a skewness: {}", skew) }
- let ranked: Vec<String> = input();
+ let (conf, ranked) = input();
let num = ranked.len() as i32;
let prio = if args.distribution == String::from("delta") {
eprintln!("\x08\x08.");
}
- output(&prio, &ranked);
+ output(&conf, &prio, &ranked);
}
fn ordinary_input() {
let mut arg: Vec<String> = Vec::new();
- let mut res: Vec<String> = Vec::new();
+ let mut exp: Vec<String> = Vec::new();
for s in vec!["", "", "Hej ☕ glade", "", "Amatör", "", ""] {
arg.push(String::from(s));
}
for s in vec!["Hej ☕ glade", "Amatör"] {
- res.push(String::from(s));
+ exp.push(String::from(s));
}
- winnow(&mut arg);
- assert_eq!(arg, res);
+ let (_, res) = winnow(arg);
+ assert_eq!(exp, res);
}
#[test]
fn whitespace() {
- let mut arg: Vec<String> =
+ let arg: Vec<String> =
"\n\nHej du\t\n glade\nta en\n\n" // Convert &str to String
.split("\n").map(|x| x.to_owned()) // with `.to_owned()` or
.collect(); // `.to_string()`
- let res: Vec<String> =
+ let exp: Vec<String> =
"Hej du\nglade\nta en"
.split("\n").map(|x| x.to_owned()).collect();
- winnow(&mut arg);
- assert_eq!(arg, res);
+ let (_, res) = winnow(arg);
+ assert_eq!(exp, res);
}