File tree Expand file tree Collapse file tree 4 files changed +44
-14
lines changed Expand file tree Collapse file tree 4 files changed +44
-14
lines changed Original file line number Diff line number Diff line change 1+ pub fn add ( left : u64 , right : u64 ) -> u64 {
2+ left + right
3+ }
Original file line number Diff line number Diff line change 1- pub fn add ( left : u64 , right : u64 ) -> u64 {
2- left + right
3- }
4-
5- #[ cfg( test) ]
6- mod tests {
7- use super :: * ;
8-
9- #[ test]
10- fn it_works ( ) {
11- let result = add ( 2 , 2 ) ;
12- assert_eq ! ( result, 4 ) ;
13- }
14- }
1+ pub mod add;
Original file line number Diff line number Diff line change 1+ [
2+ {
3+ "title" : " Example" ,
4+ "a" : 2 ,
5+ "b" : 2 ,
6+ "result" : 4
7+ }
8+ ]
Original file line number Diff line number Diff line change 1+ use exercises:: add:: add;
2+ use once_cell:: sync:: Lazy ;
3+ use serde:: Deserialize ;
4+
5+ mod common;
6+ use common:: utils:: load_json;
7+
8+ #[ derive( Debug , Deserialize ) ]
9+ struct AdderTestCase {
10+ title : String ,
11+ a : u64 ,
12+ b : u64 ,
13+ result : u64
14+ }
15+
16+ static TEST_DATA : Lazy < Vec < AdderTestCase > > =
17+ Lazy :: new ( || load_json ( "tests/add.json" ) ) ;
18+
19+ #[ cfg( test) ]
20+ mod tests {
21+ use super :: * ;
22+
23+ #[ test]
24+ fn test_adder ( ) {
25+ for test_case in TEST_DATA . iter ( ) {
26+ println ! ( "Probando AdderTestCase : {:?}" , test_case. title) ;
27+
28+ let result = add ( test_case. a , test_case. b ) ;
29+ assert_eq ! ( result, test_case. result) ;
30+ }
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments