Why doesn’t println! work in Rust unit tests?

I’ve implemented the following method and unit test: use std::fs::File; use std::path::Path; use std::io::prelude::*; fn read_file(path: &Path) { let mut file = File::open(path).unwrap(); let mut contents = String::new(); file.read_to_string(&mut contents).unwrap(); println!(“{}”, contents); } #[test] fn test_read_file() { let path = &Path::new(“/etc/hosts”); println!(“{:?}”, path); read_file(path); } I run the unit test this way: rustc –test app.rs; … Read more

Division of integers in Java

Converting the output is too late; the calculation has already taken place in integer arithmetic. You need to convert the inputs to double: System.out.println((double)completed/(double)total); Note that you don’t actually need to convert both of the inputs. So long as one of them is double, the other will be implicitly converted. But I prefer to do both, for symmetry.