1- using System ;
2- using System . Collections . Generic ;
31using System . Linq ;
42using Xunit ;
53
64public class AccumulateTests
75{
86 [ Fact ]
9- public void Empty_accumulation_produces_empty_accumulation ( )
7+ public void Accumulate_empty ( )
108 {
11- Assert . Equal ( new int [ 0 ] , new int [ 0 ] . Accumulate ( x => x * x ) ) ;
9+ int [ ] input = [ ] ;
10+ int [ ] expected = [ ] ;
11+ Assert . Equal ( expected , input . Accumulate ( ( x ) => x * x ) ) ;
1212 }
1313
1414 [ Fact ( Skip = "Remove this Skip property to run this test" ) ]
1515 public void Accumulate_squares ( )
1616 {
17- Assert . Equal ( new [ ] { 1 , 4 , 9 } , new [ ] { 1 , 2 , 3 } . Accumulate ( x => x * x ) ) ;
17+ int [ ] input = [ 1 , 2 , 3 ] ;
18+ int [ ] expected = [ 1 , 4 , 9 ] ;
19+ Assert . Equal ( expected , input . Accumulate ( ( x ) => x * x ) ) ;
1820 }
1921
2022 [ Fact ( Skip = "Remove this Skip property to run this test" ) ]
2123 public void Accumulate_upcases ( )
2224 {
23- Assert . Equal ( new List < string > { "HELLO" , "WORLD" } , new List < string > { "hello" , "world" } . Accumulate ( x => x . ToUpper ( ) ) ) ;
25+ string [ ] input = [ "Hello" , "world" ] ;
26+ string [ ] expected = [ "HELLO" , "WORLD" ] ;
27+ Assert . Equal ( expected , input . Accumulate ( ( x ) => x . ToUpper ( ) ) ) ;
2428 }
2529
2630 [ Fact ( Skip = "Remove this Skip property to run this test" ) ]
2731 public void Accumulate_reversed_strings ( )
2832 {
29- Assert . Equal ( "eht kciuq nworb xof cte" . Split ( ' ' ) , "the quick brown fox etc" . Split ( ' ' ) . Accumulate ( Reverse ) ) ;
30- }
31-
32- private static string Reverse ( string value )
33- {
34- var array = value . ToCharArray ( ) ;
35- Array . Reverse ( array ) ;
36- return new string ( array ) ;
33+ string [ ] input = [ "the" , "quick" , "brown" , "fox" , "etc" ] ;
34+ string [ ] expected = [ "eht" , "kciuq" , "nworb" , "xof" , "cte" ] ;
35+ Assert . Equal ( expected , input . Accumulate ( ( x ) => new string ( x . Reverse ( ) . ToArray ( ) ) ) ) ;
3736 }
3837
3938 [ Fact ( Skip = "Remove this Skip property to run this test" ) ]
40- public void Accumulate_within_accumulate ( )
39+ public void Accumulate_recursively ( )
4140 {
42- var actual = new [ ] { "a" , "b" , "c" } . Accumulate ( c =>
43- string . Join ( " " , new [ ] { "1" , "2 ", "3" } . Accumulate ( d => c + d ) ) ) ;
44- Assert . Equal ( new [ ] { "a1 a2 a3 " , "b1 b2 b3 " , "c1 c2 c3 " } , actual ) ;
41+ string [ ] input = [ "a" , "b" , "c" ] ;
42+ string [ ] [ ] expected = [ [ "a1" , "a2" , "a3" ] , [ "b1" , "b2" , "b3" ] , [ "c1 ", "c2" , "c3" ] ] ;
43+ Assert . Equal ( expected , input . Accumulate ( ( x ) => new [ ] { "1 " , "2 " , "3 " } . Accumulate ( ( y ) => x + y ) ) ) ;
4544 }
4645
4746 [ Fact ( Skip = "Remove this Skip property to run this test" ) ]
4847 public void Accumulate_is_lazy ( )
4948 {
5049 var counter = 0 ;
51- var accumulation = new [ ] { 1 , 2 , 3 } . Accumulate ( x => x * counter ++ ) ;
52-
50+ int [ ] input = [ 1 , 2 , 3 ] ;
51+ var accumulation = input . Accumulate ( x => x * counter ++ ) ;
5352 Assert . Equal ( 0 , counter ) ;
54- accumulation . ToList ( ) ;
53+ var _ = accumulation . ToList ( ) ;
5554 Assert . Equal ( 3 , counter ) ;
5655 }
57-
58- [ Fact ( Skip = "Remove this Skip property to run this test" ) ]
59- public void Accumulate_allows_different_return_type ( )
60- {
61- Assert . Equal ( new [ ] { "1" , "2" , "3" } , new [ ] { 1 , 2 , 3 } . Accumulate ( x => x . ToString ( ) ) ) ;
62- }
63- }
56+ }
0 commit comments