1+ // This file contains template helpers.
2+ // Prefer `./helpers.rs` if you want to extract code from your solutions.
13use std:: env;
24use std:: fs;
35
6+ pub mod helpers;
7+
48pub const ANSI_ITALIC : & str = "\x1b [3m" ;
59pub const ANSI_BOLD : & str = "\x1b [1m" ;
610pub const ANSI_RESET : & str = "\x1b [0m" ;
@@ -52,7 +56,7 @@ pub fn parse_exec_time(output: &str) -> f64 {
5256 } else {
5357 let timing = l. split ( "(elapsed: " ) . last ( ) . unwrap ( ) ;
5458 // use `contains` istd. of `ends_with`: string may contain ANSI escape sequences.
55- // possible time formats: see [rust/library/core/src/time.rs]( https://github.com/rust-lang/rust/blob/1.57 .0/library/core/src/time.rs#L1225-L1249).
59+ // for possible time formats, see: https://github.com/rust-lang/rust/blob/1.64 .0/library/core/src/time.rs#L1176-L1200
5660 if timing. contains ( "ns)" ) {
5761 acc // range below rounding precision.
5862 } else if timing. contains ( "µs)" ) {
@@ -68,23 +72,24 @@ pub fn parse_exec_time(output: &str) -> f64 {
6872 } )
6973}
7074
75+ /// copied from: https://github.com/rust-lang/rust/blob/1.64.0/library/std/src/macros.rs#L328-L333
76+ #[ cfg( test) ]
77+ macro_rules! assert_approx_eq {
78+ ( $a: expr, $b: expr) => { {
79+ let ( a, b) = ( & $a, & $b) ;
80+ assert!(
81+ ( * a - * b) . abs( ) < 1.0e-6 ,
82+ "{} is not approximately equal to {}" ,
83+ * a,
84+ * b
85+ ) ;
86+ } } ;
87+ }
88+
7189#[ cfg( test) ]
7290mod tests {
7391 use super :: * ;
7492
75- /// copied from: [rust/library/std/src/macros.rs](https://github.com/rust-lang/rust/blob/1.57.0/library/std/src/macros.rs#L311-L316)
76- macro_rules! assert_approx_eq {
77- ( $a: expr, $b: expr) => { {
78- let ( a, b) = ( & $a, & $b) ;
79- assert!(
80- ( * a - * b) . abs( ) < 1.0e-6 ,
81- "{} is not approximately equal to {}" ,
82- * a,
83- * b
84- ) ;
85- } } ;
86- }
87-
8893 #[ test]
8994 fn test_parse_exec_time ( ) {
9095 assert_approx_eq ! (
0 commit comments