@@ -193,41 +193,37 @@ class IntervalExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
193193 }
194194
195195 test(" multiply" ) {
196- def multiply (interval : String , num : Double ): Expression = {
197- MultiplyInterval (Literal (fromString(interval)), Literal (num))
196+ def check (interval : String , num : Double , expected : String ): Unit = {
197+ checkEvaluation(
198+ MultiplyInterval (Literal (fromString(interval)), Literal (num)),
199+ if (expected == null ) null else fromString(expected))
198200 }
199- checkEvaluation(multiply(" 0 seconds" , 10 ), fromString(" 0 seconds" ))
200- checkEvaluation(multiply(" 10 hours" , 0 ), fromString(" 0 hours" ))
201- checkEvaluation(multiply(" 12 months 1 microseconds" , 2 ), fromString(" 2 years 2 microseconds" ))
202- checkEvaluation(multiply(" -5 year 3 seconds" , 3 ), fromString(" -15 years 9 seconds" ))
203- checkEvaluation(multiply(" 1 year 1 second" , 0.5 ), fromString(" 6 months 500 milliseconds" ))
204- checkEvaluation(
205- multiply(" -100 years -1 millisecond" , 0.5 ),
206- fromString(" -50 years -500 microseconds" ))
207- checkEvaluation(multiply(" 2 months 4 seconds" , - 0.5 ), fromString(" -1 months -2 seconds" ))
208- checkEvaluation(
209- multiply(" 1 month 2 microseconds" , 1.5 ),
210- fromString(" 1 months 15 days 3 microseconds" ))
211- checkEvaluation(multiply(" 2 months" , Int .MaxValue ), null )
201+
202+ check(" 0 seconds" , 10 , " 0 seconds" )
203+ check(" 10 hours" , 0 , " 0 hours" )
204+ check(" 12 months 1 microseconds" , 2 , " 2 years 2 microseconds" )
205+ check(" -5 year 3 seconds" , 3 , " -15 years 9 seconds" )
206+ check(" 1 year 1 second" , 0.5 , " 6 months 500 milliseconds" )
207+ check(" -100 years -1 millisecond" , 0.5 , " -50 years -500 microseconds" )
208+ check(" 2 months 4 seconds" , - 0.5 , " -1 months -2 seconds" )
209+ check(" 1 month 2 microseconds" , 1.5 , " 1 months 15 days 3 microseconds" )
210+ check(" 2 months" , Int .MaxValue , null )
212211 }
213212
214213 test(" divide" ) {
215- def divide (interval : String , num : Double ): Expression = {
216- DivideInterval (Literal (fromString(interval)), Literal (num))
214+ def check (interval : String , num : Double , expected : String ): Unit = {
215+ checkEvaluation(
216+ DivideInterval (Literal (fromString(interval)), Literal (num)),
217+ if (expected == null ) null else fromString(expected))
217218 }
218219
219- checkEvaluation(divide(" 0 seconds" , 10 ), fromString(" 0 seconds" ))
220- checkEvaluation(
221- divide(" 12 months 3 milliseconds" , 2 ),
222- fromString(" 6 months 1 milliseconds 500 microseconds" ))
223- checkEvaluation(divide(" -5 year 3 seconds" , 3 ), fromString(" -1 years -8 months 1 seconds" ))
224- checkEvaluation(
225- divide(" 6 years -7 seconds" , 3 ),
226- fromString(" 2 years -2 seconds -333 milliseconds -333 microseconds" ))
227- checkEvaluation(divide(" 2 years -8 seconds" , 0.5 ), fromString(" 4 years -16 seconds" ))
228- checkEvaluation(divide(" -1 month 2 microseconds" , - 0.25 ),
229- fromString(" 4 months -8 microseconds" ))
230- checkEvaluation(divide(" 1 month 3 microsecond" , 1.5 ), fromString(" 20 days 2 microseconds" ))
231- checkEvaluation(divide(" 2 months" , 0 ), null )
220+ check(" 0 seconds" , 10 , " 0 seconds" )
221+ check(" 12 months 3 milliseconds" , 2 , " 6 months 0.0015 seconds" )
222+ check(" -5 year 3 seconds" , 3 , " -1 years -8 months 1 seconds" )
223+ check(" 6 years -7 seconds" , 3 , " 2 years -2.333333 seconds" )
224+ check(" 2 years -8 seconds" , 0.5 , " 4 years -16 seconds" )
225+ check(" -1 month 2 microseconds" , - 0.25 , " 4 months -8 microseconds" )
226+ check(" 1 month 3 microsecond" , 1.5 , " 20 days 2 microseconds" )
227+ check(" 2 months" , 0 , null )
232228 }
233229}
0 commit comments