@@ -18,7 +18,7 @@ impl Merger {
1818
1919 /// Merge a single timeline
2020 pub fn merge_timeline ( & mut self , timeline : & Timeline ) -> Result < ( ) > {
21- /// TODO: make sure that all days are filled with 0 between start and end
21+ // TODO: make sure that all days are filled with 0 between start and end
2222 for contribution in & timeline. contributions {
2323 let date = contribution. date . clone ( ) ;
2424 let date = git:: parse_date ( & date) ?;
@@ -48,7 +48,6 @@ impl Merger {
4848 }
4949}
5050
51-
5251#[ cfg( test) ]
5352mod test {
5453 use super :: * ;
@@ -116,12 +115,21 @@ mod test {
116115 end : "2020-01-03" . into ( ) ,
117116 } ;
118117
119- let year2 = Year { year : "2020" . into ( ) , total : 0 , range : range2 } ;
120- let year1 = Year { year : "2020" . into ( ) , total : 123 , range : range1 } ;
118+ let year1 = Year {
119+ year : "2020" . into ( ) ,
120+ total : 1234 ,
121+ range : range1,
122+ } ;
121123 timeline1. years = vec ! [ year1] ;
124+
125+ let year2 = Year {
126+ year : "2020" . into ( ) ,
127+ total : 6 ,
128+ range : range2,
129+ } ;
122130 timeline2. years = vec ! [ year2] ;
123131
124- let contributions = vec ! [
132+ let contributions1 = vec ! [
125133 Contribution {
126134 date: "2020-01-01" . into( ) ,
127135 count: 1000 ,
@@ -136,16 +144,39 @@ mod test {
136144 } ,
137145 ] ;
138146
139- timeline1. contributions = contributions. clone ( ) ;
140- timeline2. contributions = contributions. clone ( ) ;
147+ let contributions2 = vec ! [
148+ Contribution {
149+ date: "2020-01-01" . into( ) ,
150+ count: 0 ,
151+ color: "" . into( ) ,
152+ intensity: 0 ,
153+ } ,
154+ Contribution {
155+ date: "2020-01-02" . into( ) ,
156+ count: 5 ,
157+ color: "" . into( ) ,
158+ intensity: 4 ,
159+ } ,
160+ Contribution {
161+ date: "2020-01-03" . into( ) ,
162+ count: 1 ,
163+ color: "" . into( ) ,
164+ intensity: 1 ,
165+ } ,
166+ ] ;
167+
168+ timeline1. contributions = contributions1. clone ( ) ;
169+ timeline2. contributions = contributions2. clone ( ) ;
141170
142171 let mut merger = Merger :: new ( ) ;
143- let merged = merger. merge ( & [ timeline1. clone ( ) , timeline2. clone ( ) ] ) . unwrap ( ) ;
172+ let merged = merger
173+ . merge ( & [ timeline1. clone ( ) , timeline2. clone ( ) ] )
174+ . unwrap ( ) ;
144175 assert_eq ! ( merged. years. len( ) , 1 ) ;
145176 let year = & merged. years [ 0 ] ;
146177 assert_eq ! ( year. year, "2020" ) ;
147- assert_eq ! ( year. total, 2468 ) ;
178+ assert_eq ! ( year. total, 1240 ) ;
148179 assert_eq ! ( year. range. start, "2020-01-01" ) ;
149180 assert_eq ! ( year. range. end, "2020-01-03" ) ;
150- }
181+ }
151182}
0 commit comments