/* # Easy Average Grade Calculator This tool is a easy average grade average calulcator written in Rust. It takes a list of graded to calculated the average and can be used as a library by other applications. See a more complex [grade calulcator](https://www.thebestdegree.com/grade-calculator/) for weighted grade calculation for college or high school students and teachers. These tools are all implemented in Rust. ## Usage ## The easy grade calulcator can either read the input grades from arguments or a text file as shown below: ```bash grade-avg 3.5 2.5 ``` Another way to use the tool would be to create a txt file as the input grades. Create a input file `grades.txt` with the contents: ``` 1.5 3.5 2.5 ``` The average for these grades can be calculcated as below: ```bash cat ~/grades.txt | grade-avg ``` */ use grades::Grade; #[test] fn test_parse_working() { if let Ok(grade) = Grade::from("1.3") { assert_eq!("1.3", format!("{}", grade)); } } #[test] fn test_parse_comma() { if let Ok(grade) = Grade::from("1,3") { assert_eq!("1.3", format!("{}", grade)); } else { panic!("Failed to parse") } } #[test] fn test_parse_out_of_bounds() { match Grade::from("6.0") { Ok(_) => assert!(false, "Should be out of bounds"), Err(_) => assert!(true), } } #[test] fn test_avg_single() { let grade = new_grade("1.3"); let grade_list = [grade]; assert_eq!(Some(grade), grades::avg(&grade_list)); } #[test] fn test_avg_none() { assert_eq!(None, grades::avg(&[])); } #[test] fn test_avg_two() { let expected = new_grade("1.5"); assert_eq!( Some(expected), grades::avg(&[new_grade("1.0"), new_grade("2.0")]) ); } #[test] fn test_print_correct_grade() { assert_eq!("Grade A", new_grade("1.0").verbal()); assert_eq!("Grade A", new_grade("1.5").verbal()); assert_ne!("Grade A", new_grade("1.6").verbal()); } fn new_grade(input: &str) -> Grade { Grade::from(input).unwrap() }