//!
//! SPDX-License-Identifier: GPL-3.0-or-later
-// use std::env; // Replaced by clap::Parser stuff
use std::io; // bring flush() into scope with `use std::io::Write`
use std::io::prelude::*; // Bring `std::io::BufRead` in scope
-use statrs::distribution::{Exp, LogNormal, ContinuousCDF}; // Continuous needed for pdf
-// use statrs::statistics::Distribution;
-// use statrs::prec;
+// Statrs, `don't use statrs::prec` and
+// `statrs::statistics::Distribution` from examples
+use statrs::distribution::{
+ Exp, LogNormal, ContinuousCDF}; // Continuous needed for pdf
+
+// CLI Parser, replaces need for use `std::env`
use clap::Parser;
const DEBUG: bool = false;
+fn winnow(list: &mut Vec<String>) {
+ for l in &mut *list {
+ *l = l.trim().to_owned();
+ }
+ list.retain(|x| x != ""); // only keep nonempty
+ // Search bullets
+}
fn input() -> Vec<String> {
- // Consider datastructure some list of strings
let stdin = io::stdin();
- let v = stdin.lock().lines().map(|x| x.unwrap()).collect();
- v
+ let mut list: Vec<String> =
+ stdin.lock().lines()
+ .map(|x| x.unwrap())
+ .collect();
+ winnow(&mut list);
+ list
}
fn output(prio: &Vec<f64>, ranked: &Vec<String>) {
output(&prio, &ranked);
}
+
+#[test]
+
+fn ordinary_input() {
+
+ let mut arg: Vec<String> = Vec::new();
+ let mut res: 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));
+ }
+ winnow(&mut arg);
+ assert_eq!(arg, res);
+}
+
+#[test]
+
+fn whitespace() {
+
+ let mut 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> =
+ "Hej du\nglade\nta en"
+ .split("\n").map(|x| x.to_owned()).collect();
+ winnow(&mut arg);
+ assert_eq!(arg, res);
+
+}