1
+ // This file contains template helpers.
2
+ // Prefer `./helpers.rs` if you want to extract code from your solutions.
1
3
use std:: env;
2
4
use std:: fs;
3
5
6
+ pub mod helpers;
7
+
4
8
pub const ANSI_ITALIC : & str = "\x1b [3m" ;
5
9
pub const ANSI_BOLD : & str = "\x1b [1m" ;
6
10
pub const ANSI_RESET : & str = "\x1b [0m" ;
@@ -52,7 +56,7 @@ pub fn parse_exec_time(output: &str) -> f64 {
52
56
} else {
53
57
let timing = l. split ( "(elapsed: " ) . last ( ) . unwrap ( ) ;
54
58
// 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
56
60
if timing. contains ( "ns)" ) {
57
61
acc // range below rounding precision.
58
62
} else if timing. contains ( "µs)" ) {
@@ -68,23 +72,24 @@ pub fn parse_exec_time(output: &str) -> f64 {
68
72
} )
69
73
}
70
74
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
+
71
89
#[ cfg( test) ]
72
90
mod tests {
73
91
use super :: * ;
74
92
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
-
88
93
#[ test]
89
94
fn test_parse_exec_time ( ) {
90
95
assert_approx_eq ! (
0 commit comments